From 6a7da5a1d50c9a8516ff4c32aad5a54a19e8b885 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 5 Aug 2024 23:52:09 +0800 Subject: [PATCH] ... --- include/pocketpy/interpreter/frame.h | 4 +--- src/interpreter/ceval.c | 2 +- src/interpreter/frame.c | 6 ++---- src/interpreter/vm.c | 4 ++-- src/public/internal.c | 2 +- src/public/modules.c | 8 +++++--- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/pocketpy/interpreter/frame.h b/include/pocketpy/interpreter/frame.h index ab5de56d..5e92a881 100644 --- a/include/pocketpy/interpreter/frame.h +++ b/include/pocketpy/interpreter/frame.h @@ -42,7 +42,6 @@ typedef struct Frame { py_StackRef function; // a function object or NULL (global scope) py_StackRef p0; // unwinding base py_StackRef locals; // locals base - const CodeObject* locals_co; UnwindTarget* uw_list; } Frame; @@ -50,8 +49,7 @@ Frame* Frame__new(const CodeObject* co, py_TValue* module, py_StackRef function, py_StackRef p0, - py_StackRef locals, - const CodeObject* locals_co); + py_StackRef locals); void Frame__delete(Frame* self); int Frame__ip(const Frame* self); diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index 5cea6b78..39fa140e 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -136,7 +136,7 @@ FrameResult VM__run_top_frame(VM* self) { Function* ud = py_newobject(SP(), tp_function, 0, sizeof(Function)); Function__ctor(ud, decl, &frame->module); if(decl->nested) { - ud->closure = FastLocals__to_namedict(frame->locals, frame->locals_co); + ud->closure = FastLocals__to_namedict(frame->locals, frame->co); py_Name name = py_name(decl->code.name->data); // capture itself to allow recursion NameDict__set(ud->closure, name, *SP()); diff --git a/src/interpreter/frame.c b/src/interpreter/frame.c index fbf44f97..33284633 100644 --- a/src/interpreter/frame.c +++ b/src/interpreter/frame.c @@ -38,8 +38,7 @@ Frame* Frame__new(const CodeObject* co, py_TValue* module, py_StackRef function, py_StackRef p0, - py_StackRef locals, - const CodeObject* locals_co) { + py_StackRef locals) { static_assert(sizeof(Frame) <= kPoolFrameBlockSize, "!(sizeof(Frame) <= kPoolFrameBlockSize)"); Frame* self = PoolFrame_alloc(); self->f_back = NULL; @@ -49,7 +48,6 @@ Frame* Frame__new(const CodeObject* co, self->function = function; self->p0 = p0; self->locals = locals; - self->locals_co = locals_co; self->uw_list = NULL; return self; } @@ -151,5 +149,5 @@ int Frame__iblock(const Frame* self) { } py_TValue* Frame__f_locals_try_get(Frame* self, py_Name name) { - return FastLocals__try_get_by_name(self->locals, self->locals_co, name); + return FastLocals__try_get_by_name(self->locals, self->co, name); } \ No newline at end of file diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c index 1eeceb93..f3646ed8 100644 --- a/src/interpreter/vm.c +++ b/src/interpreter/vm.c @@ -409,7 +409,7 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall memcpy(argv, self->__vectorcall_buffer, co->nlocals * sizeof(py_TValue)); // submit the call if(!fn->cfunc) { - VM__push_frame(self, Frame__new(co, &fn->module, p0, p0, argv, co)); + VM__push_frame(self, Frame__new(co, &fn->module, p0, p0, argv)); return opcall ? RES_CALL : VM__run_top_frame(self); } else { bool ok = fn->cfunc(co->nlocals, argv); @@ -433,7 +433,7 @@ FrameResult VM__vectorcall(VM* self, uint16_t argc, uint16_t kwargc, bool opcall // initialize local variables to py_NIL memset(p1, 0, (char*)self->stack.sp - (char*)p1); // submit the call - VM__push_frame(self, Frame__new(co, &fn->module, p0, p0, argv, co)); + VM__push_frame(self, Frame__new(co, &fn->module, p0, p0, argv)); return opcall ? RES_CALL : VM__run_top_frame(self); case FuncType_GENERATOR: assert(false); diff --git a/src/public/internal.c b/src/public/internal.c index f6796907..58ae5ab0 100644 --- a/src/public/internal.c +++ b/src/public/internal.c @@ -93,7 +93,7 @@ bool py_exec(const char* source, const char* filename, enum py_CompileMode mode, if(!module) module = &vm->main; - Frame* frame = Frame__new(&co, module, NULL, vm->stack.sp, vm->stack.sp, &co); + Frame* frame = Frame__new(&co, module, NULL, vm->stack.sp, vm->stack.sp); VM__push_frame(vm, frame); FrameResult res = VM__run_top_frame(vm); CodeObject__dtor(&co); diff --git a/src/public/modules.c b/src/public/modules.c index e4c0338e..5c1a7b13 100644 --- a/src/public/modules.c +++ b/src/public/modules.c @@ -317,13 +317,15 @@ static bool NoneType__repr__(int argc, py_Ref argv) { static bool builtins_exec(int argc, py_Ref argv) { PY_CHECK_ARGC(1); PY_CHECK_ARG_TYPE(0, tp_str); - return py_exec(py_tostr(argv), "", EXEC_MODE, NULL); + Frame* frame = pk_current_vm->top_frame; + return py_exec(py_tostr(argv), "", EXEC_MODE, &frame->module); } static bool builtins_eval(int argc, py_Ref argv) { PY_CHECK_ARGC(1); PY_CHECK_ARG_TYPE(0, tp_str); - return py_exec(py_tostr(argv), "", EVAL_MODE, NULL); + Frame* frame = pk_current_vm->top_frame; + return py_exec(py_tostr(argv), "", EVAL_MODE, &frame->module); } static bool builtins_isinstance(int argc, py_Ref argv) { @@ -493,7 +495,7 @@ static bool super__new__(int argc, py_Ref argv) { if(frame->function) { Function* func = py_touserdata(frame->function); *class_arg = *(py_Type*)PyObject__userdata(func->clazz); - if(frame->locals_co->nlocals > 0) self_arg = &frame->locals[0]; + if(frame->co->nlocals > 0) self_arg = &frame->locals[0]; } if(class_arg == 0 || self_arg == NULL) return RuntimeError("super(): no arguments"); } else if(argc == 3) {