This commit is contained in:
blueloveTH 2024-06-01 19:44:20 +08:00
parent 75343ccb23
commit 8a5deb6ebb
4 changed files with 6 additions and 5 deletions

View File

@ -89,8 +89,9 @@ struct Exception {
}; };
struct TopLevelException: std::exception{ struct TopLevelException: std::exception{
VM* vm;
Exception* ptr; Exception* ptr;
TopLevelException(Exception* ptr): ptr(ptr) {} TopLevelException(VM* vm, Exception* ptr): vm(vm), ptr(ptr) {}
Str summary() const { return ptr->summary(); } Str summary() const { return ptr->summary(); }

View File

@ -1057,7 +1057,7 @@ __NEXT_STEP:
__pop_frame(); __pop_frame();
if(callstack.empty()){ if(callstack.empty()){
// propagate to the top level // propagate to the top level
throw TopLevelException(&_e); throw TopLevelException(this, &_e);
} }
frame = &callstack.top(); frame = &callstack.top();
PUSH(__last_exception); PUSH(__last_exception);

View File

@ -1379,7 +1379,7 @@ __EAT_DOTS_END:
vm->__last_exception = vm->call(vm->builtins->attr(type), VAR(msg)).get(); vm->__last_exception = vm->call(vm->builtins->attr(type), VAR(msg)).get();
Exception& e = vm->__last_exception->as<Exception>(); Exception& e = vm->__last_exception->as<Exception>();
e.st_push(src, lineno, cursor, ""); e.st_push(src, lineno, cursor, "");
throw TopLevelException(&e); throw TopLevelException(vm, &e);
} }
std::string_view TokenDeserializer::read_string(char c){ std::string_view TokenDeserializer::read_string(char c){

View File

@ -1442,7 +1442,7 @@ void VM::_error(PyVar e_obj){
if(callstack.empty()){ if(callstack.empty()){
e.is_re = false; e.is_re = false;
__last_exception = e_obj.get(); __last_exception = e_obj.get();
throw TopLevelException(&e); throw TopLevelException(this, &e);
} }
PUSH(e_obj); PUSH(e_obj);
__raise_exc(); __raise_exc();