From: Jérémie Astor Date: Mon, 13 Apr 2020 16:38:00 +0000 (+0200) Subject: :bug: Fix empty vararg X-Git-Tag: nightly~1706 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=6c69d08f31f53d5ce0fbb6b1430804f12fd91a04;p=gwion.git :bug: Fix empty vararg --- diff --git a/src/emit/emit.c b/src/emit/emit.c index 1faf6cbb..6a66eab4 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -1352,6 +1352,11 @@ ANN static m_bool emit_stmt_flow(const Emitter emit, const Stmt_Flow stmt) { return GW_OK; } +ANN static Instr variadic_state0(const Emitter emit, const Stmt_VarLoop stmt) { + CHECK_BO(emit_exp(emit, stmt->exp)) + return emit_add_instr(emit, BranchEqInt); +} + ANN static m_bool variadic_state(const Emitter emit, const Stmt_VarLoop stmt, const m_uint status) { regpushi(emit, status); CHECK_BB(emit_exp(emit, stmt->exp)) @@ -1364,6 +1369,7 @@ ANN static m_bool variadic_state(const Emitter emit, const Stmt_VarLoop stmt, co } ANN static m_bool emit_stmt_varloop(const Emitter emit, const Stmt_VarLoop stmt) { + DECL_OB(const Instr,state, = variadic_state0(emit, stmt)) CHECK_BB(variadic_state(emit, stmt, 1)) CHECK_BB(emit_exp(emit, stmt->exp)) const Instr instr = emit_add_instr(emit, BranchEqInt); @@ -1373,6 +1379,7 @@ ANN static m_bool emit_stmt_varloop(const Emitter emit, const Stmt_VarLoop stmt) emit_vararg_end(emit, pc); instr->m_val = emit_code_size(emit); CHECK_BB(variadic_state(emit, stmt, 0)) + state->m_val = instr->m_val = emit_code_size(emit); return GW_OK; } diff --git a/src/lib/vararg.c b/src/lib/vararg.c index 25fbb5fa..b5128c27 100644 --- a/src/lib/vararg.c +++ b/src/lib/vararg.c @@ -25,8 +25,7 @@ static DTOR(vararg_dtor) { struct Vararg_ *arg = *(struct Vararg_**)o->data; m_uint offset = 0; for(m_uint i = 0; i < vector_size(&arg->t); ++i) { - const Type t = (Type)vector_at(&arg->t, arg->i); - *(m_uint*)(arg->d + offset) = *(m_uint*)(shred->reg - SZ_INT + offset); + const Type t = (Type)vector_at(&arg->t, i); if(isa(t, shred->info->vm->gwion->type[et_object]) > 0) release(*(M_Object*)(arg->d + offset), shred); offset += t->size; diff --git a/tests/tree/empty_vararg.gw b/tests/tree/empty_vararg.gw index bc944a4d..87b9cb84 100644 --- a/tests/tree/empty_vararg.gw +++ b/tests/tree/empty_vararg.gw @@ -1,8 +1,8 @@ fun int test(...){ - vararg.start; - <<< "test" >>>; - <<< vararg $ int >>>; - vararg.end; + varloop vararg { + <<< "test" >>>; + <<< vararg $ int >>>; + } return 1; } <<< test() >>>;