From ff6a2bc4b9af371d1e6245b46b1b318914d02958 Mon Sep 17 00:00:00 2001 From: Ge Wang Date: Wed, 22 Nov 2023 23:52:09 -0800 Subject: [PATCH] add chugin DL runtime api for type name and base_name --- src/core/chuck_dl.cpp | 36 +++++++++++++++++++++++++++++++++++- src/core/chuck_dl.h | 4 ++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/core/chuck_dl.cpp b/src/core/chuck_dl.cpp index e82328891..db37a1f2e 100644 --- a/src/core/chuck_dl.cpp +++ b/src/core/chuck_dl.cpp @@ -82,6 +82,8 @@ t_CKBOOL CK_DLL_CALL ck_type_isequal( Chuck_Type * lhs, Chuck_Type * rhs ); t_CKBOOL CK_DLL_CALL ck_type_isa( Chuck_Type * lhs, Chuck_Type * rhs ); void CK_DLL_CALL ck_callback_on_instantiate( f_callback_on_instantiate callback, Chuck_Type * base_type, Chuck_VM * vm, t_CKBOOL shouldSetShredOrigin ); ckte_Origin ck_origin_hint( Chuck_Type * type ); +const char * CK_DLL_CALL ck_type_name( Chuck_Type * type ); +const char * CK_DLL_CALL ck_type_base_name( Chuck_Type * type ); Chuck_VM_Shred * CK_DLL_CALL ck_get_origin_shred( Chuck_Object * object ); void CK_DLL_CALL ck_set_origin_shred( Chuck_Object * object, Chuck_VM_Shred * shred ); Chuck_VM_Shred * CK_DLL_CALL ck_shred_parent( Chuck_VM_Shred * shred ); @@ -2535,7 +2537,9 @@ get_vtable_offset(ck_get_vtable_offset), is_equal(ck_type_isequal), isa(ck_type_isa), callback_on_instantiate(ck_callback_on_instantiate), -origin_hint(ck_origin_hint) +origin_hint(ck_origin_hint), +name(ck_type_name), +base_name(ck_type_base_name) { } @@ -2738,6 +2742,36 @@ ckte_Origin CK_DLL_CALL ck_origin_hint( Chuck_Type * type ) +//----------------------------------------------------------------------------- +// name: ck_type_name() +// desc: get type name (full, with decorations such as []) +//----------------------------------------------------------------------------- +const char * CK_DLL_CALL ck_type_name( Chuck_Type * type ) +{ + // null + if( !type ) return ""; + // return type name + return type->c_name(); +} + + + + +//----------------------------------------------------------------------------- +// name: ck_type_base_name() +// desc: get type base name (no [] decorations) +//----------------------------------------------------------------------------- +const char * CK_DLL_CALL ck_type_base_name( Chuck_Type * type ) +{ + // null + if( !type ) return ""; + // return origin hint + return type->base_name.c_str(); +} + + + + //----------------------------------------------------------------------------- // name: ck_shred_parent() // desc: where did the type originate? e.g., chugin, builtin, user-defined, etc. diff --git a/src/core/chuck_dl.h b/src/core/chuck_dl.h index 10654176c..79b413235 100644 --- a/src/core/chuck_dl.h +++ b/src/core/chuck_dl.h @@ -994,6 +994,10 @@ struct Chuck_DL_Api void (CK_DLL_CALL * const callback_on_instantiate)( f_callback_on_instantiate callback, Type base_type, Chuck_VM * vm, t_CKBOOL shouldSetShredOrigin ); // get origin hint ("where did this type originate?") ckte_Origin (CK_DLL_CALL * const origin_hint)(Type type); + // get type name (full, with decorations) (NOTE do not save a reference to the return value; make a copy if needed) | 1.5.2.0 + const char * (CK_DLL_CALL * const name)(Type type); + // get type base name (no decorations) (NOTE do not save a reference to the return value; make a copy if needed) | 1.5.2.0 + const char * (CK_DLL_CALL * const base_name)(Type type); } * const type; // api to access host-side shreds | 1.5.2.0