diff --git a/src/ceval.h b/src/ceval.h index 3ac2cfd7..5fd78a24 100644 --- a/src/ceval.h +++ b/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; diff --git a/src/common.h b/src/common.h index 4a55f012..268ec0a4 100644 --- a/src/common.h +++ b/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 diff --git a/src/iter.h b/src/iter.h index 4427e2b4..c39ed30d 100644 --- a/src/iter.h +++ b/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{ diff --git a/src/pocketpy.h b/src/pocketpy.h index c1cbb3d9..fed0c9f1 100644 --- a/src/pocketpy.h +++ b/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]; diff --git a/src/vm.h b/src/vm.h index 990f51d9..6cfbcd60 100644 --- a/src/vm.h +++ b/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);