This commit is contained in:
blueloveTH 2024-04-14 21:26:03 +08:00
parent ef521c4cd4
commit 6ec6c5290b
5 changed files with 23 additions and 25 deletions

View File

@ -173,7 +173,7 @@ struct NativeFunc {
NativeFunc(NativeFuncC f, FuncDecl_ decl); NativeFunc(NativeFuncC f, FuncDecl_ decl);
void check_size(VM* vm, ArgsView args) const; 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{ struct Function{

View File

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

View File

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

View File

@ -73,7 +73,7 @@ void init_builtins(VM* _vm) {
// builtin functions // builtin functions
_vm->bind_func<0>(_vm->builtins, "breakpoint", [](VM* vm, ArgsView args) { _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; return vm->None;
}); });

View File

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