From de52659bc2647b9d7526841ad9117dfd84b8e3f6 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 4 Feb 2023 18:06:46 +0800 Subject: [PATCH] up --- src/codeobject.h | 9 ++++----- src/vm.h | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/codeobject.h b/src/codeobject.h index eeb2ac9e..44949b13 100644 --- a/src/codeobject.h +++ b/src/codeobject.h @@ -139,6 +139,8 @@ struct CodeObject { } }; +static thread_local i64 kFrameGlobalId = 0; + struct Frame { std::vector _data; int _ip = -1; @@ -147,16 +149,13 @@ struct Frame { const _Code co; PyVar _module; pkpy::shared_ptr _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 _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; diff --git a/src/vm.h b/src/vm.h index 4008046b..9b47da7c 100644 --- a/src/vm.h +++ b/src/vm.h @@ -547,18 +547,18 @@ public: template PyVar _exec(Args&&... args){ Frame* frame = __new_frame(std::forward(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;