From 96f2a16bead81cd565d987f23e3b2071fa10c245 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Tue, 1 Jun 2021 23:38:29 +0200 Subject: [PATCH] :bug: Fix repeat loop with idx --- src/emit/emit.c | 3 +++ src/vm/vm.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/emit/emit.c b/src/emit/emit.c index d836595a..8199a6e6 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -2004,6 +2004,9 @@ ANN static m_bool _emit_stmt_loop(const Emitter emit, const Stmt_Loop stmt, const Instr instr = emit_add_instr(emit, MemSetImm); instr->m_val = emit_local(emit, emit->gwion->type[et_int]); stmt->idx->v->from->offset = offset; + const Instr idx = emit_add_instr(emit, MemSetImm); + idx->m_val = offset; + idx->m_val2 = -1; } CHECK_BB(emit_exp_pop_next(emit, stmt->cond)); regpop(emit, SZ_INT); diff --git a/src/vm/vm.c b/src/vm/vm.c index fe2c110d..ba830d1f 100644 --- a/src/vm/vm.c +++ b/src/vm/vm.c @@ -534,7 +534,7 @@ memaddimm: // (*(m_int*)(mem+VAL))--; DISPATCH(); repeatidx: - BRANCH_DISPATCH(*(m_int*)(mem+VAL2+SZ_INT) == (*(m_int*)(mem+VAL2))++); + BRANCH_DISPATCH(*(m_int*)(mem+VAL2+SZ_INT) == ++(*(m_int*)(mem+VAL2))); repeat: BRANCH_DISPATCH(!(*(m_uint*)(mem+VAL2))--); regpushme: -- 2.43.0