diff --git a/src/base/type_system/README.md b/src/base/type_system/README.md index 66f54b0..c0066e9 100644 --- a/src/base/type_system/README.md +++ b/src/base/type_system/README.md @@ -26,9 +26,9 @@ Every registered type should have it's own descriptor (`ktDescriptor`). It's a s ## type registration -To finally register a type, you should call macro `kt_register()` between `ktDescriptors_beginInit()` and `ktDescriptors_endInit()`. Better do it at the start of your program. To register all types from kerep, call `ktDescriptors_initKerepTypes()`. +To finally register a type, you should call macro `kt_register()` between `kt_beginInit()` and `kt_endInit()`. Better do it at the start of your program. To register all types from kerep, call `kt_initKerepTypes()`. -You can free internal ktDescriptors storage by calling `ktDescriptors_free()` at exit, if your debugger (valgrind in my case) sees a memory leak. +You can free internal ktDescriptors storage by calling `kt_free()` at exit, if your debugger (valgrind in my case) sees a memory leak. Examples: -+ [ktDescriptors_initKerepTypes()](src/base/type_system/init.c) -+ [kerep types registration](tests/main.cpp) ++ [kerep types registration](src/base/type_system/init.c) ++ [kt_initKerepTypes()](tests/main.cpp) diff --git a/src/base/type_system/init.c b/src/base/type_system/init.c index 7b619cb..fc5ba12 100644 --- a/src/base/type_system/init.c +++ b/src/base/type_system/init.c @@ -7,7 +7,7 @@ #include "../../Filesystem/filesystem.h" #include "base_toString.h" -void ktDescriptors_initKerepTypes(){ +void kt_initKerepTypes(){ // base types kt_register(Pointer); if(ktid_Pointer!=0) // this can break UnitypeNull diff --git a/src/base/type_system/init.h b/src/base/type_system/init.h index d08ef9d..df787ca 100644 --- a/src/base/type_system/init.h +++ b/src/base/type_system/init.h @@ -4,8 +4,8 @@ extern "C" { #endif -// call this between ktDescriptors_beginInit() and ktDescriptors_endInit() -void ktDescriptors_initKerepTypes(); +// call this between kt_beginInit() and kt_endInit() +void kt_initKerepTypes(); #if __cplusplus } diff --git a/src/base/type_system/ktDescriptor.h b/src/base/type_system/ktDescriptor.h index 8b95115..31e4ee8 100644 --- a/src/base/type_system/ktDescriptor.h +++ b/src/base/type_system/ktDescriptor.h @@ -41,6 +41,11 @@ STRUCT(ktDescriptor, toString_t toString; // NULL or function which generates string representaion of object ) +/// gets descriptor for TYPE +#define ktDescriptor_name(TYPE) ktDescriptor_##TYPE +/// gets descriptor for pointer to TYPE +#define ktDescriptor_namePtr(TYPE) ktDescriptor_##TYPE##_Ptr + #if __cplusplus } #endif \ No newline at end of file diff --git a/src/base/type_system/kt_functions.c b/src/base/type_system/kt_functions.c index b73eca0..8ced590 100644 --- a/src/base/type_system/kt_functions.c +++ b/src/base/type_system/kt_functions.c @@ -31,14 +31,14 @@ ENUM(ktDescriptorsState, ) ktDescriptorsState initState=NotInitialized; -void ktDescriptors_beginInit(){ +void kt_beginInit(){ kprintf("\e[94mtype descriptors initializing...\n"); __descriptorPointers=Autoarr_create(Pointer, 256, 256); if(__descriptorPointers==NULL) throw(ERR_NULLPTR); } -void ktDescriptors_endInit(){ +void kt_endInit(){ typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers); Autoarr_free(__descriptorPointers,true); if(typeDescriptors==NULL) throw(ERR_NULLPTR); @@ -58,6 +58,6 @@ ktDescriptor* ktDescriptor_get(ktid id){ return typeDescriptors[id]; } -void ktDescriptors_free(){ +void kt_free(){ free(typeDescriptors); } diff --git a/src/base/type_system/kt_functions.h b/src/base/type_system/kt_functions.h index 6410d38..b131ce2 100644 --- a/src/base/type_system/kt_functions.h +++ b/src/base/type_system/kt_functions.h @@ -17,14 +17,14 @@ void __kt_register(ktDescriptor* descriptor); __kt_register(&ktDescriptor_##TYPE##_Ptr); \ ktid_##TYPE##_Ptr=ktid_last; -void ktDescriptors_beginInit(); -void ktDescriptors_endInit(); +void kt_beginInit(); +void kt_endInit(); /// @param id id of registered type ktDescriptor* ktDescriptor_get(ktid id); // call it to free heap-allocated ktDescriptors array -void ktDescriptors_free(); +void kt_free(); kt_declare(Pointer); kt_declare(char); diff --git a/src/base/type_system/ktid.h b/src/base/type_system/ktid.h index 9d9c276..be08484 100644 --- a/src/base/type_system/ktid.h +++ b/src/base/type_system/ktid.h @@ -10,7 +10,9 @@ extern "C" { typedef u16 ktid; static const ktid ktid_undefined=-1; +/// gets descriptor id for TYPE #define ktid_name(TYPE) ktid_##TYPE +/// gets descriptor id for pointer to TYPE #define ktid_ptrName(TYPE) ktid_##TYPE##_Ptr #define ktid_declare(TYPE) \ diff --git a/tests/main.cpp b/tests/main.cpp index 14e310c..91594d1 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -3,11 +3,11 @@ i32 main(){ if(!setlocale(LC_ALL, "C.UTF8")) kprintf("\e[93msetlocale failed\n"); - ktDescriptors_beginInit(); - ktDescriptors_initKerepTypes(); - ktDescriptors_endInit(); + kt_beginInit(); + kt_initKerepTypes(); + kt_endInit(); test_all(); - ktDescriptors_free(); + kt_free(); kprintf("\e[0m\n"); return 0; }