From 79ac343eb237e715866da411221b99f329168bb1 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Wed, 10 Jul 2024 00:19:47 +0800 Subject: [PATCH] change type names --- include/pocketpy/pocketpy.h | 16 ++++++++-------- src/interpreter/ceval.c | 6 +++--- src/interpreter/vm.c | 26 +++++++++++++------------- src/public/error.c | 2 +- src/public/py_exception.c | 2 +- src/public/py_ops.c | 6 +++--- src/public/values.c | 4 ++-- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h index ddcb6cf5..f40566ff 100644 --- a/include/pocketpy/pocketpy.h +++ b/include/pocketpy/pocketpy.h @@ -322,7 +322,7 @@ bool py_str(py_Ref val); py_GlobalRef py_retval(); #define py_isnil(self) py_istype(self, 0) -#define py_isnone(self) py_istype(self, tp_none_type) +#define py_isnone(self) py_istype(self, tp_NoneType) /* tuple */ @@ -410,10 +410,10 @@ enum py_PredefinedTypes { tp_module, tp_function, tp_nativefunc, - tp_bound_method, + tp_boundmethod, tp_super, // 1 slot + py_Type - tp_base_exception, - tp_exception, + tp_BaseException, + tp_Exception, tp_bytes, tp_mappingproxy, tp_dict, @@ -421,11 +421,11 @@ enum py_PredefinedTypes { tp_star_wrapper, tp_staticmethod, // 1 slot tp_classmethod, // 1 slot - tp_none_type, - tp_not_implemented_type, + tp_NoneType, + tp_NotImplementedType, tp_ellipsis, - tp_syntax_error, - tp_stop_iteration, + tp_SyntaxError, + tp_StopIteration, }; #ifdef __cplusplus diff --git a/src/interpreter/ceval.c b/src/interpreter/ceval.c index f4d6aa2f..57102e86 100644 --- a/src/interpreter/ceval.c +++ b/src/interpreter/ceval.c @@ -110,7 +110,7 @@ pk_FrameResult pk_VM__run_top_frame(pk_VM* self) { DISPATCH(); } case OP_PRINT_EXPR: - if(TOP()->type != tp_none_type) { + if(TOP()->type != tp_NoneType) { bool ok = py_repr(TOP()); if(!ok) goto __ERROR; self->_stdout("%s\n", py_tostr(&self->last_retval)); @@ -756,7 +756,7 @@ bool pk_stack_binaryop(pk_VM* self, py_Name op, py_Name rop) { if(magic) { bool ok = py_call(magic, 2, SECOND()); if(!ok) return false; - if(self->last_retval.type != tp_not_implemented_type) return true; + if(self->last_retval.type != tp_NotImplementedType) return true; } // try reverse operation if(rop) { @@ -768,7 +768,7 @@ bool pk_stack_binaryop(pk_VM* self, py_Name op, py_Name rop) { if(magic) { bool ok = py_call(magic, 2, SECOND()); if(!ok) return false; - if(self->last_retval.type != tp_not_implemented_type) return true; + if(self->last_retval.type != tp_NotImplementedType) return true; } } // eq/ne op never fails due to object.__eq__ diff --git a/src/interpreter/vm.c b/src/interpreter/vm.c index 9a24cfa3..22dd2445 100644 --- a/src/interpreter/vm.c +++ b/src/interpreter/vm.c @@ -109,11 +109,11 @@ void pk_VM__ctor(pk_VM* self) { validate(tp_function, pk_function__register()); validate(tp_nativefunc, pk_nativefunc__register()); - validate(tp_bound_method, pk_VM__new_type(self, "bound_method", tp_object, NULL, false)); + validate(tp_boundmethod, pk_VM__new_type(self, "boundmethod", tp_object, NULL, false)); validate(tp_super, pk_VM__new_type(self, "super", tp_object, NULL, false)); - validate(tp_base_exception, pk_BaseException__register()); - validate(tp_exception, pk_Exception__register()); + validate(tp_BaseException, pk_BaseException__register()); + validate(tp_Exception, pk_Exception__register()); validate(tp_bytes, pk_bytes__register()); validate(tp_mappingproxy, pk_VM__new_type(self, "mappingproxy", tp_object, NULL, false)); @@ -124,13 +124,13 @@ void pk_VM__ctor(pk_VM* self) { validate(tp_staticmethod, pk_VM__new_type(self, "staticmethod", tp_object, NULL, false)); validate(tp_classmethod, pk_VM__new_type(self, "classmethod", tp_object, NULL, false)); - validate(tp_none_type, pk_VM__new_type(self, "NoneType", tp_object, NULL, false)); - validate(tp_not_implemented_type, + validate(tp_NoneType, pk_VM__new_type(self, "NoneType", tp_object, NULL, false)); + validate(tp_NotImplementedType, pk_VM__new_type(self, "NotImplementedType", tp_object, NULL, false)); validate(tp_ellipsis, pk_VM__new_type(self, "ellipsis", tp_object, NULL, false)); - validate(tp_syntax_error, pk_VM__new_type(self, "SyntaxError", tp_exception, NULL, false)); - validate(tp_stop_iteration, pk_VM__new_type(self, "StopIteration", tp_exception, NULL, false)); + validate(tp_SyntaxError, pk_VM__new_type(self, "SyntaxError", tp_Exception, NULL, false)); + validate(tp_StopIteration, pk_VM__new_type(self, "StopIteration", tp_Exception, NULL, false)); #undef validate self->builtins = pk_builtins__register(); @@ -149,10 +149,10 @@ void pk_VM__ctor(pk_VM* self) { tp_bytes, tp_dict, tp_property, - tp_base_exception, - tp_exception, - tp_stop_iteration, - tp_syntax_error}; + tp_BaseException, + tp_Exception, + tp_StopIteration, + tp_SyntaxError}; for(int i = 0; i < c11__count_array(public_types); i++) { py_Type t = public_types[i]; @@ -343,7 +343,7 @@ pk_FrameResult pk_VM__vectorcall(pk_VM* self, uint16_t argc, uint16_t kwargc, bo #if 0 // handle boundmethod, do a patch - if(p0->type == tp_bound_method) { + if(p0->type == tp_boundmethod) { assert(false); assert(py_isnil(p0 + 1)); // self must be NULL // BoundMethod& bm = PK_OBJ_GET(BoundMethod, callable); @@ -576,7 +576,7 @@ void pk_print_stack(pk_VM* self, Frame* frame, Bytecode byte) { case tp_int: c11_sbuf__write_i64(&buf, p->_i64); break; case tp_float: c11_sbuf__write_f64(&buf, p->_f64, -1); break; case tp_bool: c11_sbuf__write_cstr(&buf, p->_bool ? "True" : "False"); break; - case tp_none_type: c11_sbuf__write_cstr(&buf, "None"); break; + case tp_NoneType: c11_sbuf__write_cstr(&buf, "None"); break; case tp_list: { pk_sprintf(&buf, "list(%d)", py_list__len(p)); break; diff --git a/src/public/error.c b/src/public/error.c index 0aead857..a780c113 100644 --- a/src/public/error.c +++ b/src/public/error.c @@ -40,7 +40,7 @@ bool py_exception(const char* name, const char* fmt, ...) { py_Ref message = py_pushtmp(); py_newstrn(message, res->data, res->size); c11_string__delete(res); - bool ok = py_tpcall(tp_exception, 1, message); + bool ok = py_tpcall(tp_Exception, 1, message); py_pop(); if(!ok) abort(); diff --git a/src/public/py_exception.c b/src/public/py_exception.c index 4b33453f..73872603 100644 --- a/src/public/py_exception.c +++ b/src/public/py_exception.c @@ -76,6 +76,6 @@ py_Type pk_BaseException__register() { py_Type pk_Exception__register() { pk_VM* vm = pk_current_vm; - py_Type type = pk_VM__new_type(vm, "Exception", tp_base_exception, NULL, true); + py_Type type = pk_VM__new_type(vm, "Exception", tp_BaseException, NULL, true); return type; } \ No newline at end of file diff --git a/src/public/py_ops.c b/src/public/py_ops.c index 8d545ec6..b446d77b 100644 --- a/src/public/py_ops.c +++ b/src/public/py_ops.c @@ -9,8 +9,8 @@ bool py_isidentical(const py_Ref lhs, const py_Ref rhs) { case tp_float: return lhs->_f64 == rhs->_f64; case tp_bool: return lhs->_bool == rhs->_bool; case tp_nativefunc: return lhs->_cfunc == rhs->_cfunc; - case tp_none_type: return true; - case tp_not_implemented_type: return true; + case tp_NoneType: return true; + case tp_NotImplementedType: return true; case tp_ellipsis: return true; // fallback to pointer comparison default: return lhs->is_ptr && rhs->is_ptr && lhs->_obj == rhs->_obj; @@ -22,7 +22,7 @@ int py_bool(const py_Ref val) { case tp_bool: return val->_bool; case tp_int: return val->_i64 != 0; case tp_float: return val->_f64 != 0; - case tp_none_type: return 0; + case tp_NoneType: return 0; default: { py_Ref tmp = py_tpfindmagic(val->type, __bool__); if(tmp) { diff --git a/src/public/values.c b/src/public/values.c index ed40a3e7..9a3a1907 100644 --- a/src/public/values.c +++ b/src/public/values.c @@ -26,12 +26,12 @@ void py_newbool(py_Ref out, bool val) { } void py_newnone(py_Ref out) { - out->type = tp_none_type; + out->type = tp_NoneType; out->is_ptr = false; } void py_newnotimplemented(py_Ref out) { - out->type = tp_not_implemented_type; + out->type = tp_NotImplementedType; out->is_ptr = false; }