From e63482fab637e00f4de4bee6554c96e8b58f2192 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Fri, 3 Apr 2020 16:34:47 +0200 Subject: [PATCH] :art: Fix auto statement --- src/emit/emit.c | 9 +++++---- tests/tree/auto_ptr.gw | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index d4d93cfb..87b0d2d0 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1409,14 +1409,13 @@ ANN static m_bool emit_stmt_auto(const Emitter emit, const Stmt_Auto stmt) { const Instr s1 = emit_add_instr(emit, MemSetImm); emit_push_stack(emit); Instr cpy = stmt->is_ptr ? emit_stmt_autoptr_init(emit, stmt->v->type) : NULL; + emit_local(emit, emit->gwion->type[et_int]); + const m_uint offset = emit_local(emit, emit->gwion->type[et_int]); + stmt->v->from->offset = offset + SZ_INT; const m_uint ini_pc = emit_code_size(emit); emit_except(emit, stmt->exp->info->type); const Instr loop = emit_add_instr(emit, stmt->is_ptr ? AutoLoopPtr : AutoLoop); const Instr end = emit_add_instr(emit, BranchEqInt); -// (void)emit_addref(emit, 0); - emit_local(emit, stmt->exp->info->type); - const m_uint offset = emit_local(emit, emit->gwion->type[et_int]); - stmt->v->from->offset = offset + SZ_INT; CHECK_BB(emit_stmt(emit, stmt->body, 1)) const m_uint end_pc = emit_code_size(emit); if(stmt->is_ptr) { @@ -1427,6 +1426,8 @@ ANN static m_bool emit_stmt_auto(const Emitter emit, const Stmt_Auto stmt) { end->m_val = emit_code_size(emit); tgt->m_val = ini_pc; s1->m_val = loop->m_val = offset; + if(stmt->is_ptr) + emit_add_instr(emit, ObjectRelease); regpop(emit, SZ_INT); emit_pop_stack(emit, end_pc); return GW_OK; diff --git a/tests/tree/auto_ptr.gw b/tests/tree/auto_ptr.gw index 54adfa59..10af68c8 100644 --- a/tests/tree/auto_ptr.gw +++ b/tests/tree/auto_ptr.gw @@ -1,5 +1,5 @@ <~int~>Ptr ptr; int i[4]; -for(auto@ a : i) +for(auto ref a : i) <<< *a >>>; <<< ptr >>>; -- 2.43.0