From 1cfa339ac23b8c067e682f1f768b03234d91ea24 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 12 Nov 2022 14:35:14 +0800 Subject: [PATCH] backup --- src/codeobject.h | 8 ++++---- src/vm.h | 15 +++------------ 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/codeobject.h b/src/codeobject.h index 7403a3dd..1147227b 100644 --- a/src/codeobject.h +++ b/src/codeobject.h @@ -105,7 +105,7 @@ private: int ip = 0; public: PyVar _module; - PyVarDict& f_locals; + PyVarDict f_locals; inline PyVarDict& f_globals(){ return _module->attribs; @@ -113,7 +113,7 @@ public: const CodeObject* code; - Frame(const CodeObject* code, PyVar _module, PyVarDict& locals) + Frame(const CodeObject* code, PyVar _module, const PyVarDict& locals) : code(code), _module(_module), f_locals(locals) {} inline const ByteCode& readCode() { @@ -122,7 +122,7 @@ public: _Str errorSnapshot(){ int line = -1; - if(!isEnd()) line = code->co_code[ip-1].line; + if(!isCodeEnd()) line = code->co_code[ip-1].line; return code->src->snapshot(line); } @@ -130,7 +130,7 @@ public: return s_data.size(); } - inline bool isEnd() const { + inline bool isCodeEnd() const { return ip >= code->co_code.size(); } diff --git a/src/vm.h b/src/vm.h index c7911a38..526a79e7 100644 --- a/src/vm.h +++ b/src/vm.h @@ -30,7 +30,7 @@ private: PyVarDict _modules; // 3rd modules PyVar runFrame(Frame* frame){ - while(!frame->isEnd()){ + while(!frame->isCodeEnd()){ const ByteCode& byte = frame->readCode(); //printf("%s (%d) stack_size: %d\n", OP_NAMES[byte.op], byte.arg, frame->stackSize()); @@ -424,23 +424,14 @@ public: } } - PyVar _exec(const _Code& code, PyVar _module){ - PyVarDict locals; - return _exec(code, _module, locals); - } - - PyVar _exec(const _Code& code, PyVar _module, PyVarDict& locals){ + PyVar _exec(const _Code& code, PyVar _module, const PyVarDict& locals={}){ if(code == nullptr) UNREACHABLE(); if(callstack.size() > 1000){ throw RuntimeError("RecursionError", "maximum recursion depth exceeded", _cleanErrorAndGetSnapshots()); } - Frame* frame = new Frame( - code.get(), - _module, - locals // pass by reference - ); + Frame* frame = new Frame(code.get(), _module, locals); callstack.push(std::unique_ptr(frame)); PyVar ret = runFrame(frame); callstack.pop();