From ddb20d2f911c39b2e7094921ed82adba36b8a75a Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sun, 25 Jun 2023 18:39:16 +0800 Subject: [PATCH] fix a bug --- src/expr.h | 2 ++ src/frame.h | 5 +++++ src/linalg.h | 2 +- tests/99_bugs.py | 8 +++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/expr.h b/src/expr.h index 3c8970c4..6782437c 100644 --- a/src/expr.h +++ b/src/expr.h @@ -65,6 +65,8 @@ struct CodeEmitContext{ co->blocks[curr_block_i].end = co->codes.size(); curr_block_i = co->blocks[curr_block_i].parent; if(curr_block_i < 0) FATAL_ERROR(); + // add a no op here to make block check work + emit(OP_NO_OP, BC_NOARG, BC_KEEPLINE); } // clear the expression stack and generate bytecode diff --git a/src/frame.h b/src/frame.h index 8afd6cdf..42cde59c 100644 --- a/src/frame.h +++ b/src/frame.h @@ -182,6 +182,11 @@ struct Frame { if(_next_ip >= co->codes.size()){ while(i>=0) i = _exit_block(i); }else{ + // BUG!!! + // for i in range(4): + // _ = 0 + // # if there is no op here, the block check will fail + // while i: --i const Bytecode& next = co->codes[target]; while(i>=0 && i!=next.block) i = _exit_block(i); if(i!=next.block) throw std::runtime_error("invalid jump"); diff --git a/src/linalg.h b/src/linalg.h index 31a22fb1..1fe414c5 100644 --- a/src/linalg.h +++ b/src/linalg.h @@ -585,7 +585,7 @@ struct PyMat3x3: Mat3x3{ PyVec3& other = _CAST(PyVec3&, args[1]); return VAR_T(PyVec3, self.matmul(other)); } - vm->TypeError("unsupported operand type(s) for @"); + vm->BinaryOptError("@"); return vm->None; }; diff --git a/tests/99_bugs.py b/tests/99_bugs.py index f9934ba2..46f83156 100644 --- a/tests/99_bugs.py +++ b/tests/99_bugs.py @@ -47,4 +47,10 @@ assert ( assert f(( g(1), 2 -)) == (1, 2) \ No newline at end of file +)) == (1, 2) + +def f(): + for i in range(4): + _ = 0 + while i: --i +f() \ No newline at end of file