mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-24 13:30:18 +00:00
some rename
This commit is contained in:
parent
5bf5ddcc71
commit
782be0f1bf
@ -141,7 +141,7 @@ public:
|
|||||||
struct{
|
struct{
|
||||||
PyObject* error;
|
PyObject* error;
|
||||||
stack_no_copy<ArgsView> s_view;
|
stack_no_copy<ArgsView> s_view;
|
||||||
} _c;
|
} __c;
|
||||||
|
|
||||||
PyObject *None, *True, *False, *NotImplemented;
|
PyObject *None, *True, *False, *NotImplemented;
|
||||||
PyObject *StopIteration, *Ellipsis;
|
PyObject *StopIteration, *Ellipsis;
|
||||||
|
|||||||
@ -16,15 +16,15 @@ typedef int (*LuaStyleFuncC)(VM*);
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define PK_ASSERT_NO_ERROR() \
|
#define PK_ASSERT_NO_ERROR() \
|
||||||
if(vm->_c.error != nullptr) \
|
if(vm->__c.error != nullptr) \
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
static int count_extra_elements(VM* vm, int n){
|
static int count_extra_elements(VM* vm, int n){
|
||||||
if(vm->callstack.empty()){
|
if(vm->callstack.empty()){
|
||||||
return vm->s_data.size();
|
return vm->s_data.size();
|
||||||
}
|
}
|
||||||
PK_ASSERT(!vm->_c.s_view.empty());
|
PK_ASSERT(!vm->__c.s_view.empty());
|
||||||
return vm->s_data._sp - vm->_c.s_view.top().end();
|
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){
|
||||||
@ -33,8 +33,8 @@ static PyObject* stack_item(VM* vm, int index){
|
|||||||
if(vm->callstack.empty()){
|
if(vm->callstack.empty()){
|
||||||
begin = vm->s_data.begin();
|
begin = vm->s_data.begin();
|
||||||
}else{
|
}else{
|
||||||
PK_ASSERT(!vm->_c.s_view.empty());
|
PK_ASSERT(!vm->__c.s_view.empty());
|
||||||
begin = vm->_c.s_view.top().begin();
|
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;
|
||||||
@ -47,11 +47,11 @@ static PyObject* stack_item(VM* vm, int index){
|
|||||||
#define PK_PROTECTED(__B) \
|
#define PK_PROTECTED(__B) \
|
||||||
try{ __B } \
|
try{ __B } \
|
||||||
catch(const Exception& e ) { \
|
catch(const Exception& e ) { \
|
||||||
vm->_c.error = e.self(); \
|
vm->__c.error = e.self(); \
|
||||||
return false; \
|
return false; \
|
||||||
} catch(const std::exception& re){ \
|
} catch(const std::exception& re){ \
|
||||||
PyObject* e_t = vm->_t(vm->tp_exception); \
|
PyObject* e_t = vm->_t(vm->tp_exception); \
|
||||||
vm->_c.error = vm->call(e_t, VAR(re.what())); \
|
vm->__c.error = vm->call(e_t, VAR(re.what())); \
|
||||||
return false; \
|
return false; \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +144,8 @@ int pkpy_stack_size(pkpy_vm* vm_handle){
|
|||||||
if(vm->callstack.empty()){
|
if(vm->callstack.empty()){
|
||||||
return vm->s_data.size();
|
return vm->s_data.size();
|
||||||
}
|
}
|
||||||
if(vm->_c.s_view.empty()) exit(127);
|
if(vm->__c.s_view.empty()) exit(127);
|
||||||
return vm->s_data._sp - vm->_c.s_view.top().begin();
|
return vm->s_data._sp - vm->__c.s_view.top().begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
// int
|
// int
|
||||||
@ -325,7 +325,7 @@ struct TempViewPopper{
|
|||||||
|
|
||||||
void restore() noexcept{
|
void restore() noexcept{
|
||||||
if(used) return;
|
if(used) return;
|
||||||
vm->_c.s_view.pop();
|
vm->__c.s_view.pop();
|
||||||
used = true;
|
used = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,15 +337,15 @@ static PyObject* c_function_wrapper(VM* vm, ArgsView args) {
|
|||||||
LuaStyleFuncC f = lambda_get_userdata<LuaStyleFuncC>(args.begin());
|
LuaStyleFuncC f = lambda_get_userdata<LuaStyleFuncC>(args.begin());
|
||||||
PyObject** curr_sp = vm->s_data._sp;
|
PyObject** curr_sp = vm->s_data._sp;
|
||||||
|
|
||||||
vm->_c.s_view.push(args);
|
vm->__c.s_view.push(args);
|
||||||
TempViewPopper _tvp(vm);
|
TempViewPopper _tvp(vm);
|
||||||
int retc = f(vm); // may raise, _tvp will handle this via RAII
|
int retc = f(vm); // may raise, _tvp will handle this via RAII
|
||||||
_tvp.restore();
|
_tvp.restore();
|
||||||
|
|
||||||
// propagate_if_errored
|
// propagate_if_errored
|
||||||
if (vm->_c.error != nullptr){
|
if (vm->__c.error != nullptr){
|
||||||
PyObject* e_obj = PK_OBJ_GET(Exception, vm->_c.error).self();
|
PyObject* e_obj = PK_OBJ_GET(Exception, vm->__c.error).self();
|
||||||
vm->_c.error = nullptr;
|
vm->__c.error = nullptr;
|
||||||
vm->_error(e_obj);
|
vm->_error(e_obj);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -503,30 +503,30 @@ bool pkpy_error(pkpy_vm* vm_handle, const char* name, pkpy_CString message) {
|
|||||||
std::cerr << "[warning] pkpy_error(): " << Str(name).escape() << " not found, fallback to 'Exception'" << std::endl;
|
std::cerr << "[warning] pkpy_error(): " << Str(name).escape() << " not found, fallback to 'Exception'" << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vm->_c.error = vm->call(e_t, VAR(message));
|
vm->__c.error = vm->call(e_t, VAR(message));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pkpy_check_error(pkpy_vm* vm_handle) {
|
bool pkpy_check_error(pkpy_vm* vm_handle) {
|
||||||
VM* vm = (VM*) vm_handle;
|
VM* vm = (VM*) vm_handle;
|
||||||
return vm->_c.error != nullptr;
|
return vm->__c.error != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pkpy_clear_error(pkpy_vm* vm_handle, char** message) {
|
bool pkpy_clear_error(pkpy_vm* vm_handle, char** message) {
|
||||||
VM* vm = (VM*) vm_handle;
|
VM* vm = (VM*) vm_handle;
|
||||||
// no error
|
// no error
|
||||||
if (vm->_c.error == nullptr) return false;
|
if (vm->__c.error == nullptr) return false;
|
||||||
Exception& e = PK_OBJ_GET(Exception, vm->_c.error);
|
Exception& e = PK_OBJ_GET(Exception, vm->__c.error);
|
||||||
if (message != nullptr)
|
if (message != nullptr)
|
||||||
*message = strdup(e.summary().c_str());
|
*message = strdup(e.summary().c_str());
|
||||||
else
|
else
|
||||||
std::cout << e.summary() << std::endl;
|
std::cout << e.summary() << std::endl;
|
||||||
vm->_c.error = nullptr;
|
vm->__c.error = nullptr;
|
||||||
if(vm->callstack.empty()){
|
if(vm->callstack.empty()){
|
||||||
vm->s_data.clear();
|
vm->s_data.clear();
|
||||||
}else{
|
}else{
|
||||||
if(vm->_c.s_view.empty()) exit(127);
|
if(vm->__c.s_view.empty()) exit(127);
|
||||||
vm->s_data.reset(vm->_c.s_view.top().end());
|
vm->s_data.reset(vm->__c.s_view.top().end());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,7 +74,7 @@ namespace pkpy{
|
|||||||
|
|
||||||
VM::VM(bool enable_os) : heap(this), enable_os(enable_os) {
|
VM::VM(bool enable_os) : heap(this), enable_os(enable_os) {
|
||||||
this->vm = this;
|
this->vm = this;
|
||||||
this->_c.error = nullptr;
|
this->__c.error = nullptr;
|
||||||
_stdout = [](const char* buf, int size) { std::cout.write(buf, size); };
|
_stdout = [](const char* buf, int size) { std::cout.write(buf, size); };
|
||||||
_stderr = [](const char* buf, int size) { std::cerr.write(buf, size); };
|
_stderr = [](const char* buf, int size) { std::cerr.write(buf, size); };
|
||||||
_main = nullptr;
|
_main = nullptr;
|
||||||
@ -1336,7 +1336,7 @@ void ManagedHeap::mark() {
|
|||||||
for(auto [_, co]: vm->__cached_codes) co->_gc_mark();
|
for(auto [_, co]: vm->__cached_codes) co->_gc_mark();
|
||||||
if(vm->__last_exception) PK_OBJ_MARK(vm->__last_exception);
|
if(vm->__last_exception) PK_OBJ_MARK(vm->__last_exception);
|
||||||
if(vm->__curr_class) PK_OBJ_MARK(vm->__curr_class);
|
if(vm->__curr_class) PK_OBJ_MARK(vm->__curr_class);
|
||||||
if(vm->_c.error != nullptr) PK_OBJ_MARK(vm->_c.error);
|
if(vm->__c.error != nullptr) PK_OBJ_MARK(vm->__c.error);
|
||||||
if(_gc_marker_ex) _gc_marker_ex(vm);
|
if(_gc_marker_ex) _gc_marker_ex(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user