simplified kt initialiation function names
This commit is contained in:
parent
5bbab0a414
commit
5391862d02
@ -26,9 +26,9 @@ Every registered type should have it's own descriptor (`ktDescriptor`). It's a s
|
|||||||
|
|
||||||
## type registration
|
## 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:
|
Examples:
|
||||||
+ [ktDescriptors_initKerepTypes()](src/base/type_system/init.c)
|
+ [kerep types registration](src/base/type_system/init.c)
|
||||||
+ [kerep types registration](tests/main.cpp)
|
+ [kt_initKerepTypes()](tests/main.cpp)
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
#include "../../Filesystem/filesystem.h"
|
#include "../../Filesystem/filesystem.h"
|
||||||
#include "base_toString.h"
|
#include "base_toString.h"
|
||||||
|
|
||||||
void ktDescriptors_initKerepTypes(){
|
void kt_initKerepTypes(){
|
||||||
// base types
|
// base types
|
||||||
kt_register(Pointer);
|
kt_register(Pointer);
|
||||||
if(ktid_Pointer!=0) // this can break UnitypeNull
|
if(ktid_Pointer!=0) // this can break UnitypeNull
|
||||||
|
|||||||
@ -4,8 +4,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// call this between ktDescriptors_beginInit() and ktDescriptors_endInit()
|
// call this between kt_beginInit() and kt_endInit()
|
||||||
void ktDescriptors_initKerepTypes();
|
void kt_initKerepTypes();
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,6 +41,11 @@ STRUCT(ktDescriptor,
|
|||||||
toString_t toString; // NULL or function which generates string representaion of object
|
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
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -31,14 +31,14 @@ ENUM(ktDescriptorsState,
|
|||||||
)
|
)
|
||||||
ktDescriptorsState initState=NotInitialized;
|
ktDescriptorsState initState=NotInitialized;
|
||||||
|
|
||||||
void ktDescriptors_beginInit(){
|
void kt_beginInit(){
|
||||||
kprintf("\e[94mtype descriptors initializing...\n");
|
kprintf("\e[94mtype descriptors initializing...\n");
|
||||||
__descriptorPointers=Autoarr_create(Pointer, 256, 256);
|
__descriptorPointers=Autoarr_create(Pointer, 256, 256);
|
||||||
if(__descriptorPointers==NULL)
|
if(__descriptorPointers==NULL)
|
||||||
throw(ERR_NULLPTR);
|
throw(ERR_NULLPTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ktDescriptors_endInit(){
|
void kt_endInit(){
|
||||||
typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers);
|
typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers);
|
||||||
Autoarr_free(__descriptorPointers,true);
|
Autoarr_free(__descriptorPointers,true);
|
||||||
if(typeDescriptors==NULL) throw(ERR_NULLPTR);
|
if(typeDescriptors==NULL) throw(ERR_NULLPTR);
|
||||||
@ -58,6 +58,6 @@ ktDescriptor* ktDescriptor_get(ktid id){
|
|||||||
return typeDescriptors[id];
|
return typeDescriptors[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ktDescriptors_free(){
|
void kt_free(){
|
||||||
free(typeDescriptors);
|
free(typeDescriptors);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,14 +17,14 @@ void __kt_register(ktDescriptor* descriptor);
|
|||||||
__kt_register(&ktDescriptor_##TYPE##_Ptr); \
|
__kt_register(&ktDescriptor_##TYPE##_Ptr); \
|
||||||
ktid_##TYPE##_Ptr=ktid_last;
|
ktid_##TYPE##_Ptr=ktid_last;
|
||||||
|
|
||||||
void ktDescriptors_beginInit();
|
void kt_beginInit();
|
||||||
void ktDescriptors_endInit();
|
void kt_endInit();
|
||||||
|
|
||||||
/// @param id id of registered type
|
/// @param id id of registered type
|
||||||
ktDescriptor* ktDescriptor_get(ktid id);
|
ktDescriptor* ktDescriptor_get(ktid id);
|
||||||
|
|
||||||
// call it to free heap-allocated ktDescriptors array
|
// call it to free heap-allocated ktDescriptors array
|
||||||
void ktDescriptors_free();
|
void kt_free();
|
||||||
|
|
||||||
kt_declare(Pointer);
|
kt_declare(Pointer);
|
||||||
kt_declare(char);
|
kt_declare(char);
|
||||||
|
|||||||
@ -10,7 +10,9 @@ extern "C" {
|
|||||||
typedef u16 ktid;
|
typedef u16 ktid;
|
||||||
static const ktid ktid_undefined=-1;
|
static const ktid ktid_undefined=-1;
|
||||||
|
|
||||||
|
/// gets descriptor id for TYPE
|
||||||
#define ktid_name(TYPE) ktid_##TYPE
|
#define ktid_name(TYPE) ktid_##TYPE
|
||||||
|
/// gets descriptor id for pointer to TYPE
|
||||||
#define ktid_ptrName(TYPE) ktid_##TYPE##_Ptr
|
#define ktid_ptrName(TYPE) ktid_##TYPE##_Ptr
|
||||||
|
|
||||||
#define ktid_declare(TYPE) \
|
#define ktid_declare(TYPE) \
|
||||||
|
|||||||
@ -3,11 +3,11 @@
|
|||||||
i32 main(){
|
i32 main(){
|
||||||
if(!setlocale(LC_ALL, "C.UTF8"))
|
if(!setlocale(LC_ALL, "C.UTF8"))
|
||||||
kprintf("\e[93msetlocale failed\n");
|
kprintf("\e[93msetlocale failed\n");
|
||||||
ktDescriptors_beginInit();
|
kt_beginInit();
|
||||||
ktDescriptors_initKerepTypes();
|
kt_initKerepTypes();
|
||||||
ktDescriptors_endInit();
|
kt_endInit();
|
||||||
test_all();
|
test_all();
|
||||||
ktDescriptors_free();
|
kt_free();
|
||||||
kprintf("\e[0m\n");
|
kprintf("\e[0m\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user