mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
up
This commit is contained in:
parent
ee905c84da
commit
de52659bc2
@ -139,6 +139,8 @@ struct CodeObject {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static thread_local i64 kFrameGlobalId = 0;
|
||||||
|
|
||||||
struct Frame {
|
struct Frame {
|
||||||
std::vector<PyVar> _data;
|
std::vector<PyVar> _data;
|
||||||
int _ip = -1;
|
int _ip = -1;
|
||||||
@ -147,16 +149,13 @@ struct Frame {
|
|||||||
const _Code co;
|
const _Code co;
|
||||||
PyVar _module;
|
PyVar _module;
|
||||||
pkpy::shared_ptr<PyVarDict> _locals;
|
pkpy::shared_ptr<PyVarDict> _locals;
|
||||||
i64 _id;
|
const i64 id;
|
||||||
|
|
||||||
inline PyVarDict& f_locals() noexcept { return *_locals; }
|
inline PyVarDict& f_locals() noexcept { return *_locals; }
|
||||||
inline PyVarDict& f_globals() noexcept { return _module->attribs; }
|
inline PyVarDict& f_globals() noexcept { return _module->attribs; }
|
||||||
|
|
||||||
Frame(const _Code co, PyVar _module, pkpy::shared_ptr<PyVarDict> _locals)
|
Frame(const _Code co, PyVar _module, pkpy::shared_ptr<PyVarDict> _locals)
|
||||||
: co(co), _module(_module), _locals(_locals) {
|
: co(co), _module(_module), _locals(_locals), id(kFrameGlobalId++) { }
|
||||||
static thread_local i64 kGlobalId = 0;
|
|
||||||
_id = kGlobalId++;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline const Bytecode& next_bytecode() {
|
inline const Bytecode& next_bytecode() {
|
||||||
_ip = _next_ip;
|
_ip = _next_ip;
|
||||||
|
8
src/vm.h
8
src/vm.h
@ -547,18 +547,18 @@ public:
|
|||||||
template<typename ...Args>
|
template<typename ...Args>
|
||||||
PyVar _exec(Args&&... args){
|
PyVar _exec(Args&&... args){
|
||||||
Frame* frame = __new_frame(std::forward<Args>(args)...);
|
Frame* frame = __new_frame(std::forward<Args>(args)...);
|
||||||
i64 base_id = frame->_id;
|
i64 base_id = frame->id;
|
||||||
PyVar ret = nullptr;
|
PyVar ret = nullptr;
|
||||||
bool need_raise = false;
|
bool need_raise = false;
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
if(frame->_id < base_id) UNREACHABLE();
|
if(frame->id < base_id) UNREACHABLE();
|
||||||
try{
|
try{
|
||||||
if(need_raise){ need_raise = false; _raise(); }
|
if(need_raise){ need_raise = false; _raise(); }
|
||||||
ret = run_frame(frame);
|
ret = run_frame(frame);
|
||||||
|
|
||||||
if(ret != __py2py_call_signal){
|
if(ret != __py2py_call_signal){
|
||||||
if(frame->_id == base_id){ // [ frameBase<- ]
|
if(frame->id == base_id){ // [ frameBase<- ]
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
callstack.pop();
|
callstack.pop();
|
||||||
@ -578,7 +578,7 @@ public:
|
|||||||
|
|
||||||
if(!callstack.empty()){
|
if(!callstack.empty()){
|
||||||
frame = callstack.top().get();
|
frame = callstack.top().get();
|
||||||
if(frame->_id < base_id) throw e;
|
if(frame->id < base_id) throw e;
|
||||||
frame->push(obj);
|
frame->push(obj);
|
||||||
need_raise = true;
|
need_raise = true;
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user