aboutsummaryrefslogtreecommitdiff
path: root/src/compile/assignments.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-31 23:33:22 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-31 23:33:22 -0400
commit5fc7577b5a3bc2c445522dfd5b287e1c6eddc3e9 (patch)
tree34d44c9330dc3ec71fc850b95b3412a1ce292cb8 /src/compile/assignments.c
parenta571ccffd795a595e990a3405dcf977aafc33c6c (diff)
Switch to using optional return values for list indexing.
Diffstat (limited to 'src/compile/assignments.c')
-rw-r--r--src/compile/assignments.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/compile/assignments.c b/src/compile/assignments.c
index ab28b972..5fedad9a 100644
--- a/src/compile/assignments.c
+++ b/src/compile/assignments.c
@@ -92,7 +92,8 @@ Text_t compile_assignment_statement(env_t *env, ast_t *ast) {
if (assign->targets && !assign->targets->next) {
type_t *lhs_t = get_type(env, assign->targets->ast);
if (assign->targets->ast->tag == Index && lhs_t->tag == OptionalType
- && value_type(get_type(env, Match(assign->targets->ast, Index)->indexed))->tag == TableType)
+ && (value_type(get_type(env, Match(assign->targets->ast, Index)->indexed))->tag == TableType
+ || value_type(get_type(env, Match(assign->targets->ast, Index)->indexed))->tag == ListType))
lhs_t = Match(lhs_t, OptionalType)->type;
if (has_stack_memory(lhs_t))
code_err(ast, "Stack references cannot be assigned to "
@@ -110,7 +111,8 @@ Text_t compile_assignment_statement(env_t *env, ast_t *ast) {
value = value->next, target = target->next) {
type_t *lhs_t = get_type(env, target->ast);
if (target->ast->tag == Index && lhs_t->tag == OptionalType
- && value_type(get_type(env, Match(target->ast, Index)->indexed))->tag == TableType)
+ && (value_type(get_type(env, Match(target->ast, Index)->indexed))->tag == TableType
+ || value_type(get_type(env, Match(target->ast, Index)->indexed))->tag == ListType))
lhs_t = Match(lhs_t, OptionalType)->type;
if (has_stack_memory(lhs_t))
code_err(ast, "Stack references cannot be assigned to "
@@ -166,14 +168,9 @@ Text_t compile_lvalue(env_t *env, ast_t *ast) {
? compile_int_to_type(env, index->index, Type(IntType, .bits = TYPE_IBITS64))
: (index_t->tag == BigIntType ? Texts("Int64$from_int(", compile(env, index->index), ", no)")
: Texts("(Int64_t)(", compile(env, index->index), ")"));
- if (index->unchecked) {
- return Texts("List_lvalue_unchecked(", compile_type(item_type), ", ", target_code, ", ", index_code,
- ")");
- } else {
- return Texts("List_lvalue(", compile_type(item_type), ", ", target_code, ", ", index_code, ", ",
- String((int)(ast->start - ast->file->text)), ", ",
- String((int)(ast->end - ast->file->text)), ")");
- }
+ return Texts("List_lvalue(", compile_type(item_type), ", ", target_code, ", ", index_code, ", ",
+ String((int)(ast->start - ast->file->text)), ", ", String((int)(ast->end - ast->file->text)),
+ ")");
} else if (container_t->tag == TableType) {
DeclareMatch(table_type, container_t, TableType);
if (table_type->default_value) {
@@ -184,7 +181,6 @@ Text_t compile_lvalue(env_t *env, ast_t *ast) {
compile_to_type(env, table_type->default_value, table_type->value_type), ", ",
compile_type_info(container_t), ")");
}
- if (index->unchecked) code_err(ast, "Table indexes cannot be unchecked");
return Texts("*(", compile_type(Type(PointerType, table_type->value_type)), ")Table$reserve(",
compile_to_pointer_depth(env, index->indexed, 1, false), ", ",
compile_to_type(env, index->index, Type(PointerType, table_type->key_type, .is_stack = true)),