mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
some fix
This commit is contained in:
parent
857b798172
commit
c89c7bd1ac
@ -33,7 +33,6 @@ PyObject* pk_ManagedHeap__gcnew(pk_ManagedHeap* self, Type type, int size);
|
||||
|
||||
// external implementation
|
||||
void pk_ManagedHeap__mark(pk_ManagedHeap* self);
|
||||
void pk_ManagedHeap__delete_obj(pk_ManagedHeap* self, PyObject* obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -21,12 +21,8 @@ static_assert(sizeof(PyObject) <= 16, "!(sizeof(PyObject) <= 16)");
|
||||
#define PK_OBJ_GET(T, val) (*(T*)(PyObject__value_ptr((val)._obj)))
|
||||
#define PK_OBJ_SIZEOF(T) (sizeof(T) + 16)
|
||||
|
||||
PK_INLINE void PyObject__ctor(PyObject* self, Type type, bool gc_is_large){
|
||||
self->type = type;
|
||||
self->gc_is_large = gc_is_large;
|
||||
self->gc_marked = false;
|
||||
self->dict = NULL;
|
||||
}
|
||||
PyObject* PyObject__new(Type type, int size);
|
||||
void PyObject__delete(PyObject* self);
|
||||
|
||||
PK_INLINE PyVar PyVar__fromobj(PyObject* obj){
|
||||
PyVar retval = {
|
||||
|
@ -10,7 +10,7 @@ typedef struct PyVar PyVar;
|
||||
typedef struct pk_VM pk_VM;
|
||||
typedef struct py_Error py_Error;
|
||||
|
||||
typedef unsigned (*py_CFunction)(const PyVar*, int);
|
||||
typedef int (*py_CFunction)(const PyVar*, int);
|
||||
|
||||
extern pk_VM* pk_vm;
|
||||
|
||||
|
@ -17,11 +17,11 @@ void pk_ManagedHeap__ctor(pk_ManagedHeap *self, pk_VM *vm){
|
||||
void pk_ManagedHeap__dtor(pk_ManagedHeap *self){
|
||||
for(int i = 0; i < self->gen.count; i++){
|
||||
PyObject* obj = c11__getitem(PyObject*, &self->gen, i);
|
||||
pk_ManagedHeap__delete_obj(self, obj);
|
||||
PyObject__delete(obj);
|
||||
}
|
||||
for(int i = 0; i < self->no_gc.count; i++){
|
||||
PyObject* obj = c11__getitem(PyObject*, &self->no_gc, i);
|
||||
pk_ManagedHeap__delete_obj(self, obj);
|
||||
PyObject__delete(obj);
|
||||
}
|
||||
c11_vector__dtor(&self->no_gc);
|
||||
c11_vector__dtor(&self->gen);
|
||||
@ -67,7 +67,7 @@ int pk_ManagedHeap__sweep(pk_ManagedHeap *self){
|
||||
if(self->_gc_on_delete){
|
||||
self->_gc_on_delete(self->vm, obj);
|
||||
}
|
||||
pk_ManagedHeap__delete_obj(self, obj);
|
||||
PyObject__delete(obj);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,29 +89,29 @@ int pk_ManagedHeap__sweep(pk_ManagedHeap *self){
|
||||
}
|
||||
|
||||
PyObject* pk_ManagedHeap__new(pk_ManagedHeap *self, Type type, int size){
|
||||
PyObject* obj;
|
||||
if(size <= kPoolObjectBlockSize){
|
||||
obj = PoolObject_alloc();
|
||||
PyObject__ctor(obj, type, false);
|
||||
}else{
|
||||
obj = malloc(size);
|
||||
PyObject__ctor(obj, type, true);
|
||||
}
|
||||
PyObject* obj = PyObject__new(type, size);
|
||||
c11_vector__push(PyObject*, &self->no_gc, obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
PyObject* pk_ManagedHeap__gcnew(pk_ManagedHeap *self, Type type, int size){
|
||||
PyObject* obj;
|
||||
if(size <= kPoolObjectBlockSize){
|
||||
obj = PoolObject_alloc();
|
||||
PyObject__ctor(obj, type, false);
|
||||
}else{
|
||||
obj = malloc(size);
|
||||
PyObject__ctor(obj, type, true);
|
||||
}
|
||||
PyObject* obj = PyObject__new(type, size);
|
||||
c11_vector__push(PyObject*, &self->gen, obj);
|
||||
self->gc_counter++;
|
||||
return obj;
|
||||
}
|
||||
|
||||
PyObject* PyObject__new(Type type, int size){
|
||||
PyObject* self;
|
||||
if(size <= kPoolObjectBlockSize){
|
||||
self = PoolObject_alloc();
|
||||
self->gc_is_large = false;
|
||||
}else{
|
||||
self = malloc(size);
|
||||
self->gc_is_large = true;
|
||||
}
|
||||
self->type = type;
|
||||
self->gc_marked = false;
|
||||
self->dict = NULL;
|
||||
return self;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "pocketpy/interpreter/vm.h"
|
||||
#include "pocketpy/common/memorypool.h"
|
||||
|
||||
static unsigned char* pk_default_import_file(pk_VM* vm, const char* path){
|
||||
return NULL;
|
||||
@ -161,3 +162,30 @@ Type pk_VM__new_type(pk_VM* self, const char* name, Type base, PyObject* module,
|
||||
pk_TypeInfo__ctor(ti, pk_StrName__map(name), base, typeobj, module, subclass_enabled);
|
||||
return type;
|
||||
}
|
||||
|
||||
/****************************************/
|
||||
void PyObject__delete(PyObject *self){
|
||||
pk_TypeInfo* ti = c11__getitem(pk_TypeInfo*, &pk_vm->types, self->type);
|
||||
if(ti->dtor) ti->dtor(PyObject__value_ptr(self));
|
||||
if(self->dict) pk_NameDict__delete(self->dict);
|
||||
if(self->gc_is_large){
|
||||
free(self);
|
||||
}else{
|
||||
PoolObject_dealloc(self);
|
||||
}
|
||||
}
|
||||
|
||||
void pk_ManagedHeap__mark(pk_ManagedHeap* self){
|
||||
// for(int i=0; i<self->no_gc.count; i++){
|
||||
// PyObject* obj = c11__getitem(PyObject*, &self->no_gc, i);
|
||||
// vm->__obj_gc_mark(obj);
|
||||
// }
|
||||
// vm->callstack.apply([vm](Frame& frame) {
|
||||
// frame._gc_mark(vm);
|
||||
// });
|
||||
// vm->obj_gc_mark(vm->__last_exception);
|
||||
// vm->obj_gc_mark(vm->__curr_class);
|
||||
// vm->obj_gc_mark(vm->__c.error);
|
||||
// vm->__stack_gc_mark(vm->s_data.begin(), vm->s_data.end());
|
||||
// if(self->_gc_marker_ex) self->_gc_marker_ex((pkpy_VM*)vm);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user