This commit is contained in:
blueloveTH 2023-02-04 18:06:46 +08:00
parent ee905c84da
commit de52659bc2
2 changed files with 8 additions and 9 deletions

View File

@ -139,6 +139,8 @@ struct CodeObject {
}
};
static thread_local i64 kFrameGlobalId = 0;
struct Frame {
std::vector<PyVar> _data;
int _ip = -1;
@ -147,16 +149,13 @@ struct Frame {
const _Code co;
PyVar _module;
pkpy::shared_ptr<PyVarDict> _locals;
i64 _id;
const i64 id;
inline PyVarDict& f_locals() noexcept { return *_locals; }
inline PyVarDict& f_globals() noexcept { return _module->attribs; }
Frame(const _Code co, PyVar _module, pkpy::shared_ptr<PyVarDict> _locals)
: co(co), _module(_module), _locals(_locals) {
static thread_local i64 kGlobalId = 0;
_id = kGlobalId++;
}
: co(co), _module(_module), _locals(_locals), id(kFrameGlobalId++) { }
inline const Bytecode& next_bytecode() {
_ip = _next_ip;

View File

@ -547,18 +547,18 @@ public:
template<typename ...Args>
PyVar _exec(Args&&... args){
Frame* frame = __new_frame(std::forward<Args>(args)...);
i64 base_id = frame->_id;
i64 base_id = frame->id;
PyVar ret = nullptr;
bool need_raise = false;
while(true){
if(frame->_id < base_id) UNREACHABLE();
if(frame->id < base_id) UNREACHABLE();
try{
if(need_raise){ need_raise = false; _raise(); }
ret = run_frame(frame);
if(ret != __py2py_call_signal){
if(frame->_id == base_id){ // [ frameBase<- ]
if(frame->id == base_id){ // [ frameBase<- ]
break;
}else{
callstack.pop();
@ -578,7 +578,7 @@ public:
if(!callstack.empty()){
frame = callstack.top().get();
if(frame->_id < base_id) throw e;
if(frame->id < base_id) throw e;
frame->push(obj);
need_raise = true;
continue;