From a7c75cfda21ec31f3eebc8ea415aab86a8410682 Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 9 Sep 2022 20:28:15 +0600 Subject: [PATCH] type system readme --- src/base/type_system/README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/base/type_system/README.md b/src/base/type_system/README.md index e69de29..843a227 100644 --- a/src/base/type_system/README.md +++ b/src/base/type_system/README.md @@ -0,0 +1,30 @@ +# kerep type system + +For using some kerep capabilities, such as generic structs, unitype, and kprint, types should be *registered*. + +## type id + +Every registered type has its own id (`ktId`), which should be declared in header file and defined in source file. +Example: +```c +//someStruct.h +typedef struct { } someStruct; +ktId_declare(ktId_someStruct); +ktId_declare(ktId_someStructPtr); // pointer to type is another type +``` +```c +//someStruct.c +ktId_define(ktId_someStruct); +ktId_define(ktId_someStructPtr); +``` + +## type descriptors + +Every registered type should have it's own descriptor (`ktDescriptor`). It's a struct, which contains some information about type and pointers to some specific functions for this type (`toString`, `freeMembers`). + +## 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()`. +Examples: ++ [ktDescriptors_initKerepTypes()](src/base/type_system/init.c) ++ [kerep types registration](tests/main.cpp)