mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 12:00:18 +00:00
remove VM::top_frame
This commit is contained in:
parent
4f520a0c26
commit
fd12deeec3
@ -168,10 +168,6 @@ public:
|
||||
void set_main_argv(int argc, char** argv);
|
||||
void __breakpoint();
|
||||
|
||||
Frame* top_frame(){
|
||||
return &callstack.top();
|
||||
}
|
||||
|
||||
void __pop_frame(){
|
||||
s_data.reset(callstack.top()._sp_base);
|
||||
callstack.pop();
|
||||
|
@ -81,7 +81,7 @@ bool VM::py_ge(PyObject* _0, PyObject* _1){
|
||||
#undef BINARY_F_COMPARE
|
||||
|
||||
PyObject* VM::__run_top_frame(){
|
||||
Frame* frame = top_frame();
|
||||
Frame* frame = &callstack.top();
|
||||
const Frame* base_frame = frame;
|
||||
bool need_raise = false;
|
||||
|
||||
@ -667,7 +667,7 @@ __NEXT_STEP:;
|
||||
true
|
||||
);
|
||||
if(_0 == PY_OP_CALL){
|
||||
frame = top_frame();
|
||||
frame = &callstack.top();
|
||||
goto __NEXT_FRAME;
|
||||
}
|
||||
PUSH(_0);
|
||||
@ -702,7 +702,7 @@ __NEXT_STEP:;
|
||||
);
|
||||
}
|
||||
if(_0 == PY_OP_CALL){
|
||||
frame = top_frame();
|
||||
frame = &callstack.top();
|
||||
goto __NEXT_FRAME;
|
||||
}
|
||||
PUSH(_0);
|
||||
@ -713,7 +713,7 @@ __NEXT_STEP:;
|
||||
if(frame == base_frame){ // [ frameBase<- ]
|
||||
return _0;
|
||||
}else{
|
||||
frame = top_frame();
|
||||
frame = &callstack.top();
|
||||
PUSH(_0);
|
||||
goto __NEXT_FRAME;
|
||||
}
|
||||
@ -983,7 +983,7 @@ __NEXT_STEP:;
|
||||
bool is_base_frame_to_be_popped = frame == base_frame;
|
||||
__pop_frame();
|
||||
if(callstack.empty()) throw _e; // propagate to the top level
|
||||
frame = top_frame();
|
||||
frame = &callstack.top();
|
||||
PUSH(e_obj);
|
||||
if(is_base_frame_to_be_popped) throw ToBeRaisedException();
|
||||
need_raise = true;
|
||||
|
@ -100,7 +100,7 @@ void add_module_json(VM* vm){
|
||||
sv = CAST(Str&, args[0]).sv();
|
||||
}
|
||||
CodeObject_ code = vm->compile(sv, "<json>", JSON_MODE);
|
||||
return vm->_exec(code, vm->top_frame()->_module);
|
||||
return vm->_exec(code, vm->callstack.top()._module);
|
||||
});
|
||||
|
||||
vm->bind_func<1>(mod, "dumps", [](VM* vm, ArgsView args) {
|
||||
|
@ -74,7 +74,7 @@ void init_builtins(VM* _vm) {
|
||||
// builtin functions
|
||||
_vm->bind_func<0>(_vm->builtins, "breakpoint", [](VM* vm, ArgsView args) {
|
||||
#if PK_ENABLE_PROFILER
|
||||
vm->_next_breakpoint = NextBreakpoint(vm->callstack.size(), vm->top_frame()->curr_lineno(), false);
|
||||
vm->_next_breakpoint = NextBreakpoint(vm->callstack.size(), vm->callstack.top().curr_lineno(), false);
|
||||
#endif
|
||||
return vm->None;
|
||||
});
|
||||
@ -86,7 +86,7 @@ void init_builtins(VM* _vm) {
|
||||
class_arg = args[0];
|
||||
self_arg = args[1];
|
||||
}else if(args.size() == 0){
|
||||
Frame* frame = vm->top_frame();
|
||||
Frame* frame = &vm->callstack.top();
|
||||
if(frame->_callable != nullptr){
|
||||
class_arg = PK_OBJ_GET(Function, frame->_callable)._class;
|
||||
if(frame->_locals.size() > 0) self_arg = frame->_locals[0];
|
||||
@ -140,7 +140,7 @@ void init_builtins(VM* _vm) {
|
||||
});
|
||||
|
||||
_vm->bind_func<0>(_vm->builtins, "globals", [](VM* vm, ArgsView args) {
|
||||
PyObject* mod = vm->top_frame()->_module;
|
||||
PyObject* mod = vm->callstack.top()._module;
|
||||
return VAR(MappingProxy(mod));
|
||||
});
|
||||
|
||||
@ -201,7 +201,7 @@ void init_builtins(VM* _vm) {
|
||||
CodeObject_ code = vm->compile(CAST(Str&, args[0]), "<eval>", EVAL_MODE, true);
|
||||
PyObject* globals = args[1];
|
||||
if(globals == vm->None){
|
||||
Frame* frame = vm->top_frame();
|
||||
Frame* frame = &vm->callstack.top();
|
||||
return vm->_exec(code.get(), frame->_module, frame->_callable, frame->_locals);
|
||||
}
|
||||
vm->check_type(globals, VM::tp_mappingproxy);
|
||||
@ -213,7 +213,7 @@ void init_builtins(VM* _vm) {
|
||||
CodeObject_ code = vm->compile(CAST(Str&, args[0]), "<exec>", EXEC_MODE, true);
|
||||
PyObject* globals = args[1];
|
||||
if(globals == vm->None){
|
||||
Frame* frame = vm->top_frame();
|
||||
Frame* frame = &vm->callstack.top();
|
||||
vm->_exec(code.get(), frame->_module, frame->_callable, frame->_locals);
|
||||
return vm->None;
|
||||
}
|
||||
|
@ -694,7 +694,7 @@ void VM::_log_s_data(const char* title) {
|
||||
if(f._sp_base == nullptr) PK_FATAL_ERROR();
|
||||
sp_bases[f._sp_base] += 1;
|
||||
}
|
||||
Frame* frame = top_frame();
|
||||
Frame* frame = &callstack.top();
|
||||
int line = frame->co->lines[frame->_ip];
|
||||
ss << frame->co->name << ":" << line << " [";
|
||||
for(PyObject** p=s_data.begin(); p!=s_data.end(); p++){
|
||||
@ -1298,7 +1298,7 @@ void VM::_error(PyObject* e_obj){
|
||||
}
|
||||
|
||||
void VM::__raise(bool re_raise){
|
||||
Frame* frame = top_frame();
|
||||
Frame* frame = &callstack.top();
|
||||
Exception& e = PK_OBJ_GET(Exception, s_data.top());
|
||||
if(!re_raise){
|
||||
e._ip_on_error = frame->_ip;
|
||||
@ -1497,7 +1497,7 @@ void NativeFunc::check_size(VM* vm, ArgsView args) const{
|
||||
#if PK_ENABLE_PROFILER
|
||||
void NextBreakpoint::_step(VM* vm){
|
||||
int curr_callstack_size = vm->callstack.size();
|
||||
int curr_lineno = vm->top_frame()->curr_lineno();
|
||||
int curr_lineno = vm->callstack.top().curr_lineno();
|
||||
if(should_step_into){
|
||||
if(curr_callstack_size != callstack_size || curr_lineno != lineno){
|
||||
vm->__breakpoint();
|
||||
|
Loading…
x
Reference in New Issue
Block a user