mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
backup
This commit is contained in:
parent
2e55d890fc
commit
1cfa339ac2
@ -105,7 +105,7 @@ private:
|
|||||||
int ip = 0;
|
int ip = 0;
|
||||||
public:
|
public:
|
||||||
PyVar _module;
|
PyVar _module;
|
||||||
PyVarDict& f_locals;
|
PyVarDict f_locals;
|
||||||
|
|
||||||
inline PyVarDict& f_globals(){
|
inline PyVarDict& f_globals(){
|
||||||
return _module->attribs;
|
return _module->attribs;
|
||||||
@ -113,7 +113,7 @@ public:
|
|||||||
|
|
||||||
const CodeObject* code;
|
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) {}
|
: code(code), _module(_module), f_locals(locals) {}
|
||||||
|
|
||||||
inline const ByteCode& readCode() {
|
inline const ByteCode& readCode() {
|
||||||
@ -122,7 +122,7 @@ public:
|
|||||||
|
|
||||||
_Str errorSnapshot(){
|
_Str errorSnapshot(){
|
||||||
int line = -1;
|
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);
|
return code->src->snapshot(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ public:
|
|||||||
return s_data.size();
|
return s_data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool isEnd() const {
|
inline bool isCodeEnd() const {
|
||||||
return ip >= code->co_code.size();
|
return ip >= code->co_code.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
src/vm.h
15
src/vm.h
@ -30,7 +30,7 @@ private:
|
|||||||
PyVarDict _modules; // 3rd modules
|
PyVarDict _modules; // 3rd modules
|
||||||
|
|
||||||
PyVar runFrame(Frame* frame){
|
PyVar runFrame(Frame* frame){
|
||||||
while(!frame->isEnd()){
|
while(!frame->isCodeEnd()){
|
||||||
const ByteCode& byte = frame->readCode();
|
const ByteCode& byte = frame->readCode();
|
||||||
//printf("%s (%d) stack_size: %d\n", OP_NAMES[byte.op], byte.arg, frame->stackSize());
|
//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){
|
PyVar _exec(const _Code& code, PyVar _module, const PyVarDict& locals={}){
|
||||||
PyVarDict locals;
|
|
||||||
return _exec(code, _module, locals);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyVar _exec(const _Code& code, PyVar _module, PyVarDict& locals){
|
|
||||||
if(code == nullptr) UNREACHABLE();
|
if(code == nullptr) UNREACHABLE();
|
||||||
|
|
||||||
if(callstack.size() > 1000){
|
if(callstack.size() > 1000){
|
||||||
throw RuntimeError("RecursionError", "maximum recursion depth exceeded", _cleanErrorAndGetSnapshots());
|
throw RuntimeError("RecursionError", "maximum recursion depth exceeded", _cleanErrorAndGetSnapshots());
|
||||||
}
|
}
|
||||||
|
|
||||||
Frame* frame = new Frame(
|
Frame* frame = new Frame(code.get(), _module, locals);
|
||||||
code.get(),
|
|
||||||
_module,
|
|
||||||
locals // pass by reference
|
|
||||||
);
|
|
||||||
callstack.push(std::unique_ptr<Frame>(frame));
|
callstack.push(std::unique_ptr<Frame>(frame));
|
||||||
PyVar ret = runFrame(frame);
|
PyVar ret = runFrame(frame);
|
||||||
callstack.pop();
|
callstack.pop();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user