blueloveTH 1 vuosi sitten
vanhempi
commit
bf481b84dc
6 muutettua tiedostoa jossa 12 lisäystä ja 10 poistoa
  1. 2 2
      include/pocketpy/gc.h
  2. 3 1
      include/pocketpy/tuplelist.h
  3. 3 3
      src/gc.cpp
  4. 1 1
      src/pocketpy.cpp
  5. 1 1
      src/tuplelist.cpp
  6. 2 2
      src/vm.cpp

+ 2 - 2
include/pocketpy/gc.h

@@ -42,7 +42,7 @@ struct ManagedHeap{
     PyVar gcnew(Type type, Args&&... args){
     PyVar gcnew(Type type, Args&&... args){
         using __T = Py_<std::decay_t<T>>;
         using __T = Py_<std::decay_t<T>>;
         // https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476
         // https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476
-        PyObject* p = new(pool64_alloc<__T>()) Py_<std::decay_t<T>>(std::forward<Args>(args)...);
+        PyObject* p = new(pool128_alloc<__T>()) Py_<std::decay_t<T>>(std::forward<Args>(args)...);
         PyVar obj(type, p);
         PyVar obj(type, p);
         gen.push_back(obj);
         gen.push_back(obj);
         gc_counter++;
         gc_counter++;
@@ -53,7 +53,7 @@ struct ManagedHeap{
     PyVar _new(Type type, Args&&... args){
     PyVar _new(Type type, Args&&... args){
         using __T = Py_<std::decay_t<T>>;
         using __T = Py_<std::decay_t<T>>;
         // https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476
         // https://github.com/pocketpy/pocketpy/issues/94#issuecomment-1594784476
-        PyObject* p = new(pool64_alloc<__T>()) Py_<std::decay_t<T>>(std::forward<Args>(args)...);
+        PyObject* p = new(pool128_alloc<__T>()) Py_<std::decay_t<T>>(std::forward<Args>(args)...);
         PyVar obj(type, p);
         PyVar obj(type, p);
         obj->gc_enabled = false;
         obj->gc_enabled = false;
         _no_gc.push_back(obj);
         _no_gc.push_back(obj);

+ 3 - 1
include/pocketpy/tuplelist.h

@@ -10,8 +10,10 @@ namespace pkpy {
 using List = pod_vector<PyVar, 4>;
 using List = pod_vector<PyVar, 4>;
 
 
 struct Tuple {
 struct Tuple {
+    static const int INLINED_SIZE = 4;
+
     PyVar* _args;
     PyVar* _args;
-    PyVar _inlined[4];
+    PyVar _inlined[INLINED_SIZE];
     int _size;
     int _size;
 
 
     Tuple(int n);
     Tuple(int n);

+ 3 - 3
src/gc.cpp

@@ -14,7 +14,7 @@ namespace pkpy{
 #endif
 #endif
                 if(_gc_on_delete) _gc_on_delete(vm, obj);
                 if(_gc_on_delete) _gc_on_delete(vm, obj);
                 obj->~PyObject();
                 obj->~PyObject();
-                pool64_dealloc(obj.get());
+                pool128_dealloc(obj.get());
             }
             }
         }
         }
 
 
@@ -55,8 +55,8 @@ namespace pkpy{
     }
     }
 
 
     ManagedHeap::~ManagedHeap(){
     ManagedHeap::~ManagedHeap(){
-        for(PyVar obj: _no_gc) { obj->~PyObject(); pool64_dealloc(obj.get()); }
-        for(PyVar obj: gen) { obj->~PyObject(); pool64_dealloc(obj.get()); }
+        for(PyVar obj: _no_gc) { obj->~PyObject(); pool128_dealloc(obj.get()); }
+        for(PyVar obj: gen) { obj->~PyObject(); pool128_dealloc(obj.get()); }
     }
     }
 
 
 
 

+ 1 - 1
src/pocketpy.cpp

@@ -1530,7 +1530,7 @@ void VM::__post_init_builtin_types(){
     bind_property(_t(tp_object), "__class__", PK_LAMBDA(vm->_t(args[0])));
     bind_property(_t(tp_object), "__class__", PK_LAMBDA(vm->_t(args[0])));
     bind_property(_t(tp_type), "__base__", [](VM* vm, ArgsView args){
     bind_property(_t(tp_type), "__base__", [](VM* vm, ArgsView args){
         const PyTypeInfo& info = vm->_all_types[PK_OBJ_GET(Type, args[0])];
         const PyTypeInfo& info = vm->_all_types[PK_OBJ_GET(Type, args[0])];
-        return info.base.index == -1 ? vm->None : vm->_all_types[info.base].obj;
+        return info.base ? vm->_all_types[info.base].obj : vm->None;
     });
     });
     bind_property(_t(tp_type), "__name__", [](VM* vm, ArgsView args){
     bind_property(_t(tp_type), "__name__", [](VM* vm, ArgsView args){
         const PyTypeInfo& info = vm->_all_types[PK_OBJ_GET(Type, args[0])];
         const PyTypeInfo& info = vm->_all_types[PK_OBJ_GET(Type, args[0])];

+ 1 - 1
src/tuplelist.cpp

@@ -3,7 +3,7 @@
 namespace pkpy {
 namespace pkpy {
 
 
 Tuple::Tuple(int n){
 Tuple::Tuple(int n){
-    if(n <= 3){
+    if(n <= INLINED_SIZE){
         this->_args = _inlined;
         this->_args = _inlined;
     }else{
     }else{
         this->_args = (PyVar*)pool128_alloc(n * sizeof(void*));
         this->_args = (PyVar*)pool128_alloc(n * sizeof(void*));

+ 2 - 2
src/vm.cpp

@@ -149,7 +149,7 @@ namespace pkpy{
             val = _t(cls)->attr().try_get(name);
             val = _t(cls)->attr().try_get(name);
             if(val != nullptr) return val;
             if(val != nullptr) return val;
             cls = _all_types[cls].base;
             cls = _all_types[cls].base;
-            if(cls.index == -1) break;
+            if(!cls) break;
         }while(true);
         }while(true);
         return nullptr;
         return nullptr;
     }
     }
@@ -162,7 +162,7 @@ namespace pkpy{
         do{
         do{
             if(cls == base) return true;
             if(cls == base) return true;
             Type next = _all_types[cls].base;
             Type next = _all_types[cls].base;
-            if(next.index == -1) break;
+            if(!next) break;
             cls = next;
             cls = next;
         }while(true);
         }while(true);
         return false;
         return false;