blueloveTH 2 years ago
parent
commit
742014c332
2 changed files with 15 additions and 13 deletions
  1. 3 13
      include/pocketpy/vm.h
  2. 12 0
      src/vm.cpp

+ 3 - 13
include/pocketpy/vm.h

@@ -49,9 +49,9 @@ namespace pkpy{
 typedef PyObject* (*BinaryFuncC)(VM*, PyObject*, PyObject*);
 
 struct PyTypeInfo{
-    PyObject* obj;
+    PyObject* obj;      // never be garbage collected
     Type base;
-    PyObject* mod;
+    PyObject* mod;      // never be garbage collected
     Str name;
     bool subclass_enabled;
 
@@ -353,17 +353,7 @@ public:
         _error(Exception(name, msg));
     }
 
-    void _raise(bool re_raise=false){
-        Frame* top = top_frame().get();
-        if(!re_raise){
-            Exception& e = PK_OBJ_GET(Exception, s_data.top());
-            e._ip_on_error = top->_ip;
-            e._code_on_error = (void*)top->co;
-        }
-        bool ok = top->jump_to_exception_handler();
-        if(ok) throw HandledException();
-        else throw UnhandledException();
-    }
+    void _raise(bool re_raise=false);
 
     void StackOverflowError() { _error("StackOverflowError", ""); }
     void IOError(const Str& msg) { _error("IOError", msg); }

+ 12 - 0
src/vm.cpp

@@ -1078,6 +1078,18 @@ void VM::_error(Exception e){
     _raise();
 }
 
+void VM::_raise(bool re_raise){
+    Frame* top = top_frame().get();
+    if(!re_raise){
+        Exception& e = PK_OBJ_GET(Exception, s_data.top());
+        e._ip_on_error = top->_ip;
+        e._code_on_error = (void*)top->co;
+    }
+    bool ok = top->jump_to_exception_handler();
+    if(ok) throw HandledException();
+    else throw UnhandledException();
+}
+
 void ManagedHeap::mark() {
     for(PyObject* obj: _no_gc) PK_OBJ_MARK(obj);
     for(auto& frame : vm->callstack.data()) frame._gc_mark();