From 222fbcd0027f085c48e93c6e70445699eec79d96 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 24 Aug 2025 18:09:45 -0400 Subject: Move assignment code. --- src/compile/statements.c | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) (limited to 'src/compile/statements.c') diff --git a/src/compile/statements.c b/src/compile/statements.c index da6ad465..642b900d 100644 --- a/src/compile/statements.c +++ b/src/compile/statements.c @@ -354,49 +354,7 @@ static Text_t _compile_statement(env_t *env, ast_t *ast) { return Texts(compile_declaration(t, Texts("_$", name)), " = ", val_code, ";"); } } - case Assign: { - DeclareMatch(assign, ast, Assign); - // Single assignment, no temp vars needed: - 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) - lhs_t = Match(lhs_t, OptionalType)->type; - if (has_stack_memory(lhs_t)) - code_err(ast, "Stack references cannot be assigned to " - "variables because the " - "variable's scope may outlive the scope of the " - "stack memory."); - env_t *val_env = with_enum_scope(env, lhs_t); - Text_t val = compile_to_type(val_env, assign->values->ast, lhs_t); - return Texts(compile_assignment(env, assign->targets->ast, val), ";\n"); - } - - Text_t code = Text("{ // Assignment\n"); - int64_t i = 1; - for (ast_list_t *value = assign->values, *target = assign->targets; value && target; - 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) - lhs_t = Match(lhs_t, OptionalType)->type; - if (has_stack_memory(lhs_t)) - code_err(ast, "Stack references cannot be assigned to " - "variables because the " - "variable's scope may outlive the scope of the " - "stack memory."); - env_t *val_env = with_enum_scope(env, lhs_t); - Text_t val = compile_to_type(val_env, value->ast, lhs_t); - code = Texts(code, compile_type(lhs_t), " $", String(i), " = ", val, ";\n"); - i += 1; - } - i = 1; - for (ast_list_t *target = assign->targets; target; target = target->next) { - code = Texts(code, compile_assignment(env, target->ast, Texts("$", String(i))), ";\n"); - i += 1; - } - return Texts(code, "\n}"); - } + case Assign: return compile_assignment_statement(env, ast); case PlusUpdate: { DeclareMatch(update, ast, PlusUpdate); type_t *lhs_t = get_type(env, update->lhs); -- cgit v1.2.3