mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
...
This commit is contained in:
parent
b950e75a0c
commit
7b29b4afb3
@ -117,6 +117,9 @@ public:
|
||||
NameDict _modules; // loaded modules
|
||||
std::map<StrName, Str> _lazy_modules; // lazy loaded modules
|
||||
|
||||
PyObject* _reg[32]; // registers for user purpose, also used by C-API
|
||||
static constexpr int REG_COUNT = sizeof(_reg) / sizeof(void*);
|
||||
|
||||
PyObject* None;
|
||||
PyObject* True;
|
||||
PyObject* False;
|
||||
|
@ -50,18 +50,20 @@ struct LuaStack: public ValueStackImpl<32>{
|
||||
return false; \
|
||||
}
|
||||
|
||||
class CVM;
|
||||
void gc_marker_ex(CVM* vm);
|
||||
|
||||
class CVM: public VM {
|
||||
public:
|
||||
LuaStack c_data;
|
||||
LuaStack c_data; // operation stack
|
||||
PyObject* error;
|
||||
|
||||
CVM(bool use_stdio, bool enable_os) : VM(enable_os) {
|
||||
c_data = new LuaStack();
|
||||
error = nullptr;
|
||||
heap._gc_marker_ex = (void (*)(VM*)) gc_marker_ex;
|
||||
heap._gc_marker_ex = [](VM* vm_) {
|
||||
CVM* vm = (CVM*)vm_;
|
||||
for(PyObject* obj: vm->c_data) if(obj!=nullptr) PK_OBJ_MARK(obj);
|
||||
if(vm->error != nullptr) PK_OBJ_MARK(vm->error);
|
||||
};
|
||||
|
||||
if (!use_stdio) {
|
||||
_stdout = _stderr = [](VM* vm, const Str& s){
|
||||
PK_UNUSED(vm);
|
||||
@ -71,10 +73,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void gc_marker_ex(CVM* vm) {
|
||||
for(PyObject* obj: *vm->c_data) if(obj!=nullptr) PK_OBJ_MARK(obj);
|
||||
if(vm->error != nullptr) PK_OBJ_MARK(vm->error);
|
||||
}
|
||||
|
||||
//for now I will unpack a tuple automatically, we may not want to handle
|
||||
//it this way, not sure
|
||||
|
@ -4,6 +4,7 @@ namespace pkpy{
|
||||
|
||||
VM::VM(bool enable_os) : heap(this), enable_os(enable_os) {
|
||||
this->vm = this;
|
||||
for(int i=0; i<REG_COUNT; i++) _reg[i] = nullptr;
|
||||
_stdout = [](VM* vm, const Str& s) {
|
||||
PK_UNUSED(vm);
|
||||
std::cout << s;
|
||||
@ -999,6 +1000,9 @@ void ManagedHeap::mark() {
|
||||
for(PyObject* obj: vm->s_data) PK_OBJ_MARK(obj);
|
||||
if(_gc_marker_ex) _gc_marker_ex(vm);
|
||||
if(vm->_last_exception) PK_OBJ_MARK(vm->_last_exception);
|
||||
for(int i=0; i<vm->REG_COUNT; i++){
|
||||
if(vm->_reg[i] != nullptr) PK_OBJ_MARK(vm->_reg[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Str obj_type_name(VM *vm, Type type){
|
||||
|
Loading…
x
Reference in New Issue
Block a user