This commit is contained in:
blueloveTH 2022-11-12 14:35:14 +08:00
parent 2e55d890fc
commit 1cfa339ac2
2 changed files with 7 additions and 16 deletions

View File

@ -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();
}

View File

@ -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>(frame));
PyVar ret = runFrame(frame);
callstack.pop();