This commit is contained in:
blueloveTH 2024-05-19 18:24:37 +08:00
parent 844813b787
commit 9a085d1767
2 changed files with 10 additions and 10 deletions

View File

@ -69,7 +69,7 @@ struct ValueStack {
}; };
struct Frame { struct Frame {
const Bytecode* _ip_addr; const Bytecode* _ip;
// This is for unwinding only, use `actual_sp_base()` for value stack access // This is for unwinding only, use `actual_sp_base()` for value stack access
PyVar* _sp_base; PyVar* _sp_base;
@ -80,19 +80,19 @@ struct Frame {
NameDict& f_globals() { return _module->attr(); } NameDict& f_globals() { return _module->attr(); }
PyVar f_closure_try_get(StrName name); PyVar f_closure_try_get(StrName name);
int ip() const { return _ip_addr - co->codes.data(); } int ip() const { return _ip - co->codes.data(); }
// function scope // function scope
Frame(PyVar* p0, const CodeObject* co, PyVar _module, PyVar _callable, PyVar* _locals_base) Frame(PyVar* p0, const CodeObject* co, PyVar _module, PyVar _callable, PyVar* _locals_base)
: _ip_addr(co->codes.data()-1), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(co, _locals_base) { } : _ip(co->codes.data()-1), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(co, _locals_base) { }
// exec/eval // exec/eval
Frame(PyVar* p0, const CodeObject* co, PyVar _module, PyVar _callable, FastLocals _locals) Frame(PyVar* p0, const CodeObject* co, PyVar _module, PyVar _callable, FastLocals _locals)
: _ip_addr(co->codes.data()-1), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(_locals) { } : _ip(co->codes.data()-1), _sp_base(p0), co(co), _module(_module), _callable(_callable), _locals(_locals) { }
// global scope // global scope
Frame(PyVar* p0, const CodeObject_& co, PyVar _module) Frame(PyVar* p0, const CodeObject_& co, PyVar _module)
: _ip_addr(co->codes.data()-1), _sp_base(p0), co(co.get()), _module(_module), _callable(nullptr), _locals(co.get(), p0) {} : _ip(co->codes.data()-1), _sp_base(p0), co(co.get()), _module(_module), _callable(nullptr), _locals(co.get(), p0) {}
PyVar* actual_sp_base() const { return _locals.a; } PyVar* actual_sp_base() const { return _locals.a; }

View File

@ -94,8 +94,8 @@ bool VM::py_ge(PyVar _0, PyVar _1){
} }
#endif #endif
#define DISPATCH() { frame->_ip_addr++; goto __NEXT_STEP; } #define DISPATCH() { frame->_ip++; goto __NEXT_STEP; }
#define DISPATCH_JUMP(__target) { frame->_ip_addr = co_codes+__target; goto __NEXT_STEP; } #define DISPATCH_JUMP(__target) { frame->_ip=co_codes+__target; goto __NEXT_STEP; }
PyVar VM::__run_top_frame(){ PyVar VM::__run_top_frame(){
Frame* frame = &callstack.top(); Frame* frame = &callstack.top();
@ -113,10 +113,10 @@ __NEXT_FRAME:
if(__internal_exception.type == InternalExceptionType::Null){ if(__internal_exception.type == InternalExceptionType::Null){
// None // None
frame->_ip_addr++; frame->_ip++;
}else if(__internal_exception.type == InternalExceptionType::Handled){ }else if(__internal_exception.type == InternalExceptionType::Handled){
// HandledException + continue // HandledException + continue
frame->_ip_addr = co_codes + __internal_exception.arg; frame->_ip = co_codes + __internal_exception.arg;
__internal_exception = {}; __internal_exception = {};
}else{ }else{
// UnhandledException + continue (need_raise = true) // UnhandledException + continue (need_raise = true)
@ -126,7 +126,7 @@ __NEXT_FRAME:
} }
__NEXT_STEP: __NEXT_STEP:
byte = *frame->_ip_addr; byte = *frame->_ip;
CEVAL_STEP_CALLBACK() CEVAL_STEP_CALLBACK()
#if PK_DEBUG_CEVAL_STEP #if PK_DEBUG_CEVAL_STEP