mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-24 13:30:18 +00:00
some fix
This commit is contained in:
parent
e7aababa36
commit
62df3c9b5d
@ -8,11 +8,6 @@ namespace pkpy{
|
|||||||
void* pool128_alloc(size_t) noexcept;
|
void* pool128_alloc(size_t) noexcept;
|
||||||
void pool128_dealloc(void*) noexcept;
|
void pool128_dealloc(void*) noexcept;
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void* pool128_alloc() noexcept{
|
|
||||||
return pool128_alloc(sizeof(T));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pools_shrink_to_fit() noexcept;
|
void pools_shrink_to_fit() noexcept;
|
||||||
|
|
||||||
std::string pool64_info() noexcept;
|
std::string pool64_info() noexcept;
|
||||||
|
|||||||
@ -147,7 +147,7 @@ struct CallStack{
|
|||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void emplace(Args&&... args){
|
void emplace(Args&&... args){
|
||||||
_tail = new(pool128_alloc<LinkedFrame>()) LinkedFrame(_tail, std::forward<Args>(args)...);
|
_tail = new(pool128_alloc(sizeof(LinkedFrame))) LinkedFrame(_tail, std::forward<Args>(args)...);
|
||||||
++_size;
|
++_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,20 +42,13 @@ struct PyObject final{
|
|||||||
|
|
||||||
// backdoor for important builtin types
|
// backdoor for important builtin types
|
||||||
if constexpr(std::is_same_v<T, DummyInstance>){
|
if constexpr(std::is_same_v<T, DummyInstance>){
|
||||||
_enable_instance_dict();
|
_attr = new NameDict();
|
||||||
}else if constexpr(std::is_same_v<T, Type>){
|
}else if constexpr(std::is_same_v<T, Type>){
|
||||||
_enable_instance_dict(PK_TYPE_ATTR_LOAD_FACTOR);
|
_attr = new NameDict(PK_TYPE_ATTR_LOAD_FACTOR);
|
||||||
}else if constexpr(std::is_same_v<T, DummyModule>){
|
}else if constexpr(std::is_same_v<T, DummyModule>){
|
||||||
_enable_instance_dict(PK_TYPE_ATTR_LOAD_FACTOR);
|
_attr = new NameDict(PK_TYPE_ATTR_LOAD_FACTOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _enable_instance_dict() {
|
|
||||||
_attr = new(pool128_alloc<NameDict>()) NameDict();
|
|
||||||
}
|
|
||||||
void _enable_instance_dict(float lf){
|
|
||||||
_attr = new(pool128_alloc<NameDict>()) NameDict(lf);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(sizeof(PyObject) <= 16);
|
static_assert(sizeof(PyObject) <= 16);
|
||||||
|
|||||||
@ -584,7 +584,7 @@ PyVar VM::__py_exec_internal(const CodeObject_& code, PyVar globals, PyVar local
|
|||||||
check_compatible_type(globals, VM::tp_dict);
|
check_compatible_type(globals, VM::tp_dict);
|
||||||
// make a temporary object and copy globals into it
|
// make a temporary object and copy globals into it
|
||||||
globals_obj = new_object<DummyInstance>(VM::tp_object).get();
|
globals_obj = new_object<DummyInstance>(VM::tp_object).get();
|
||||||
globals_obj->_enable_instance_dict();
|
globals_obj->_attr = new NameDict();
|
||||||
globals_dict = &PK_OBJ_GET(Dict, globals);
|
globals_dict = &PK_OBJ_GET(Dict, globals);
|
||||||
globals_dict->apply([&](PyVar k, PyVar v){
|
globals_dict->apply([&](PyVar k, PyVar v){
|
||||||
globals_obj->attr().set(CAST(Str&, k), v);
|
globals_obj->attr().set(CAST(Str&, k), v);
|
||||||
@ -1877,10 +1877,7 @@ void ManagedHeap::mark() {
|
|||||||
void ManagedHeap::_delete(PyObject* obj){
|
void ManagedHeap::_delete(PyObject* obj){
|
||||||
const PyTypeInfo* ti = vm->_tp_info(obj->type);
|
const PyTypeInfo* ti = vm->_tp_info(obj->type);
|
||||||
if(ti->vt._dtor) ti->vt._dtor(obj->_value_ptr());
|
if(ti->vt._dtor) ti->vt._dtor(obj->_value_ptr());
|
||||||
if(obj->_attr){
|
delete obj->_attr; // delete __dict__ if exists
|
||||||
obj->_attr->~NameDict();
|
|
||||||
pool128_dealloc(obj->_attr);
|
|
||||||
}
|
|
||||||
pool128_dealloc(obj);
|
pool128_dealloc(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -272,7 +272,7 @@ void add_module___builtins(VM* vm){
|
|||||||
PyVar self = args[0];
|
PyVar self = args[0];
|
||||||
if(is_tagged(self)) vm->TypeError("object: tagged object cannot enable instance dict");
|
if(is_tagged(self)) vm->TypeError("object: tagged object cannot enable instance dict");
|
||||||
if(self->is_attr_valid()) vm->RuntimeError("object: instance dict is already enabled");
|
if(self->is_attr_valid()) vm->RuntimeError("object: instance dict is already enabled");
|
||||||
self->_enable_instance_dict();
|
self->_attr = new NameDict();
|
||||||
return vm->None;
|
return vm->None;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1517,7 +1517,7 @@ void __init_builtins(VM* _vm) {
|
|||||||
Type cls = PK_OBJ_GET(Type, args[0]);
|
Type cls = PK_OBJ_GET(Type, args[0]);
|
||||||
StrName cls_name = _type_name(vm, cls);
|
StrName cls_name = _type_name(vm, cls);
|
||||||
PyObject* e_obj = vm->heap.gcnew<Exception>(cls, cls_name);
|
PyObject* e_obj = vm->heap.gcnew<Exception>(cls, cls_name);
|
||||||
e_obj->_enable_instance_dict();
|
e_obj->_attr = new NameDict();
|
||||||
e_obj->as<Exception>()._self = e_obj;
|
e_obj->as<Exception>()._self = e_obj;
|
||||||
return e_obj;
|
return e_obj;
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user