This commit is contained in:
blueloveTH 2024-05-13 02:20:11 +08:00
parent 47463290a6
commit bf481b84dc
6 changed files with 12 additions and 10 deletions

View File

@ -42,7 +42,7 @@ struct ManagedHeap{
PyVar gcnew(Type type, Args&&... args){
using __T = Py_<std::decay_t<T>>;
// 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);
gen.push_back(obj);
gc_counter++;
@ -53,7 +53,7 @@ struct ManagedHeap{
PyVar _new(Type type, Args&&... args){
using __T = Py_<std::decay_t<T>>;
// 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);
obj->gc_enabled = false;
_no_gc.push_back(obj);

View File

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

View File

@ -14,7 +14,7 @@ namespace pkpy{
#endif
if(_gc_on_delete) _gc_on_delete(vm, obj);
obj->~PyObject();
pool64_dealloc(obj.get());
pool128_dealloc(obj.get());
}
}
@ -55,8 +55,8 @@ namespace pkpy{
}
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()); }
}

View File

@ -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_type), "__base__", [](VM* vm, ArgsView args){
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){
const PyTypeInfo& info = vm->_all_types[PK_OBJ_GET(Type, args[0])];

View File

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

View File

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