mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 03:50:16 +00:00
...
This commit is contained in:
parent
e384407494
commit
084725e2b3
11
src/iter.h
11
src/iter.h
@ -41,7 +41,7 @@ public:
|
|||||||
return array->operator[](index++);
|
return array->operator[](index++);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _gc_mark() const override {
|
void _gc_mark() const{
|
||||||
OBJ_MARK(ref);
|
OBJ_MARK(ref);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -60,7 +60,7 @@ public:
|
|||||||
return VAR(str->u8_getitem(index++));
|
return VAR(str->u8_getitem(index++));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _gc_mark() const override {
|
void _gc_mark() const{
|
||||||
OBJ_MARK(ref);
|
OBJ_MARK(ref);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -95,11 +95,4 @@ inline void Generator::_gc_mark() const{
|
|||||||
for(PyObject* obj: s_backup) OBJ_MARK(obj);
|
for(PyObject* obj: s_backup) OBJ_MARK(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void gc_mark(T& t) {
|
|
||||||
if constexpr(std::is_base_of_v<BaseIter, T>){
|
|
||||||
t._gc_mark();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace pkpy
|
} // namespace pkpy
|
11
src/obj.h
11
src/obj.h
@ -93,7 +93,6 @@ protected:
|
|||||||
VM* vm;
|
VM* vm;
|
||||||
public:
|
public:
|
||||||
BaseIter(VM* vm) : vm(vm) {}
|
BaseIter(VM* vm) : vm(vm) {}
|
||||||
virtual void _gc_mark() const {}
|
|
||||||
virtual PyObject* next() = 0;
|
virtual PyObject* next() = 0;
|
||||||
virtual ~BaseIter() = default;
|
virtual ~BaseIter() = default;
|
||||||
};
|
};
|
||||||
@ -128,11 +127,18 @@ struct PyObject{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename, typename=void> struct has_gc_marker : std::false_type {};
|
||||||
|
template <typename T> struct has_gc_marker<T, std::void_t<decltype(&T::_gc_mark)>> : std::true_type {};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Py_ final: PyObject {
|
struct Py_ final: PyObject {
|
||||||
T _value;
|
T _value;
|
||||||
void* value() override { return &_value; }
|
void* value() override { return &_value; }
|
||||||
void _obj_gc_mark() override {}
|
void _obj_gc_mark() override {
|
||||||
|
if constexpr (has_gc_marker<T>::value) {
|
||||||
|
_value._gc_mark();
|
||||||
|
}
|
||||||
|
}
|
||||||
Py_(Type type, const T& value) : PyObject(type), _value(value) {}
|
Py_(Type type, const T& value) : PyObject(type), _value(value) {}
|
||||||
Py_(Type type, T&& value) : PyObject(type), _value(std::move(value)) {}
|
Py_(Type type, T&& value) : PyObject(type), _value(std::move(value)) {}
|
||||||
};
|
};
|
||||||
@ -140,7 +146,6 @@ struct Py_ final: PyObject {
|
|||||||
struct MappingProxy{
|
struct MappingProxy{
|
||||||
PyObject* obj;
|
PyObject* obj;
|
||||||
MappingProxy(PyObject* obj) : obj(obj) {}
|
MappingProxy(PyObject* obj) : obj(obj) {}
|
||||||
|
|
||||||
NameDict& attr() noexcept { return obj->attr(); }
|
NameDict& attr() noexcept { return obj->attr(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user