mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
rollback
This commit is contained in:
parent
6185bae227
commit
a8fef67dbd
90
src/frame.h
90
src/frame.h
@ -112,46 +112,60 @@ template<> inline void gc_mark<Function>(Function& t){
|
|||||||
t._closure._gc_mark();
|
t._closure._gc_mark();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ValueStack {
|
struct ValueStack: pod_vector<PyObject*> {
|
||||||
PyObject** _begin;
|
PyObject*& top(){ return back(); }
|
||||||
PyObject** _sp;
|
PyObject* top() const { return back(); }
|
||||||
|
PyObject*& second(){ return (*this)[size()-2]; }
|
||||||
ValueStack(int n=16): _begin((PyObject**)pool128.alloc(n * sizeof(void*))), _sp(_begin) { }
|
PyObject* second() const { return (*this)[size()-2]; }
|
||||||
|
PyObject*& peek(int n){ return (*this)[size()-n]; }
|
||||||
PyObject*& top(){ return _sp[-1]; }
|
PyObject* peek(int n) const { return (*this)[size()-n]; }
|
||||||
PyObject* top() const { return _sp[-1]; }
|
void push(PyObject* v){ push_back(v); }
|
||||||
PyObject*& second(){ return _sp[-2]; }
|
void pop(){ pop_back(); }
|
||||||
PyObject* second() const { return _sp[-2]; }
|
PyObject* popx(){ return popx_back(); }
|
||||||
PyObject*& peek(int n){ return _sp[-n]; }
|
ArgsView view(int n){ return ArgsView(end()-n, end()); }
|
||||||
PyObject* peek(int n) const { return _sp[-n]; }
|
void shrink(int n){ resize(size() - n); }
|
||||||
void push(PyObject* v){ *_sp++ = v; }
|
|
||||||
void pop(){ --_sp; }
|
|
||||||
PyObject* popx(){ return *--_sp; }
|
|
||||||
ArgsView view(int n){ return ArgsView(_sp-n, _sp); }
|
|
||||||
void shrink(int n){ _sp -= n; }
|
|
||||||
int size() const { return _sp - _begin; }
|
|
||||||
bool empty() const { return _sp == _begin; }
|
|
||||||
PyObject** begin() const { return _begin; }
|
|
||||||
PyObject** end() const { return _sp; }
|
|
||||||
void resize(int n) { _sp = _begin + n; }
|
|
||||||
|
|
||||||
ValueStack(ValueStack&& other) noexcept{
|
|
||||||
_begin = other._begin;
|
|
||||||
_sp = other._sp;
|
|
||||||
other._begin = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ValueStack& operator=(ValueStack&& other) noexcept{
|
|
||||||
if(_begin != nullptr) pool128.dealloc(_begin);
|
|
||||||
_begin = other._begin;
|
|
||||||
_sp = other._sp;
|
|
||||||
other._begin = nullptr;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
~ValueStack(){ if(_begin!=nullptr) pool128.dealloc(_begin); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// struct ValueStack {
|
||||||
|
// PyObject** _begin;
|
||||||
|
// PyObject** _sp;
|
||||||
|
|
||||||
|
// ValueStack(int n=16): _begin((PyObject**)pool128.alloc(n * sizeof(void*))), _sp(_begin) { }
|
||||||
|
|
||||||
|
// PyObject*& top(){ return _sp[-1]; }
|
||||||
|
// PyObject* top() const { return _sp[-1]; }
|
||||||
|
// PyObject*& second(){ return _sp[-2]; }
|
||||||
|
// PyObject* second() const { return _sp[-2]; }
|
||||||
|
// PyObject*& peek(int n){ return _sp[-n]; }
|
||||||
|
// PyObject* peek(int n) const { return _sp[-n]; }
|
||||||
|
// void push(PyObject* v){ *_sp++ = v; }
|
||||||
|
// void pop(){ --_sp; }
|
||||||
|
// PyObject* popx(){ return *--_sp; }
|
||||||
|
// ArgsView view(int n){ return ArgsView(_sp-n, _sp); }
|
||||||
|
// void shrink(int n){ _sp -= n; }
|
||||||
|
// int size() const { return _sp - _begin; }
|
||||||
|
// bool empty() const { return _sp == _begin; }
|
||||||
|
// PyObject** begin() const { return _begin; }
|
||||||
|
// PyObject** end() const { return _sp; }
|
||||||
|
// void resize(int n) { _sp = _begin + n; }
|
||||||
|
|
||||||
|
// ValueStack(ValueStack&& other) noexcept{
|
||||||
|
// _begin = other._begin;
|
||||||
|
// _sp = other._sp;
|
||||||
|
// other._begin = nullptr;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ValueStack& operator=(ValueStack&& other) noexcept{
|
||||||
|
// if(_begin != nullptr) pool128.dealloc(_begin);
|
||||||
|
// _begin = other._begin;
|
||||||
|
// _sp = other._sp;
|
||||||
|
// other._begin = nullptr;
|
||||||
|
// return *this;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ~ValueStack(){ if(_begin!=nullptr) pool128.dealloc(_begin); }
|
||||||
|
// };
|
||||||
|
|
||||||
struct Frame {
|
struct Frame {
|
||||||
int _ip = -1;
|
int _ip = -1;
|
||||||
int _next_ip = 0;
|
int _next_ip = 0;
|
||||||
|
27
src/gc.h
27
src/gc.h
@ -56,15 +56,6 @@ struct ManagedHeap{
|
|||||||
inline static std::map<Type, int> deleted;
|
inline static std::map<Type, int> deleted;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
~ManagedHeap(){
|
|
||||||
for(PyObject* obj: _no_gc) obj->~PyObject(), pool64.dealloc(obj);
|
|
||||||
#if DEBUG_GC_STATS
|
|
||||||
for(auto& [type, count]: deleted){
|
|
||||||
std::cout << "GC: " << obj_type_name(vm, type) << "=" << count << std::endl;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int sweep(){
|
int sweep(){
|
||||||
std::vector<PyObject*> alive;
|
std::vector<PyObject*> alive;
|
||||||
for(PyObject* obj: gen){
|
for(PyObject* obj: gen){
|
||||||
@ -108,6 +99,16 @@ struct ManagedHeap{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mark();
|
void mark();
|
||||||
|
|
||||||
|
~ManagedHeap(){
|
||||||
|
for(PyObject* obj: _no_gc) obj->~PyObject(), pool64.dealloc(obj);
|
||||||
|
for(PyObject* obj: gen) obj->~PyObject(), pool64.dealloc(obj);
|
||||||
|
#if DEBUG_GC_STATS
|
||||||
|
for(auto& [type, count]: deleted){
|
||||||
|
std::cout << "GC: " << obj_type_name(vm, type) << "=" << count << std::endl;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void FuncDecl::_gc_mark() const{
|
inline void FuncDecl::_gc_mark() const{
|
||||||
@ -116,11 +117,15 @@ inline void FuncDecl::_gc_mark() const{
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<> inline void gc_mark<List>(List& t){
|
template<> inline void gc_mark<List>(List& t){
|
||||||
for(PyObject* obj: t) OBJ_MARK(obj);
|
for(PyObject* obj: t){
|
||||||
|
OBJ_MARK(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> inline void gc_mark<Tuple>(Tuple& t){
|
template<> inline void gc_mark<Tuple>(Tuple& t){
|
||||||
for(int i=0; i<t.size(); i++) OBJ_MARK(t[i]);
|
for(PyObject* obj: t){
|
||||||
|
OBJ_MARK(obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<> inline void gc_mark<NameDict>(NameDict& t){
|
template<> inline void gc_mark<NameDict>(NameDict& t){
|
||||||
|
@ -192,6 +192,14 @@ while(!_items[i].first.empty()) { \
|
|||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear(){
|
||||||
|
for(uint16_t i=0; i<_capacity; i++){
|
||||||
|
_items[i].first = StrName();
|
||||||
|
_items[i].second = nullptr;
|
||||||
|
}
|
||||||
|
_size = 0;
|
||||||
|
}
|
||||||
#undef HASH_PROBE
|
#undef HASH_PROBE
|
||||||
#undef _hash
|
#undef _hash
|
||||||
};
|
};
|
||||||
|
@ -71,6 +71,7 @@ struct pod_vector{
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pop_back() { _size--; }
|
void pop_back() { _size--; }
|
||||||
|
T popx_back() { T t = std::move(_data[_size-1]); _size--; return t; }
|
||||||
void extend(const pod_vector& other){
|
void extend(const pod_vector& other){
|
||||||
for(int i=0; i<other.size(); i++) push_back(other[i]);
|
for(int i=0; i<other.size(); i++) push_back(other[i]);
|
||||||
}
|
}
|
||||||
@ -89,7 +90,6 @@ struct pod_vector{
|
|||||||
int size() const { return _size; }
|
int size() const { return _size; }
|
||||||
T* data() { return _data; }
|
T* data() { return _data; }
|
||||||
const T* data() const { return _data; }
|
const T* data() const { return _data; }
|
||||||
void pop_back_n(int n) { _size -= n; }
|
|
||||||
void clear() { _size=0; }
|
void clear() { _size=0; }
|
||||||
|
|
||||||
template<typename __ValueT>
|
template<typename __ValueT>
|
||||||
|
7
src/vm.h
7
src/vm.h
@ -326,7 +326,12 @@ public:
|
|||||||
return _all_types[OBJ_GET(Type, _t(obj->type)).index].obj;
|
return _all_types[OBJ_GET(Type, _t(obj->type)).index].obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
~VM() { heap.collect(); }
|
~VM() {
|
||||||
|
callstack.clear();
|
||||||
|
_all_types.clear();
|
||||||
|
_modules.clear();
|
||||||
|
_lazy_modules.clear();
|
||||||
|
}
|
||||||
|
|
||||||
CodeObject_ compile(Str source, Str filename, CompileMode mode);
|
CodeObject_ compile(Str source, Str filename, CompileMode mode);
|
||||||
PyObject* num_negated(PyObject* obj);
|
PyObject* num_negated(PyObject* obj);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user