mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
...
This commit is contained in:
parent
b4f684ff31
commit
a24202989c
@ -125,8 +125,8 @@ bool pkpy_clear_error(pkpy_vm* vm_handle, char** message) {
|
||||
}
|
||||
|
||||
void gc_marker_ex(CVM* vm) {
|
||||
for(PyObject* obj: *vm->c_data) if(obj!=nullptr) OBJ_MARK(obj);
|
||||
if(vm->error != nullptr) OBJ_MARK(vm->error);
|
||||
for(PyObject* obj: *vm->c_data) if(obj!=nullptr) PK_OBJ_MARK(obj);
|
||||
if(vm->error != nullptr) PK_OBJ_MARK(vm->error);
|
||||
}
|
||||
|
||||
static OutputHandler stdout_handler = nullptr;
|
||||
|
@ -161,7 +161,7 @@ struct CodeObject {
|
||||
std::vector<FuncDecl_> func_decls;
|
||||
|
||||
void _gc_mark() const {
|
||||
for(PyObject* v : consts) OBJ_MARK(v);
|
||||
for(PyObject* v : consts) PK_OBJ_MARK(v);
|
||||
for(auto& decl: func_decls) decl->_gc_mark();
|
||||
}
|
||||
|
||||
|
@ -142,8 +142,8 @@ struct Dict{
|
||||
void _gc_mark() const{
|
||||
for(int i=0; i<_capacity; i++){
|
||||
if(_items[i].first == nullptr) continue;
|
||||
OBJ_MARK(_items[i].first);
|
||||
OBJ_MARK(_items[i].second);
|
||||
PK_OBJ_MARK(_items[i].first);
|
||||
PK_OBJ_MARK(_items[i].second);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -194,7 +194,7 @@ struct Frame {
|
||||
}
|
||||
|
||||
void _gc_mark() const {
|
||||
OBJ_MARK(_module);
|
||||
PK_OBJ_MARK(_module);
|
||||
co->_gc_mark();
|
||||
}
|
||||
};
|
||||
|
2
src/gc.h
2
src/gc.h
@ -128,7 +128,7 @@ struct ManagedHeap{
|
||||
|
||||
inline void FuncDecl::_gc_mark() const{
|
||||
code->_gc_mark();
|
||||
for(int i=0; i<kwargs.size(); i++) OBJ_MARK(kwargs[i].value);
|
||||
for(int i=0; i<kwargs.size(); i++) PK_OBJ_MARK(kwargs[i].value);
|
||||
}
|
||||
|
||||
} // namespace pkpy
|
||||
|
@ -36,7 +36,7 @@ struct ArrayIter{
|
||||
ArrayIter(PyObject* ref, PyObject** begin, PyObject** end)
|
||||
: ref(ref), begin(begin), end(end), current(begin) {}
|
||||
|
||||
void _gc_mark() const{ OBJ_MARK(ref); }
|
||||
void _gc_mark() const{ PK_OBJ_MARK(ref); }
|
||||
|
||||
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
||||
vm->_all_types[PK_OBJ_GET(Type, type)].subclass_enabled = false;
|
||||
@ -58,7 +58,7 @@ struct StringIter{
|
||||
|
||||
StringIter(PyObject* ref) : ref(ref), str(&PK_OBJ_GET(Str, ref)), index(0) {}
|
||||
|
||||
void _gc_mark() const{ OBJ_MARK(ref); }
|
||||
void _gc_mark() const{ PK_OBJ_MARK(ref); }
|
||||
|
||||
static void _register(VM* vm, PyObject* mod, PyObject* type){
|
||||
vm->_all_types[PK_OBJ_GET(Type, type)].subclass_enabled = false;
|
||||
@ -85,7 +85,7 @@ struct Generator{
|
||||
|
||||
void _gc_mark() const{
|
||||
frame._gc_mark();
|
||||
for(PyObject* obj: s_backup) OBJ_MARK(obj);
|
||||
for(PyObject* obj: s_backup) PK_OBJ_MARK(obj);
|
||||
}
|
||||
|
||||
PyObject* next(VM* vm){
|
||||
|
@ -168,6 +168,12 @@ struct MemoryPool{
|
||||
}
|
||||
};
|
||||
|
||||
MemoryPool() = default;
|
||||
MemoryPool(const MemoryPool&) = delete;
|
||||
MemoryPool& operator=(const MemoryPool&) = delete;
|
||||
MemoryPool(MemoryPool&&) = delete;
|
||||
MemoryPool& operator=(MemoryPool&&) = delete;
|
||||
|
||||
DoubleLinkedList<Arena> _arenas;
|
||||
DoubleLinkedList<Arena> _empty_arenas;
|
||||
|
||||
|
30
src/obj.h
30
src/obj.h
@ -201,7 +201,7 @@ struct MappingProxy{
|
||||
|
||||
#define PK_OBJ_GET(T, obj) (((Py_<T>*)(obj))->_value)
|
||||
|
||||
#define OBJ_MARK(obj) \
|
||||
#define PK_OBJ_MARK(obj) \
|
||||
if(!is_tagged(obj) && !(obj)->gc.marked) { \
|
||||
(obj)->gc.marked = true; \
|
||||
(obj)->_obj_gc_mark(); \
|
||||
@ -212,7 +212,7 @@ inline void gc_mark_namedict(NameDict& t){
|
||||
if(t.size() == 0) return;
|
||||
for(uint16_t i=0; i<t._capacity; i++){
|
||||
if(t._items[i].first.empty()) continue;
|
||||
OBJ_MARK(t._items[i].second);
|
||||
PK_OBJ_MARK(t._items[i].second);
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,7 +308,7 @@ struct Py_<List> final: PyObject {
|
||||
Py_(Type type, const List& val): PyObject(type), _value(val) {}
|
||||
|
||||
void _obj_gc_mark() override {
|
||||
for(PyObject* obj: _value) OBJ_MARK(obj);
|
||||
for(PyObject* obj: _value) PK_OBJ_MARK(obj);
|
||||
}
|
||||
};
|
||||
|
||||
@ -319,7 +319,7 @@ struct Py_<Tuple> final: PyObject {
|
||||
Py_(Type type, const Tuple& val): PyObject(type), _value(val) {}
|
||||
|
||||
void _obj_gc_mark() override {
|
||||
for(PyObject* obj: _value) OBJ_MARK(obj);
|
||||
for(PyObject* obj: _value) PK_OBJ_MARK(obj);
|
||||
}
|
||||
};
|
||||
|
||||
@ -328,7 +328,7 @@ struct Py_<MappingProxy> final: PyObject {
|
||||
MappingProxy _value;
|
||||
Py_(Type type, MappingProxy val): PyObject(type), _value(val) {}
|
||||
void _obj_gc_mark() override {
|
||||
OBJ_MARK(_value.obj);
|
||||
PK_OBJ_MARK(_value.obj);
|
||||
}
|
||||
};
|
||||
|
||||
@ -337,8 +337,8 @@ struct Py_<BoundMethod> final: PyObject {
|
||||
BoundMethod _value;
|
||||
Py_(Type type, BoundMethod val): PyObject(type), _value(val) {}
|
||||
void _obj_gc_mark() override {
|
||||
OBJ_MARK(_value.self);
|
||||
OBJ_MARK(_value.func);
|
||||
PK_OBJ_MARK(_value.self);
|
||||
PK_OBJ_MARK(_value.func);
|
||||
}
|
||||
};
|
||||
|
||||
@ -347,7 +347,7 @@ struct Py_<StarWrapper> final: PyObject {
|
||||
StarWrapper _value;
|
||||
Py_(Type type, StarWrapper val): PyObject(type), _value(val) {}
|
||||
void _obj_gc_mark() override {
|
||||
OBJ_MARK(_value.obj);
|
||||
PK_OBJ_MARK(_value.obj);
|
||||
}
|
||||
};
|
||||
|
||||
@ -356,8 +356,8 @@ struct Py_<Property> final: PyObject {
|
||||
Property _value;
|
||||
Py_(Type type, Property val): PyObject(type), _value(val) {}
|
||||
void _obj_gc_mark() override {
|
||||
OBJ_MARK(_value.getter);
|
||||
OBJ_MARK(_value.setter);
|
||||
PK_OBJ_MARK(_value.getter);
|
||||
PK_OBJ_MARK(_value.setter);
|
||||
}
|
||||
};
|
||||
|
||||
@ -366,9 +366,9 @@ struct Py_<Slice> final: PyObject {
|
||||
Slice _value;
|
||||
Py_(Type type, Slice val): PyObject(type), _value(val) {}
|
||||
void _obj_gc_mark() override {
|
||||
OBJ_MARK(_value.start);
|
||||
OBJ_MARK(_value.stop);
|
||||
OBJ_MARK(_value.step);
|
||||
PK_OBJ_MARK(_value.start);
|
||||
PK_OBJ_MARK(_value.stop);
|
||||
PK_OBJ_MARK(_value.step);
|
||||
}
|
||||
};
|
||||
|
||||
@ -380,7 +380,7 @@ struct Py_<Function> final: PyObject {
|
||||
}
|
||||
void _obj_gc_mark() override {
|
||||
_value.decl->_gc_mark();
|
||||
if(_value._module != nullptr) OBJ_MARK(_value._module);
|
||||
if(_value._module != nullptr) PK_OBJ_MARK(_value._module);
|
||||
if(_value._closure != nullptr) gc_mark_namedict(*_value._closure);
|
||||
}
|
||||
};
|
||||
@ -399,7 +399,7 @@ struct Py_<Super> final: PyObject {
|
||||
Super _value;
|
||||
Py_(Type type, Super val): PyObject(type), _value(val) {}
|
||||
void _obj_gc_mark() override {
|
||||
OBJ_MARK(_value.first);
|
||||
PK_OBJ_MARK(_value.first);
|
||||
}
|
||||
};
|
||||
|
||||
|
6
src/vm.h
6
src/vm.h
@ -1529,11 +1529,11 @@ inline void VM::_error(Exception e){
|
||||
}
|
||||
|
||||
inline void ManagedHeap::mark() {
|
||||
for(PyObject* obj: _no_gc) OBJ_MARK(obj);
|
||||
for(PyObject* obj: _no_gc) PK_OBJ_MARK(obj);
|
||||
for(auto& frame : vm->callstack.data()) frame._gc_mark();
|
||||
for(PyObject* obj: vm->s_data) OBJ_MARK(obj);
|
||||
for(PyObject* obj: vm->s_data) PK_OBJ_MARK(obj);
|
||||
if(_gc_marker_ex) _gc_marker_ex(vm);
|
||||
if(vm->_last_exception) OBJ_MARK(vm->_last_exception);
|
||||
if(vm->_last_exception) PK_OBJ_MARK(vm->_last_exception);
|
||||
}
|
||||
|
||||
inline Str obj_type_name(VM *vm, Type type){
|
||||
|
Loading…
x
Reference in New Issue
Block a user