blueloveTH 1 년 전
부모
커밋
6ec6c5290b
5개의 변경된 파일23개의 추가작업 그리고 25개의 파일을 삭제
  1. 1 1
      include/pocketpy/codeobject.h
  2. 9 6
      include/pocketpy/vm.h
  3. 1 1
      src/ceval.cpp
  4. 1 1
      src/pocketpy.cpp
  5. 11 16
      src/vm.cpp

+ 1 - 1
include/pocketpy/codeobject.h

@@ -173,7 +173,7 @@ struct NativeFunc {
     NativeFunc(NativeFuncC f, FuncDecl_ decl);
 
     void check_size(VM* vm, ArgsView args) const;
-    PyObject* call(VM* vm, ArgsView args) const;
+    PyObject* call(VM* vm, ArgsView args) const { return f(vm, args); }
 };
 
 struct Function{

+ 9 - 6
include/pocketpy/vm.h

@@ -30,14 +30,13 @@ namespace pkpy{
 typedef PyObject* (*BinaryFuncC)(VM*, PyObject*, PyObject*);
 
 struct NextBreakpoint{
-    LinkedFrame* linked_frame;
+    int callstack_size;
     int lineno;
     bool should_step_into;
-    NextBreakpoint(): linked_frame(nullptr) {}
-    NextBreakpoint(LinkedFrame* lf, bool should_step_into): 
-        linked_frame(lf), lineno(lf->frame.curr_lineno()), should_step_into(should_step_into) {}
-    void _step(VM* vm, LinkedFrame* lf);
-    bool empty() const { return linked_frame == nullptr; }
+    NextBreakpoint(): callstack_size(0) {}
+    NextBreakpoint(int callstack_size, int lineno, bool should_step_into): callstack_size(callstack_size), lineno(lineno), should_step_into(should_step_into) {}
+    void _step(VM* vm);
+    bool empty() const { return callstack_size == 0; }
 };
 
 struct PyTypeInfo{
@@ -175,6 +174,10 @@ public:
     void _pop_frame(){
         s_data.reset(callstack.top()._sp_base);
         callstack.pop();
+        
+        if(!_next_breakpoint.empty() && callstack.size()<_next_breakpoint.callstack_size){
+            _next_breakpoint = NextBreakpoint();
+        }
     }
 
     PyObject* py_str(PyObject* obj);

+ 1 - 1
src/ceval.cpp

@@ -75,7 +75,7 @@ PyObject* VM::_run_top_frame(){
 #define CEVAL_STEP_CALLBACK() \
     if(_ceval_on_step) _ceval_on_step(this, frame, byte);   \
     if(_profiler) _profiler->_step(callstack._tail);        \
-    if(!_next_breakpoint.empty()) { _next_breakpoint._step(this, callstack._tail); }
+    if(!_next_breakpoint.empty()) { _next_breakpoint._step(this); }
 
 #define DISPATCH_OP_CALL() { frame = top_frame(); goto __NEXT_FRAME; }
 __NEXT_FRAME:

+ 1 - 1
src/pocketpy.cpp

@@ -73,7 +73,7 @@ void init_builtins(VM* _vm) {
 
     // builtin functions
     _vm->bind_func<0>(_vm->builtins, "breakpoint", [](VM* vm, ArgsView args) {
-        vm->_next_breakpoint = NextBreakpoint(vm->callstack._tail, false);
+        vm->_next_breakpoint = NextBreakpoint(vm->callstack.size(), vm->top_frame()->curr_lineno(), false);
         return vm->None;
     });
 

+ 11 - 16
src/vm.cpp

@@ -1349,24 +1349,19 @@ void NativeFunc::check_size(VM* vm, ArgsView args) const{
     }
 }
 
-PyObject* NativeFunc::call(VM *vm, ArgsView args) const {
-    return f(vm, args);
-}
-
-void NextBreakpoint::_step(VM* vm, LinkedFrame* linked_frame){
-    int lineno = linked_frame->frame.curr_lineno();
+void NextBreakpoint::_step(VM* vm){
+    int curr_callstack_size = vm->callstack.size();
+    int curr_lineno = vm->top_frame()->curr_lineno();
     if(should_step_into){
-        if(linked_frame != this->linked_frame || lineno != this->lineno){
+        if(curr_callstack_size != callstack_size || curr_lineno != lineno){
             vm->_breakpoint();
         }
     }else{
-        if(linked_frame == this->linked_frame){
-            if(lineno != this->lineno) vm->_breakpoint();
-        }else{
-            if(this->linked_frame->f_back == linked_frame){
-                // returning
-                vm->_breakpoint();
-            }
+        if(curr_callstack_size == callstack_size) {
+            if(curr_lineno != lineno) vm->_breakpoint();
+        }else if(curr_callstack_size < callstack_size){
+            // returning
+            vm->_breakpoint();
         }
     }
 }
@@ -1436,11 +1431,11 @@ void VM::_breakpoint(){
             PK_UNREACHABLE()
         }
         if(line == "n" || line == "next"){
-            vm->_next_breakpoint = NextBreakpoint(frames[0], false);
+            vm->_next_breakpoint = NextBreakpoint(vm->callstack.size(), frame_0->curr_lineno(), false);
             break;
         }
         if(line == "s" || line == "step"){
-            vm->_next_breakpoint = NextBreakpoint(frames[0], true);
+            vm->_next_breakpoint = NextBreakpoint(vm->callstack.size(), frame_0->curr_lineno(), true);
             break;
         }
         if(line == "w" || line == "where"){