blueloveTH 1 год назад
Родитель
Сommit
4e9072165b

+ 5 - 5
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);

+ 0 - 2
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

+ 13 - 0
src/interpreter/vm.cpp

@@ -1,5 +1,6 @@
 #include "pocketpy/interpreter/vm.hpp"
 #include "pocketpy/common/memorypool.h"
+#include "pocketpy/objects/base.h"
 
 #include <iostream>
 #include <cmath>
@@ -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;

+ 0 - 13
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};