fix a bug

This commit is contained in:
blueloveTH 2023-06-25 18:39:16 +08:00
parent 718edd9b9d
commit ddb20d2f91
4 changed files with 15 additions and 2 deletions

View File

@ -65,6 +65,8 @@ struct CodeEmitContext{
co->blocks[curr_block_i].end = co->codes.size(); co->blocks[curr_block_i].end = co->codes.size();
curr_block_i = co->blocks[curr_block_i].parent; curr_block_i = co->blocks[curr_block_i].parent;
if(curr_block_i < 0) FATAL_ERROR(); 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 // clear the expression stack and generate bytecode

View File

@ -182,6 +182,11 @@ struct Frame {
if(_next_ip >= co->codes.size()){ if(_next_ip >= co->codes.size()){
while(i>=0) i = _exit_block(i); while(i>=0) i = _exit_block(i);
}else{ }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]; const Bytecode& next = co->codes[target];
while(i>=0 && i!=next.block) i = _exit_block(i); while(i>=0 && i!=next.block) i = _exit_block(i);
if(i!=next.block) throw std::runtime_error("invalid jump"); if(i!=next.block) throw std::runtime_error("invalid jump");

View File

@ -585,7 +585,7 @@ struct PyMat3x3: Mat3x3{
PyVec3& other = _CAST(PyVec3&, args[1]); PyVec3& other = _CAST(PyVec3&, args[1]);
return VAR_T(PyVec3, self.matmul(other)); return VAR_T(PyVec3, self.matmul(other));
} }
vm->TypeError("unsupported operand type(s) for @"); vm->BinaryOptError("@");
return vm->None; return vm->None;
}; };

View File

@ -48,3 +48,9 @@ assert f((
g(1), g(1),
2 2
)) == (1, 2) )) == (1, 2)
def f():
for i in range(4):
_ = 0
while i: --i
f()