mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
some fix
This commit is contained in:
parent
ef521c4cd4
commit
6ec6c5290b
@ -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{
|
||||
|
@ -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);
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
});
|
||||
|
||||
|
23
src/vm.cpp
23
src/vm.cpp
@ -1349,26 +1349,21 @@ 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){
|
||||
if(curr_callstack_size == callstack_size) {
|
||||
if(curr_lineno != lineno) vm->_breakpoint();
|
||||
}else if(curr_callstack_size < callstack_size){
|
||||
// returning
|
||||
vm->_breakpoint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void 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"){
|
||||
|
Loading…
x
Reference in New Issue
Block a user