diff --git a/include/pocketpy/interpreter/frame.h b/include/pocketpy/interpreter/frame.h index 8b0fcf22..15577be4 100644 --- a/include/pocketpy/interpreter/frame.h +++ b/include/pocketpy/interpreter/frame.h @@ -11,12 +11,9 @@ typedef struct ValueStack { py_TValue* sp; py_TValue* end; // We allocate extra places to keep `_sp` valid to detect stack overflow - py_TValue begin[PK_VM_STACK_SIZE + PK_MAX_CO_VARNAMES * 2]; + py_TValue begin[PK_VM_STACK_SIZE + PK_MAX_CO_VARNAMES]; } ValueStack; -void ValueStack__ctor(ValueStack* self); -void ValueStack__dtor(ValueStack* self); - typedef struct UnwindTarget { struct UnwindTarget* next; int iblock; diff --git a/src/interpreter/frame.c b/src/interpreter/frame.c index 2c7eccb5..6a70054c 100644 --- a/src/interpreter/frame.c +++ b/src/interpreter/frame.c @@ -7,12 +7,6 @@ #include #include -void ValueStack__ctor(ValueStack* self) { - self->sp = self->begin; - self->end = self->begin + PK_VM_STACK_SIZE; -} - -void ValueStack__dtor(ValueStack* self) { self->sp = self->begin; } void FastLocals__to_dict(py_TValue* locals, const CodeObject* co) { py_StackRef dict = py_pushtmp(); diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c index eb5109a6..bc9f5979 100644 --- a/src/interpreter/vm.c +++ b/src/interpreter/vm.c @@ -110,7 +110,8 @@ void VM__ctor(VM* self) { FixedMemoryPool__ctor(&self->pool_frame, sizeof(py_Frame), 32); ManagedHeap__ctor(&self->heap); - ValueStack__ctor(&self->stack); + self->stack.sp = self->stack.begin; + self->stack.end = self->stack.begin + PK_VM_STACK_SIZE; CachedNames__ctor(&self->cached_names); NameDict__ctor(&self->compile_time_funcs, PK_TYPE_ATTR_LOAD_FACTOR); @@ -288,11 +289,11 @@ void VM__dtor(VM* self) { // destroy all objects ManagedHeap__dtor(&self->heap); // clear frames - while(self->top_frame) + while(self->top_frame) { VM__pop_frame(self); + } BinTree__dtor(&self->modules); FixedMemoryPool__dtor(&self->pool_frame); - ValueStack__dtor(&self->stack); CachedNames__dtor(&self->cached_names); NameDict__dtor(&self->compile_time_funcs); c11_vector__dtor(&self->types);