diff --git a/include/pocketpy/interpreter/vm.hpp b/include/pocketpy/interpreter/vm.hpp index d2b5d1a8..ddea3931 100644 --- a/include/pocketpy/interpreter/vm.hpp +++ b/include/pocketpy/interpreter/vm.hpp @@ -218,11 +218,11 @@ public: constexpr static Type tp_none_type = Type(kTpNoneTypeIndex), tp_not_implemented_type = Type(kTpNotImplementedTypeIndex); constexpr static Type tp_ellipsis = Type(26); - inline static PyVar True = pkpy_True; - inline static PyVar False = pkpy_False; - inline static PyVar None = pkpy_None; - inline static PyVar NotImplemented = pkpy_NotImplemented; - inline static PyVar Ellipsis = pkpy_Ellipsis; + PyVar True; + PyVar False; + PyVar None; + PyVar NotImplemented; + PyVar Ellipsis; const bool enable_os; VM(bool enable_os = true); diff --git a/include/pocketpy/objects/base.h b/include/pocketpy/objects/base.h index 18024469..5b6b36df 100644 --- a/include/pocketpy/objects/base.h +++ b/include/pocketpy/objects/base.h @@ -74,8 +74,6 @@ PK_INLINE bool PyVar__IS_OP(const PyVar* a, const PyVar* b){ bool pkpy_Var__eq__(void *vm, PyVar a, PyVar b); int64_t pkpy_Var__hash__(void *vm, PyVar a); -extern PyVar pkpy_True, pkpy_False, pkpy_None; -extern PyVar pkpy_NotImplemented, pkpy_Ellipsis; extern PyVar pkpy_NULL, pkpy_OP_CALL, pkpy_OP_YIELD; #ifdef __cplusplus diff --git a/src/interpreter/vm.cpp b/src/interpreter/vm.cpp index 7e8b1232..ad81fdfc 100644 --- a/src/interpreter/vm.cpp +++ b/src/interpreter/vm.cpp @@ -1,5 +1,6 @@ #include "pocketpy/interpreter/vm.hpp" #include "pocketpy/common/memorypool.h" +#include "pocketpy/objects/base.h" #include #include @@ -84,6 +85,18 @@ struct JsonSerializer { VM::VM(bool enable_os) : heap(this), enable_os(enable_os) { Pools_initialize(); pkpy_StrName__initialize(); + static ::PyObject __true_obj = {.type=tp_bool, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; + static ::PyObject __false_obj = {.type=tp_bool, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; + static ::PyObject __none_obj = {.type=tp_none_type, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; + static ::PyObject __not_implemented_obj = {.type=tp_not_implemented_type, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; + static ::PyObject __ellipsis_obj = {.type=tp_ellipsis, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; + + /* Must be heap objects to support `==` and `is` and `is not` */ + this->True = (::PyVar){.type=tp_bool, .is_ptr=true, .extra=1, ._obj=&__true_obj}; + this->False = (::PyVar){.type=tp_bool, .is_ptr=true, .extra=0, ._obj=&__false_obj}; + this->None = (::PyVar){.type=tp_none_type, .is_ptr=true, ._obj=&__none_obj}; + this->NotImplemented = (::PyVar){.type=tp_not_implemented_type, .is_ptr=true, ._obj=&__not_implemented_obj}; + this->Ellipsis = (::PyVar){.type=tp_ellipsis, .is_ptr=true, ._obj=&__ellipsis_obj}; this->vm = this; this->__c.error = nullptr; diff --git a/src/objects/object.c b/src/objects/object.c index 302acd22..c6e8f25e 100644 --- a/src/objects/object.c +++ b/src/objects/object.c @@ -6,16 +6,3 @@ void PyVar__ctor3(PyVar* self, PyObject* existing){ self->is_ptr = true; self->_obj = existing; } - -static PyObject __true_obj = {.type=tp_bool, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; -static PyObject __false_obj = {.type=tp_bool, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; -static PyObject __none_obj = {.type=tp_none_type, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; -static PyObject __not_implemented_obj = {.type=tp_not_implemented_type, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; -static PyObject __ellipsis_obj = {.type=tp_ellipsis, .gc_is_large=false, .gc_marked=false, ._attr=NULL}; - -/* Must be heap objects to support `==` and `is` and `is not` */ -PyVar pkpy_True = {.type=tp_bool, .is_ptr=true, .extra=1, ._obj=&__true_obj}; -PyVar pkpy_False = {.type=tp_bool, .is_ptr=true, .extra=0, ._obj=&__false_obj}; -PyVar pkpy_None = {.type=tp_none_type, .is_ptr=true, ._obj=&__none_obj}; -PyVar pkpy_NotImplemented = {.type=tp_not_implemented_type, .is_ptr=true, ._obj=&__not_implemented_obj}; -PyVar pkpy_Ellipsis = {.type=tp_ellipsis, .is_ptr=true, ._obj=&__ellipsis_obj}; \ No newline at end of file