blueloveTH 1 год назад
Родитель
Сommit
8a5deb6ebb
4 измененных файлов с 6 добавлено и 5 удалено
  1. 3 2
      include/pocketpy/error.h
  2. 1 1
      src/ceval.cpp
  3. 1 1
      src/compiler.cpp
  4. 1 1
      src/vm.cpp

+ 3 - 2
include/pocketpy/error.h

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

+ 1 - 1
src/ceval.cpp

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

+ 1 - 1
src/compiler.cpp

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

+ 1 - 1
src/vm.cpp

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