fix a bug

This commit is contained in:
BLUELOVETH 2023-06-02 15:02:06 +08:00
parent 1614502741
commit 932c034673
4 changed files with 14 additions and 3 deletions

View File

@ -786,7 +786,7 @@ __SUBSCR_END:
if(match(TK("(")) && !match(TK(")"))){ if(match(TK("(")) && !match(TK(")"))){
EXPR(false); consume(TK(")")); EXPR(false); consume(TK(")"));
}else{ }else{
ctx()->emit(OP_LOAD_NONE, BC_NOARG, BC_KEEPLINE); ctx()->emit(OP_LOAD_NONE, BC_NOARG, kw_line);
} }
ctx()->emit(OP_RAISE, dummy_t, kw_line); ctx()->emit(OP_RAISE, dummy_t, kw_line);
consume_end_stmt(); consume_end_stmt();

View File

@ -166,7 +166,7 @@ struct Frame {
// get the stack size of the try block (depth of for loops) // get the stack size of the try block (depth of for loops)
int _stack_size = co->blocks[block].for_loop_depth; int _stack_size = co->blocks[block].for_loop_depth;
if(stack_size() < _stack_size) throw std::runtime_error("invalid stack size"); if(stack_size() < _stack_size) throw std::runtime_error("invalid stack size");
_s->reset(actual_sp_base() + _stack_size); // rollback the stack _s->reset(actual_sp_base() + _locals.size() + _stack_size); // rollback the stack
_s->push(obj); // push exception object _s->push(obj); // push exception object
_next_ip = co->blocks[block].end; _next_ip = co->blocks[block].end;
return true; return true;

View File

@ -983,7 +983,7 @@ inline std::string _opcode_argstr(VM* vm, Bytecode byte, const CodeObject* co){
break; break;
case OP_LOAD_NAME: case OP_LOAD_GLOBAL: case OP_LOAD_NONLOCAL: case OP_STORE_GLOBAL: case OP_LOAD_NAME: case OP_LOAD_GLOBAL: case OP_LOAD_NONLOCAL: case OP_STORE_GLOBAL:
case OP_LOAD_ATTR: case OP_LOAD_METHOD: case OP_STORE_ATTR: case OP_DELETE_ATTR: case OP_LOAD_ATTR: case OP_LOAD_METHOD: case OP_STORE_ATTR: case OP_DELETE_ATTR:
case OP_IMPORT_NAME: case OP_BEGIN_CLASS: case OP_IMPORT_NAME: case OP_BEGIN_CLASS: case OP_RAISE:
case OP_DELETE_GLOBAL: case OP_INC_GLOBAL: case OP_DEC_GLOBAL: case OP_DELETE_GLOBAL: case OP_INC_GLOBAL: case OP_DEC_GLOBAL:
argStr += fmt(" (", StrName(byte.arg).sv(), ")"); argStr += fmt(" (", StrName(byte.arg).sv(), ")");
break; break;

View File

@ -71,3 +71,14 @@ try:
exit(1) exit(1)
except AssertionError: except AssertionError:
pass pass
def f(a: list):
try:
raise ValueError
exit(1)
except:
pass
a[0] = 1
a = [0]
f(a)
assert a == [1]