blueloveTH vor 2 Jahren
Ursprung
Commit
b8a54d0d43
5 geänderte Dateien mit 11 neuen und 7 gelöschten Zeilen
  1. 2 4
      src/ceval.h
  2. 1 1
      src/common.h
  3. 1 1
      src/iter.h
  4. 1 1
      src/pocketpy.h
  5. 6 0
      src/vm.h

+ 2 - 4
src/ceval.h

@@ -381,9 +381,7 @@ __NEXT_STEP:;
         DISPATCH();
     TARGET(RETURN_VALUE)
         _0 = POPX();
-        // cleanup the stack on return
-        callstack.pop();
-        s_data.reset(frame->_sp_base);
+        _pop_frame();
         if(frame.index == base_id){       // [ frameBase<- ]
             return _0;
         }else{
@@ -570,7 +568,7 @@ __NEXT_STEP:;
             PyObject* obj = POPX();
             Exception& _e = CAST(Exception&, obj);
             _e.st_push(frame->snapshot());
-            callstack.pop();
+            _pop_frame();
             if(callstack.empty()){
 #if DEBUG_FULL_EXCEPTION
                 std::cerr << _e.summary() << std::endl;

+ 1 - 1
src/common.h

@@ -37,7 +37,7 @@
 #define DEBUG_DIS_EXEC				1
 #define DEBUG_CEVAL_STEP			0
 #define DEBUG_CEVAL_STEP_MIN		0
-#define DEBUG_FULL_EXCEPTION		0
+#define DEBUG_FULL_EXCEPTION		1
 #define DEBUG_MEMORY_POOL			0
 #define DEBUG_NO_MEMORY_POOL		0
 #define DEBUG_NO_AUTO_GC			0

+ 1 - 1
src/iter.h

@@ -72,7 +72,7 @@ inline PyObject* Generator::next(){
         // backup the context
         frame = std::move(vm->callstack.top());
         for(PyObject* obj: frame.stack_view()) s_data.push_back(obj);
-        vm->callstack.pop();
+        vm->_pop_frame();
         state = 1;
         return frame._s->popx();
     }else{

+ 1 - 1
src/pocketpy.h

@@ -769,11 +769,11 @@ inline void VM::post_init(){
     add_module_math(this);
     add_module_re(this);
     add_module_dis(this);
-    add_module_random(this);
     add_module_io(this);
     add_module_os(this);
     add_module_c(this);
     add_module_gc(this);
+    add_module_random(this);
 
     for(const char* name: {"this", "functools", "collections", "heapq", "bisect"}){
         _lazy_modules[name] = kPythonLibs[name];

+ 6 - 0
src/vm.h

@@ -195,6 +195,12 @@ public:
         return _run_top_frame();
     }
 
+    void _pop_frame(){
+        Frame* frame = &callstack.top();
+        s_data.reset(frame->_sp_base);
+        callstack.pop();
+    }
+
     void _push_varargs(int n, ...){
         va_list args;
         va_start(args, n);