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);
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{

View File

@ -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);

View File

@ -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:

View File

@ -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;
});

View File

@ -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"){