rename to _type_name

This commit is contained in:
blueloveTH 2024-01-17 15:01:00 +08:00
parent 7d92a1f183
commit 123c8a6a92
6 changed files with 12 additions and 12 deletions

View File

@ -36,7 +36,7 @@ static cJSON* convert_python_object_to_cjson(PyObject* obj, VM* vm){
case VM::tp_tuple.index: return convert_list_to_cjson<Tuple>(_CAST(Tuple&, obj), vm); case VM::tp_tuple.index: return convert_list_to_cjson<Tuple>(_CAST(Tuple&, obj), vm);
default: break; default: break;
} }
vm->TypeError(fmt("unrecognized type ", obj_type_name(vm, obj_t).escape())); vm->TypeError(fmt("unrecognized type ", _type_name(vm, obj_t).escape()));
PK_UNREACHABLE() PK_UNREACHABLE()
} }

View File

@ -280,7 +280,7 @@ void lua_push_from_python(VM* vm, PyObject* val){
lua_rawgeti(_L, LUA_REGISTRYINDEX, func.r); lua_rawgeti(_L, LUA_REGISTRYINDEX, func.r);
return; return;
} }
vm->RuntimeError(fmt("unsupported python type: ", obj_type_name(vm, t).escape())); vm->RuntimeError(fmt("unsupported python type: ", _type_name(vm, t).escape()));
} }
PyObject* lua_popx_to_python(VM* vm) { PyObject* lua_popx_to_python(VM* vm) {

View File

@ -207,7 +207,7 @@ inline void gc_mark_namedict(NameDict& t){
}); });
} }
StrName obj_type_name(VM* vm, Type type); StrName _type_name(VM* vm, Type type);
#if PK_DEBUG_NO_BUILTINS #if PK_DEBUG_NO_BUILTINS
#define OBJ_NAME(obj) Str("<?>") #define OBJ_NAME(obj) Str("<?>")

View File

@ -25,7 +25,7 @@ namespace pkpy{
#if PK_DEBUG_GC_STATS #if PK_DEBUG_GC_STATS
for(auto& [type, count]: deleted){ for(auto& [type, count]: deleted){
std::cout << "GC: " << obj_type_name(vm, type).sv() << "=" << count << std::endl; std::cout << "GC: " << _type_name(vm, type).sv() << "=" << count << std::endl;
} }
std::cout << "GC: " << alive.size() << "/" << gen.size() << " (" << freed << " freed)" << std::endl; std::cout << "GC: " << alive.size() << "/" << gen.size() << " (" << freed << " freed)" << std::endl;
deleted.clear(); deleted.clear();

View File

@ -70,8 +70,8 @@ void init_builtins(VM* _vm) {
vm->check_non_tagged_type(class_arg, vm->tp_type); vm->check_non_tagged_type(class_arg, vm->tp_type);
Type type = PK_OBJ_GET(Type, class_arg); Type type = PK_OBJ_GET(Type, class_arg);
if(!vm->isinstance(self_arg, type)){ if(!vm->isinstance(self_arg, type)){
StrName _0 = obj_type_name(vm, vm->_tp(self_arg)); StrName _0 = _type_name(vm, vm->_tp(self_arg));
StrName _1 = obj_type_name(vm, type); StrName _1 = _type_name(vm, type);
vm->TypeError("super(): " + _0.escape() + " is not an instance of " + _1.escape()); vm->TypeError("super(): " + _0.escape() + " is not an instance of " + _1.escape());
} }
return vm->heap.gcnew<Super>(vm->tp_super, self_arg, vm->_all_types[type].base); return vm->heap.gcnew<Super>(vm->tp_super, self_arg, vm->_all_types[type].base);
@ -1304,7 +1304,7 @@ void init_builtins(VM* _vm) {
// tp_exception // tp_exception
_vm->bind_constructor<-1>(_vm->_t(VM::tp_exception), [](VM* vm, ArgsView args){ _vm->bind_constructor<-1>(_vm->_t(VM::tp_exception), [](VM* vm, ArgsView args){
Type cls = PK_OBJ_GET(Type, args[0]); Type cls = PK_OBJ_GET(Type, args[0]);
StrName cls_name = obj_type_name(vm, cls); StrName cls_name = _type_name(vm, cls);
PyObject* e_obj = vm->heap.gcnew<Exception>(cls, cls_name); PyObject* e_obj = vm->heap.gcnew<Exception>(cls, cls_name);
e_obj->_enable_instance_dict(); e_obj->_enable_instance_dict();
PK_OBJ_GET(Exception, e_obj)._self = e_obj; PK_OBJ_GET(Exception, e_obj)._self = e_obj;
@ -1323,7 +1323,7 @@ void init_builtins(VM* _vm) {
_vm->bind__repr__(VM::tp_exception, [](VM* vm, PyObject* obj) { _vm->bind__repr__(VM::tp_exception, [](VM* vm, PyObject* obj) {
Exception& self = _CAST(Exception&, obj); Exception& self = _CAST(Exception&, obj);
return VAR(fmt(obj_type_name(vm, obj->type), '(', self.msg.escape(), ')')); return VAR(fmt(_type_name(vm, obj->type), '(', self.msg.escape(), ')'));
}); });
_vm->bind__str__(VM::tp_exception, [](VM* vm, PyObject* obj) { _vm->bind__str__(VM::tp_exception, [](VM* vm, PyObject* obj) {

View File

@ -27,7 +27,7 @@ namespace pkpy{
if(!first) ss << ", "; if(!first) ss << ", ";
first = false; first = false;
if(!is_non_tagged_type(k, vm->tp_str)){ if(!is_non_tagged_type(k, vm->tp_str)){
vm->TypeError(fmt("json keys must be string, got ", obj_type_name(vm, vm->_tp(k)))); vm->TypeError(fmt("json keys must be string, got ", _type_name(vm, vm->_tp(k))));
} }
ss << _CAST(Str&, k).escape(false) << ": "; ss << _CAST(Str&, k).escape(false) << ": ";
write_object(v); write_object(v);
@ -56,7 +56,7 @@ namespace pkpy{
}else if(obj_t == vm->tp_dict){ }else if(obj_t == vm->tp_dict){
write_dict(_CAST(Dict&, obj)); write_dict(_CAST(Dict&, obj));
}else{ }else{
vm->TypeError(fmt("unrecognized type ", obj_type_name(vm, obj_t).escape())); vm->TypeError(fmt("unrecognized type ", _type_name(vm, obj_t).escape()));
} }
} }
@ -667,7 +667,7 @@ void VM::_log_s_data(const char* title) {
} else if(is_type(obj, tp_tuple)){ } else if(is_type(obj, tp_tuple)){
auto& t = CAST(Tuple&, obj); auto& t = CAST(Tuple&, obj);
ss << "tuple(size=" << t.size() << ")"; ss << "tuple(size=" << t.size() << ")";
} else ss << "(" << obj_type_name(this, obj->type) << ")"; } else ss << "(" << _type_name(this, obj->type) << ")";
ss << ", "; ss << ", ";
} }
std::string output = ss.str(); std::string output = ss.str();
@ -1252,7 +1252,7 @@ void ManagedHeap::mark() {
if(_gc_marker_ex) _gc_marker_ex(vm); if(_gc_marker_ex) _gc_marker_ex(vm);
} }
StrName obj_type_name(VM *vm, Type type){ StrName _type_name(VM *vm, Type type){
return vm->_all_types[type].name; return vm->_all_types[type].name;
} }