From eca678026fc33901408adb88dfc290b59f720a4f Mon Sep 17 00:00:00 2001 From: timerix Date: Wed, 31 Aug 2022 21:44:14 +0600 Subject: [PATCH 01/17] startsWith() & endsWith() --- src/base/cptr.c | 13 +++++++++++++ src/base/cptr.h | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/base/cptr.c b/src/base/cptr.c index 22a6b36..a4080fe 100644 --- a/src/base/cptr.c +++ b/src/base/cptr.c @@ -34,3 +34,16 @@ char* char_multiply(char c, uint32 n){ rez[n]=c; return rez; } + +bool cptr_startsWith(char* ptr, char* fragment){ + for(char cs=*ptr, cf=*fragment; cf; cs=*++ptr, cf=*++fragment) + if(cs!=cf) return false; + return true; +} + +bool cptr_endsWith(char* ptr, char* fragment){ + ptr+=cptr_length(ptr)-cptr_length(fragment); + for(char cs=*ptr, cf=*fragment; cf; cs=*++ptr, cf=*++fragment) + if(cs!=cf) return false; + return true; +} \ No newline at end of file diff --git a/src/base/cptr.h b/src/base/cptr.h index ccce381..b750842 100644 --- a/src/base/cptr.h +++ b/src/base/cptr.h @@ -18,6 +18,10 @@ bool cptr_compare(char* key0, char* key1); // multiplies char n times char* char_multiply(char c, uint32 n); +bool cptr_startsWith(char* ptr, char* fragment); + +bool cptr_endsWith(char* ptr, char* fragment); + #if __cplusplus } #endif \ No newline at end of file From 2b4046313d51959037ad851ebd62fecbcc58e9cf Mon Sep 17 00:00:00 2001 From: timerix Date: Wed, 31 Aug 2022 21:44:56 +0600 Subject: [PATCH 02/17] kprint_format --- src/base/base.h | 1 + src/base/kprint/README.md | 2 + src/base/kprint/data_fmt.txt | 13 ++++++ src/base/kprint/kprint.c | 22 +++++++++++ src/base/kprint/kprint.h | 51 ++++++++++++++++++++++++ src/base/kprint/kprint_colors.h | 55 ++++++++++++++++++++++++++ src/base/kprint/kprint_format.h | 70 +++++++++++++++++++++++++++++++++ src/base/std.h | 1 + 8 files changed, 215 insertions(+) create mode 100644 src/base/kprint/README.md create mode 100644 src/base/kprint/data_fmt.txt create mode 100644 src/base/kprint/kprint.c create mode 100644 src/base/kprint/kprint.h create mode 100644 src/base/kprint/kprint_colors.h create mode 100644 src/base/kprint/kprint_format.h diff --git a/src/base/base.h b/src/base/base.h index cd9346a..c728a94 100644 --- a/src/base/base.h +++ b/src/base/base.h @@ -11,6 +11,7 @@ extern "C" { #include "types.h" #include "unitype.h" #include "init.h" +#include "kprint/kprint.h" #if __cplusplus } diff --git a/src/base/kprint/README.md b/src/base/kprint/README.md new file mode 100644 index 0000000..e375f83 --- /dev/null +++ b/src/base/kprint/README.md @@ -0,0 +1,2 @@ +## kprint +I don't really like printf function, so i made safer and more convinient replacement. \ No newline at end of file diff --git a/src/base/kprint/data_fmt.txt b/src/base/kprint/data_fmt.txt new file mode 100644 index 0000000..31f434f --- /dev/null +++ b/src/base/kprint/data_fmt.txt @@ -0,0 +1,13 @@ +[data types] +int 0x2000 00100000 00000000 +uint + withPostfix + uppercase 0x2001 00100000 00000001 +hex + withPrefix + uppercase 0x2002 00100000 00000010 +bin + withPrefix 0x2003 00100000 00000011 +float + withPostfix + uppercase 0x3000 00110000 00000000 +char 0x3001 00110000 00000001 +string 0x3002 00110000 00000010 +??? 0x3003 00110000 00000011 + +[optional flags] +withPrefix = withPostfix 0x0004 00000000 00000100 +upperase 0x0008 00000000 00001000 \ No newline at end of file diff --git a/src/base/kprint/kprint.c b/src/base/kprint/kprint.c new file mode 100644 index 0000000..ade114d --- /dev/null +++ b/src/base/kprint/kprint.c @@ -0,0 +1,22 @@ +#include "../base.h" + + + +Maybe __ksprint(uint8 n, uint16 sizes[32], ...){ + for(uint8 i=0; i #include #include +#include #include #include #include From 885259f82af70e81c104b9c34c08e6abef692e93 Mon Sep 17 00:00:00 2001 From: timerix Date: Wed, 31 Aug 2022 21:48:46 +0600 Subject: [PATCH 03/17] fixed some mistakes --- src/base/kprint/kprint.c | 4 ++-- src/base/kprint/kprint.h | 6 +++--- src/base/kprint/kprint_format.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/base/kprint/kprint.c b/src/base/kprint/kprint.c index ade114d..1323c3c 100644 --- a/src/base/kprint/kprint.c +++ b/src/base/kprint/kprint.c @@ -2,7 +2,7 @@ -Maybe __ksprint(uint8 n, uint16 sizes[32], ...){ +/* Maybe __ksprint(uint8 n, uint16 sizes[32], ...){ for(uint8 i=0; i Date: Wed, 31 Aug 2022 21:49:29 +0600 Subject: [PATCH 04/17] removed unneeded `else` from try() --- src/base/errors.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base/errors.h b/src/base/errors.h index 4109782..06f0017 100644 --- a/src/base/errors.h +++ b/src/base/errors.h @@ -59,12 +59,12 @@ char* __unknownErr( ); freeMem;\ _rezult.errmsg=__extendErrMsg(_rezult.errmsg, __FILE__,__LINE__,__func__);\ return _rezult;\ - }else + } #define tryLast(_funcCall, _rezult) Maybe _rezult=_funcCall; if(_rezult.errmsg){\ _rezult.errmsg=__extendErrMsg(_rezult.errmsg, __FILE__,__LINE__,__func__);\ __EXIT(_rezult.errmsg);\ - }else + } #endif From 55ab45eb56f7ac9db810c48038203b00e728076a Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Tue, 6 Sep 2022 15:17:58 +0600 Subject: [PATCH 05/17] kprint.h without variadic functions --- src/base/kprint/kprint.h | 60 ++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/src/base/kprint/kprint.h b/src/base/kprint/kprint.h index 38bb526..e6ec8f5 100644 --- a/src/base/kprint/kprint.h +++ b/src/base/kprint/kprint.h @@ -8,43 +8,67 @@ extern "C" { #include "kprint_colors.h" #include "kprint_format.h" -#define __count_va_args(\ +#define __count_args(\ a0, a1, a2, a3, a4, a5, a6, a7,\ a8, a9, a10,a11,a12,a13,a14,a15,\ a16,a17,a18,a19,a20,a21,a22,a23,\ a24,a25,a26,a27,a28,a29,a30,a31,\ a32) a32 -#define count_va_args(ARGS...) __count_va_args(\ +#define count_args(ARGS...) __count_args(\ ARGS,\ 32,31,30,29,28,27,26,25,\ 24,23,22,21,20,19,18,17,\ 16,15,14,13,12,11,10,9,\ 8, 7, 6, 5, 4, 3, 2, 1, 0) -#define __get_va_args_sizes(\ +#define __kprint_argsToFormats8(\ + a0, a1, a2, a3, a4, a5, a6, a7)\ + (kprint_format[]{ a0,a2,a4,a6 }) +#define __kprint_argsToObjects8(\ + a0, a1, a2, a3, a4, a5, a6, a7)\ + (void*[]{ a1,a3,a5,a7 }) + +#define __kprint_argsToFormats16(\ + a0, a1, a2, a3, a4, a5, a6, a7,\ + a8, a9, a10,a11,a12,a13,a14,a15)\ + (kprint_format[]{ a0,a2,a4,a6,a8,a10,a12,a14 }) +#define __kprint_argsToObjects16(\ + a0, a1, a2, a3, a4, a5, a6, a7,\ + a8, a9, a10,a11,a12,a13,a14,a15)\ + (void*[]{ a1,a3,a5,a7,a9,a11,a13,a15 }) + +#define __kprint_argsToFormats32(\ a0, a1, a2, a3, a4, a5, a6, a7,\ a8, a9, a10,a11,a12,a13,a14,a15,\ a16,a17,a18,a19,a20,a21,a22,a23,\ a24,a25,a26,a27,a28,a29,a30,a31)\ - (uint16[]{\ - sizeof(a0), sizeof(a1), sizeof(a2), sizeof(a3), sizeof(a4), sizeof(a5), sizeof(a6), sizeof(a7),\ - sizeof(a8), sizeof(a9), sizeof(a10),sizeof(a11),sizeof(a12),sizeof(a13),sizeof(a14),sizeof(a15),\ - sizeof(a16),sizeof(a17),sizeof(a18),sizeof(a19),sizeof(a20),sizeof(a21),sizeof(a22),sizeof(a23),\ - sizeof(a24),sizeof(a25),sizeof(a26),sizeof(a27),sizeof(a28),sizeof(a29),sizeof(a30),sizeof(a31)\ - }) -#define get_va_args_sizes(ARGS...) __get_va_args_sizes(ARGS,\ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) + (kprint_format[]{ a0,a2,a4,a6,a8,a10,a12,a14,a16,a18,a20,a22,a24,a26,a28,a30 } +#define __kprint_argsToObjects32(\ + a0, a1, a2, a3, a4, a5, a6, a7,\ + a8, a9, a10,a11,a12,a13,a14,a15,\ + a16,a17,a18,a19,a20,a21,a22,a23,\ + a24,a25,a26,a27,a28,a29,a30,a31)\ + (void*[]{ a1,a3,a5,a7,a9,a11,a13,a15,a17,a19,a21,a23,a25,a27,a29,a31 }) + +#define __32zeroes 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 + +#define __kprint_argsToArrs(COUNT,ARGS...)(\ + (COUNT<=8 __kprint_argsToFormats8(ARGS,__32zeroes) :\ + COUNT<=16 __kprint_argsToFormats16(ARGS,__32zeroes) :\ + __kprint_argsToFormats32(ARGS,__32zeroes)),\ + (COUNT<=8 __kprint_argsToObjects8(ARGS,__32zeroes) :\ + COUNT<=16 __kprint_argsToObjects16(ARGS) :\ + __kprint_argsToObjects32(ARGS,__32zeroes)) -Maybe __ksprint(uint8 n, uint16 sizes[32], ...); -#define ksprint(ARGS...) __ksprint(count_va_args(ARGS), get_va_args_sizes(ARGS), ARGS) +Maybe __ksprint(uint8 n, kprint_format* formats, void** objects); +#define ksprint(ARGS...) __ksprint(count_args(ARGS), __kprint_argsToArrs(count_args(ARGS),ARGS)) -Maybe __kfprint(FILE* fd, uint8 n, uint16 sizes[32], ...); -#define kfprint(FD, ARGS...) __kfprint(FD, count_va_args(ARGS), get_va_args_sizes(ARGS), ARGS) +Maybe __kfprint(FILE* fd, uint8 n, kprint_format* formats, void** objects); +#define kfprint(FD, ARGS...) __kfprint(FD, count_args(ARGS), __kprint_argsToArrs(count_args(ARGS),ARGS)) -void __kprint(uint8 n, uint16 sizes[32], ...); -#define kprint(ARGS...) __kprint(count_va_args(ARGS), get_va_args_sizes(ARGS), ARGS) +void __kprint(uint8 n, kprint_format* formats, void** objects); +#define kprint(ARGS...) __kprint(count_args(ARGS), __kprint_argsToArrs(count_args(ARGS),ARGS)) #if __cplusplus } From 3eb1e82f062309aeda1b96b74e0e74f1c50a8fac Mon Sep 17 00:00:00 2001 From: Timerix22 Date: Tue, 6 Sep 2022 15:19:14 +0600 Subject: [PATCH 06/17] script which chmods other scripts --- chmod_scripts.sh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 chmod_scripts.sh diff --git a/chmod_scripts.sh b/chmod_scripts.sh new file mode 100644 index 0000000..ec71ae9 --- /dev/null +++ b/chmod_scripts.sh @@ -0,0 +1,7 @@ +#!/bin/bash +SCRIPTS="$(find build_scripts -name '*.sh')" +for F in $SCRIPTS +do + echo $F + chmod +x $F +done From e63056d2446cbc5ef28aa42060b7bbcb32ffa76c Mon Sep 17 00:00:00 2001 From: timerix Date: Tue, 6 Sep 2022 15:53:13 +0600 Subject: [PATCH 07/17] some type system updates --- src/DtsodParser/DtsodV24_deserialize.c | 14 +-- src/DtsodParser/DtsodV24_serialize.c | 2 +- src/String/string.c | 3 + src/String/string.h | 2 + src/base/init.c | 136 +++++++++++++------------ src/base/types.c | 15 ++- src/base/types.h | 17 +++- src/base/unitype.c | 4 +- src/base/unitype.h | 16 +-- tests/test_marshalling.c | 2 +- tests/test_searchtree.c | 4 +- 11 files changed, 119 insertions(+), 96 deletions(-) diff --git a/src/DtsodParser/DtsodV24_deserialize.c b/src/DtsodParser/DtsodV24_deserialize.c index cd84b53..8acc293 100644 --- a/src/DtsodParser/DtsodV24_deserialize.c +++ b/src/DtsodParser/DtsodV24_deserialize.c @@ -98,9 +98,9 @@ Maybe __ReadName(DeserializeSharedData* shared){ case '}': if(!calledRecursively || nameStr.length!=0) safethrow_wrongchar(c,;); - return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr,NULL)); + return SUCCESS(UniHeap(kerepTypeId_CharPtr,NULL)); case ':': - return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr,string_extract(nameStr))); + return SUCCESS(UniHeap(kerepTypeId_CharPtr,string_extract(nameStr))); case '$': if(nameStr.length!=0) safethrow_wrongchar(c,;); @@ -113,7 +113,7 @@ Maybe __ReadName(DeserializeSharedData* shared){ } if(nameStr.length>0) safethrow(ERR_ENDOFSTR,;); - return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr,NULL)); + return SUCCESS(UniHeap(kerepTypeId_CharPtr,NULL)); } #define ReadName() __ReadName(shared) @@ -137,7 +137,7 @@ Maybe __ReadString(DeserializeSharedData* shared){ } else { char* str=StringBuilder_build(b).ptr; - return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr,str)); + return SUCCESS(UniHeap(kerepTypeId_CharPtr,str)); } } else { @@ -163,7 +163,7 @@ Maybe __ReadList(DeserializeSharedData* shared){ } } - return SUCCESS(UniPtrHeap(kerepTypeId_AutoarrUnitypePtr,list)); + return SUCCESS(UniHeap(kerepTypeId_AutoarrUnitypePtr,list)); }; #define ReadList() __ReadList(shared) @@ -321,7 +321,7 @@ Maybe __deserialize(char** _text, bool _calledRecursively) { } else{ list=Autoarr_create(Unitype,ARR_BC,ARR_BL); - Hashtable_add(dict,nameCPtr,UniPtrHeap(kerepTypeId_AutoarrUnitypePtr,list)); + Hashtable_add(dict,nameCPtr,UniHeap(kerepTypeId_AutoarrUnitypePtr,list)); } Autoarr_add(list,val.value); } @@ -331,7 +331,7 @@ Maybe __deserialize(char** _text, bool _calledRecursively) { END: *_text=text; - return SUCCESS(UniPtrHeap(kerepTypeId_HashtablePtr,dict)); + return SUCCESS(UniHeap(kerepTypeId_HashtablePtr,dict)); } Maybe DtsodV24_deserialize(char* _text) { diff --git a/src/DtsodParser/DtsodV24_serialize.c b/src/DtsodParser/DtsodV24_serialize.c index 601c0c0..3ab0346 100644 --- a/src/DtsodParser/DtsodV24_serialize.c +++ b/src/DtsodParser/DtsodV24_serialize.c @@ -126,5 +126,5 @@ Maybe DtsodV24_serialize(Hashtable* dtsod){ StringBuilder* sb=StringBuilder_create(); try(__serialize(sb,0,dtsod),__, StringBuilder_free(sb)); char* str=StringBuilder_build(sb).ptr; - return SUCCESS(UniPtrHeap(kerepTypeId_CharPtr, str)); + return SUCCESS(UniHeap(kerepTypeId_CharPtr, str)); } diff --git a/src/String/string.c b/src/String/string.c index 2926359..e7d92a6 100644 --- a/src/String/string.c +++ b/src/String/string.c @@ -1,5 +1,8 @@ #include "string.h" +kerepTypeId_define(kerepTypeId_string); +kerepTypeId_define(kerepTypeId_stringPtr); + // copies str content to new char pointer value (adding '\0' at the end) char* string_extract(string str){ if(str.length==0) return NULL; diff --git a/src/String/string.h b/src/String/string.h index e2076ee..0b9a658 100644 --- a/src/String/string.h +++ b/src/String/string.h @@ -12,6 +12,8 @@ typedef struct string{ char* ptr; // char pointer uint32 length; // amount of chars in ptr value } string; +kerepTypeId_declare(kerepTypeId_string); +kerepTypeId_declare(kerepTypeId_stringPtr); static const string stringNull={NULL,0}; diff --git a/src/base/init.c b/src/base/init.c index f838c64..cef81d1 100644 --- a/src/base/init.c +++ b/src/base/init.c @@ -6,92 +6,98 @@ void kerepTypeDescriptors_initKerepTypes(){ // null - kerepType_register(NULL, kerepTypeId_Null, NULL); + kerepType_register(NULL, kerepTypeId_Null, NULL, NULL); // base types - kerepType_register(char, kerepTypeId_Char, NULL); - kerepType_register(bool, kerepTypeId_Bool, NULL); - kerepType_register(float32, kerepTypeId_Float32, NULL); - kerepType_register(float64, kerepTypeId_Float64, NULL); - kerepType_register(int8, kerepTypeId_Int8, NULL); - kerepType_register(uint8, kerepTypeId_UInt8, NULL); - kerepType_register(int16, kerepTypeId_Int16, NULL); - kerepType_register(uint16, kerepTypeId_UInt16, NULL); - kerepType_register(int32, kerepTypeId_Int32, NULL); - kerepType_register(uint32, kerepTypeId_UInt32, NULL); - kerepType_register(int64, kerepTypeId_Int64, NULL); - kerepType_register(uint64, kerepTypeId_UInt64, NULL); + kerepType_register(char, kerepTypeId_Char, NULL, NULL); + kerepType_register(bool, kerepTypeId_Bool, NULL, NULL); + kerepType_register(float32, kerepTypeId_Float32, NULL, NULL); + kerepType_register(float64, kerepTypeId_Float64, NULL, NULL); + kerepType_register(int8, kerepTypeId_Int8, NULL, NULL); + kerepType_register(uint8, kerepTypeId_UInt8, NULL, NULL); + kerepType_register(int16, kerepTypeId_Int16, NULL, NULL); + kerepType_register(uint16, kerepTypeId_UInt16, NULL, NULL); + kerepType_register(int32, kerepTypeId_Int32, NULL, NULL); + kerepType_register(uint32, kerepTypeId_UInt32, NULL, NULL); + kerepType_register(int64, kerepTypeId_Int64, NULL, NULL); + kerepType_register(uint64, kerepTypeId_UInt64, NULL, NULL); // base type pointers - kerepType_register(char*, kerepTypeId_CharPtr, NULL); - kerepType_register(bool*, kerepTypeId_BoolPtr, NULL); - kerepType_register(float32*, kerepTypeId_Float32Ptr, NULL); - kerepType_register(float64*, kerepTypeId_Float64Ptr, NULL); - kerepType_register(int8*, kerepTypeId_Int8Ptr, NULL); - kerepType_register(uint8*, kerepTypeId_UInt8Ptr, NULL); - kerepType_register(int16*, kerepTypeId_Int16Ptr, NULL); - kerepType_register(uint16*, kerepTypeId_UInt16Ptr, NULL); - kerepType_register(int32*, kerepTypeId_Int32Ptr, NULL); - kerepType_register(uint32*, kerepTypeId_UInt32Ptr, NULL); - kerepType_register(int64*, kerepTypeId_Int64Ptr, NULL); - kerepType_register(uint64*, kerepTypeId_UInt64Ptr, NULL); + kerepType_register(char*, kerepTypeId_CharPtr, NULL, NULL); + kerepType_register(bool*, kerepTypeId_BoolPtr, NULL, NULL); + kerepType_register(float32*, kerepTypeId_Float32Ptr, NULL, NULL); + kerepType_register(float64*, kerepTypeId_Float64Ptr, NULL, NULL); + kerepType_register(int8*, kerepTypeId_Int8Ptr, NULL, NULL); + kerepType_register(uint8*, kerepTypeId_UInt8Ptr, NULL, NULL); + kerepType_register(int16*, kerepTypeId_Int16Ptr, NULL, NULL); + kerepType_register(uint16*, kerepTypeId_UInt16Ptr, NULL, NULL); + kerepType_register(int32*, kerepTypeId_Int32Ptr, NULL, NULL); + kerepType_register(uint32*, kerepTypeId_UInt32Ptr, NULL, NULL); + kerepType_register(int64*, kerepTypeId_Int64Ptr, NULL, NULL); + kerepType_register(uint64*, kerepTypeId_UInt64Ptr, NULL, NULL); + // kerepTypeDescriptor + kerepType_register(kerepTypeDescriptor, kerepTypeId_kerepTypeDescriptor, NULL, NULL); + kerepType_register(kerepTypeDescriptor*, kerepTypeId_kerepTypeDescriptorPtr, NULL, NULL); // base type autoarrs - kerepType_register(Autoarr_char, kerepTypeId_AutoarrChar, ____Autoarr_free_char); - kerepType_register(Autoarr_bool, kerepTypeId_AutoarrBool, ____Autoarr_free_bool); - kerepType_register(Autoarr_float32, kerepTypeId_AutoarrFloat32, ____Autoarr_free_float32); - kerepType_register(Autoarr_float64, kerepTypeId_AutoarrFloat64, ____Autoarr_free_float64); - kerepType_register(Autoarr_int8, kerepTypeId_AutoarrInt8, ____Autoarr_free_int8); - kerepType_register(Autoarr_uint8, kerepTypeId_AutoarrUInt8, ____Autoarr_free_uint8); - kerepType_register(Autoarr_int16, kerepTypeId_AutoarrInt16, ____Autoarr_free_int16); - kerepType_register(Autoarr_uint16, kerepTypeId_AutoarrUInt16, ____Autoarr_free_uint16); - kerepType_register(Autoarr_int32, kerepTypeId_AutoarrInt32, ____Autoarr_free_int32); - kerepType_register(Autoarr_uint32, kerepTypeId_AutoarrUInt32, ____Autoarr_free_uint32); - kerepType_register(Autoarr_int64, kerepTypeId_AutoarrInt64, ____Autoarr_free_int64); - kerepType_register(Autoarr_uint64, kerepTypeId_AutoarrUInt64, ____Autoarr_free_uint64); + kerepType_register(Autoarr_char, kerepTypeId_AutoarrChar, ____Autoarr_free_char, NULL); + kerepType_register(Autoarr_bool, kerepTypeId_AutoarrBool, ____Autoarr_free_bool, NULL); + kerepType_register(Autoarr_float32, kerepTypeId_AutoarrFloat32, ____Autoarr_free_float32, NULL); + kerepType_register(Autoarr_float64, kerepTypeId_AutoarrFloat64, ____Autoarr_free_float64, NULL); + kerepType_register(Autoarr_int8, kerepTypeId_AutoarrInt8, ____Autoarr_free_int8, NULL); + kerepType_register(Autoarr_uint8, kerepTypeId_AutoarrUInt8, ____Autoarr_free_uint8, NULL); + kerepType_register(Autoarr_int16, kerepTypeId_AutoarrInt16, ____Autoarr_free_int16, NULL); + kerepType_register(Autoarr_uint16, kerepTypeId_AutoarrUInt16, ____Autoarr_free_uint16, NULL); + kerepType_register(Autoarr_int32, kerepTypeId_AutoarrInt32, ____Autoarr_free_int32, NULL); + kerepType_register(Autoarr_uint32, kerepTypeId_AutoarrUInt32, ____Autoarr_free_uint32, NULL); + kerepType_register(Autoarr_int64, kerepTypeId_AutoarrInt64, ____Autoarr_free_int64, NULL); + kerepType_register(Autoarr_uint64, kerepTypeId_AutoarrUInt64, ____Autoarr_free_uint64, NULL); // base type autoarr pointers - kerepType_register(Autoarr_char*, kerepTypeId_AutoarrCharPtr, ____Autoarr_free_char); - kerepType_register(Autoarr_bool*, kerepTypeId_AutoarrBoolPtr, ____Autoarr_free_bool); - kerepType_register(Autoarr_float32*, kerepTypeId_AutoarrFloat32Ptr, ____Autoarr_free_float32); - kerepType_register(Autoarr_float64*, kerepTypeId_AutoarrFloat64Ptr, ____Autoarr_free_float64); - kerepType_register(Autoarr_int8*, kerepTypeId_AutoarrInt8Ptr, ____Autoarr_free_int8); - kerepType_register(Autoarr_uint8*, kerepTypeId_AutoarrUInt8Ptr, ____Autoarr_free_uint8); - kerepType_register(Autoarr_int16*, kerepTypeId_AutoarrInt16Ptr, ____Autoarr_free_int16); - kerepType_register(Autoarr_uint16*, kerepTypeId_AutoarrUInt16Ptr, ____Autoarr_free_uint16); - kerepType_register(Autoarr_int32*, kerepTypeId_AutoarrInt32Ptr, ____Autoarr_free_int32); - kerepType_register(Autoarr_uint32*, kerepTypeId_AutoarrUInt32Ptr, ____Autoarr_free_uint32); - kerepType_register(Autoarr_int64*, kerepTypeId_AutoarrInt64Ptr, ____Autoarr_free_int64); - kerepType_register(Autoarr_uint64*, kerepTypeId_AutoarrUInt64Ptr, ____Autoarr_free_uint64); + kerepType_register(Autoarr_char*, kerepTypeId_AutoarrCharPtr, ____Autoarr_free_char, NULL); + kerepType_register(Autoarr_bool*, kerepTypeId_AutoarrBoolPtr, ____Autoarr_free_bool, NULL); + kerepType_register(Autoarr_float32*, kerepTypeId_AutoarrFloat32Ptr, ____Autoarr_free_float32, NULL); + kerepType_register(Autoarr_float64*, kerepTypeId_AutoarrFloat64Ptr, ____Autoarr_free_float64, NULL); + kerepType_register(Autoarr_int8*, kerepTypeId_AutoarrInt8Ptr, ____Autoarr_free_int8, NULL); + kerepType_register(Autoarr_uint8*, kerepTypeId_AutoarrUInt8Ptr, ____Autoarr_free_uint8, NULL); + kerepType_register(Autoarr_int16*, kerepTypeId_AutoarrInt16Ptr, ____Autoarr_free_int16, NULL); + kerepType_register(Autoarr_uint16*, kerepTypeId_AutoarrUInt16Ptr, ____Autoarr_free_uint16, NULL); + kerepType_register(Autoarr_int32*, kerepTypeId_AutoarrInt32Ptr, ____Autoarr_free_int32, NULL); + kerepType_register(Autoarr_uint32*, kerepTypeId_AutoarrUInt32Ptr, ____Autoarr_free_uint32, NULL); + kerepType_register(Autoarr_int64*, kerepTypeId_AutoarrInt64Ptr, ____Autoarr_free_int64, NULL); + kerepType_register(Autoarr_uint64*, kerepTypeId_AutoarrUInt64Ptr, ____Autoarr_free_uint64, NULL); // Unitype - kerepType_register(Unitype, kerepTypeId_Unitype, __UnitypePtr_free); - kerepType_register(Unitype*, kerepTypeId_UnitypePtr, __UnitypePtr_free); - kerepType_register(Autoarr_Unitype, kerepTypeId_AutoarrUnitype, ____Autoarr_free_Unitype_); - kerepType_register(Autoarr_Unitype*, kerepTypeId_AutoarrUnitypePtr, ____Autoarr_free_Unitype_); + kerepType_register(Unitype, kerepTypeId_Unitype, __UnitypePtr_free, NULL); + kerepType_register(Unitype*, kerepTypeId_UnitypePtr, __UnitypePtr_free, NULL); + kerepType_register(Autoarr_Unitype, kerepTypeId_AutoarrUnitype, ____Autoarr_free_Unitype_, NULL); + kerepType_register(Autoarr_Unitype*, kerepTypeId_AutoarrUnitypePtr, ____Autoarr_free_Unitype_, NULL); // replacing autogenerated freear() function to custom Autoarr_Unitype* _uar=Autoarr_create(Unitype, 1, 1); _uar->functions->freear=__Autoarr_free_Unitype_; Autoarr_free(_uar, true); // SearchTreeNode - kerepType_register(STNode, kerepTypeId_STNode, __STNode_free); - kerepType_register(STNode*, kerepTypeId_STNodePtr, __STNode_free); + kerepType_register(STNode, kerepTypeId_STNode, __STNode_free, NULL); + kerepType_register(STNode*, kerepTypeId_STNodePtr, __STNode_free, NULL); // KeyValuePair - kerepType_register(KVPair, kerepTypeId_KVPair, __KVPair_free); - kerepType_register(KVPair*, kerepTypeId_KVPairPtr, __KVPair_free); - kerepType_register(Autoarr_KVPair, kerepTypeId_AutoarrKVPair, ____Autoarr_free_KVPair_); - kerepType_register(Autoarr_KVPair*, kerepTypeId_AutoarrKVPairPtr, ____Autoarr_free_KVPair_); + kerepType_register(KVPair, kerepTypeId_KVPair, __KVPair_free, NULL); + kerepType_register(KVPair*, kerepTypeId_KVPairPtr, __KVPair_free, NULL); + kerepType_register(Autoarr_KVPair, kerepTypeId_AutoarrKVPair, ____Autoarr_free_KVPair_, NULL); + kerepType_register(Autoarr_KVPair*, kerepTypeId_AutoarrKVPairPtr, ____Autoarr_free_KVPair_, NULL); // replacing autogenerated freear() function to custom Autoarr_KVPair* _kvpar=Autoarr_create(KVPair, 1, 1); _kvpar->functions->freear=__Autoarr_free_KVPair_; Autoarr_free(_kvpar, true); // Hashtable - kerepType_register(Hashtable, kerepTypeId_Hashtable, __Hashtable_free); - kerepType_register(Hashtable*, kerepTypeId_HashtablePtr, __Hashtable_free); + kerepType_register(Hashtable, kerepTypeId_Hashtable, __Hashtable_free, NULL); + kerepType_register(Hashtable*, kerepTypeId_HashtablePtr, __Hashtable_free, NULL); + // string + kerepType_register(string, kerepTypeId_string, NULL, NULL); + kerepType_register(string*, kerepTypeId_stringPtr, NULL, NULL); + kerepType_register(string, kerepTypeId_AutoarrString, ____Autoarr_free_string, NULL); + kerepType_register(string*, kerepTypeId_AutoarrStringPtr, ____Autoarr_free_string, NULL); // StringBuilder - kerepType_register(Autoarr_string, kerepTypeId_AutoarrString, ____Autoarr_free_string); - kerepType_register(Autoarr_string*, kerepTypeId_AutoarrStringPtr, ____Autoarr_free_string); - kerepType_register(StringBuilder, kerepTypeId_StringBuilder, __StringBuilder_free); - kerepType_register(StringBuilder*, kerepTypeId_StringBuilderPtr, __StringBuilder_free); + kerepType_register(StringBuilder, kerepTypeId_StringBuilder, __StringBuilder_free, NULL); + kerepType_register(StringBuilder*, kerepTypeId_StringBuilderPtr, __StringBuilder_free, NULL); } diff --git a/src/base/types.c b/src/base/types.c index b96bdb6..9bf5ce1 100644 --- a/src/base/types.c +++ b/src/base/types.c @@ -32,6 +32,9 @@ kerepTypeId_define(kerepTypeId_UInt32Ptr); kerepTypeId_define(kerepTypeId_Int64Ptr); kerepTypeId_define(kerepTypeId_UInt64Ptr); +kerepTypeId_define(kerepTypeId_kerepTypeDescriptor); +kerepTypeId_define(kerepTypeId_kerepTypeDescriptorPtr); + // type descriptors are stored here during initialization Autoarr(kerepTypeDescriptor)* __kerepTypeDescriptors=NULL; // here type descriptors are stored when initialization is complited @@ -56,16 +59,18 @@ void kerepTypeDescriptors_endInit(){ printf("\e[92minitialized %u type descriptors\n", kerepTypeId_last); } -void __kerepType_register(char* name, int16 size, void (*free_members)(void*)){ +void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, int32)){ kerepTypeDescriptor typeDesc={ .name=name, .size=size, - .free_members=free_members, - .id=++kerepTypeId_last + .id=++kerepTypeId_last, + .freeMembers=freeMembers, + .toString=toString }; Autoarr_add(__kerepTypeDescriptors, typeDesc); } -kerepTypeDescriptor kerepTypeDescriptor_get(kerepTypeId id){ - return typeDescriptors[id]; +Maybe kerepTypeDescriptor_get(kerepTypeId id){ + if(id>kerepTypeId_last) safethrow("invalid type id",;); + return SUCCESS(UniStack(kerepTypeId_kerepTypeDescriptorPtr, &typeDescriptors[id])); } diff --git a/src/base/types.h b/src/base/types.h index 8d5dd23..96ff861 100644 --- a/src/base/types.h +++ b/src/base/types.h @@ -9,10 +9,12 @@ extern "C" { typedef uint16 kerepTypeId; typedef struct kerepTypeDescriptor{ - void (*free_members)(void*); // NULL or function which frees all struct members char* name; kerepTypeId id; uint16 size; + void (*freeMembers)(void*); // NULL or function which frees all struct members + ///@return Maybe + Maybe (*toString)(void*, int32); // NULL or function which generates string representaion of object } kerepTypeDescriptor; #define kerepTypeId_declare(ID_VAR_NAME)\ @@ -21,15 +23,17 @@ typedef struct kerepTypeDescriptor{ kerepTypeId ID_VAR_NAME=-1 extern kerepTypeId kerepTypeId_last; -void __kerepType_register(char* name, int16 size, void (*free_members)(void*)); +void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, int32)); -#define kerepType_register(TYPE, ID_VAR_NAME, FREE_MEMBERS_FUNC)\ - __kerepType_register(#ID_VAR_NAME, sizeof(TYPE), FREE_MEMBERS_FUNC);\ +#define kerepType_register(TYPE, ID_VAR_NAME, FREE_MEMBERS_FUNC, TO_STRING_FUNC)\ + __kerepType_register(#ID_VAR_NAME, sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\ ID_VAR_NAME=kerepTypeId_last; void kerepTypeDescriptors_beginInit(); void kerepTypeDescriptors_endInit(); -kerepTypeDescriptor kerepTypeDescriptor_get(kerepTypeId id); +/// @param id id of registered type +/// @return Maybe +Maybe kerepTypeDescriptor_get(kerepTypeId id); kerepTypeId_declare(kerepTypeId_Null); @@ -59,6 +63,9 @@ kerepTypeId_declare(kerepTypeId_UInt32Ptr); kerepTypeId_declare(kerepTypeId_Int64Ptr); kerepTypeId_declare(kerepTypeId_UInt64Ptr); +kerepTypeId_declare(kerepTypeId_kerepTypeDescriptor); +kerepTypeId_declare(kerepTypeId_kerepTypeDescriptorPtr); + #if __cplusplus } #endif \ No newline at end of file diff --git a/src/base/unitype.c b/src/base/unitype.c index 8a555c5..2167a9c 100644 --- a/src/base/unitype.c +++ b/src/base/unitype.c @@ -5,8 +5,8 @@ kerepTypeId_define(kerepTypeId_UnitypePtr); void Unitype_free(Unitype u){ kerepTypeDescriptor type=kerepTypeDescriptor_get(u.typeId); - if(type.free_members) - type.free_members(u.VoidPtr); + if(type.freeMembers) + type.freeMembers(u.VoidPtr); if(u.allocatedInHeap) free(u.VoidPtr); } diff --git a/src/base/unitype.h b/src/base/unitype.h index 146c5d1..5dfa097 100644 --- a/src/base/unitype.h +++ b/src/base/unitype.h @@ -22,20 +22,20 @@ kerepTypeId_declare(kerepTypeId_Unitype); kerepTypeId_declare(kerepTypeId_UnitypePtr); -#define Uni(TYPE, VAL) (Unitype){\ +#define __UniDef(TYPE, VAL) (Unitype){\ .TYPE=VAL, .typeId=kerepTypeId_##TYPE, .allocatedInHeap=false} -#define UniInt64(VAL) Uni(Int64, VAL) -#define UniUInt64(VAL) Uni(UInt64, VAL) -#define UniFloat64(VAL) Uni(Float64, VAL) -#define UniBool(VAL) Uni(Bool, VAL) +#define UniInt64(VAL) __UniDef(Int64, VAL) +#define UniUInt64(VAL) __UniDef(UInt64, VAL) +#define UniFloat64(VAL) __UniDef(Float64, VAL) +#define UniBool(VAL) __UniDef(Bool, VAL) -#define UniPtrStack(ID_VAR_NAME, VAL) (Unitype){\ +#define UniStack(ID_VAR_NAME, VAL) (Unitype){\ .VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=false} -#define UniPtrHeap(ID_VAR_NAME, VAL) (Unitype){\ +#define UniHeap(ID_VAR_NAME, VAL) (Unitype){\ .VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=true} -#define UniNull UniPtrStack(kerepTypeId_Null, NULL) +#define UniNull UniStack(kerepTypeId_Null, NULL) #define UniTrue UniBool(true) #define UniFalse UniBool(false) diff --git a/tests/test_marshalling.c b/tests/test_marshalling.c index 21c5721..74e2129 100644 --- a/tests/test_marshalling.c +++ b/tests/test_marshalling.c @@ -4,7 +4,7 @@ EXPORT void CALL test_marshalling(char* text, KVPair** kptr){ KVPair* k=malloc(sizeof(KVPair)); k->key="message"; char* tc=cptr_copy(text); - Unitype u=UniPtrHeap(kerepTypeId_CharPtr,tc); + Unitype u=UniHeap(kerepTypeId_CharPtr,tc); k->value=u; *kptr=k; } diff --git a/tests/test_searchtree.c b/tests/test_searchtree.c index 6309e85..c67e8fd 100644 --- a/tests/test_searchtree.c +++ b/tests/test_searchtree.c @@ -44,11 +44,11 @@ void test_searchtree(){ printuni(u); ST_push(node,"channel_id", u); printf(" -> channel_id\n "); - u=UniPtrHeap(kerepTypeId_CharPtr, cptr_copy("32.2004")); + u=UniHeap(kerepTypeId_CharPtr, cptr_copy("32.2004")); printuni(u); ST_push(node,"message_id", u); printf(" -> message_id\n "); - u=UniPtrStack(kerepTypeId_CharPtr,"some text UwU"); + u=UniStack(kerepTypeId_CharPtr,"some text UwU"); printuni(u); ST_push(node,"text", u); printf(" -> text\n"); From 07cd352f653fd5697f52da76afa1a4a6a99b73e4 Mon Sep 17 00:00:00 2001 From: timerix Date: Tue, 6 Sep 2022 15:54:44 +0600 Subject: [PATCH 08/17] kprint.c --- src/base/kprint/kprint.c | 112 ++++++++++++++++++++++++++++---- src/base/kprint/kprint_format.h | 3 - 2 files changed, 101 insertions(+), 14 deletions(-) diff --git a/src/base/kprint/kprint.c b/src/base/kprint/kprint.c index 1323c3c..2fb60a8 100644 --- a/src/base/kprint/kprint.c +++ b/src/base/kprint/kprint.c @@ -1,22 +1,112 @@ #include "../base.h" +#include "../../String/StringBuilder.h" +Maybe __next_toString(uint16 size, va_list args, StringBuilder* strb){ + kprint_format format=va_arg(args, kprint_format); + if(!format.dataFmtSet) + safethrow("format is not set", StringBuilder_free(strb)); + // detecting type + if(!format.typeId) switch(format.dataFmt){ + case kprint_fmtInt: + case kprint_fmtHex: + case kprint_fmtBin: + switch(size){ + case 1: format.typeId=kerepTypeId_Int8; break; + case 2: format.typeId=kerepTypeId_Int16; break; + case 4: format.typeId=kerepTypeId_Int32; break; + case 8: format.typeId=kerepTypeId_Int64; break; + default: safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); + } + break; + case kprint_fmtUInt: + switch(size){ + case 1: format.typeId=kerepTypeId_UInt8; break; + case 2: format.typeId=kerepTypeId_UInt16; break; + case 4: format.typeId=kerepTypeId_UInt32; break; + case 8: format.typeId=kerepTypeId_UInt64; break; + default: safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); + } + break; + case kprint_fmtFloat: + switch(size){ + case 4: format.typeId=kerepTypeId_Float32; break; + case 8: format.typeId=kerepTypeId_Float64; break; + default: safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); + } + break; + case kprint_fmtChar: + if(size!=1) + safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); + format.typeId=kerepTypeId_Char; + break; + case kprint_fmtString: + switch(size){ + case sizeof(char*): format.typeId=kerepTypeId_CharPtr; break; + case sizeof(string): format.typeId=kerepTypeId_string; break; + default: safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); + } + break; + default: + safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); + } + try(kerepTypeDescriptor_get(format.typeId),mtd,StringBuilder_free(strb)); + kerepTypeDescriptor typeDesc=*(kerepTypeDescriptor*)mtd.value.VoidPtr; + if(size Date: Tue, 6 Sep 2022 20:06:08 +0600 Subject: [PATCH 09/17] a lot of changes --- src/DtsodParser/DtsodV24_deserialize.c | 6 +- src/base/base.h | 4 +- src/base/cptr.h | 2 +- src/base/errors.h | 2 +- src/base/kprint/README.md | 35 ++++- src/base/kprint/data_fmt.txt | 13 -- src/base/kprint/kprint.c | 151 +++++++++------------ src/base/kprint/kprint.h | 3 + src/base/kprint/kprint_colors.h | 72 +++++----- src/base/kprint/kprint_format.h | 68 ++++------ src/base/kprint/kprint_format.md | 72 ++++++++++ src/base/optime.h | 2 +- src/base/type_system/README.md | 0 src/base/type_system/kerepTypeDescriptor.h | 22 +++ src/base/type_system/kerepTypeId.h | 17 +++ src/base/{ => type_system}/types.c | 6 +- src/base/{ => type_system}/types.h | 22 +-- src/base/{ => type_system}/unitype.c | 8 +- src/base/{ => type_system}/unitype.h | 2 +- tests/test_hashtable.c | 2 +- tests/test_safethrow.c | 2 +- 21 files changed, 294 insertions(+), 217 deletions(-) delete mode 100644 src/base/kprint/data_fmt.txt create mode 100644 src/base/kprint/kprint_format.md create mode 100644 src/base/type_system/README.md create mode 100644 src/base/type_system/kerepTypeDescriptor.h create mode 100644 src/base/type_system/kerepTypeId.h rename src/base/{ => type_system}/types.c (96%) rename src/base/{ => type_system}/types.h (75%) rename src/base/{ => type_system}/unitype.c (81%) rename src/base/{ => type_system}/unitype.h (98%) diff --git a/src/DtsodParser/DtsodV24_deserialize.c b/src/DtsodParser/DtsodV24_deserialize.c index 8acc293..ecf1322 100644 --- a/src/DtsodParser/DtsodV24_deserialize.c +++ b/src/DtsodParser/DtsodV24_deserialize.c @@ -182,7 +182,7 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){ // Float64 case 'f': { char* _c=string_extract(str); - Unitype rez=Uni(Float64,strtod(_c,NULL)); + Unitype rez=UniFloat64(strtod(_c,NULL)); free(_c); return SUCCESS(rez); } @@ -199,7 +199,7 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){ safethrow(err,free(_c)); } free(_c); - return SUCCESS(Uni(UInt64,lu)); + return SUCCESS(UniUInt64(lu)); } // Int64 case '0': case '1': case '2': case '3': case '4': @@ -215,7 +215,7 @@ Maybe __ParseValue(DeserializeSharedData* shared, string str){ safethrow(err,free(_c)); } free(_c); - return SUCCESS(Uni(Int64,li)); + return SUCCESS(UniInt64(li)); } // wrong type default: diff --git a/src/base/base.h b/src/base/base.h index c728a94..fce8588 100644 --- a/src/base/base.h +++ b/src/base/base.h @@ -8,8 +8,8 @@ extern "C" { #include "errors.h" #include "cptr.h" #include "optime.h" -#include "types.h" -#include "unitype.h" +#include "type_system/types.h" +#include "type_system/unitype.h" #include "init.h" #include "kprint/kprint.h" diff --git a/src/base/cptr.h b/src/base/cptr.h index b750842..6372931 100644 --- a/src/base/cptr.h +++ b/src/base/cptr.h @@ -4,7 +4,7 @@ extern "C" { #endif -#include "types.h" +#include "std.h" // returns length of char buffer (without \0) uint32 cptr_length(char* str); diff --git a/src/base/errors.h b/src/base/errors.h index 06f0017..324695e 100644 --- a/src/base/errors.h +++ b/src/base/errors.h @@ -5,7 +5,7 @@ extern "C" { #endif #include "std.h" -#include "unitype.h" +#include "type_system/unitype.h" typedef enum ErrorId { SUCCESS, // not an error diff --git a/src/base/kprint/README.md b/src/base/kprint/README.md index e375f83..c02cdac 100644 --- a/src/base/kprint/README.md +++ b/src/base/kprint/README.md @@ -1,2 +1,33 @@ -## kprint -I don't really like printf function, so i made safer and more convinient replacement. \ No newline at end of file +# kprint +I don't really like printf function (and its variants), so i made safer and more convinient replacement. + +| function | returns | arguments | +|----------|---------|-----------| +| kprint | void/throw | kprint_format, void*, kprint_format, void*... | +| ksprint | Maybe | kprint_format, void*, kprint_format, void*... | +| kfprint | Maybe | FILE*, kprint_format, void*, kprint_format, void*... | + +## how to use it: ++ **format construction:** + ``` + kprint_format fmt= kprint_fgColor | kprint_fbgColor | kprint_fdataFmt | flags | kerepTypeId; + ``` + [more about `kprint_format`](kprint_format.md) + + fgColor and bgColor can be set to change console output color + + you should set dataFormat for `int`/`uint`/`float`/`char*` arguments and kerepTypeId for other types + + flags can be set to modify TypeDescriptor.toString() behavior + + don't forget to set TypeDescriptor.toString when registering type, or kprint will crash + ++ **using base type arguments:** + you can just put them into a function + ``` + kprint(kprint_fmtHex | kprint_fmtUppercase | kprint_fmtWithPrefix, 255); + ``` + output: 0xFF ++ **using other registered types:** + should be sent as pointers + ``` + Maybe m=MaybeNull; + kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | kerepTypeId_MaybePtr, &m); + ``` + output: Maybe: {value={0, kerepTypeId_Null}} \ No newline at end of file diff --git a/src/base/kprint/data_fmt.txt b/src/base/kprint/data_fmt.txt deleted file mode 100644 index 31f434f..0000000 --- a/src/base/kprint/data_fmt.txt +++ /dev/null @@ -1,13 +0,0 @@ -[data types] -int 0x2000 00100000 00000000 -uint + withPostfix + uppercase 0x2001 00100000 00000001 -hex + withPrefix + uppercase 0x2002 00100000 00000010 -bin + withPrefix 0x2003 00100000 00000011 -float + withPostfix + uppercase 0x3000 00110000 00000000 -char 0x3001 00110000 00000001 -string 0x3002 00110000 00000010 -??? 0x3003 00110000 00000011 - -[optional flags] -withPrefix = withPostfix 0x0004 00000000 00000100 -upperase 0x0008 00000000 00001000 \ No newline at end of file diff --git a/src/base/kprint/kprint.c b/src/base/kprint/kprint.c index 2fb60a8..fc89c72 100644 --- a/src/base/kprint/kprint.c +++ b/src/base/kprint/kprint.c @@ -1,112 +1,87 @@ -#include "../base.h" +/* #include "../base.h" #include "../../String/StringBuilder.h" -Maybe __next_toString(uint16 size, va_list args, StringBuilder* strb){ - kprint_format format=va_arg(args, kprint_format); - if(!format.dataFmtSet) - safethrow("format is not set", StringBuilder_free(strb)); +Maybe __next_toString(kprint_format format, void* object){ // detecting type - if(!format.typeId) switch(format.dataFmt){ + if(!format.typeId) switch((kprint_dataFormat)((uint32)0 | format.dataFmt)){ case kprint_fmtInt: case kprint_fmtHex: - case kprint_fmtBin: - switch(size){ - case 1: format.typeId=kerepTypeId_Int8; break; - case 2: format.typeId=kerepTypeId_Int16; break; - case 4: format.typeId=kerepTypeId_Int32; break; - case 8: format.typeId=kerepTypeId_Int64; break; - default: safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); - } - break; + case kprint_fmtBin: + format.typeId=kerepTypeId_Int64; break; case kprint_fmtUInt: - switch(size){ - case 1: format.typeId=kerepTypeId_UInt8; break; - case 2: format.typeId=kerepTypeId_UInt16; break; - case 4: format.typeId=kerepTypeId_UInt32; break; - case 8: format.typeId=kerepTypeId_UInt64; break; - default: safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); - } - break; + format.typeId=kerepTypeId_UInt64; break; case kprint_fmtFloat: - switch(size){ - case 4: format.typeId=kerepTypeId_Float32; break; - case 8: format.typeId=kerepTypeId_Float64; break; - default: safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); - } - break; + format.typeId=kerepTypeId_Float64; break; case kprint_fmtChar: - if(size!=1) - safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); - format.typeId=kerepTypeId_Char; - break; + format.typeId=kerepTypeId_Char; break; case kprint_fmtString: - switch(size){ - case sizeof(char*): format.typeId=kerepTypeId_CharPtr; break; - case sizeof(string): format.typeId=kerepTypeId_string; break; - default: safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); - } - break; + format.typeId=kerepTypeId_CharPtr; break; default: - safethrow("typeId is not set, can't autodetect type", StringBuilder_free(strb)); + safethrow("typeId is not set, can't autodetect type",;); } - try(kerepTypeDescriptor_get(format.typeId),mtd,StringBuilder_free(strb)); + try(kerepTypeDescriptor_get(format.typeId),mtd,;); kerepTypeDescriptor typeDesc=*(kerepTypeDescriptor*)mtd.value.VoidPtr; - if(size + Maybe (*toString)(void*, int32); // NULL or function which generates string representaion of object +} kerepTypeDescriptor; + +#if __cplusplus +} +#endif \ No newline at end of file diff --git a/src/base/type_system/kerepTypeId.h b/src/base/type_system/kerepTypeId.h new file mode 100644 index 0000000..6f4f4af --- /dev/null +++ b/src/base/type_system/kerepTypeId.h @@ -0,0 +1,17 @@ +#pragma once + +#if __cplusplus +extern "C" { +#endif + +#include "../std.h" +typedef uint16 kerepTypeId; + +#define kerepTypeId_declare(ID_VAR_NAME)\ + extern kerepTypeId ID_VAR_NAME +#define kerepTypeId_define(ID_VAR_NAME)\ + kerepTypeId ID_VAR_NAME=-1 + +#if __cplusplus +} +#endif \ No newline at end of file diff --git a/src/base/types.c b/src/base/type_system/types.c similarity index 96% rename from src/base/types.c rename to src/base/type_system/types.c index 9bf5ce1..82d2d6d 100644 --- a/src/base/types.c +++ b/src/base/type_system/types.c @@ -1,5 +1,5 @@ -#include "../Autoarr/Autoarr.h" -#include "unitype.h" +#include "../../Autoarr/Autoarr.h" +#include "types.h" Autoarr_declare(kerepTypeDescriptor) Autoarr_define(kerepTypeDescriptor) @@ -59,7 +59,7 @@ void kerepTypeDescriptors_endInit(){ printf("\e[92minitialized %u type descriptors\n", kerepTypeId_last); } -void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, int32)){ +void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), Maybe (*toString)(void*, int32)){ kerepTypeDescriptor typeDesc={ .name=name, .size=size, diff --git a/src/base/types.h b/src/base/type_system/types.h similarity index 75% rename from src/base/types.h rename to src/base/type_system/types.h index 96ff861..8cbaa6b 100644 --- a/src/base/types.h +++ b/src/base/type_system/types.h @@ -4,26 +4,13 @@ extern "C" { #endif -#include "std.h" +#include "../std.h" +#include "kerepTypeId.h" +#include "kerepTypeDescriptor.h" -typedef uint16 kerepTypeId; - -typedef struct kerepTypeDescriptor{ - char* name; - kerepTypeId id; - uint16 size; - void (*freeMembers)(void*); // NULL or function which frees all struct members - ///@return Maybe - Maybe (*toString)(void*, int32); // NULL or function which generates string representaion of object -} kerepTypeDescriptor; - -#define kerepTypeId_declare(ID_VAR_NAME)\ - extern kerepTypeId ID_VAR_NAME -#define kerepTypeId_define(ID_VAR_NAME)\ - kerepTypeId ID_VAR_NAME=-1 extern kerepTypeId kerepTypeId_last; -void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, int32)); +void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), Maybe (*toString)(void*, int32)); #define kerepType_register(TYPE, ID_VAR_NAME, FREE_MEMBERS_FUNC, TO_STRING_FUNC)\ __kerepType_register(#ID_VAR_NAME, sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\ @@ -35,6 +22,7 @@ void kerepTypeDescriptors_endInit(); /// @return Maybe Maybe kerepTypeDescriptor_get(kerepTypeId id); + kerepTypeId_declare(kerepTypeId_Null); kerepTypeId_declare(kerepTypeId_Char); diff --git a/src/base/unitype.c b/src/base/type_system/unitype.c similarity index 81% rename from src/base/unitype.c rename to src/base/type_system/unitype.c index 2167a9c..8b44641 100644 --- a/src/base/unitype.c +++ b/src/base/type_system/unitype.c @@ -1,10 +1,11 @@ -#include "base.h" +#include "../base.h" kerepTypeId_define(kerepTypeId_Unitype); kerepTypeId_define(kerepTypeId_UnitypePtr); void Unitype_free(Unitype u){ - kerepTypeDescriptor type=kerepTypeDescriptor_get(u.typeId); + tryLast(kerepTypeDescriptor_get(u.typeId), mType); + kerepTypeDescriptor type=*(kerepTypeDescriptor*)mType.value.VoidPtr; if(type.freeMembers) type.freeMembers(u.VoidPtr); if(u.allocatedInHeap) @@ -15,7 +16,8 @@ void __UnitypePtr_free(void* u) { Unitype_free(*(Unitype*)u); } #define BUFSIZE 64 char* sprintuni(Unitype v){ char* buf=malloc(BUFSIZE); - kerepTypeDescriptor type=kerepTypeDescriptor_get(v.typeId); + tryLast(kerepTypeDescriptor_get(v.typeId), mType); + kerepTypeDescriptor type=*(kerepTypeDescriptor*)mType.value.VoidPtr; if(v.typeId==kerepTypeId_Null) sprintf_s(buf, BUFSIZE, "{Null}"); else if(v.typeId==kerepTypeId_Float64) diff --git a/src/base/unitype.h b/src/base/type_system/unitype.h similarity index 98% rename from src/base/unitype.h rename to src/base/type_system/unitype.h index 5dfa097..9f28bf7 100644 --- a/src/base/unitype.h +++ b/src/base/type_system/unitype.h @@ -4,7 +4,7 @@ extern "C" { #endif -#include "types.h" +#include "kerepTypeId.h" typedef struct Unitype{ union { diff --git a/tests/test_hashtable.c b/tests/test_hashtable.c index 8ff1d53..e68d02a 100644 --- a/tests/test_hashtable.c +++ b/tests/test_hashtable.c @@ -47,7 +47,7 @@ char* genkey(uint32 i){ void fill(Hashtable* ht){ for(uint32 i=0;i<100000;i++) - Hashtable_add(ht,genkey(i),Uni(UInt64,i)); + Hashtable_add(ht,genkey(i),UniUInt64(i)); } Unitype gett(Hashtable* ht){ diff --git a/tests/test_safethrow.c b/tests/test_safethrow.c index 4ccd4dc..f37812d 100644 --- a/tests/test_safethrow.c +++ b/tests/test_safethrow.c @@ -1,7 +1,7 @@ #include "tests.h" Maybe dont_throw(){ - return SUCCESS(Uni(UInt64, 9/2)); + return SUCCESS(UniUInt64(9/2)); } Maybe throw_error(){ From 67e1328ee7d28430707425145d0fb6f720c04864 Mon Sep 17 00:00:00 2001 From: timerix Date: Tue, 6 Sep 2022 21:25:03 +0600 Subject: [PATCH 10/17] kerepType -> kt --- src/Autoarr/Autoarr.c | 52 ++++----- src/Autoarr/Autoarr.h | 52 ++++----- src/DtsodParser/DtsodV24_deserialize.c | 18 +-- src/DtsodParser/DtsodV24_serialize.c | 18 +-- src/Hashtable/Hashtable.c | 6 +- src/Hashtable/Hashtable.h | 4 +- src/Hashtable/KeyValuePair.c | 8 +- src/Hashtable/KeyValuePair.h | 8 +- src/SearchTree/SearchTree.c | 6 +- src/SearchTree/SearchTree.h | 4 +- src/String/StringBuilder.c | 8 +- src/String/StringBuilder.h | 8 +- src/String/string.c | 4 +- src/String/string.h | 4 +- src/base/base.h | 4 +- src/base/init.c | 103 ------------------ src/base/init.h | 12 -- src/base/kprint/README.md | 8 +- src/base/kprint/kprint.c | 22 ++-- src/base/kprint/kprint_format.h | 4 +- src/base/kprint/kprint_format.md | 2 +- src/base/type_system/init.c | 103 ++++++++++++++++++ src/base/type_system/init.h | 12 ++ src/base/type_system/kerepTypeId.h | 17 --- .../{kerepTypeDescriptor.h => ktDescriptor.h} | 8 +- src/base/type_system/ktId.h | 17 +++ src/base/type_system/kt_functions.c | 75 +++++++++++++ src/base/type_system/kt_functions.h | 59 ++++++++++ src/base/type_system/type_system.h | 4 + src/base/type_system/types.c | 76 ------------- src/base/type_system/types.h | 59 ---------- src/base/type_system/unitype.c | 22 ++-- src/base/type_system/unitype.h | 12 +- tests/main.cpp | 6 +- tests/test_dtsod.c | 2 +- tests/test_marshalling.c | 2 +- tests/test_searchtree.c | 4 +- 37 files changed, 417 insertions(+), 416 deletions(-) delete mode 100644 src/base/init.c delete mode 100644 src/base/init.h create mode 100644 src/base/type_system/init.c create mode 100644 src/base/type_system/init.h delete mode 100644 src/base/type_system/kerepTypeId.h rename src/base/type_system/{kerepTypeDescriptor.h => ktDescriptor.h} (77%) create mode 100644 src/base/type_system/ktId.h create mode 100644 src/base/type_system/kt_functions.c create mode 100644 src/base/type_system/kt_functions.h create mode 100644 src/base/type_system/type_system.h delete mode 100644 src/base/type_system/types.c delete mode 100644 src/base/type_system/types.h diff --git a/src/Autoarr/Autoarr.c b/src/Autoarr/Autoarr.c index abff22b..a87502c 100644 --- a/src/Autoarr/Autoarr.c +++ b/src/Autoarr/Autoarr.c @@ -13,35 +13,35 @@ Autoarr_define(int32) Autoarr_define(uint64) Autoarr_define(int64) -kerepTypeId_define(kerepTypeId_AutoarrChar); -kerepTypeId_define(kerepTypeId_AutoarrBool); -kerepTypeId_define(kerepTypeId_AutoarrFloat32); -kerepTypeId_define(kerepTypeId_AutoarrFloat64); -kerepTypeId_define(kerepTypeId_AutoarrInt8); -kerepTypeId_define(kerepTypeId_AutoarrUInt8); -kerepTypeId_define(kerepTypeId_AutoarrInt16); -kerepTypeId_define(kerepTypeId_AutoarrUInt16); -kerepTypeId_define(kerepTypeId_AutoarrInt32); -kerepTypeId_define(kerepTypeId_AutoarrUInt32); -kerepTypeId_define(kerepTypeId_AutoarrInt64); -kerepTypeId_define(kerepTypeId_AutoarrUInt64); +ktId_define(ktId_AutoarrChar); +ktId_define(ktId_AutoarrBool); +ktId_define(ktId_AutoarrFloat32); +ktId_define(ktId_AutoarrFloat64); +ktId_define(ktId_AutoarrInt8); +ktId_define(ktId_AutoarrUInt8); +ktId_define(ktId_AutoarrInt16); +ktId_define(ktId_AutoarrUInt16); +ktId_define(ktId_AutoarrInt32); +ktId_define(ktId_AutoarrUInt32); +ktId_define(ktId_AutoarrInt64); +ktId_define(ktId_AutoarrUInt64); -kerepTypeId_define(kerepTypeId_AutoarrCharPtr); -kerepTypeId_define(kerepTypeId_AutoarrBoolPtr); -kerepTypeId_define(kerepTypeId_AutoarrFloat32Ptr); -kerepTypeId_define(kerepTypeId_AutoarrFloat64Ptr); -kerepTypeId_define(kerepTypeId_AutoarrInt8Ptr); -kerepTypeId_define(kerepTypeId_AutoarrUInt8Ptr); -kerepTypeId_define(kerepTypeId_AutoarrInt16Ptr); -kerepTypeId_define(kerepTypeId_AutoarrUInt16Ptr); -kerepTypeId_define(kerepTypeId_AutoarrInt32Ptr); -kerepTypeId_define(kerepTypeId_AutoarrUInt32Ptr); -kerepTypeId_define(kerepTypeId_AutoarrInt64Ptr); -kerepTypeId_define(kerepTypeId_AutoarrUInt64Ptr); +ktId_define(ktId_AutoarrCharPtr); +ktId_define(ktId_AutoarrBoolPtr); +ktId_define(ktId_AutoarrFloat32Ptr); +ktId_define(ktId_AutoarrFloat64Ptr); +ktId_define(ktId_AutoarrInt8Ptr); +ktId_define(ktId_AutoarrUInt8Ptr); +ktId_define(ktId_AutoarrInt16Ptr); +ktId_define(ktId_AutoarrUInt16Ptr); +ktId_define(ktId_AutoarrInt32Ptr); +ktId_define(ktId_AutoarrUInt32Ptr); +ktId_define(ktId_AutoarrInt64Ptr); +ktId_define(ktId_AutoarrUInt64Ptr); Autoarr_define(Unitype) -kerepTypeId_define(kerepTypeId_AutoarrUnitype); -kerepTypeId_define(kerepTypeId_AutoarrUnitypePtr); +ktId_define(ktId_AutoarrUnitype); +ktId_define(ktId_AutoarrUnitypePtr); // right func to clear array of unitype values void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr){ diff --git a/src/Autoarr/Autoarr.h b/src/Autoarr/Autoarr.h index d96fcf6..be32c5c 100644 --- a/src/Autoarr/Autoarr.h +++ b/src/Autoarr/Autoarr.h @@ -20,35 +20,35 @@ Autoarr_declare(uint32) Autoarr_declare(int64) Autoarr_declare(uint64) -kerepTypeId_declare(kerepTypeId_AutoarrChar); -kerepTypeId_declare(kerepTypeId_AutoarrBool); -kerepTypeId_declare(kerepTypeId_AutoarrFloat32); -kerepTypeId_declare(kerepTypeId_AutoarrFloat64); -kerepTypeId_declare(kerepTypeId_AutoarrInt8); -kerepTypeId_declare(kerepTypeId_AutoarrUInt8); -kerepTypeId_declare(kerepTypeId_AutoarrInt16); -kerepTypeId_declare(kerepTypeId_AutoarrUInt16); -kerepTypeId_declare(kerepTypeId_AutoarrInt32); -kerepTypeId_declare(kerepTypeId_AutoarrUInt32); -kerepTypeId_declare(kerepTypeId_AutoarrInt64); -kerepTypeId_declare(kerepTypeId_AutoarrUInt64); +ktId_declare(ktId_AutoarrChar); +ktId_declare(ktId_AutoarrBool); +ktId_declare(ktId_AutoarrFloat32); +ktId_declare(ktId_AutoarrFloat64); +ktId_declare(ktId_AutoarrInt8); +ktId_declare(ktId_AutoarrUInt8); +ktId_declare(ktId_AutoarrInt16); +ktId_declare(ktId_AutoarrUInt16); +ktId_declare(ktId_AutoarrInt32); +ktId_declare(ktId_AutoarrUInt32); +ktId_declare(ktId_AutoarrInt64); +ktId_declare(ktId_AutoarrUInt64); -kerepTypeId_declare(kerepTypeId_AutoarrCharPtr); -kerepTypeId_declare(kerepTypeId_AutoarrBoolPtr); -kerepTypeId_declare(kerepTypeId_AutoarrFloat32Ptr); -kerepTypeId_declare(kerepTypeId_AutoarrFloat64Ptr); -kerepTypeId_declare(kerepTypeId_AutoarrInt8Ptr); -kerepTypeId_declare(kerepTypeId_AutoarrUInt8Ptr); -kerepTypeId_declare(kerepTypeId_AutoarrInt16Ptr); -kerepTypeId_declare(kerepTypeId_AutoarrUInt16Ptr); -kerepTypeId_declare(kerepTypeId_AutoarrInt32Ptr); -kerepTypeId_declare(kerepTypeId_AutoarrUInt32Ptr); -kerepTypeId_declare(kerepTypeId_AutoarrInt64Ptr); -kerepTypeId_declare(kerepTypeId_AutoarrUInt64Ptr); +ktId_declare(ktId_AutoarrCharPtr); +ktId_declare(ktId_AutoarrBoolPtr); +ktId_declare(ktId_AutoarrFloat32Ptr); +ktId_declare(ktId_AutoarrFloat64Ptr); +ktId_declare(ktId_AutoarrInt8Ptr); +ktId_declare(ktId_AutoarrUInt8Ptr); +ktId_declare(ktId_AutoarrInt16Ptr); +ktId_declare(ktId_AutoarrUInt16Ptr); +ktId_declare(ktId_AutoarrInt32Ptr); +ktId_declare(ktId_AutoarrUInt32Ptr); +ktId_declare(ktId_AutoarrInt64Ptr); +ktId_declare(ktId_AutoarrUInt64Ptr); Autoarr_declare(Unitype) -kerepTypeId_declare(kerepTypeId_AutoarrUnitype); -kerepTypeId_declare(kerepTypeId_AutoarrUnitypePtr); +ktId_declare(ktId_AutoarrUnitype); +ktId_declare(ktId_AutoarrUnitypePtr); // this function is injected in kerep_init() void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr); diff --git a/src/DtsodParser/DtsodV24_deserialize.c b/src/DtsodParser/DtsodV24_deserialize.c index ecf1322..20107ef 100644 --- a/src/DtsodParser/DtsodV24_deserialize.c +++ b/src/DtsodParser/DtsodV24_deserialize.c @@ -98,9 +98,9 @@ Maybe __ReadName(DeserializeSharedData* shared){ case '}': if(!calledRecursively || nameStr.length!=0) safethrow_wrongchar(c,;); - return SUCCESS(UniHeap(kerepTypeId_CharPtr,NULL)); + return SUCCESS(UniHeap(ktId_CharPtr,NULL)); case ':': - return SUCCESS(UniHeap(kerepTypeId_CharPtr,string_extract(nameStr))); + return SUCCESS(UniHeap(ktId_CharPtr,string_extract(nameStr))); case '$': if(nameStr.length!=0) safethrow_wrongchar(c,;); @@ -113,7 +113,7 @@ Maybe __ReadName(DeserializeSharedData* shared){ } if(nameStr.length>0) safethrow(ERR_ENDOFSTR,;); - return SUCCESS(UniHeap(kerepTypeId_CharPtr,NULL)); + return SUCCESS(UniHeap(ktId_CharPtr,NULL)); } #define ReadName() __ReadName(shared) @@ -137,7 +137,7 @@ Maybe __ReadString(DeserializeSharedData* shared){ } else { char* str=StringBuilder_build(b).ptr; - return SUCCESS(UniHeap(kerepTypeId_CharPtr,str)); + return SUCCESS(UniHeap(ktId_CharPtr,str)); } } else { @@ -157,13 +157,13 @@ Maybe __ReadList(DeserializeSharedData* shared){ try(ReadValue((&readingList)), val, Autoarr_free(list, true)) Autoarr_add(list,val.value); if (!readingList){ - if(val.value.typeId==kerepTypeId_Null) + if(val.value.typeId==ktId_Null) Autoarr_pop(list); break; } } - return SUCCESS(UniHeap(kerepTypeId_AutoarrUnitypePtr,list)); + return SUCCESS(UniHeap(ktId_AutoarrUnitypePtr,list)); }; #define ReadList() __ReadList(shared) @@ -275,7 +275,7 @@ Maybe __ReadValue(DeserializeSharedData* shared, bool* readingList){ case ';': case ',': if(valueStr.length!=0){ - if(value.typeId!=kerepTypeId_Null) + if(value.typeId!=ktId_Null) safethrow_wrongchar(c,Unitype_free(value)); try(ParseValue(valueStr),maybeParsed,;) value=maybeParsed.value; @@ -321,7 +321,7 @@ Maybe __deserialize(char** _text, bool _calledRecursively) { } else{ list=Autoarr_create(Unitype,ARR_BC,ARR_BL); - Hashtable_add(dict,nameCPtr,UniHeap(kerepTypeId_AutoarrUnitypePtr,list)); + Hashtable_add(dict,nameCPtr,UniHeap(ktId_AutoarrUnitypePtr,list)); } Autoarr_add(list,val.value); } @@ -331,7 +331,7 @@ Maybe __deserialize(char** _text, bool _calledRecursively) { END: *_text=text; - return SUCCESS(UniHeap(kerepTypeId_HashtablePtr,dict)); + return SUCCESS(UniHeap(ktId_HashtablePtr,dict)); } Maybe DtsodV24_deserialize(char* _text) { diff --git a/src/DtsodParser/DtsodV24_serialize.c b/src/DtsodParser/DtsodV24_serialize.c index 3ab0346..cf48d34 100644 --- a/src/DtsodParser/DtsodV24_serialize.c +++ b/src/DtsodParser/DtsodV24_serialize.c @@ -23,18 +23,18 @@ void __AppendTabs(SerializeSharedData* shared) { Maybe __AppendValue(SerializeSharedData* shared, Unitype u); #define AppendValue(UNI) __AppendValue(shared, UNI) Maybe __AppendValue(SerializeSharedData* shared, Unitype u){ - if(u.typeId==kerepTypeId_Int64){ + if(u.typeId==ktId_Int64){ StringBuilder_append_int64(b,u.Int64); } - else if(u.typeId==kerepTypeId_UInt64){ + else if(u.typeId==ktId_UInt64){ StringBuilder_append_uint64(b,u.UInt64); addc('u'); } - else if(u.typeId==kerepTypeId_Float64){ + else if(u.typeId==ktId_Float64){ StringBuilder_append_float64(b,u.Float64); addc('f'); } - else if(u.typeId==kerepTypeId_CharPtr){ + else if(u.typeId==ktId_CharPtr){ addc('"'); char c; while((c=*(char*)(u.VoidPtr++))){ @@ -43,13 +43,13 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){ } addc('"'); } - else if(u.typeId==kerepTypeId_Bool){ + else if(u.typeId==ktId_Bool){ StringBuilder_append_cptr(b, u.Bool ? "true" : "false"); } - else if(u.typeId==kerepTypeId_Null){ + else if(u.typeId==ktId_Null){ safethrow("Null isn't supported in DtsodV24",;); } - else if(u.typeId==kerepTypeId_AutoarrUnitypePtr){ + else if(u.typeId==ktId_AutoarrUnitypePtr){ if(Autoarr_length(((Autoarr_Unitype*)(u.VoidPtr)))){ addc('\n'); AppendTabs(); @@ -72,7 +72,7 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){ addc(']'); } } - else if(u.typeId==kerepTypeId_HashtablePtr){ + else if(u.typeId==ktId_HashtablePtr){ // check hashtable is blank bool hashtableNotBlank=false; Hashtable_foreach(((Hashtable*)u.VoidPtr), __, ({ @@ -126,5 +126,5 @@ Maybe DtsodV24_serialize(Hashtable* dtsod){ StringBuilder* sb=StringBuilder_create(); try(__serialize(sb,0,dtsod),__, StringBuilder_free(sb)); char* str=StringBuilder_build(sb).ptr; - return SUCCESS(UniHeap(kerepTypeId_CharPtr, str)); + return SUCCESS(UniHeap(ktId_CharPtr, str)); } diff --git a/src/Hashtable/Hashtable.c b/src/Hashtable/Hashtable.c index 4b1b921..e5eb77d 100644 --- a/src/Hashtable/Hashtable.c +++ b/src/Hashtable/Hashtable.c @@ -1,7 +1,7 @@ #include "Hashtable.h" -kerepTypeId_define(kerepTypeId_Hashtable); -kerepTypeId_define(kerepTypeId_HashtablePtr); +ktId_define(ktId_Hashtable); +ktId_define(ktId_HashtablePtr); // amount of rows static const uint16 HT_HEIGHTS[]={17,61,257,1021,4099,16381,65521}; @@ -96,7 +96,7 @@ Unitype Hashtable_get(Hashtable* ht, char* key){ bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output){ Unitype u=Hashtable_get(ht,key); *output=u; - return u.typeId!=kerepTypeId_Null; + return u.typeId!=ktId_Null; } void Hashtable_addOrSet(Hashtable* ht, char* key, Unitype u){ diff --git a/src/Hashtable/Hashtable.h b/src/Hashtable/Hashtable.h index 58f446d..9437ca2 100644 --- a/src/Hashtable/Hashtable.h +++ b/src/Hashtable/Hashtable.h @@ -11,8 +11,8 @@ typedef struct Hashtable{ uint8 hein; // height=HT_HEIGHTS[hein] Autoarr(KVPair)** rows; // Autoarr[height] } Hashtable; -kerepTypeId_declare(kerepTypeId_Hashtable); -kerepTypeId_declare(kerepTypeId_HashtablePtr); +ktId_declare(ktId_Hashtable); +ktId_declare(ktId_HashtablePtr); Hashtable* Hashtable_create(); void Hashtable_free(Hashtable* ht); diff --git a/src/Hashtable/KeyValuePair.c b/src/Hashtable/KeyValuePair.c index 22c3f5e..cb4a2d0 100644 --- a/src/Hashtable/KeyValuePair.c +++ b/src/Hashtable/KeyValuePair.c @@ -1,11 +1,11 @@ #include "KeyValuePair.h" -kerepTypeId_define(kerepTypeId_KVPair); -kerepTypeId_define(kerepTypeId_KVPairPtr); +ktId_define(ktId_KVPair); +ktId_define(ktId_KVPairPtr); Autoarr_define(KVPair) -kerepTypeId_define(kerepTypeId_AutoarrKVPair); -kerepTypeId_define(kerepTypeId_AutoarrKVPairPtr); +ktId_define(ktId_AutoarrKVPair); +ktId_define(ktId_AutoarrKVPairPtr); // proper way to clear a KVP void KVPair_free(KVPair p){ diff --git a/src/Hashtable/KeyValuePair.h b/src/Hashtable/KeyValuePair.h index 832c6c7..666b839 100644 --- a/src/Hashtable/KeyValuePair.h +++ b/src/Hashtable/KeyValuePair.h @@ -11,12 +11,12 @@ typedef struct KVPair{ char* key; Unitype value; } KVPair; -kerepTypeId_declare(kerepTypeId_KVPair); -kerepTypeId_declare(kerepTypeId_KVPairPtr); +ktId_declare(ktId_KVPair); +ktId_declare(ktId_KVPairPtr); Autoarr_declare(KVPair) -kerepTypeId_declare(kerepTypeId_AutoarrKVPair); -kerepTypeId_declare(kerepTypeId_AutoarrKVPairPtr); +ktId_declare(ktId_AutoarrKVPair); +ktId_declare(ktId_AutoarrKVPairPtr); // proper way to clear a KVP void KVPair_free(KVPair p); diff --git a/src/SearchTree/SearchTree.c b/src/SearchTree/SearchTree.c index 23aa853..c174da9 100644 --- a/src/SearchTree/SearchTree.c +++ b/src/SearchTree/SearchTree.c @@ -1,12 +1,12 @@ #include "SearchTree.h" -kerepTypeId_define(kerepTypeId_STNode); -kerepTypeId_define(kerepTypeId_STNodePtr); +ktId_define(ktId_STNode); +ktId_define(ktId_STNodePtr); STNode* STNode_create(){ STNode* node=malloc(sizeof(STNode)); node->branches=NULL; - node->value.typeId=kerepTypeId_Null; + node->value.typeId=ktId_Null; node->value.UInt64=0; return node; } diff --git a/src/SearchTree/SearchTree.h b/src/SearchTree/SearchTree.h index 3d1a8e0..6ae9e74 100644 --- a/src/SearchTree/SearchTree.h +++ b/src/SearchTree/SearchTree.h @@ -11,8 +11,8 @@ typedef struct SearchTreeNode{ struct SearchTreeNode**** branches; // *STNode[8][8][4] Unitype value; } STNode; -kerepTypeId_declare(kerepTypeId_STNode); -kerepTypeId_declare(kerepTypeId_STNodePtr); +ktId_declare(ktId_STNode); +ktId_declare(ktId_STNodePtr); STNode* STNode_create(); void STNode_free(STNode* node); diff --git a/src/String/StringBuilder.c b/src/String/StringBuilder.c index 167e916..461f45d 100644 --- a/src/String/StringBuilder.c +++ b/src/String/StringBuilder.c @@ -1,11 +1,11 @@ #include "StringBuilder.h" Autoarr_define(string) -kerepTypeId_define(kerepTypeId_AutoarrString); -kerepTypeId_define(kerepTypeId_AutoarrStringPtr); +ktId_define(ktId_AutoarrString); +ktId_define(ktId_AutoarrStringPtr); -kerepTypeId_define(kerepTypeId_StringBuilder); -kerepTypeId_define(kerepTypeId_StringBuilderPtr); +ktId_define(ktId_StringBuilder); +ktId_define(ktId_StringBuilderPtr); #define BL_C 32 #define BL_L 1024 diff --git a/src/String/StringBuilder.h b/src/String/StringBuilder.h index 50e63a7..7cb5d91 100644 --- a/src/String/StringBuilder.h +++ b/src/String/StringBuilder.h @@ -8,15 +8,15 @@ extern "C" { #include "string.h" Autoarr_declare(string) -kerepTypeId_declare(kerepTypeId_AutoarrString); -kerepTypeId_declare(kerepTypeId_AutoarrStringPtr); +ktId_declare(ktId_AutoarrString); +ktId_declare(ktId_AutoarrStringPtr); typedef struct StringBuilder{ Autoarr(string)* compl_bufs; Autoarr(int8)* curr_buf; } StringBuilder; -kerepTypeId_declare(kerepTypeId_StringBuilder); -kerepTypeId_declare(kerepTypeId_StringBuilderPtr); +ktId_declare(ktId_StringBuilder); +ktId_declare(ktId_StringBuilderPtr); StringBuilder* StringBuilder_create(void); void StringBuilder_free(StringBuilder* b); diff --git a/src/String/string.c b/src/String/string.c index e7d92a6..cbcb46e 100644 --- a/src/String/string.c +++ b/src/String/string.c @@ -1,7 +1,7 @@ #include "string.h" -kerepTypeId_define(kerepTypeId_string); -kerepTypeId_define(kerepTypeId_stringPtr); +ktId_define(ktId_string); +ktId_define(ktId_stringPtr); // copies str content to new char pointer value (adding '\0' at the end) char* string_extract(string str){ diff --git a/src/String/string.h b/src/String/string.h index 0b9a658..9313dae 100644 --- a/src/String/string.h +++ b/src/String/string.h @@ -12,8 +12,8 @@ typedef struct string{ char* ptr; // char pointer uint32 length; // amount of chars in ptr value } string; -kerepTypeId_declare(kerepTypeId_string); -kerepTypeId_declare(kerepTypeId_stringPtr); +ktId_declare(ktId_string); +ktId_declare(ktId_stringPtr); static const string stringNull={NULL,0}; diff --git a/src/base/base.h b/src/base/base.h index fce8588..9ca2951 100644 --- a/src/base/base.h +++ b/src/base/base.h @@ -8,9 +8,7 @@ extern "C" { #include "errors.h" #include "cptr.h" #include "optime.h" -#include "type_system/types.h" -#include "type_system/unitype.h" -#include "init.h" +#include "type_system/type_system.h" #include "kprint/kprint.h" #if __cplusplus diff --git a/src/base/init.c b/src/base/init.c deleted file mode 100644 index cef81d1..0000000 --- a/src/base/init.c +++ /dev/null @@ -1,103 +0,0 @@ -#include "base.h" -#include "../Autoarr/Autoarr.h" -#include "../SearchTree/SearchTree.h" -#include "../Hashtable/Hashtable.h" -#include "../String/StringBuilder.h" - -void kerepTypeDescriptors_initKerepTypes(){ - // null - kerepType_register(NULL, kerepTypeId_Null, NULL, NULL); - // base types - kerepType_register(char, kerepTypeId_Char, NULL, NULL); - kerepType_register(bool, kerepTypeId_Bool, NULL, NULL); - kerepType_register(float32, kerepTypeId_Float32, NULL, NULL); - kerepType_register(float64, kerepTypeId_Float64, NULL, NULL); - kerepType_register(int8, kerepTypeId_Int8, NULL, NULL); - kerepType_register(uint8, kerepTypeId_UInt8, NULL, NULL); - kerepType_register(int16, kerepTypeId_Int16, NULL, NULL); - kerepType_register(uint16, kerepTypeId_UInt16, NULL, NULL); - kerepType_register(int32, kerepTypeId_Int32, NULL, NULL); - kerepType_register(uint32, kerepTypeId_UInt32, NULL, NULL); - kerepType_register(int64, kerepTypeId_Int64, NULL, NULL); - kerepType_register(uint64, kerepTypeId_UInt64, NULL, NULL); - // base type pointers - kerepType_register(char*, kerepTypeId_CharPtr, NULL, NULL); - kerepType_register(bool*, kerepTypeId_BoolPtr, NULL, NULL); - kerepType_register(float32*, kerepTypeId_Float32Ptr, NULL, NULL); - kerepType_register(float64*, kerepTypeId_Float64Ptr, NULL, NULL); - kerepType_register(int8*, kerepTypeId_Int8Ptr, NULL, NULL); - kerepType_register(uint8*, kerepTypeId_UInt8Ptr, NULL, NULL); - kerepType_register(int16*, kerepTypeId_Int16Ptr, NULL, NULL); - kerepType_register(uint16*, kerepTypeId_UInt16Ptr, NULL, NULL); - kerepType_register(int32*, kerepTypeId_Int32Ptr, NULL, NULL); - kerepType_register(uint32*, kerepTypeId_UInt32Ptr, NULL, NULL); - kerepType_register(int64*, kerepTypeId_Int64Ptr, NULL, NULL); - kerepType_register(uint64*, kerepTypeId_UInt64Ptr, NULL, NULL); - // kerepTypeDescriptor - kerepType_register(kerepTypeDescriptor, kerepTypeId_kerepTypeDescriptor, NULL, NULL); - kerepType_register(kerepTypeDescriptor*, kerepTypeId_kerepTypeDescriptorPtr, NULL, NULL); - - // base type autoarrs - kerepType_register(Autoarr_char, kerepTypeId_AutoarrChar, ____Autoarr_free_char, NULL); - kerepType_register(Autoarr_bool, kerepTypeId_AutoarrBool, ____Autoarr_free_bool, NULL); - kerepType_register(Autoarr_float32, kerepTypeId_AutoarrFloat32, ____Autoarr_free_float32, NULL); - kerepType_register(Autoarr_float64, kerepTypeId_AutoarrFloat64, ____Autoarr_free_float64, NULL); - kerepType_register(Autoarr_int8, kerepTypeId_AutoarrInt8, ____Autoarr_free_int8, NULL); - kerepType_register(Autoarr_uint8, kerepTypeId_AutoarrUInt8, ____Autoarr_free_uint8, NULL); - kerepType_register(Autoarr_int16, kerepTypeId_AutoarrInt16, ____Autoarr_free_int16, NULL); - kerepType_register(Autoarr_uint16, kerepTypeId_AutoarrUInt16, ____Autoarr_free_uint16, NULL); - kerepType_register(Autoarr_int32, kerepTypeId_AutoarrInt32, ____Autoarr_free_int32, NULL); - kerepType_register(Autoarr_uint32, kerepTypeId_AutoarrUInt32, ____Autoarr_free_uint32, NULL); - kerepType_register(Autoarr_int64, kerepTypeId_AutoarrInt64, ____Autoarr_free_int64, NULL); - kerepType_register(Autoarr_uint64, kerepTypeId_AutoarrUInt64, ____Autoarr_free_uint64, NULL); - // base type autoarr pointers - kerepType_register(Autoarr_char*, kerepTypeId_AutoarrCharPtr, ____Autoarr_free_char, NULL); - kerepType_register(Autoarr_bool*, kerepTypeId_AutoarrBoolPtr, ____Autoarr_free_bool, NULL); - kerepType_register(Autoarr_float32*, kerepTypeId_AutoarrFloat32Ptr, ____Autoarr_free_float32, NULL); - kerepType_register(Autoarr_float64*, kerepTypeId_AutoarrFloat64Ptr, ____Autoarr_free_float64, NULL); - kerepType_register(Autoarr_int8*, kerepTypeId_AutoarrInt8Ptr, ____Autoarr_free_int8, NULL); - kerepType_register(Autoarr_uint8*, kerepTypeId_AutoarrUInt8Ptr, ____Autoarr_free_uint8, NULL); - kerepType_register(Autoarr_int16*, kerepTypeId_AutoarrInt16Ptr, ____Autoarr_free_int16, NULL); - kerepType_register(Autoarr_uint16*, kerepTypeId_AutoarrUInt16Ptr, ____Autoarr_free_uint16, NULL); - kerepType_register(Autoarr_int32*, kerepTypeId_AutoarrInt32Ptr, ____Autoarr_free_int32, NULL); - kerepType_register(Autoarr_uint32*, kerepTypeId_AutoarrUInt32Ptr, ____Autoarr_free_uint32, NULL); - kerepType_register(Autoarr_int64*, kerepTypeId_AutoarrInt64Ptr, ____Autoarr_free_int64, NULL); - kerepType_register(Autoarr_uint64*, kerepTypeId_AutoarrUInt64Ptr, ____Autoarr_free_uint64, NULL); - - // Unitype - kerepType_register(Unitype, kerepTypeId_Unitype, __UnitypePtr_free, NULL); - kerepType_register(Unitype*, kerepTypeId_UnitypePtr, __UnitypePtr_free, NULL); - kerepType_register(Autoarr_Unitype, kerepTypeId_AutoarrUnitype, ____Autoarr_free_Unitype_, NULL); - kerepType_register(Autoarr_Unitype*, kerepTypeId_AutoarrUnitypePtr, ____Autoarr_free_Unitype_, NULL); - // replacing autogenerated freear() function to custom - Autoarr_Unitype* _uar=Autoarr_create(Unitype, 1, 1); - _uar->functions->freear=__Autoarr_free_Unitype_; - Autoarr_free(_uar, true); - - // SearchTreeNode - kerepType_register(STNode, kerepTypeId_STNode, __STNode_free, NULL); - kerepType_register(STNode*, kerepTypeId_STNodePtr, __STNode_free, NULL); - - // KeyValuePair - kerepType_register(KVPair, kerepTypeId_KVPair, __KVPair_free, NULL); - kerepType_register(KVPair*, kerepTypeId_KVPairPtr, __KVPair_free, NULL); - kerepType_register(Autoarr_KVPair, kerepTypeId_AutoarrKVPair, ____Autoarr_free_KVPair_, NULL); - kerepType_register(Autoarr_KVPair*, kerepTypeId_AutoarrKVPairPtr, ____Autoarr_free_KVPair_, NULL); - // replacing autogenerated freear() function to custom - Autoarr_KVPair* _kvpar=Autoarr_create(KVPair, 1, 1); - _kvpar->functions->freear=__Autoarr_free_KVPair_; - Autoarr_free(_kvpar, true); - - // Hashtable - kerepType_register(Hashtable, kerepTypeId_Hashtable, __Hashtable_free, NULL); - kerepType_register(Hashtable*, kerepTypeId_HashtablePtr, __Hashtable_free, NULL); - - // string - kerepType_register(string, kerepTypeId_string, NULL, NULL); - kerepType_register(string*, kerepTypeId_stringPtr, NULL, NULL); - kerepType_register(string, kerepTypeId_AutoarrString, ____Autoarr_free_string, NULL); - kerepType_register(string*, kerepTypeId_AutoarrStringPtr, ____Autoarr_free_string, NULL); - // StringBuilder - kerepType_register(StringBuilder, kerepTypeId_StringBuilder, __StringBuilder_free, NULL); - kerepType_register(StringBuilder*, kerepTypeId_StringBuilderPtr, __StringBuilder_free, NULL); -} diff --git a/src/base/init.h b/src/base/init.h deleted file mode 100644 index dfe5e69..0000000 --- a/src/base/init.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#if __cplusplus -extern "C" { -#endif - -// call this between kerepTypeDescriptors_beginInit() and kerepTypeDescriptors_endInit() -void kerepTypeDescriptors_initKerepTypes(); - -#if __cplusplus -} -#endif \ No newline at end of file diff --git a/src/base/kprint/README.md b/src/base/kprint/README.md index c02cdac..6961b00 100644 --- a/src/base/kprint/README.md +++ b/src/base/kprint/README.md @@ -10,11 +10,11 @@ I don't really like printf function (and its variants), so i made safer and more ## how to use it: + **format construction:** ``` - kprint_format fmt= kprint_fgColor | kprint_fbgColor | kprint_fdataFmt | flags | kerepTypeId; + kprint_format fmt= kprint_fgColor | kprint_fbgColor | kprint_fdataFmt | flags | ktId; ``` [more about `kprint_format`](kprint_format.md) + fgColor and bgColor can be set to change console output color - + you should set dataFormat for `int`/`uint`/`float`/`char*` arguments and kerepTypeId for other types + + you should set dataFormat for `int`/`uint`/`float`/`char*` arguments and ktId for other types + flags can be set to modify TypeDescriptor.toString() behavior + don't forget to set TypeDescriptor.toString when registering type, or kprint will crash @@ -28,6 +28,6 @@ I don't really like printf function (and its variants), so i made safer and more should be sent as pointers ``` Maybe m=MaybeNull; - kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | kerepTypeId_MaybePtr, &m); + kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | ktId_MaybePtr, &m); ``` - output: Maybe: {value={0, kerepTypeId_Null}} \ No newline at end of file + output: Maybe: {value={0, ktId_Null}} \ No newline at end of file diff --git a/src/base/kprint/kprint.c b/src/base/kprint/kprint.c index fc89c72..3ef337a 100644 --- a/src/base/kprint/kprint.c +++ b/src/base/kprint/kprint.c @@ -7,20 +7,20 @@ Maybe __next_toString(kprint_format format, void* object){ case kprint_fmtInt: case kprint_fmtHex: case kprint_fmtBin: - format.typeId=kerepTypeId_Int64; break; + format.typeId=ktId_Int64; break; case kprint_fmtUInt: - format.typeId=kerepTypeId_UInt64; break; + format.typeId=ktId_UInt64; break; case kprint_fmtFloat: - format.typeId=kerepTypeId_Float64; break; + format.typeId=ktId_Float64; break; case kprint_fmtChar: - format.typeId=kerepTypeId_Char; break; + format.typeId=ktId_Char; break; case kprint_fmtString: - format.typeId=kerepTypeId_CharPtr; break; + format.typeId=ktId_CharPtr; break; default: safethrow("typeId is not set, can't autodetect type",;); } - try(kerepTypeDescriptor_get(format.typeId),mtd,;); - kerepTypeDescriptor typeDesc=*(kerepTypeDescriptor*)mtd.value.VoidPtr; + try(ktDescriptor_get(format.typeId),mtd,;); + ktDescriptor typeDesc=*(ktDescriptor*)mtd.value.VoidPtr; if(!typeDesc.toString) safethrow("type descriptor doesnt have toString() func",;); try(typeDesc.toString(object, &format), mStr,;); @@ -34,7 +34,7 @@ Maybe __ksprint(uint8 n, kprint_format* formats, void** objects){ StringBuilder_append_cptr(strb, mStr.value.VoidPtr); } char* rezult=StringBuilder_build(strb).ptr; - return SUCCESS(UniHeap(kerepTypeId_CharPtr, rezult)); + return SUCCESS(UniHeap(ktId_CharPtr, rezult)); } Maybe __kfprint(FILE* file, uint8 n, kprint_format* formats, void** objects){ @@ -68,9 +68,9 @@ void kprint_setColor(kprint_format f){ -Maybe ksprint_ar(uint32 count, kprint_format format, kerepTypeId typeId, void* array){ - try(kerepTypeDescriptor_get(format.typeId),mtd,;); - kerepTypeDescriptor typeDesc=*(kerepTypeDescriptor*)mtd.value.VoidPtr; +Maybe ksprint_ar(uint32 count, kprint_format format, ktId typeId, void* array){ + try(ktDescriptor_get(format.typeId),mtd,;); + ktDescriptor typeDesc=*(ktDescriptor*)mtd.value.VoidPtr; if(!typeDesc.toString) safethrow("type descriptor doesnt have toString() func",;); StringBuilder* strb=StringBuilder_create(); diff --git a/src/base/kprint/kprint_format.h b/src/base/kprint/kprint_format.h index 3fcfc68..1087c71 100644 --- a/src/base/kprint/kprint_format.h +++ b/src/base/kprint/kprint_format.h @@ -4,7 +4,7 @@ extern "C" { #endif -#include "../type_system/kerepTypeId.h" +#include "../type_system/ktId.h" typedef enum kprint_dataFormat{ // 00000000 00000000 00000000 00000000 @@ -39,7 +39,7 @@ typedef struct { unsigned char fgColor : 4; unsigned char bgColor : 4; unsigned char dataFmt : 4; - kerepTypeId typeId; + ktId typeId; } kprint_format; #if __cplusplus diff --git a/src/base/kprint/kprint_format.md b/src/base/kprint/kprint_format.md index 9d3da81..fcd4a95 100644 --- a/src/base/kprint/kprint_format.md +++ b/src/base/kprint/kprint_format.md @@ -2,7 +2,7 @@ ``` 00000000 00000000 00000000 00000000 -fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ kerepTypeId +fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ ktId bgColorSet─┘││ │ bgColor └data format prefix┬────┘│ └fgColor postfix └uppercase diff --git a/src/base/type_system/init.c b/src/base/type_system/init.c new file mode 100644 index 0000000..755756a --- /dev/null +++ b/src/base/type_system/init.c @@ -0,0 +1,103 @@ +#include "../base.h" +#include "../../Autoarr/Autoarr.h" +#include "../../SearchTree/SearchTree.h" +#include "../../Hashtable/Hashtable.h" +#include "../../String/StringBuilder.h" + +void ktDescriptors_initKerepTypes(){ + // null + kt_register(NULL, ktId_Null, NULL, NULL); + // base types + kt_register(char, ktId_Char, NULL, NULL); + kt_register(bool, ktId_Bool, NULL, NULL); + kt_register(float32, ktId_Float32, NULL, NULL); + kt_register(float64, ktId_Float64, NULL, NULL); + kt_register(int8, ktId_Int8, NULL, NULL); + kt_register(uint8, ktId_UInt8, NULL, NULL); + kt_register(int16, ktId_Int16, NULL, NULL); + kt_register(uint16, ktId_UInt16, NULL, NULL); + kt_register(int32, ktId_Int32, NULL, NULL); + kt_register(uint32, ktId_UInt32, NULL, NULL); + kt_register(int64, ktId_Int64, NULL, NULL); + kt_register(uint64, ktId_UInt64, NULL, NULL); + // base type pointers + kt_register(char*, ktId_CharPtr, NULL, NULL); + kt_register(bool*, ktId_BoolPtr, NULL, NULL); + kt_register(float32*, ktId_Float32Ptr, NULL, NULL); + kt_register(float64*, ktId_Float64Ptr, NULL, NULL); + kt_register(int8*, ktId_Int8Ptr, NULL, NULL); + kt_register(uint8*, ktId_UInt8Ptr, NULL, NULL); + kt_register(int16*, ktId_Int16Ptr, NULL, NULL); + kt_register(uint16*, ktId_UInt16Ptr, NULL, NULL); + kt_register(int32*, ktId_Int32Ptr, NULL, NULL); + kt_register(uint32*, ktId_UInt32Ptr, NULL, NULL); + kt_register(int64*, ktId_Int64Ptr, NULL, NULL); + kt_register(uint64*, ktId_UInt64Ptr, NULL, NULL); + // ktDescriptor + kt_register(ktDescriptor, ktId_ktDescriptor, NULL, NULL); + kt_register(ktDescriptor*, ktId_ktDescriptorPtr, NULL, NULL); + + // base type autoarrs + kt_register(Autoarr_char, ktId_AutoarrChar, ____Autoarr_free_char, NULL); + kt_register(Autoarr_bool, ktId_AutoarrBool, ____Autoarr_free_bool, NULL); + kt_register(Autoarr_float32, ktId_AutoarrFloat32, ____Autoarr_free_float32, NULL); + kt_register(Autoarr_float64, ktId_AutoarrFloat64, ____Autoarr_free_float64, NULL); + kt_register(Autoarr_int8, ktId_AutoarrInt8, ____Autoarr_free_int8, NULL); + kt_register(Autoarr_uint8, ktId_AutoarrUInt8, ____Autoarr_free_uint8, NULL); + kt_register(Autoarr_int16, ktId_AutoarrInt16, ____Autoarr_free_int16, NULL); + kt_register(Autoarr_uint16, ktId_AutoarrUInt16, ____Autoarr_free_uint16, NULL); + kt_register(Autoarr_int32, ktId_AutoarrInt32, ____Autoarr_free_int32, NULL); + kt_register(Autoarr_uint32, ktId_AutoarrUInt32, ____Autoarr_free_uint32, NULL); + kt_register(Autoarr_int64, ktId_AutoarrInt64, ____Autoarr_free_int64, NULL); + kt_register(Autoarr_uint64, ktId_AutoarrUInt64, ____Autoarr_free_uint64, NULL); + // base type autoarr pointers + kt_register(Autoarr_char*, ktId_AutoarrCharPtr, ____Autoarr_free_char, NULL); + kt_register(Autoarr_bool*, ktId_AutoarrBoolPtr, ____Autoarr_free_bool, NULL); + kt_register(Autoarr_float32*, ktId_AutoarrFloat32Ptr, ____Autoarr_free_float32, NULL); + kt_register(Autoarr_float64*, ktId_AutoarrFloat64Ptr, ____Autoarr_free_float64, NULL); + kt_register(Autoarr_int8*, ktId_AutoarrInt8Ptr, ____Autoarr_free_int8, NULL); + kt_register(Autoarr_uint8*, ktId_AutoarrUInt8Ptr, ____Autoarr_free_uint8, NULL); + kt_register(Autoarr_int16*, ktId_AutoarrInt16Ptr, ____Autoarr_free_int16, NULL); + kt_register(Autoarr_uint16*, ktId_AutoarrUInt16Ptr, ____Autoarr_free_uint16, NULL); + kt_register(Autoarr_int32*, ktId_AutoarrInt32Ptr, ____Autoarr_free_int32, NULL); + kt_register(Autoarr_uint32*, ktId_AutoarrUInt32Ptr, ____Autoarr_free_uint32, NULL); + kt_register(Autoarr_int64*, ktId_AutoarrInt64Ptr, ____Autoarr_free_int64, NULL); + kt_register(Autoarr_uint64*, ktId_AutoarrUInt64Ptr, ____Autoarr_free_uint64, NULL); + + // Unitype + kt_register(Unitype, ktId_Unitype, __UnitypePtr_free, NULL); + kt_register(Unitype*, ktId_UnitypePtr, __UnitypePtr_free, NULL); + kt_register(Autoarr_Unitype, ktId_AutoarrUnitype, ____Autoarr_free_Unitype_, NULL); + kt_register(Autoarr_Unitype*, ktId_AutoarrUnitypePtr, ____Autoarr_free_Unitype_, NULL); + // replacing autogenerated freear() function to custom + Autoarr_Unitype* _uar=Autoarr_create(Unitype, 1, 1); + _uar->functions->freear=__Autoarr_free_Unitype_; + Autoarr_free(_uar, true); + + // SearchTreeNode + kt_register(STNode, ktId_STNode, __STNode_free, NULL); + kt_register(STNode*, ktId_STNodePtr, __STNode_free, NULL); + + // KeyValuePair + kt_register(KVPair, ktId_KVPair, __KVPair_free, NULL); + kt_register(KVPair*, ktId_KVPairPtr, __KVPair_free, NULL); + kt_register(Autoarr_KVPair, ktId_AutoarrKVPair, ____Autoarr_free_KVPair_, NULL); + kt_register(Autoarr_KVPair*, ktId_AutoarrKVPairPtr, ____Autoarr_free_KVPair_, NULL); + // replacing autogenerated freear() function to custom + Autoarr_KVPair* _kvpar=Autoarr_create(KVPair, 1, 1); + _kvpar->functions->freear=__Autoarr_free_KVPair_; + Autoarr_free(_kvpar, true); + + // Hashtable + kt_register(Hashtable, ktId_Hashtable, __Hashtable_free, NULL); + kt_register(Hashtable*, ktId_HashtablePtr, __Hashtable_free, NULL); + + // string + kt_register(string, ktId_string, NULL, NULL); + kt_register(string*, ktId_stringPtr, NULL, NULL); + kt_register(string, ktId_AutoarrString, ____Autoarr_free_string, NULL); + kt_register(string*, ktId_AutoarrStringPtr, ____Autoarr_free_string, NULL); + // StringBuilder + kt_register(StringBuilder, ktId_StringBuilder, __StringBuilder_free, NULL); + kt_register(StringBuilder*, ktId_StringBuilderPtr, __StringBuilder_free, NULL); +} diff --git a/src/base/type_system/init.h b/src/base/type_system/init.h new file mode 100644 index 0000000..d08ef9d --- /dev/null +++ b/src/base/type_system/init.h @@ -0,0 +1,12 @@ +#pragma once + +#if __cplusplus +extern "C" { +#endif + +// call this between ktDescriptors_beginInit() and ktDescriptors_endInit() +void ktDescriptors_initKerepTypes(); + +#if __cplusplus +} +#endif \ No newline at end of file diff --git a/src/base/type_system/kerepTypeId.h b/src/base/type_system/kerepTypeId.h deleted file mode 100644 index 6f4f4af..0000000 --- a/src/base/type_system/kerepTypeId.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#if __cplusplus -extern "C" { -#endif - -#include "../std.h" -typedef uint16 kerepTypeId; - -#define kerepTypeId_declare(ID_VAR_NAME)\ - extern kerepTypeId ID_VAR_NAME -#define kerepTypeId_define(ID_VAR_NAME)\ - kerepTypeId ID_VAR_NAME=-1 - -#if __cplusplus -} -#endif \ No newline at end of file diff --git a/src/base/type_system/kerepTypeDescriptor.h b/src/base/type_system/ktDescriptor.h similarity index 77% rename from src/base/type_system/kerepTypeDescriptor.h rename to src/base/type_system/ktDescriptor.h index b402200..907d002 100644 --- a/src/base/type_system/kerepTypeDescriptor.h +++ b/src/base/type_system/ktDescriptor.h @@ -6,16 +6,16 @@ extern "C" { #include "../std.h" #include "../errors.h" -#include "kerepTypeId.h" +#include "ktId.h" -typedef struct kerepTypeDescriptor{ +typedef struct ktDescriptor{ char* name; - kerepTypeId id; + ktId id; uint16 size; void (*freeMembers)(void*); // NULL or function which frees all struct members ///@return Maybe Maybe (*toString)(void*, int32); // NULL or function which generates string representaion of object -} kerepTypeDescriptor; +} ktDescriptor; #if __cplusplus } diff --git a/src/base/type_system/ktId.h b/src/base/type_system/ktId.h new file mode 100644 index 0000000..8c37985 --- /dev/null +++ b/src/base/type_system/ktId.h @@ -0,0 +1,17 @@ +#pragma once + +#if __cplusplus +extern "C" { +#endif + +#include "../std.h" +typedef uint16 ktId; + +#define ktId_declare(ID_VAR_NAME)\ + extern ktId ID_VAR_NAME +#define ktId_define(ID_VAR_NAME)\ + ktId ID_VAR_NAME=-1 + +#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 new file mode 100644 index 0000000..0bc4f7d --- /dev/null +++ b/src/base/type_system/kt_functions.c @@ -0,0 +1,75 @@ +#include "../../Autoarr/Autoarr.h" + +Autoarr_declare(ktDescriptor) +Autoarr_define(ktDescriptor) + +ktId_define(ktId_Null); + +ktId_define(ktId_Char); +ktId_define(ktId_Bool); +ktId_define(ktId_Float32); +ktId_define(ktId_Float64); +ktId_define(ktId_Int8); +ktId_define(ktId_UInt8); +ktId_define(ktId_Int16); +ktId_define(ktId_UInt16); +ktId_define(ktId_Int32); +ktId_define(ktId_UInt32); +ktId_define(ktId_Int64); +ktId_define(ktId_UInt64); + +ktId_define(ktId_CharPtr); +ktId_define(ktId_BoolPtr); +ktId_define(ktId_Float32Ptr); +ktId_define(ktId_Float64Ptr); +ktId_define(ktId_Int8Ptr); +ktId_define(ktId_UInt8Ptr); +ktId_define(ktId_Int16Ptr); +ktId_define(ktId_UInt16Ptr); +ktId_define(ktId_Int32Ptr); +ktId_define(ktId_UInt32Ptr); +ktId_define(ktId_Int64Ptr); +ktId_define(ktId_UInt64Ptr); + +ktId_define(ktId_ktDescriptor); +ktId_define(ktId_ktDescriptorPtr); + +// type descriptors are stored here during initialization +Autoarr(ktDescriptor)* __ktDescriptors=NULL; +// here type descriptors are stored when initialization is complited +ktDescriptor* typeDescriptors=NULL; +ktId ktId_last=-1; + +typedef enum{ + NotInitialized, Initializing, Initialized +} ktDescriptorsState; +ktDescriptorsState initState=NotInitialized; + +void ktDescriptors_beginInit(){ + printf("\e[94mtype descriptors initializing...\n"); + __ktDescriptors=Autoarr_create(ktDescriptor, 256, 256); + if(__ktDescriptors==NULL) throw(ERR_NULLPTR); +} + +void ktDescriptors_endInit(){ + typeDescriptors=Autoarr_toArray(__ktDescriptors); + Autoarr_free(__ktDescriptors,true); + if(typeDescriptors==NULL) throw(ERR_NULLPTR); + printf("\e[92minitialized %u type descriptors\n", ktId_last); +} + +void __kt_register(char* name, int16 size, void (*freeMembers)(void*), Maybe (*toString)(void*, int32)){ + ktDescriptor typeDesc={ + .name=name, + .size=size, + .id=++ktId_last, + .freeMembers=freeMembers, + .toString=toString + }; + Autoarr_add(__ktDescriptors, typeDesc); +} + +Maybe ktDescriptor_get(ktId id){ + if(id>ktId_last) safethrow("invalid type id",;); + return SUCCESS(UniStack(ktId_ktDescriptorPtr, &typeDescriptors[id])); +} diff --git a/src/base/type_system/kt_functions.h b/src/base/type_system/kt_functions.h new file mode 100644 index 0000000..2f13b74 --- /dev/null +++ b/src/base/type_system/kt_functions.h @@ -0,0 +1,59 @@ +#pragma once + +#if __cplusplus +extern "C" { +#endif + +#include "../std.h" +#include "ktId.h" +#include "ktDescriptor.h" + + +extern ktId ktId_last; +void __kt_register(char* name, int16 size, void (*freeMembers)(void*), Maybe (*toString)(void*, int32)); + +#define kt_register(TYPE, ID_VAR_NAME, FREE_MEMBERS_FUNC, TO_STRING_FUNC)\ + __kt_register(#ID_VAR_NAME, sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\ + ID_VAR_NAME=ktId_last; + +void ktDescriptors_beginInit(); +void ktDescriptors_endInit(); +/// @param id id of registered type +/// @return Maybe +Maybe ktDescriptor_get(ktId id); + + +ktId_declare(ktId_Null); + +ktId_declare(ktId_Char); +ktId_declare(ktId_Bool); +ktId_declare(ktId_Float32); +ktId_declare(ktId_Float64); +ktId_declare(ktId_Int8); +ktId_declare(ktId_UInt8); +ktId_declare(ktId_Int16); +ktId_declare(ktId_UInt16); +ktId_declare(ktId_Int32); +ktId_declare(ktId_UInt32); +ktId_declare(ktId_Int64); +ktId_declare(ktId_UInt64); + +ktId_declare(ktId_CharPtr); +ktId_declare(ktId_BoolPtr); +ktId_declare(ktId_Float32Ptr); +ktId_declare(ktId_Float64Ptr); +ktId_declare(ktId_Int8Ptr); +ktId_declare(ktId_UInt8Ptr); +ktId_declare(ktId_Int16Ptr); +ktId_declare(ktId_UInt16Ptr); +ktId_declare(ktId_Int32Ptr); +ktId_declare(ktId_UInt32Ptr); +ktId_declare(ktId_Int64Ptr); +ktId_declare(ktId_UInt64Ptr); + +ktId_declare(ktId_ktDescriptor); +ktId_declare(ktId_ktDescriptorPtr); + +#if __cplusplus +} +#endif \ No newline at end of file diff --git a/src/base/type_system/type_system.h b/src/base/type_system/type_system.h new file mode 100644 index 0000000..f685112 --- /dev/null +++ b/src/base/type_system/type_system.h @@ -0,0 +1,4 @@ + +#include "init.h" +#include "kt_functions.h" +#include "unitype.h" \ No newline at end of file diff --git a/src/base/type_system/types.c b/src/base/type_system/types.c deleted file mode 100644 index 82d2d6d..0000000 --- a/src/base/type_system/types.c +++ /dev/null @@ -1,76 +0,0 @@ -#include "../../Autoarr/Autoarr.h" -#include "types.h" - -Autoarr_declare(kerepTypeDescriptor) -Autoarr_define(kerepTypeDescriptor) - -kerepTypeId_define(kerepTypeId_Null); - -kerepTypeId_define(kerepTypeId_Char); -kerepTypeId_define(kerepTypeId_Bool); -kerepTypeId_define(kerepTypeId_Float32); -kerepTypeId_define(kerepTypeId_Float64); -kerepTypeId_define(kerepTypeId_Int8); -kerepTypeId_define(kerepTypeId_UInt8); -kerepTypeId_define(kerepTypeId_Int16); -kerepTypeId_define(kerepTypeId_UInt16); -kerepTypeId_define(kerepTypeId_Int32); -kerepTypeId_define(kerepTypeId_UInt32); -kerepTypeId_define(kerepTypeId_Int64); -kerepTypeId_define(kerepTypeId_UInt64); - -kerepTypeId_define(kerepTypeId_CharPtr); -kerepTypeId_define(kerepTypeId_BoolPtr); -kerepTypeId_define(kerepTypeId_Float32Ptr); -kerepTypeId_define(kerepTypeId_Float64Ptr); -kerepTypeId_define(kerepTypeId_Int8Ptr); -kerepTypeId_define(kerepTypeId_UInt8Ptr); -kerepTypeId_define(kerepTypeId_Int16Ptr); -kerepTypeId_define(kerepTypeId_UInt16Ptr); -kerepTypeId_define(kerepTypeId_Int32Ptr); -kerepTypeId_define(kerepTypeId_UInt32Ptr); -kerepTypeId_define(kerepTypeId_Int64Ptr); -kerepTypeId_define(kerepTypeId_UInt64Ptr); - -kerepTypeId_define(kerepTypeId_kerepTypeDescriptor); -kerepTypeId_define(kerepTypeId_kerepTypeDescriptorPtr); - -// type descriptors are stored here during initialization -Autoarr(kerepTypeDescriptor)* __kerepTypeDescriptors=NULL; -// here type descriptors are stored when initialization is complited -kerepTypeDescriptor* typeDescriptors=NULL; -kerepTypeId kerepTypeId_last=-1; - -typedef enum{ - NotInitialized, Initializing, Initialized -} kerepTypeDescriptorsState; -kerepTypeDescriptorsState initState=NotInitialized; - -void kerepTypeDescriptors_beginInit(){ - printf("\e[94mtype descriptors initializing...\n"); - __kerepTypeDescriptors=Autoarr_create(kerepTypeDescriptor, 256, 256); - if(__kerepTypeDescriptors==NULL) throw(ERR_NULLPTR); -} - -void kerepTypeDescriptors_endInit(){ - typeDescriptors=Autoarr_toArray(__kerepTypeDescriptors); - Autoarr_free(__kerepTypeDescriptors,true); - if(typeDescriptors==NULL) throw(ERR_NULLPTR); - printf("\e[92minitialized %u type descriptors\n", kerepTypeId_last); -} - -void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), Maybe (*toString)(void*, int32)){ - kerepTypeDescriptor typeDesc={ - .name=name, - .size=size, - .id=++kerepTypeId_last, - .freeMembers=freeMembers, - .toString=toString - }; - Autoarr_add(__kerepTypeDescriptors, typeDesc); -} - -Maybe kerepTypeDescriptor_get(kerepTypeId id){ - if(id>kerepTypeId_last) safethrow("invalid type id",;); - return SUCCESS(UniStack(kerepTypeId_kerepTypeDescriptorPtr, &typeDescriptors[id])); -} diff --git a/src/base/type_system/types.h b/src/base/type_system/types.h deleted file mode 100644 index 8cbaa6b..0000000 --- a/src/base/type_system/types.h +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#if __cplusplus -extern "C" { -#endif - -#include "../std.h" -#include "kerepTypeId.h" -#include "kerepTypeDescriptor.h" - - -extern kerepTypeId kerepTypeId_last; -void __kerepType_register(char* name, int16 size, void (*freeMembers)(void*), Maybe (*toString)(void*, int32)); - -#define kerepType_register(TYPE, ID_VAR_NAME, FREE_MEMBERS_FUNC, TO_STRING_FUNC)\ - __kerepType_register(#ID_VAR_NAME, sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\ - ID_VAR_NAME=kerepTypeId_last; - -void kerepTypeDescriptors_beginInit(); -void kerepTypeDescriptors_endInit(); -/// @param id id of registered type -/// @return Maybe -Maybe kerepTypeDescriptor_get(kerepTypeId id); - - -kerepTypeId_declare(kerepTypeId_Null); - -kerepTypeId_declare(kerepTypeId_Char); -kerepTypeId_declare(kerepTypeId_Bool); -kerepTypeId_declare(kerepTypeId_Float32); -kerepTypeId_declare(kerepTypeId_Float64); -kerepTypeId_declare(kerepTypeId_Int8); -kerepTypeId_declare(kerepTypeId_UInt8); -kerepTypeId_declare(kerepTypeId_Int16); -kerepTypeId_declare(kerepTypeId_UInt16); -kerepTypeId_declare(kerepTypeId_Int32); -kerepTypeId_declare(kerepTypeId_UInt32); -kerepTypeId_declare(kerepTypeId_Int64); -kerepTypeId_declare(kerepTypeId_UInt64); - -kerepTypeId_declare(kerepTypeId_CharPtr); -kerepTypeId_declare(kerepTypeId_BoolPtr); -kerepTypeId_declare(kerepTypeId_Float32Ptr); -kerepTypeId_declare(kerepTypeId_Float64Ptr); -kerepTypeId_declare(kerepTypeId_Int8Ptr); -kerepTypeId_declare(kerepTypeId_UInt8Ptr); -kerepTypeId_declare(kerepTypeId_Int16Ptr); -kerepTypeId_declare(kerepTypeId_UInt16Ptr); -kerepTypeId_declare(kerepTypeId_Int32Ptr); -kerepTypeId_declare(kerepTypeId_UInt32Ptr); -kerepTypeId_declare(kerepTypeId_Int64Ptr); -kerepTypeId_declare(kerepTypeId_UInt64Ptr); - -kerepTypeId_declare(kerepTypeId_kerepTypeDescriptor); -kerepTypeId_declare(kerepTypeId_kerepTypeDescriptorPtr); - -#if __cplusplus -} -#endif \ No newline at end of file diff --git a/src/base/type_system/unitype.c b/src/base/type_system/unitype.c index 8b44641..f727fc7 100644 --- a/src/base/type_system/unitype.c +++ b/src/base/type_system/unitype.c @@ -1,11 +1,11 @@ #include "../base.h" -kerepTypeId_define(kerepTypeId_Unitype); -kerepTypeId_define(kerepTypeId_UnitypePtr); +ktId_define(ktId_Unitype); +ktId_define(ktId_UnitypePtr); void Unitype_free(Unitype u){ - tryLast(kerepTypeDescriptor_get(u.typeId), mType); - kerepTypeDescriptor type=*(kerepTypeDescriptor*)mType.value.VoidPtr; + tryLast(ktDescriptor_get(u.typeId), mType); + ktDescriptor type=*(ktDescriptor*)mType.value.VoidPtr; if(type.freeMembers) type.freeMembers(u.VoidPtr); if(u.allocatedInHeap) @@ -16,17 +16,17 @@ void __UnitypePtr_free(void* u) { Unitype_free(*(Unitype*)u); } #define BUFSIZE 64 char* sprintuni(Unitype v){ char* buf=malloc(BUFSIZE); - tryLast(kerepTypeDescriptor_get(v.typeId), mType); - kerepTypeDescriptor type=*(kerepTypeDescriptor*)mType.value.VoidPtr; - if(v.typeId==kerepTypeId_Null) + tryLast(ktDescriptor_get(v.typeId), mType); + ktDescriptor type=*(ktDescriptor*)mType.value.VoidPtr; + if(v.typeId==ktId_Null) sprintf_s(buf, BUFSIZE, "{Null}"); - else if(v.typeId==kerepTypeId_Float64) + else if(v.typeId==ktId_Float64) sprintf_s(buf, BUFSIZE, "{%s : %lf}", type.name,v.Float64); - else if(v.typeId==kerepTypeId_Bool || v.typeId==kerepTypeId_UInt64) + else if(v.typeId==ktId_Bool || v.typeId==ktId_UInt64) sprintf_s(buf, BUFSIZE, "{%s : " IFWIN("%llu", "%lu") "}", type.name,v.UInt64); - else if(v.typeId==kerepTypeId_Int64) + else if(v.typeId==ktId_Int64) sprintf_s(buf, BUFSIZE, "{%s : " IFWIN("%lld", "%ld") "}", type.name,v.Int64); - else if(v.typeId==kerepTypeId_CharPtr){ + else if(v.typeId==ktId_CharPtr){ size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2; buf=realloc(buf, newBUFSIZE); sprintf_s(buf, BUFSIZE, "{%s : \"%s\"}", type.name,(char*)v.VoidPtr); diff --git a/src/base/type_system/unitype.h b/src/base/type_system/unitype.h index 9f28bf7..2fbbdf6 100644 --- a/src/base/type_system/unitype.h +++ b/src/base/type_system/unitype.h @@ -4,7 +4,7 @@ extern "C" { #endif -#include "kerepTypeId.h" +#include "ktId.h" typedef struct Unitype{ union { @@ -15,15 +15,15 @@ typedef struct Unitype{ void* VoidPtr; char Bytes[8]; }; - kerepTypeId typeId; + ktId typeId; bool allocatedInHeap; // should Unitype_free call free() to VoidPtr* } Unitype; -kerepTypeId_declare(kerepTypeId_Unitype); -kerepTypeId_declare(kerepTypeId_UnitypePtr); +ktId_declare(ktId_Unitype); +ktId_declare(ktId_UnitypePtr); #define __UniDef(TYPE, VAL) (Unitype){\ - .TYPE=VAL, .typeId=kerepTypeId_##TYPE, .allocatedInHeap=false} + .TYPE=VAL, .typeId=ktId_##TYPE, .allocatedInHeap=false} #define UniInt64(VAL) __UniDef(Int64, VAL) #define UniUInt64(VAL) __UniDef(UInt64, VAL) @@ -35,7 +35,7 @@ kerepTypeId_declare(kerepTypeId_UnitypePtr); #define UniHeap(ID_VAR_NAME, VAL) (Unitype){\ .VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=true} -#define UniNull UniStack(kerepTypeId_Null, NULL) +#define UniNull UniStack(ktId_Null, NULL) #define UniTrue UniBool(true) #define UniFalse UniBool(false) diff --git a/tests/main.cpp b/tests/main.cpp index 1f74e68..9136271 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -13,9 +13,9 @@ void test_all(){ int main(){ setlocale(LC_ALL, "en-US.Unicode"); - kerepTypeDescriptors_beginInit(); - kerepTypeDescriptors_initKerepTypes(); - kerepTypeDescriptors_endInit(); + ktDescriptors_beginInit(); + ktDescriptors_initKerepTypes(); + ktDescriptors_endInit(); printf("\e[97mkerep tests are starting!\n"); optime("test_all",1,test_all()); printf("\e[0m\n"); diff --git a/tests/test_dtsod.c b/tests/test_dtsod.c index f14c582..23ef429 100644 --- a/tests/test_dtsod.c +++ b/tests/test_dtsod.c @@ -18,7 +18,7 @@ void print_dtsod(Hashtable* dtsod){ printf("\e[92m"); Hashtable_foreach(dtsod, p,({ printkvp(p); - if(p.value.typeId==kerepTypeId_HashtablePtr){ + if(p.value.typeId==ktId_HashtablePtr){ printf(": {\n"); Hashtable* sub=p.value.VoidPtr; Hashtable_foreach(sub, _p,({ diff --git a/tests/test_marshalling.c b/tests/test_marshalling.c index 74e2129..1614c6c 100644 --- a/tests/test_marshalling.c +++ b/tests/test_marshalling.c @@ -4,7 +4,7 @@ EXPORT void CALL test_marshalling(char* text, KVPair** kptr){ KVPair* k=malloc(sizeof(KVPair)); k->key="message"; char* tc=cptr_copy(text); - Unitype u=UniHeap(kerepTypeId_CharPtr,tc); + Unitype u=UniHeap(ktId_CharPtr,tc); k->value=u; *kptr=k; } diff --git a/tests/test_searchtree.c b/tests/test_searchtree.c index c67e8fd..109c116 100644 --- a/tests/test_searchtree.c +++ b/tests/test_searchtree.c @@ -44,11 +44,11 @@ void test_searchtree(){ printuni(u); ST_push(node,"channel_id", u); printf(" -> channel_id\n "); - u=UniHeap(kerepTypeId_CharPtr, cptr_copy("32.2004")); + u=UniHeap(ktId_CharPtr, cptr_copy("32.2004")); printuni(u); ST_push(node,"message_id", u); printf(" -> message_id\n "); - u=UniStack(kerepTypeId_CharPtr,"some text UwU"); + u=UniStack(ktId_CharPtr,"some text UwU"); printuni(u); ST_push(node,"text", u); printf(" -> text\n"); From a3c8ef6486e7aa9d06a258bc4e83653d98513bf7 Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 9 Sep 2022 19:06:35 +0600 Subject: [PATCH 11/17] build_scripts removed --- .../build_configurations/build_shared_lib.sh | 10 --- .../build_configurations/build_static_lib.sh | 10 --- .../build_static_lib_dbg.sh | 10 --- .../build_configurations/build_test.sh | 10 --- .../build_configurations/build_test_dbg.sh | 10 --- build_scripts/build_configurations/test.sh | 8 -- .../build_configurations/test_valgrind.sh | 9 -- build_scripts/colors.sh | 11 --- build_scripts/default.config.sh | 43 --------- build_scripts/functions.sh | 89 ------------------- build_scripts/init.sh | 22 ----- 11 files changed, 232 deletions(-) delete mode 100644 build_scripts/build_configurations/build_shared_lib.sh delete mode 100644 build_scripts/build_configurations/build_static_lib.sh delete mode 100644 build_scripts/build_configurations/build_static_lib_dbg.sh delete mode 100644 build_scripts/build_configurations/build_test.sh delete mode 100644 build_scripts/build_configurations/build_test_dbg.sh delete mode 100644 build_scripts/build_configurations/test.sh delete mode 100644 build_scripts/build_configurations/test_valgrind.sh delete mode 100644 build_scripts/colors.sh delete mode 100644 build_scripts/default.config.sh delete mode 100644 build_scripts/functions.sh delete mode 100644 build_scripts/init.sh diff --git a/build_scripts/build_configurations/build_shared_lib.sh b/build_scripts/build_configurations/build_shared_lib.sh deleted file mode 100644 index dbe33c9..0000000 --- a/build_scripts/build_configurations/build_shared_lib.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source build_scripts/init.sh - -print "${CYAN}==========[build_shared_lib]==========\n" -clear_dir "$OUTDIR" -clear_dir "$OBJDIR" -compile_c "$BUILD_SHARED_LIB_C_ARGS" "$SRC_C tests/test_marshalling.c" -compile_cpp "$BUILD_SHARED_LIB_CPP_ARGS" "$SRC_CPP" -link "$BUILD_SHARED_LIB_CPP_ARGS $BUILD_SHARED_LIB_LINKER_ARGS" "$SHARED_LIB_FILE" diff --git a/build_scripts/build_configurations/build_static_lib.sh b/build_scripts/build_configurations/build_static_lib.sh deleted file mode 100644 index 692155e..0000000 --- a/build_scripts/build_configurations/build_static_lib.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source build_scripts/init.sh - -print "${CYAN}==========[build_static_lib]==========\n" -clear_dir "$OUTDIR" -clear_dir "$OBJDIR" -compile_c "$BUILD_STATIC_LIB_C_ARGS" "$SRC_C tests/test_marshalling.c" -compile_cpp "$BUILD_STATIC_LIB_CPP_ARGS" "$SRC_CPP" -pack_static_lib "$STATIC_LIB_FILE" diff --git a/build_scripts/build_configurations/build_static_lib_dbg.sh b/build_scripts/build_configurations/build_static_lib_dbg.sh deleted file mode 100644 index ef8aa3d..0000000 --- a/build_scripts/build_configurations/build_static_lib_dbg.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source build_scripts/init.sh - -print "${CYAN}==========[build_static_lib_dbg]==========\n" -clear_dir "$OUTDIR" -clear_dir "$OBJDIR" -compile_c "$BUILD_STATIC_LIB_DBG_C_ARGS" "$SRC_C tests/test_marshalling.c" -compile_cpp "$BUILD_STATIC_LIB_DBG_CPP_ARGS" "$SRC_CPP" -pack_static_lib "$STATIC_LIB_DBG_FILE" diff --git a/build_scripts/build_configurations/build_test.sh b/build_scripts/build_configurations/build_test.sh deleted file mode 100644 index 570de5a..0000000 --- a/build_scripts/build_configurations/build_test.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source build_scripts/init.sh - -print "${CYAN}=============[build_test]=============\n" -clear_dir "$OUTDIR" -clear_dir "$OBJDIR" -compile_c "$BUILD_TEST_C_ARGS" "$SRC_C $TESTS_C" -compile_cpp "$BUILD_TEST_CPP_ARGS" "$SRC_CPP $TESTS_CPP" -link "$BUILD_TEST_CPP_ARGS $BUILD_TEST_LINKER_ARGS" $TEST_FILE diff --git a/build_scripts/build_configurations/build_test_dbg.sh b/build_scripts/build_configurations/build_test_dbg.sh deleted file mode 100644 index ff56aa0..0000000 --- a/build_scripts/build_configurations/build_test_dbg.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -source build_scripts/init.sh - -print "${CYAN}===========[build_test_dbg]===========\n" -clear_dir "$OUTDIR" -clear_dir "$OBJDIR" -compile_c "$BUILD_TEST_DBG_C_ARGS" "$SRC_C $TESTS_C" -compile_cpp "$BUILD_TEST_DBG_CPP_ARGS" "$SRC_CPP $TESTS_CPP" -link "$BUILD_TEST_DBG_CPP_ARGS $BUILD_TEST_DBG_LINKER_ARGS" $TEST_DBG_FILE diff --git a/build_scripts/build_configurations/test.sh b/build_scripts/build_configurations/test.sh deleted file mode 100644 index 45ac85c..0000000 --- a/build_scripts/build_configurations/test.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -source build_scripts/init.sh - -print "${CYAN}================[test]================\n" -cd $OUTDIR -./$TEST_FILE -cd .. diff --git a/build_scripts/build_configurations/test_valgrind.sh b/build_scripts/build_configurations/test_valgrind.sh deleted file mode 100644 index a92df20..0000000 --- a/build_scripts/build_configurations/test_valgrind.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -source build_scripts/init.sh - -print "${CYAN}===========[test_valgrind]============\n" -cd $OUTDIR -valgrind $VALGRIND_ARGS ./$TEST_DBG_FILE -cat "valgrind.log" -cd .. diff --git a/build_scripts/colors.sh b/build_scripts/colors.sh deleted file mode 100644 index e3e8363..0000000 --- a/build_scripts/colors.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -BLACK='\033[0;30m' -GRAY='\033[0;37m' -WHITE='\033[0;97m' -RED='\033[0;91m' -GREEN='\033[0;92m' -YELLOW='\033[0;93m' -BLUE='\033[0;94m' -PURPLE='\033[0;95m' -CYAN='\033[0;96m' diff --git a/build_scripts/default.config.sh b/build_scripts/default.config.sh deleted file mode 100644 index 7c2c541..0000000 --- a/build_scripts/default.config.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -OUTDIR=bin -OBJDIR=obj -CMP_C=gcc -CMP_CPP=g++ -STD_C=c11 -STD_CPP=c++17 -WARN_C="-Wall -Wno-discarded-qualifiers" -WARN_CPP="-Wall" -SRC_C="$( find src -name '*.c')" -SRC_CPP="$( find src -name '*.cpp')" -TESTS_C="$( find tests -name '*.c')" -TESTS_CPP="$(find tests -name '*.cpp')" -VALGRIND_ARGS="-s --log-file=valgrind.log --read-var-info=yes --track-origins=yes --fullpath-after=kerep/ --leak-check=full --show-leak-kinds=all" - -# build_test -TEST_FILE=kerep.com -BUILD_TEST_C_ARGS="-O2" -BUILD_TEST_CPP_ARGS="$BUILD_TEST_C_ARGS" -BUILD_TEST_LINKER_ARGS="" - -# build_test_dbg -TEST_DBG_FILE=$TEST_FILE.dbg -BUILD_TEST_DBG_C_ARGS="-O0 -g" -BUILD_TEST_DBG_CPP_ARGS="$BUILD_TEST_DBG_C_ARGS" -BUILD_TEST_DBG_LINKER_ARGS="" - -# build_shared_lib -SHARED_LIB_FILE=kerep.so -BUILD_SHARED_LIB_C_ARGS="-O2 -fpic -flto -shared" -BUILD_SHARED_LIB_CPP_ARGS="$BUILD_SHARED_LIB_C_ARGS" -BUILD_SHARED_LIB_LINKER_ARGS="-Wl,-soname,$SHARED_LIB_FILE" - -# build_static_lib -STATIC_LIB_FILE=kerep.a -BUILD_STATIC_LIB_C_ARGS="-O2 -fpic" -BUILD_STATIC_LIB_CPP_ARGS="$BUILD_STATIC_LIB_C_ARGS" - -# build_static_lib_dbg -STATIC_LIB_DBG_FILE="$STATIC_LIB_FILE" -BUILD_STATIC_LIB_DBG_C_ARGS="-O0 -g" -BUILD_STATIC_LIB_DBG_CPP_ARGS="$BUILD_STATIC_LIB_DBG_C_ARGS" diff --git a/build_scripts/functions.sh b/build_scripts/functions.sh deleted file mode 100644 index a2486e0..0000000 --- a/build_scripts/functions.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/bin/bash - -function print { - printf "$1$GRAY" -} - -function clear_dir { - print "${BLUE}clearing $1\n" - rm -rf $1 - mkdir $1 -} - -function compile { - local cmp=$1 - print "${BLUE}compiler: ${GRAY}$cmp\n" - local std=$2 - print "${BLUE}standard: ${GRAY}$std\n" - local warn=$3 - print "${BLUE}warnings: ${GRAY}$warn\n" - local args=$4 - print "${BLUE}args: ${GRAY}$args\n" - local sources=$5 - print "${BLUE}sources: ${GRAY}$sources\n" - local compilation_error=0 - - for srcfile in $sources - do ( - local object="$OBJDIR/$(basename $srcfile).o" - if ! $($cmp -std=$std $warn $args -c -o $object $srcfile) - then - print "${RED}some error happened\n" - compilation_error=1 - fi - ) & done - wait - - if [ $compilation_error != 0 ] - then - exit 1 - fi -} - -# (args, sources) -function compile_c { - print "${CYAN}-------------[compile_c]--------------\n" - compile $CMP_C $STD_C "$WARN_C" "$1" "$2" -} - -# (args, sources) -function compile_cpp { - print "${CYAN}------------[compile_cpp]-------------\n" - compile $CMP_CPP $STD_CPP "$WARN_CPP" "$1" "$2" -} - -# (args, outfile) -function link { - print "${CYAN}----------------[link]----------------\n" - local args=$1 - print "${BLUE}args: ${GRAY}$args\n" - local outfile=$OUTDIR/$2 - print "${BLUE}outfile: ${GRAY}$outfile\n" - local objects="$(find $OBJDIR -name *.o)" - print "${BLUE}objects: ${GRAY}$objects\n" - if $CMP_CPP $args -o $outfile $(echo $objects | tr '\n' ' ') - then - print "${GREEN}file $CYAN$outfile ${GREEN}created\n" - rm -rf $OBJDIR - else - print "${RED}some error happened\n" - exit 1 - fi -} - -# (outfile) -function pack_static_lib { - print "${CYAN}----------------[link]----------------\n" - local outfile=$OUTDIR/$1 - print "${BLUE}outfile: ${GRAY}$outfile\n" - local objects="$(find $OBJDIR -name *.o)" - print "${BLUE}objects: ${GRAY}$objects\n" - if ar rcs $outfile $(echo $objects | tr '\n' ' ') - then - print "${GREEN}file $CYAN$outfile ${GREEN}created\n" - rm -rf $OBJDIR - else - print "${RED}some error happened\n" - exit 1 - fi -} \ No newline at end of file diff --git a/build_scripts/init.sh b/build_scripts/init.sh deleted file mode 100644 index 868baf5..0000000 --- a/build_scripts/init.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash - -tabs 4 - -source build_scripts/colors.sh -source build_scripts/functions.sh - -if [ ! -f ".config" ]; then - print "${YELLOW}./.config doesn't exists\n" - cp build_scripts/default.config.sh .config - print "${YELLOW}default config created\n" - while true; do - print "${WHITE}continue? (y/n) " - read answ - case $answ in - [Yy] ) break;; - [Nn] ) exit;; - * ) print "${RED}incorrect answer\n";; - esac - done -fi -source .config From e08da5f4a7dbcbe4dc1b10718835d32d1e4c2bec Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 9 Sep 2022 19:06:49 +0600 Subject: [PATCH 12/17] added cbuild --- .gitmodules | 3 +++ Makefile | 32 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..dd060e8 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cbuild"] + path = cbuild + url = https://github.com/Timerix22/cbuild.git diff --git a/Makefile b/Makefile index 49eea86..c00ea21 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,24 @@ -###### Building tasks ####### -build_test: - @build_scripts/build_configurations/build_test.sh - -build_test_dbg: - @build_scripts/build_configurations/build_test_dbg.sh +###### Build cbuild/default_tasks ####### +build_exec: + @cbuild/default_tasks/build_exec.sh +build_exec_dbg: + @cbuild/default_tasks/build_exec_dbg.sh build_shared_lib: - @build_scripts/build_configurations/build_shared_lib.sh + @cbuild/default_tasks/build_shared_lib.sh +build_shared_lib_dbg: + @cbuild/default_tasks/build_shared_lib_dbg.sh build_static_lib: - @build_scripts/build_configurations/build_static_lib.sh - + @cbuild/default_tasks/build_static_lib.sh build_static_lib_dbg: - @build_scripts/build_configurations/build_static_lib_dbg.sh + @cbuild/default_tasks/build_static_lib_dbg.sh -###### Testing tasks ####### -test: build_test - @build_scripts/build_configurations/test.sh +###### Launch cbuild/default_tasks ####### +exec: build_exec + @cbuild/default_tasks/exec.sh -test_valgrind: build_test_dbg - @build_scripts/build_configurations/test_valgrind.sh +valgrind: build_exec_dbg + @cbuild/default_tasks/valgrind.sh -all: build_test +all: build_exec From 5ceb60a581961a7d4a63717dd0a40827726c4935 Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 9 Sep 2022 19:10:49 +0600 Subject: [PATCH 13/17] .vscode --- .gitignore | 1 - .vscode/.gitignore | 1 + .vscode/launch.json | 34 +++++++++++++++++++++++++++ .vscode/tasks.json | 57 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 .vscode/.gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 6e5b49f..d59895f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ obj/ # user files .old*/ .vs/ -.vscode/ .vshistory/ .editorconfig *.user diff --git a/.vscode/.gitignore b/.vscode/.gitignore new file mode 100644 index 0000000..c3d3a20 --- /dev/null +++ b/.vscode/.gitignore @@ -0,0 +1 @@ +settings.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..421e47a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,34 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Debug", + "type": "cppdbg", + "request": "launch", + "preLaunchTask": "build_exec_dbg", + "program": "${workspaceFolder}/bin/kerep.com", + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "externalConsole": true, + "internalConsoleOptions": "openOnSessionStart", + "miDebuggerPath": "/usr/bin/gdb", + "MIMode": "gdb", + "pipeTransport": { + "debuggerPath": "gdb", + "pipeProgram": "bash", + "pipeArgs": ["-c"], + "pipeCwd": "${workspaceFolder}" + } + }, + { + "name": "(msvc) Debug", + "type": "cppvsdbg", + "request": "launch", + "preLaunchTask": "build_dbg", + "cwd": "${workspaceFolder}\\bin", + "program": "${workspaceFolder}\\bin\\kerep.com", + "stopAtEntry": false, + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..7fb803b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,57 @@ + +{ + + "version": "2.0.0", + "tasks": [ + { + "label": "build_exec", + "detail": "build project", + "type": "cppbuild", + "command": "make", + "args": [ + "build_exec" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + }, + + { + "label": "build_exec_dbg", + "detail": "build project with debug symbols", + "type": "cppbuild", + "command": "make", + "args": [ + "build_exec_dbg" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": ["$gcc"], + "group": { + "kind": "build" + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": false, + "clear": true + } + } + ] + } \ No newline at end of file From 5b7f74b445653198390b33f99319051cfe3b79dd Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 9 Sep 2022 19:55:14 +0600 Subject: [PATCH 14/17] chmod_scripts moved into submodule --- cbuild | 1 + chmod_scripts.sh | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) create mode 160000 cbuild delete mode 100644 chmod_scripts.sh diff --git a/cbuild b/cbuild new file mode 160000 index 0000000..3152566 --- /dev/null +++ b/cbuild @@ -0,0 +1 @@ +Subproject commit 315256694e1564200213b388170384cede255838 diff --git a/chmod_scripts.sh b/chmod_scripts.sh deleted file mode 100644 index ec71ae9..0000000 --- a/chmod_scripts.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -SCRIPTS="$(find build_scripts -name '*.sh')" -for F in $SCRIPTS -do - echo $F - chmod +x $F -done From a7c75cfda21ec31f3eebc8ea415aab86a8410682 Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 9 Sep 2022 20:28:15 +0600 Subject: [PATCH 15/17] 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) From 50fea51a3e8bb8f05ad78627f16c9057923147fe Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 9 Sep 2022 20:43:30 +0600 Subject: [PATCH 16/17] cbuild updated --- cbuild | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbuild b/cbuild index 3152566..8817640 160000 --- a/cbuild +++ b/cbuild @@ -1 +1 @@ -Subproject commit 315256694e1564200213b388170384cede255838 +Subproject commit 881764061a019e9484970e530cb437a892f99007 From dbbfb64820d59fb7458c642818673ad90c506228 Mon Sep 17 00:00:00 2001 From: timerix Date: Fri, 9 Sep 2022 22:12:39 +0600 Subject: [PATCH 17/17] cbuild updated --- Makefile | 16 ++++++++-------- cbuild | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index c00ea21..c61ed41 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,24 @@ ###### Build cbuild/default_tasks ####### build_exec: - @cbuild/default_tasks/build_exec.sh + @cbuild/call_task.sh build_exec build_exec_dbg: - @cbuild/default_tasks/build_exec_dbg.sh + @cbuild/call_task.sh build_exec_dbg build_shared_lib: - @cbuild/default_tasks/build_shared_lib.sh + @cbuild/call_task.sh build_shared_lib build_shared_lib_dbg: - @cbuild/default_tasks/build_shared_lib_dbg.sh + @cbuild/call_task.sh build_shared_lib_dbg build_static_lib: - @cbuild/default_tasks/build_static_lib.sh + @cbuild/call_task.sh build_static_lib build_static_lib_dbg: - @cbuild/default_tasks/build_static_lib_dbg.sh + @cbuild/call_task.sh build_static_lib_dbg ###### Launch cbuild/default_tasks ####### exec: build_exec - @cbuild/default_tasks/exec.sh + @cbuild/call_task.sh exec valgrind: build_exec_dbg - @cbuild/default_tasks/valgrind.sh + @cbuild/call_task.sh valgrind all: build_exec diff --git a/cbuild b/cbuild index 8817640..ff04da5 160000 --- a/cbuild +++ b/cbuild @@ -1 +1 @@ -Subproject commit 881764061a019e9484970e530cb437a892f99007 +Subproject commit ff04da5c198cea82a7948eb882e3cc96c7b5686c