Revert "..."

This reverts commit 584939ee10afb4d1d4505c3079bbcc3a9a5143c5.
This commit is contained in:
BLUELOVETH 2023-07-19 18:20:25 +08:00
parent 584939ee10
commit 9a5fae3659

View File

@ -17,35 +17,23 @@ typedef int (*LuaStyleFuncC)(VM*);
if(vm->_c.error != nullptr) \ if(vm->_c.error != nullptr) \
return false; return false;
static PyObject** vstack_ro_begin(VM* vm){
if(vm->_c.s_view.empty()){
if(vm->callstack.empty()) return vm->s_data.begin();
else{
return vm->callstack.top()._locals.end();
}
}else{
return vm->_c.s_view.top().end();
}
}
static PyObject** vstack_begin(VM* vm){
if(vm->_c.s_view.empty()){
if(vm->callstack.empty()) return vm->s_data.begin();
else{
return vm->callstack.top()._locals.begin();
}
}else{
return vm->_c.s_view.top().begin();
}
}
static int count_extra_elements(VM* vm, int n){ static int count_extra_elements(VM* vm, int n){
return vm->s_data._sp - vstack_ro_begin(vm); if(vm->callstack.empty()){
return vm->s_data.size();
}
PK_ASSERT(!vm->_c.s_view.empty());
return vm->s_data._sp - vm->_c.s_view.top().end();
} }
static PyObject* stack_item(VM* vm, int index){ static PyObject* stack_item(VM* vm, int index){
PyObject** begin = vstack_begin(vm); PyObject** begin;
PyObject** end = vm->s_data.end(); PyObject** end = vm->s_data.end();
if(vm->callstack.empty()){
begin = vm->s_data.begin();
}else{
PK_ASSERT(!vm->_c.s_view.empty());
begin = vm->_c.s_view.top().begin();
}
int size = end - begin; int size = end - begin;
if(index < 0) index += size; if(index < 0) index += size;
if(index < 0 || index >= size){ if(index < 0 || index >= size){
@ -146,7 +134,11 @@ bool pkpy_rot_two(pkpy_vm* vm_handle){
int pkpy_stack_size(pkpy_vm* vm_handle){ int pkpy_stack_size(pkpy_vm* vm_handle){
VM* vm = (VM*)vm_handle; VM* vm = (VM*)vm_handle;
PK_ASSERT_NO_ERROR() PK_ASSERT_NO_ERROR()
return vm->s_data._sp - vstack_begin(vm); if(vm->callstack.empty()){
return vm->s_data.size();
}
if(vm->_c.s_view.empty()) exit(127);
return vm->s_data._sp - vm->_c.s_view.top().begin();
} }
// int // int
@ -514,7 +506,12 @@ bool pkpy_clear_error(pkpy_vm* vm_handle, char** message) {
else else
std::cout << e.summary() << std::endl; std::cout << e.summary() << std::endl;
vm->_c.error = nullptr; vm->_c.error = nullptr;
vm->s_data.reset(vstack_begin(vm)); if(vm->callstack.empty()){
vm->s_data.clear();
}else{
if(vm->_c.s_view.empty()) exit(127);
vm->s_data.reset(vm->_c.s_view.top().end());
}
return true; return true;
} }