yet another ktid type system refactoring
This commit is contained in:
parent
00c7987fa2
commit
e846f6d304
@ -1,27 +1,16 @@
|
|||||||
#include "Array.h"
|
#include "Array.h"
|
||||||
|
|
||||||
ktId_define(ArrayChar);
|
Array_define(char)
|
||||||
ktId_define(ArrayBool);
|
Array_define(bool)
|
||||||
ktId_define(ArrayFloat32);
|
Array_define(float32)
|
||||||
ktId_define(ArrayFloat64);
|
Array_define(float64)
|
||||||
ktId_define(ArrayInt8);
|
Array_define(int8)
|
||||||
ktId_define(ArrayUInt8);
|
Array_define(uint8)
|
||||||
ktId_define(ArrayInt16);
|
Array_define(int16)
|
||||||
ktId_define(ArrayUInt16);
|
Array_define(uint16)
|
||||||
ktId_define(ArrayInt32);
|
Array_define(int32)
|
||||||
ktId_define(ArrayUInt32);
|
Array_define(uint32)
|
||||||
ktId_define(ArrayInt64);
|
Array_define(int64)
|
||||||
ktId_define(ArrayUInt64);
|
Array_define(uint64)
|
||||||
|
|
||||||
ktId_define(ArrayCharPtr);
|
Array_define(Unitype)
|
||||||
ktId_define(ArrayBoolPtr);
|
|
||||||
ktId_define(ArrayFloat32Ptr);
|
|
||||||
ktId_define(ArrayFloat64Ptr);
|
|
||||||
ktId_define(ArrayInt8Ptr);
|
|
||||||
ktId_define(ArrayUInt8Ptr);
|
|
||||||
ktId_define(ArrayInt16Ptr);
|
|
||||||
ktId_define(ArrayUInt16Ptr);
|
|
||||||
ktId_define(ArrayInt32Ptr);
|
|
||||||
ktId_define(ArrayUInt32Ptr);
|
|
||||||
ktId_define(ArrayInt64Ptr);
|
|
||||||
ktId_define(ArrayUInt64Ptr);
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
#include "Array_declare.h"
|
#include "Array_declare.h"
|
||||||
|
#include "Array_define.h"
|
||||||
|
|
||||||
Array_declare(char)
|
Array_declare(char)
|
||||||
Array_declare(bool)
|
Array_declare(bool)
|
||||||
@ -13,28 +14,4 @@ Array_declare(uint32)
|
|||||||
Array_declare(int64)
|
Array_declare(int64)
|
||||||
Array_declare(uint64)
|
Array_declare(uint64)
|
||||||
|
|
||||||
ktId_declare(ArrayChar);
|
Array_declare(Unitype)
|
||||||
ktId_declare(ArrayBool);
|
|
||||||
ktId_declare(ArrayFloat32);
|
|
||||||
ktId_declare(ArrayFloat64);
|
|
||||||
ktId_declare(ArrayInt8);
|
|
||||||
ktId_declare(ArrayUInt8);
|
|
||||||
ktId_declare(ArrayInt16);
|
|
||||||
ktId_declare(ArrayUInt16);
|
|
||||||
ktId_declare(ArrayInt32);
|
|
||||||
ktId_declare(ArrayUInt32);
|
|
||||||
ktId_declare(ArrayInt64);
|
|
||||||
ktId_declare(ArrayUInt64);
|
|
||||||
|
|
||||||
ktId_declare(ArrayCharPtr);
|
|
||||||
ktId_declare(ArrayBoolPtr);
|
|
||||||
ktId_declare(ArrayFloat32Ptr);
|
|
||||||
ktId_declare(ArrayFloat64Ptr);
|
|
||||||
ktId_declare(ArrayInt8Ptr);
|
|
||||||
ktId_declare(ArrayUInt8Ptr);
|
|
||||||
ktId_declare(ArrayInt16Ptr);
|
|
||||||
ktId_declare(ArrayUInt16Ptr);
|
|
||||||
ktId_declare(ArrayInt32Ptr);
|
|
||||||
ktId_declare(ArrayUInt32Ptr);
|
|
||||||
ktId_declare(ArrayInt64Ptr);
|
|
||||||
ktId_declare(ArrayUInt64Ptr);
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ typedef struct Array_##type{\
|
|||||||
bool allocatedOnHeap;\
|
bool allocatedOnHeap;\
|
||||||
} Array_##type;\
|
} Array_##type;\
|
||||||
\
|
\
|
||||||
|
ktid_declare(Array_##type);\
|
||||||
\
|
\
|
||||||
static inline Array_##type Array_##type##_allocValues(uint32 length){\
|
static inline Array_##type Array_##type##_allocValues(uint32 length){\
|
||||||
return (Array_##type) {\
|
return (Array_##type) {\
|
||||||
|
|||||||
14
src/Array/Array_define.h
Normal file
14
src/Array/Array_define.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "../base/base.h"
|
||||||
|
|
||||||
|
#define Array_define(type)\
|
||||||
|
ktid_define(Array_##type);
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@ -1,2 +1,2 @@
|
|||||||
# Array struct
|
# Array struct
|
||||||
This struct stores array pointer and length. If you want to use `Array` of some type, it should be declared in header file by macro `Array_declare`. It uses `static inline` functions, so all definitions will be generated in header.
|
This struct stores array pointer and length. If you want to use `Array` of some type, it should be declared in header file by macro `Array_declare` and defined in source file by `Array_define`.
|
||||||
|
|||||||
@ -12,40 +12,3 @@ Autoarr_define(uint32)
|
|||||||
Autoarr_define(int32)
|
Autoarr_define(int32)
|
||||||
Autoarr_define(uint64)
|
Autoarr_define(uint64)
|
||||||
Autoarr_define(int64)
|
Autoarr_define(int64)
|
||||||
|
|
||||||
ktId_define(AutoarrChar);
|
|
||||||
ktId_define(AutoarrBool);
|
|
||||||
ktId_define(AutoarrFloat32);
|
|
||||||
ktId_define(AutoarrFloat64);
|
|
||||||
ktId_define(AutoarrInt8);
|
|
||||||
ktId_define(AutoarrUInt8);
|
|
||||||
ktId_define(AutoarrInt16);
|
|
||||||
ktId_define(AutoarrUInt16);
|
|
||||||
ktId_define(AutoarrInt32);
|
|
||||||
ktId_define(AutoarrUInt32);
|
|
||||||
ktId_define(AutoarrInt64);
|
|
||||||
ktId_define(AutoarrUInt64);
|
|
||||||
|
|
||||||
ktId_define(AutoarrCharPtr);
|
|
||||||
ktId_define(AutoarrBoolPtr);
|
|
||||||
ktId_define(AutoarrFloat32Ptr);
|
|
||||||
ktId_define(AutoarrFloat64Ptr);
|
|
||||||
ktId_define(AutoarrInt8Ptr);
|
|
||||||
ktId_define(AutoarrUInt8Ptr);
|
|
||||||
ktId_define(AutoarrInt16Ptr);
|
|
||||||
ktId_define(AutoarrUInt16Ptr);
|
|
||||||
ktId_define(AutoarrInt32Ptr);
|
|
||||||
ktId_define(AutoarrUInt32Ptr);
|
|
||||||
ktId_define(AutoarrInt64Ptr);
|
|
||||||
ktId_define(AutoarrUInt64Ptr);
|
|
||||||
|
|
||||||
Autoarr_define(Unitype)
|
|
||||||
ktId_define(AutoarrUnitype);
|
|
||||||
ktId_define(AutoarrUnitypePtr);
|
|
||||||
|
|
||||||
// right func to clear array of unitype values
|
|
||||||
void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr){
|
|
||||||
Autoarr_foreach(ar, u,Unitype_free(u));
|
|
||||||
__Autoarr_free_Unitype(ar, freePtr);
|
|
||||||
}
|
|
||||||
void ____Autoarr_free_Unitype_(void* ar) { __Autoarr_free_Unitype_((Autoarr(Unitype)*)ar, false); }
|
|
||||||
@ -6,6 +6,7 @@ extern "C" {
|
|||||||
|
|
||||||
#include "Autoarr_declare.h"
|
#include "Autoarr_declare.h"
|
||||||
#include "Autoarr_define.h"
|
#include "Autoarr_define.h"
|
||||||
|
#include "Autoarr_Unitype.h"
|
||||||
|
|
||||||
Autoarr_declare(char)
|
Autoarr_declare(char)
|
||||||
Autoarr_declare(bool)
|
Autoarr_declare(bool)
|
||||||
@ -20,54 +21,6 @@ Autoarr_declare(uint32)
|
|||||||
Autoarr_declare(int64)
|
Autoarr_declare(int64)
|
||||||
Autoarr_declare(uint64)
|
Autoarr_declare(uint64)
|
||||||
|
|
||||||
ktId_declare(AutoarrChar);
|
|
||||||
ktId_declare(AutoarrBool);
|
|
||||||
ktId_declare(AutoarrFloat32);
|
|
||||||
ktId_declare(AutoarrFloat64);
|
|
||||||
ktId_declare(AutoarrInt8);
|
|
||||||
ktId_declare(AutoarrUInt8);
|
|
||||||
ktId_declare(AutoarrInt16);
|
|
||||||
ktId_declare(AutoarrUInt16);
|
|
||||||
ktId_declare(AutoarrInt32);
|
|
||||||
ktId_declare(AutoarrUInt32);
|
|
||||||
ktId_declare(AutoarrInt64);
|
|
||||||
ktId_declare(AutoarrUInt64);
|
|
||||||
|
|
||||||
ktId_declare(AutoarrCharPtr);
|
|
||||||
ktId_declare(AutoarrBoolPtr);
|
|
||||||
ktId_declare(AutoarrFloat32Ptr);
|
|
||||||
ktId_declare(AutoarrFloat64Ptr);
|
|
||||||
ktId_declare(AutoarrInt8Ptr);
|
|
||||||
ktId_declare(AutoarrUInt8Ptr);
|
|
||||||
ktId_declare(AutoarrInt16Ptr);
|
|
||||||
ktId_declare(AutoarrUInt16Ptr);
|
|
||||||
ktId_declare(AutoarrInt32Ptr);
|
|
||||||
ktId_declare(AutoarrUInt32Ptr);
|
|
||||||
ktId_declare(AutoarrInt64Ptr);
|
|
||||||
ktId_declare(AutoarrUInt64Ptr);
|
|
||||||
|
|
||||||
Autoarr_declare(Unitype)
|
|
||||||
ktId_declare(AutoarrUnitype);
|
|
||||||
ktId_declare(AutoarrUnitypePtr);
|
|
||||||
|
|
||||||
// this function is injected in kerep_init()
|
|
||||||
void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr);
|
|
||||||
void ____Autoarr_free_Unitype_(void* ar);
|
|
||||||
|
|
||||||
#define Autoarr_foreach(ar,elem,codeblock)({\
|
|
||||||
if(ar->blocks_count>0) {\
|
|
||||||
typeof(**ar->values) elem;\
|
|
||||||
for(uint32 blockI=0;blockI<ar->blocks_count-1;blockI++)\
|
|
||||||
for(uint32 elemI=0;elemI<ar->max_block_length;elemI++){\
|
|
||||||
elem=ar->values[blockI][elemI];\
|
|
||||||
(codeblock);\
|
|
||||||
}\
|
|
||||||
for(uint32 elemI=0;elemI<ar->block_length;elemI++){\
|
|
||||||
elem=ar->values[ar->blocks_count-1][elemI];\
|
|
||||||
(codeblock);\
|
|
||||||
}\
|
|
||||||
}\
|
|
||||||
})
|
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/Autoarr/Autoarr_Unitype.c
Normal file
12
src/Autoarr/Autoarr_Unitype.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include "Autoarr.h"
|
||||||
|
|
||||||
|
Autoarr_define(Unitype);
|
||||||
|
|
||||||
|
// right func to clear array of unitype values
|
||||||
|
void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr){
|
||||||
|
Autoarr_foreach(ar, u,Unitype_free(u));
|
||||||
|
__Autoarr_free_Unitype(ar, freePtr);
|
||||||
|
}
|
||||||
|
void ____Autoarr_free_Unitype_(void* ar) {
|
||||||
|
__Autoarr_free_Unitype_((Autoarr(Unitype)*)ar, false);
|
||||||
|
}
|
||||||
33
src/Autoarr/Autoarr_Unitype.h
Normal file
33
src/Autoarr/Autoarr_Unitype.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Autoarr_declare.h"
|
||||||
|
#include "Autoarr_define.h"
|
||||||
|
|
||||||
|
Autoarr_declare(Unitype)
|
||||||
|
|
||||||
|
// this function is injected in kerep_init()
|
||||||
|
void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr);
|
||||||
|
void ____Autoarr_free_Unitype_(void* ar);
|
||||||
|
|
||||||
|
#define Autoarr_foreach(ar,elem,codeblock)({\
|
||||||
|
if(ar->blocks_count>0) {\
|
||||||
|
typeof(**ar->values) elem;\
|
||||||
|
for(uint32 blockI=0;blockI<ar->blocks_count-1;blockI++)\
|
||||||
|
for(uint32 elemI=0;elemI<ar->max_block_length;elemI++){\
|
||||||
|
elem=ar->values[blockI][elemI];\
|
||||||
|
(codeblock);\
|
||||||
|
}\
|
||||||
|
for(uint32 elemI=0;elemI<ar->block_length;elemI++){\
|
||||||
|
elem=ar->values[ar->blocks_count-1][elemI];\
|
||||||
|
(codeblock);\
|
||||||
|
}\
|
||||||
|
}\
|
||||||
|
})
|
||||||
|
|
||||||
|
#if __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@ -28,6 +28,8 @@ typedef struct Autoarr_##type{\
|
|||||||
__functions_list_t_##type* functions;\
|
__functions_list_t_##type* functions;\
|
||||||
} Autoarr_##type;\
|
} Autoarr_##type;\
|
||||||
\
|
\
|
||||||
|
ktid_declare(Autoarr_##type);\
|
||||||
|
\
|
||||||
Autoarr_##type* __Autoarr_create_##type(uint16 max_blocks_count, uint16 max_block_length);\
|
Autoarr_##type* __Autoarr_create_##type(uint16 max_blocks_count, uint16 max_block_length);\
|
||||||
void __Autoarr_free_##type(Autoarr_##type* ar, bool freePtr);\
|
void __Autoarr_free_##type(Autoarr_##type* ar, bool freePtr);\
|
||||||
void ____Autoarr_free_##type(void* ar);
|
void ____Autoarr_free_##type(void* ar);
|
||||||
|
|||||||
@ -8,6 +8,8 @@ extern "C" {
|
|||||||
|
|
||||||
#define Autoarr_define(type)\
|
#define Autoarr_define(type)\
|
||||||
\
|
\
|
||||||
|
ktid_define(Autoarr_##type);\
|
||||||
|
\
|
||||||
void __Autoarr_add_##type(Autoarr_##type* ar, type element){\
|
void __Autoarr_add_##type(Autoarr_##type* ar, type element){\
|
||||||
if(!ar->values){\
|
if(!ar->values){\
|
||||||
ar->values=malloc(ar->max_blocks_count*sizeof(type*));\
|
ar->values=malloc(ar->max_blocks_count*sizeof(type*));\
|
||||||
|
|||||||
@ -98,9 +98,9 @@ Maybe __ReadName(DeserializeSharedData* shared){
|
|||||||
case '}':
|
case '}':
|
||||||
if(!calledRecursively || nameStr.length!=0)
|
if(!calledRecursively || nameStr.length!=0)
|
||||||
safethrow_wrongchar(c,;);
|
safethrow_wrongchar(c,;);
|
||||||
return SUCCESS(UniHeap(ktId_CharPtr,NULL));
|
return SUCCESS(UniHeapPtr(char,NULL));
|
||||||
case ':':
|
case ':':
|
||||||
return SUCCESS(UniHeap(ktId_CharPtr,string_extract(nameStr)));
|
return SUCCESS(UniHeapPtr(char,string_extract(nameStr)));
|
||||||
case '$':
|
case '$':
|
||||||
if(nameStr.length!=0)
|
if(nameStr.length!=0)
|
||||||
safethrow_wrongchar(c,;);
|
safethrow_wrongchar(c,;);
|
||||||
@ -113,7 +113,7 @@ Maybe __ReadName(DeserializeSharedData* shared){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(nameStr.length>0) safethrow(ERR_ENDOFSTR,;);
|
if(nameStr.length>0) safethrow(ERR_ENDOFSTR,;);
|
||||||
return SUCCESS(UniHeap(ktId_CharPtr,NULL));
|
return SUCCESS(UniHeapPtr(char,NULL));
|
||||||
}
|
}
|
||||||
#define ReadName() __ReadName(shared)
|
#define ReadName() __ReadName(shared)
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ Maybe __ReadString(DeserializeSharedData* shared){
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char* str=StringBuilder_build(b).ptr;
|
char* str=StringBuilder_build(b).ptr;
|
||||||
return SUCCESS(UniHeap(ktId_CharPtr,str));
|
return SUCCESS(UniHeapPtr(char,str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -157,13 +157,13 @@ Maybe __ReadList(DeserializeSharedData* shared){
|
|||||||
try(ReadValue((&readingList)), val, Autoarr_free(list, true))
|
try(ReadValue((&readingList)), val, Autoarr_free(list, true))
|
||||||
Autoarr_add(list,val.value);
|
Autoarr_add(list,val.value);
|
||||||
if (!readingList){
|
if (!readingList){
|
||||||
if(val.value.typeId==ktId_Null)
|
if(val.value.typeId==ktid_Null)
|
||||||
Autoarr_pop(list);
|
Autoarr_pop(list);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCESS(UniHeap(ktId_AutoarrUnitypePtr,list));
|
return SUCCESS(UniHeapPtr(Autoarr_Unitype,list));
|
||||||
};
|
};
|
||||||
#define ReadList() __ReadList(shared)
|
#define ReadList() __ReadList(shared)
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ Maybe __ReadValue(DeserializeSharedData* shared, bool* readingList){
|
|||||||
case ';':
|
case ';':
|
||||||
case ',':
|
case ',':
|
||||||
if(valueStr.length!=0){
|
if(valueStr.length!=0){
|
||||||
if(value.typeId!=ktId_Null)
|
if(value.typeId!=ktid_Null)
|
||||||
safethrow_wrongchar(c,Unitype_free(value));
|
safethrow_wrongchar(c,Unitype_free(value));
|
||||||
try(ParseValue(valueStr),maybeParsed,;)
|
try(ParseValue(valueStr),maybeParsed,;)
|
||||||
value=maybeParsed.value;
|
value=maybeParsed.value;
|
||||||
@ -321,7 +321,7 @@ Maybe __deserialize(char** _text, bool _calledRecursively) {
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
list=Autoarr_create(Unitype,ARR_BC,ARR_BL);
|
list=Autoarr_create(Unitype,ARR_BC,ARR_BL);
|
||||||
Hashtable_add(dict,nameCPtr,UniHeap(ktId_AutoarrUnitypePtr,list));
|
Hashtable_add(dict,nameCPtr,UniHeapPtr(Autoarr_Unitype,list));
|
||||||
}
|
}
|
||||||
Autoarr_add(list,val.value);
|
Autoarr_add(list,val.value);
|
||||||
}
|
}
|
||||||
@ -331,7 +331,7 @@ Maybe __deserialize(char** _text, bool _calledRecursively) {
|
|||||||
|
|
||||||
END:
|
END:
|
||||||
*_text=text;
|
*_text=text;
|
||||||
return SUCCESS(UniHeap(ktId_HashtablePtr,dict));
|
return SUCCESS(UniHeapPtr(Hashtable,dict));
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe DtsodV24_deserialize(char* _text) {
|
Maybe DtsodV24_deserialize(char* _text) {
|
||||||
|
|||||||
@ -23,18 +23,18 @@ void __AppendTabs(SerializeSharedData* shared) {
|
|||||||
Maybe __AppendValue(SerializeSharedData* shared, Unitype u);
|
Maybe __AppendValue(SerializeSharedData* shared, Unitype u);
|
||||||
#define AppendValue(UNI) __AppendValue(shared, UNI)
|
#define AppendValue(UNI) __AppendValue(shared, UNI)
|
||||||
Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
|
Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
|
||||||
if(u.typeId==ktId_Int64){
|
if(u.typeId==ktid_name(int64)){
|
||||||
StringBuilder_append_int64(b,u.Int64);
|
StringBuilder_append_int64(b,u.Int64);
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktId_UInt64){
|
else if(u.typeId==ktid_name(uint64)){
|
||||||
StringBuilder_append_uint64(b,u.UInt64);
|
StringBuilder_append_uint64(b,u.UInt64);
|
||||||
addc('u');
|
addc('u');
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktId_Float64){
|
else if(u.typeId==ktid_name(float64)){
|
||||||
StringBuilder_append_float64(b,u.Float64);
|
StringBuilder_append_float64(b,u.Float64);
|
||||||
addc('f');
|
addc('f');
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktId_CharPtr){
|
else if(u.typeId==ktid_ptrName(char)){
|
||||||
addc('"');
|
addc('"');
|
||||||
char c;
|
char c;
|
||||||
while((c=*(char*)(u.VoidPtr++))){
|
while((c=*(char*)(u.VoidPtr++))){
|
||||||
@ -43,13 +43,13 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
|
|||||||
}
|
}
|
||||||
addc('"');
|
addc('"');
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktId_Bool){
|
else if(u.typeId==ktid_name(bool)){
|
||||||
StringBuilder_append_cptr(b, u.Bool ? "true" : "false");
|
StringBuilder_append_cptr(b, u.Bool ? "true" : "false");
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktId_Null){
|
else if(u.typeId==ktid_Null){
|
||||||
safethrow("Null isn't supported in DtsodV24",;);
|
safethrow("Null isn't supported in DtsodV24",;);
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktId_AutoarrUnitypePtr){
|
else if(u.typeId==ktid_ptrName(Autoarr_Unitype)){
|
||||||
if(Autoarr_length(((Autoarr_Unitype*)(u.VoidPtr)))){
|
if(Autoarr_length(((Autoarr_Unitype*)(u.VoidPtr)))){
|
||||||
addc('\n');
|
addc('\n');
|
||||||
AppendTabs();
|
AppendTabs();
|
||||||
@ -72,7 +72,7 @@ Maybe __AppendValue(SerializeSharedData* shared, Unitype u){
|
|||||||
addc(']');
|
addc(']');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(u.typeId==ktId_HashtablePtr){
|
else if(u.typeId==ktid_ptrName(Hashtable)){
|
||||||
// check hashtable is blank
|
// check hashtable is blank
|
||||||
bool hashtableNotBlank=false;
|
bool hashtableNotBlank=false;
|
||||||
Hashtable_foreach(((Hashtable*)u.VoidPtr), __, ({
|
Hashtable_foreach(((Hashtable*)u.VoidPtr), __, ({
|
||||||
@ -126,5 +126,5 @@ Maybe DtsodV24_serialize(Hashtable* dtsod){
|
|||||||
StringBuilder* sb=StringBuilder_create();
|
StringBuilder* sb=StringBuilder_create();
|
||||||
try(__serialize(sb,0,dtsod),__, StringBuilder_free(sb));
|
try(__serialize(sb,0,dtsod),__, StringBuilder_free(sb));
|
||||||
char* str=StringBuilder_build(sb).ptr;
|
char* str=StringBuilder_build(sb).ptr;
|
||||||
return SUCCESS(UniHeap(ktId_CharPtr, str));
|
return SUCCESS(UniHeapPtr(char, str));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#include "Hashtable.h"
|
#include "Hashtable.h"
|
||||||
|
|
||||||
ktId_define(Hashtable);
|
ktid_define(Hashtable);
|
||||||
ktId_define(HashtablePtr);
|
|
||||||
|
|
||||||
// amount of rows
|
// amount of rows
|
||||||
static const uint16 HT_HEIGHTS[]={17,61,257,1021,4099,16381,65521};
|
static const uint16 HT_HEIGHTS[]={17,61,257,1021,4099,16381,65521};
|
||||||
@ -96,7 +95,7 @@ Unitype Hashtable_get(Hashtable* ht, char* key){
|
|||||||
bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output){
|
bool Hashtable_try_get(Hashtable* ht, char* key, Unitype* output){
|
||||||
Unitype u=Hashtable_get(ht,key);
|
Unitype u=Hashtable_get(ht,key);
|
||||||
*output=u;
|
*output=u;
|
||||||
return u.typeId!=ktId_Null;
|
return u.typeId!=ktid_Null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hashtable_addOrSet(Hashtable* ht, char* key, Unitype u){
|
void Hashtable_addOrSet(Hashtable* ht, char* key, Unitype u){
|
||||||
|
|||||||
@ -11,8 +11,7 @@ typedef struct Hashtable{
|
|||||||
uint8 hein; // height=HT_HEIGHTS[hein]
|
uint8 hein; // height=HT_HEIGHTS[hein]
|
||||||
Autoarr(KVPair)** rows; // Autoarr[height]
|
Autoarr(KVPair)** rows; // Autoarr[height]
|
||||||
} Hashtable;
|
} Hashtable;
|
||||||
ktId_declare(Hashtable);
|
ktid_declare(Hashtable);
|
||||||
ktId_declare(HashtablePtr);
|
|
||||||
|
|
||||||
Hashtable* Hashtable_create();
|
Hashtable* Hashtable_create();
|
||||||
void Hashtable_free(Hashtable* ht);
|
void Hashtable_free(Hashtable* ht);
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
#include "KeyValuePair.h"
|
#include "KeyValuePair.h"
|
||||||
|
|
||||||
ktId_define(KVPair);
|
ktid_define(KVPair);
|
||||||
ktId_define(KVPairPtr);
|
|
||||||
|
|
||||||
Autoarr_define(KVPair)
|
Autoarr_define(KVPair)
|
||||||
ktId_define(AutoarrKVPair);
|
|
||||||
ktId_define(AutoarrKVPairPtr);
|
|
||||||
|
|
||||||
// proper way to clear a KVP
|
// proper way to clear a KVP
|
||||||
void KVPair_free(KVPair p){
|
void KVPair_free(KVPair p){
|
||||||
|
|||||||
@ -11,12 +11,9 @@ typedef struct KVPair{
|
|||||||
char* key;
|
char* key;
|
||||||
Unitype value;
|
Unitype value;
|
||||||
} KVPair;
|
} KVPair;
|
||||||
ktId_declare(KVPair);
|
ktid_declare(KVPair);
|
||||||
ktId_declare(KVPairPtr);
|
|
||||||
|
|
||||||
Autoarr_declare(KVPair)
|
Autoarr_declare(KVPair)
|
||||||
ktId_declare(AutoarrKVPair);
|
|
||||||
ktId_declare(AutoarrKVPairPtr);
|
|
||||||
|
|
||||||
// proper way to clear a KVP
|
// proper way to clear a KVP
|
||||||
void KVPair_free(KVPair p);
|
void KVPair_free(KVPair p);
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
#include "SearchTree.h"
|
#include "SearchTree.h"
|
||||||
|
|
||||||
ktId_define(STNode);
|
ktid_define(STNode);
|
||||||
ktId_define(STNodePtr);
|
|
||||||
|
|
||||||
STNode* STNode_create(){
|
STNode* STNode_create(){
|
||||||
STNode* node=malloc(sizeof(STNode));
|
STNode* node=malloc(sizeof(STNode));
|
||||||
node->branches=NULL;
|
node->branches=NULL;
|
||||||
node->value.typeId=ktId_Null;
|
node->value.typeId=ktid_Null;
|
||||||
node->value.UInt64=0;
|
node->value.UInt64=0;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,8 +11,7 @@ typedef struct SearchTreeNode{
|
|||||||
struct SearchTreeNode**** branches; // *STNode[8][8][4]
|
struct SearchTreeNode**** branches; // *STNode[8][8][4]
|
||||||
Unitype value;
|
Unitype value;
|
||||||
} STNode;
|
} STNode;
|
||||||
ktId_declare(STNode);
|
ktid_declare(STNode);
|
||||||
ktId_declare(STNodePtr);
|
|
||||||
|
|
||||||
STNode* STNode_create();
|
STNode* STNode_create();
|
||||||
void STNode_free(STNode* node);
|
void STNode_free(STNode* node);
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
#include "StringBuilder.h"
|
#include "StringBuilder.h"
|
||||||
|
|
||||||
Autoarr_define(string)
|
Autoarr_define(string)
|
||||||
ktId_define(AutoarrString);
|
|
||||||
ktId_define(AutoarrStringPtr);
|
|
||||||
|
|
||||||
ktId_define(StringBuilder);
|
ktid_define(StringBuilder);
|
||||||
ktId_define(StringBuilderPtr);
|
|
||||||
|
|
||||||
#define BL_C 32
|
#define BL_C 32
|
||||||
#define BL_L 1024
|
#define BL_L 1024
|
||||||
|
|||||||
@ -8,15 +8,12 @@ extern "C" {
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
Autoarr_declare(string)
|
Autoarr_declare(string)
|
||||||
ktId_declare(AutoarrString);
|
|
||||||
ktId_declare(AutoarrStringPtr);
|
|
||||||
|
|
||||||
typedef struct StringBuilder{
|
typedef struct StringBuilder{
|
||||||
Autoarr(string)* compl_bufs;
|
Autoarr(string)* compl_bufs;
|
||||||
Autoarr(int8)* curr_buf;
|
Autoarr(int8)* curr_buf;
|
||||||
} StringBuilder;
|
} StringBuilder;
|
||||||
ktId_declare(StringBuilder);
|
ktid_declare(StringBuilder);
|
||||||
ktId_declare(StringBuilderPtr);
|
|
||||||
|
|
||||||
StringBuilder* StringBuilder_create(void);
|
StringBuilder* StringBuilder_create(void);
|
||||||
void StringBuilder_free(StringBuilder* b);
|
void StringBuilder_free(StringBuilder* b);
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
ktId_define(string);
|
ktid_define(string);
|
||||||
ktId_define(stringPtr);
|
|
||||||
|
|
||||||
// copies str content to new char pointer value (adding '\0' at the end)
|
// copies str content to new char pointer value (adding '\0' at the end)
|
||||||
char* string_extract(string str){
|
char* string_extract(string str){
|
||||||
|
|||||||
@ -12,8 +12,7 @@ typedef struct string{
|
|||||||
char* ptr; // char pointer
|
char* ptr; // char pointer
|
||||||
uint32 length; // amount of chars in ptr value
|
uint32 length; // amount of chars in ptr value
|
||||||
} string;
|
} string;
|
||||||
ktId_declare(string);
|
ktid_declare(string);
|
||||||
ktId_declare(stringPtr);
|
|
||||||
|
|
||||||
static const string stringNull={NULL,0};
|
static const string stringNull={NULL,0};
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,8 @@ char* errname(ErrorId err){
|
|||||||
case ERR_KEYNOTFOUND: return "ERR_KEYNOTFOUND";
|
case ERR_KEYNOTFOUND: return "ERR_KEYNOTFOUND";
|
||||||
case ERR_FORMAT: return "ERR_FORMAT";
|
case ERR_FORMAT: return "ERR_FORMAT";
|
||||||
case ERR_UNEXPECTEDVAL: return "ERR_UNEXPECTEDVAL";
|
case ERR_UNEXPECTEDVAL: return "ERR_UNEXPECTEDVAL";
|
||||||
|
case ERR_IO: return "ERR_IO";
|
||||||
|
case ERR_IO_EOF: return "ERR_IO_EOF";
|
||||||
default: return "UNKNOWN_ERROR";
|
default: return "UNKNOWN_ERROR";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,8 @@ typedef enum ErrorId {
|
|||||||
SUCCESS, // not an error
|
SUCCESS, // not an error
|
||||||
ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX,
|
ERR_MAXLENGTH, ERR_WRONGTYPE, ERR_WRONGINDEX,
|
||||||
ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR,
|
ERR_NOTIMPLEMENTED, ERR_NULLPTR, ERR_ENDOFSTR,
|
||||||
ERR_KEYNOTFOUND, ERR_FORMAT, ERR_UNEXPECTEDVAL
|
ERR_KEYNOTFOUND, ERR_FORMAT, ERR_UNEXPECTEDVAL,
|
||||||
|
ERR_IO, ERR_IO_EOF
|
||||||
} ErrorId;
|
} ErrorId;
|
||||||
|
|
||||||
char* errname(ErrorId err);
|
char* errname(ErrorId err);
|
||||||
@ -34,7 +35,7 @@ void printMaybe(Maybe e);
|
|||||||
|
|
||||||
#define SUCCESS(REZLT) (Maybe){.errmsg=NULL, .value=REZLT}
|
#define SUCCESS(REZLT) (Maybe){.errmsg=NULL, .value=REZLT}
|
||||||
|
|
||||||
#define __RETURN_EXCEPTION(ERRMSG) return (Maybe){.errmsg=ERRMSG, .value=UniNull}
|
#define __RETURN_EXCEPTION(ERRMSG) return (Maybe){.value=UniNull, .errmsg=ERRMSG}
|
||||||
|
|
||||||
#define __EXIT(ERRMSG) ({ kprintf("\e[91m%s\e[0m \n", ERRMSG); free(ERRMSG); exit(128); })
|
#define __EXIT(ERRMSG) ({ kprintf("\e[91m%s\e[0m \n", ERRMSG); free(ERRMSG); exit(128); })
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ extern "C" {
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -23,6 +22,15 @@ typedef int64_t int64;
|
|||||||
typedef uint64_t uint64;
|
typedef uint64_t uint64;
|
||||||
typedef float float32;
|
typedef float float32;
|
||||||
typedef double float64;
|
typedef double float64;
|
||||||
|
// Usually bool from stdbool.h is defined as macro,
|
||||||
|
// so in other macros like ktid_##TYPE it will be replaced by _Bool.
|
||||||
|
// ktid__Bool will be created instead of ktid_bool
|
||||||
|
// In C++ bool is a keyword, so there is no need to redefine it.
|
||||||
|
#if !__cplusplus
|
||||||
|
typedef uint8 bool;
|
||||||
|
#define true 1
|
||||||
|
#define false 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#define dbg(N) kprintf("\e[95m%d\n",N)
|
#define dbg(N) kprintf("\e[95m%d\n",N)
|
||||||
|
|
||||||
|
|||||||
@ -4,18 +4,16 @@ For using some kerep capabilities, such as generic structs, unitype, and kprint,
|
|||||||
|
|
||||||
## type id
|
## type id
|
||||||
|
|
||||||
Every registered type has its own id (`ktId`), which should be declared in header file and defined in source file.
|
Every registered type has its own id (`ktid`), which should be declared in header file and defined in source file.
|
||||||
Example:
|
Example:
|
||||||
```c
|
```c
|
||||||
//someStruct.h
|
//someStruct.h
|
||||||
typedef struct { } someStruct;
|
typedef struct { } someStruct;
|
||||||
ktId_declare(someStruct);
|
ktid_declare(someStruct);
|
||||||
ktId_declare(someStructPtr); // pointer to type is another type
|
|
||||||
```
|
```
|
||||||
```c
|
```c
|
||||||
//someStruct.c
|
//someStruct.c
|
||||||
ktId_define(someStruct);
|
ktid_define(someStruct);
|
||||||
ktId_define(someStructPtr);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## type descriptors
|
## type descriptors
|
||||||
|
|||||||
@ -3,14 +3,18 @@
|
|||||||
#include "../../kprint/kprint_format.h"
|
#include "../../kprint/kprint_format.h"
|
||||||
|
|
||||||
char* __toString_char(void* c, uint32 fmt) {
|
char* __toString_char(void* c, uint32 fmt) {
|
||||||
char* cc=malloc(2);
|
//*c=char
|
||||||
cc[0]=*(char*)c;
|
if(kprint_format_dataFormat(fmt)==kprint_fmtChar){
|
||||||
cc[1]=0;
|
char* cc=malloc(2);
|
||||||
return cc;
|
cc[0]=*(char*)c;
|
||||||
}
|
cc[1]=0;
|
||||||
|
return cc;
|
||||||
char* __toString_charPtr(void* c, uint32 fmt){
|
}
|
||||||
return cptr_copy(*(char**)c);
|
// *c=cstring
|
||||||
|
else if(kprint_format_dataFormat(fmt)==kprint_fmtString){
|
||||||
|
return cptr_copy(*(char**)c);
|
||||||
|
}
|
||||||
|
else throw(ERR_FORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* __toString_bool(void* c, uint32 fmt) {
|
char* __toString_bool(void* c, uint32 fmt) {
|
||||||
|
|||||||
@ -7,8 +7,8 @@ extern "C" {
|
|||||||
#include "../errors.h"
|
#include "../errors.h"
|
||||||
|
|
||||||
// functions for base types
|
// functions for base types
|
||||||
|
// has different output for fmtChar and fmtString
|
||||||
char* __toString_char(void* c, uint32 fmt);
|
char* __toString_char(void* c, uint32 fmt);
|
||||||
char* __toString_charPtr(void* c, uint32 fmt);
|
|
||||||
char* __toString_bool(void* c, uint32 fmt);
|
char* __toString_bool(void* c, uint32 fmt);
|
||||||
|
|
||||||
char* toString_int(int64 n);
|
char* toString_int(int64 n);
|
||||||
|
|||||||
@ -8,127 +8,80 @@
|
|||||||
|
|
||||||
void ktDescriptors_initKerepTypes(){
|
void ktDescriptors_initKerepTypes(){
|
||||||
// null
|
// null
|
||||||
kt_register(NULL, ktId_Null, NULL, NULL);
|
__kt_register("Null", sizeof(NULL), NULL, NULL);
|
||||||
|
ktid_Null=ktid_last;
|
||||||
// base types
|
// base types
|
||||||
kt_register(char, ktId_Char, NULL, __toString_char);
|
kt_register(char, NULL, __toString_char);
|
||||||
kt_register(bool, ktId_Bool, NULL, __toString_bool);
|
kt_register(bool, NULL, __toString_bool);
|
||||||
kt_register(float32, ktId_Float32, NULL, __toString_float32);
|
kt_register(float32, NULL, __toString_float32);
|
||||||
kt_register(float64, ktId_Float64, NULL, __toString_float64);
|
kt_register(float64, NULL, __toString_float64);
|
||||||
kt_register(int8, ktId_Int8, NULL, __toString_int8);
|
kt_register(int8, NULL, __toString_int8);
|
||||||
kt_register(uint8, ktId_UInt8, NULL, __toString_uint8);
|
kt_register(uint8, NULL, __toString_uint8);
|
||||||
kt_register(int16, ktId_Int16, NULL, __toString_int16);
|
kt_register(int16, NULL, __toString_int16);
|
||||||
kt_register(uint16, ktId_UInt16, NULL, __toString_uint16);
|
kt_register(uint16, NULL, __toString_uint16);
|
||||||
kt_register(int32, ktId_Int32, NULL, __toString_int32);
|
kt_register(int32, NULL, __toString_int32);
|
||||||
kt_register(uint32, ktId_UInt32, NULL, __toString_uint32);
|
kt_register(uint32, NULL, __toString_uint32);
|
||||||
kt_register(int64, ktId_Int64, NULL, __toString_int64);
|
kt_register(int64, NULL, __toString_int64);
|
||||||
kt_register(uint64, ktId_UInt64, NULL, __toString_uint64);
|
kt_register(uint64, NULL, __toString_uint64);
|
||||||
// base type pointers
|
|
||||||
kt_register(char*, ktId_CharPtr, NULL, __toString_charPtr);
|
|
||||||
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
|
// ktDescriptor
|
||||||
kt_register(ktDescriptor, ktId_ktDescriptor, NULL, NULL);
|
kt_register(ktDescriptor, NULL, NULL);
|
||||||
kt_register(ktDescriptor*, ktId_ktDescriptorPtr, NULL, NULL);
|
|
||||||
|
|
||||||
|
|
||||||
// base type arrays
|
// base type arrays
|
||||||
kt_register(Array_char, ktId_ArrayChar, (freeMembers_t)Array_char_freeValues, NULL);
|
kt_register(Array_char, (freeMembers_t)Array_char_freeValues, NULL);
|
||||||
kt_register(Array_bool, ktId_ArrayBool, (freeMembers_t)Array_bool_freeValues, NULL);
|
kt_register(Array_bool, (freeMembers_t)Array_bool_freeValues, NULL);
|
||||||
kt_register(Array_float32, ktId_ArrayFloat32, (freeMembers_t)Array_float32_freeValues, NULL);
|
kt_register(Array_float32, (freeMembers_t)Array_float32_freeValues, NULL);
|
||||||
kt_register(Array_float64, ktId_ArrayFloat64, (freeMembers_t)Array_float64_freeValues, NULL);
|
kt_register(Array_float64, (freeMembers_t)Array_float64_freeValues, NULL);
|
||||||
kt_register(Array_int8, ktId_ArrayInt8, (freeMembers_t)Array_int8_freeValues, NULL);
|
kt_register(Array_int8, (freeMembers_t)Array_int8_freeValues, NULL);
|
||||||
kt_register(Array_uint8, ktId_ArrayUInt8, (freeMembers_t)Array_uint8_freeValues, NULL);
|
kt_register(Array_uint8, (freeMembers_t)Array_uint8_freeValues, NULL);
|
||||||
kt_register(Array_int16, ktId_ArrayInt16, (freeMembers_t)Array_int16_freeValues, NULL);
|
kt_register(Array_int16, (freeMembers_t)Array_int16_freeValues, NULL);
|
||||||
kt_register(Array_uint16, ktId_ArrayUInt16, (freeMembers_t)Array_uint16_freeValues, NULL);
|
kt_register(Array_uint16, (freeMembers_t)Array_uint16_freeValues, NULL);
|
||||||
kt_register(Array_int32, ktId_ArrayInt32, (freeMembers_t)Array_int32_freeValues, NULL);
|
kt_register(Array_int32, (freeMembers_t)Array_int32_freeValues, NULL);
|
||||||
kt_register(Array_uint32, ktId_ArrayUInt32, (freeMembers_t)Array_uint32_freeValues, NULL);
|
kt_register(Array_uint32, (freeMembers_t)Array_uint32_freeValues, NULL);
|
||||||
kt_register(Array_int64, ktId_ArrayInt64, (freeMembers_t)Array_int64_freeValues, NULL);
|
kt_register(Array_int64, (freeMembers_t)Array_int64_freeValues, NULL);
|
||||||
kt_register(Array_uint64, ktId_ArrayUInt64, (freeMembers_t)Array_uint64_freeValues, NULL);
|
kt_register(Array_uint64, (freeMembers_t)Array_uint64_freeValues, NULL);
|
||||||
// base type array pointers
|
|
||||||
kt_register(Array_char*, ktId_ArrayCharPtr, (freeMembers_t)Array_char_freeValues, NULL);
|
|
||||||
kt_register(Array_bool*, ktId_ArrayBoolPtr, (freeMembers_t)Array_bool_freeValues, NULL);
|
|
||||||
kt_register(Array_float32*, ktId_ArrayFloat32Ptr, (freeMembers_t)Array_float32_freeValues, NULL);
|
|
||||||
kt_register(Array_float64*, ktId_ArrayFloat64Ptr, (freeMembers_t)Array_float64_freeValues, NULL);
|
|
||||||
kt_register(Array_int8*, ktId_ArrayInt8Ptr, (freeMembers_t)Array_int8_freeValues, NULL);
|
|
||||||
kt_register(Array_uint8*, ktId_ArrayUInt8Ptr, (freeMembers_t)Array_uint8_freeValues, NULL);
|
|
||||||
kt_register(Array_int16*, ktId_ArrayInt16Ptr, (freeMembers_t)Array_int16_freeValues, NULL);
|
|
||||||
kt_register(Array_uint16*, ktId_ArrayUInt16Ptr, (freeMembers_t)Array_uint16_freeValues, NULL);
|
|
||||||
kt_register(Array_int32*, ktId_ArrayInt32Ptr, (freeMembers_t)Array_int32_freeValues, NULL);
|
|
||||||
kt_register(Array_uint32*, ktId_ArrayUInt32Ptr, (freeMembers_t)Array_uint32_freeValues, NULL);
|
|
||||||
kt_register(Array_int64*, ktId_ArrayInt64Ptr, (freeMembers_t)Array_int64_freeValues, NULL);
|
|
||||||
kt_register(Array_uint64*, ktId_ArrayUInt64Ptr, (freeMembers_t)Array_uint64_freeValues, NULL);
|
|
||||||
|
|
||||||
// base type autoarrs
|
// base type autoarrs
|
||||||
kt_register(Autoarr_char, ktId_AutoarrChar, ____Autoarr_free_char, NULL);
|
kt_register(Autoarr_char, ____Autoarr_free_char, NULL);
|
||||||
kt_register(Autoarr_bool, ktId_AutoarrBool, ____Autoarr_free_bool, NULL);
|
kt_register(Autoarr_bool, ____Autoarr_free_bool, NULL);
|
||||||
kt_register(Autoarr_float32, ktId_AutoarrFloat32, ____Autoarr_free_float32, NULL);
|
kt_register(Autoarr_float32, ____Autoarr_free_float32, NULL);
|
||||||
kt_register(Autoarr_float64, ktId_AutoarrFloat64, ____Autoarr_free_float64, NULL);
|
kt_register(Autoarr_float64, ____Autoarr_free_float64, NULL);
|
||||||
kt_register(Autoarr_int8, ktId_AutoarrInt8, ____Autoarr_free_int8, NULL);
|
kt_register(Autoarr_int8, ____Autoarr_free_int8, NULL);
|
||||||
kt_register(Autoarr_uint8, ktId_AutoarrUInt8, ____Autoarr_free_uint8, NULL);
|
kt_register(Autoarr_uint8, ____Autoarr_free_uint8, NULL);
|
||||||
kt_register(Autoarr_int16, ktId_AutoarrInt16, ____Autoarr_free_int16, NULL);
|
kt_register(Autoarr_int16, ____Autoarr_free_int16, NULL);
|
||||||
kt_register(Autoarr_uint16, ktId_AutoarrUInt16, ____Autoarr_free_uint16, NULL);
|
kt_register(Autoarr_uint16, ____Autoarr_free_uint16, NULL);
|
||||||
kt_register(Autoarr_int32, ktId_AutoarrInt32, ____Autoarr_free_int32, NULL);
|
kt_register(Autoarr_int32, ____Autoarr_free_int32, NULL);
|
||||||
kt_register(Autoarr_uint32, ktId_AutoarrUInt32, ____Autoarr_free_uint32, NULL);
|
kt_register(Autoarr_uint32, ____Autoarr_free_uint32, NULL);
|
||||||
kt_register(Autoarr_int64, ktId_AutoarrInt64, ____Autoarr_free_int64, NULL);
|
kt_register(Autoarr_int64, ____Autoarr_free_int64, NULL);
|
||||||
kt_register(Autoarr_uint64, ktId_AutoarrUInt64, ____Autoarr_free_uint64, NULL);
|
kt_register(Autoarr_uint64, ____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
|
// Unitype
|
||||||
kt_register(Unitype, ktId_Unitype, __UnitypePtr_free, NULL);
|
kt_register(Unitype, __UnitypePtr_free, NULL);
|
||||||
kt_register(Unitype*, ktId_UnitypePtr, __UnitypePtr_free, NULL);
|
kt_register(Array_Unitype, (freeMembers_t)Array_Unitype_freeValues, NULL);
|
||||||
kt_register(Autoarr_Unitype, ktId_AutoarrUnitype, ____Autoarr_free_Unitype_, NULL);
|
kt_register(Autoarr_Unitype, ____Autoarr_free_Unitype_, NULL);
|
||||||
kt_register(Autoarr_Unitype*, ktId_AutoarrUnitypePtr, ____Autoarr_free_Unitype_, NULL);
|
|
||||||
// replacing autogenerated freear() function to custom
|
// replacing autogenerated freear() function to custom
|
||||||
Autoarr_Unitype* _uar=Autoarr_create(Unitype, 1, 1);
|
Autoarr_Unitype* _uar=Autoarr_create(Unitype, 1, 1);
|
||||||
_uar->functions->freear=__Autoarr_free_Unitype_;
|
_uar->functions->freear=__Autoarr_free_Unitype_;
|
||||||
Autoarr_free(_uar, true);
|
Autoarr_free(_uar, true);
|
||||||
|
|
||||||
// SearchTreeNode
|
// SearchTreeNode
|
||||||
kt_register(STNode, ktId_STNode, __STNode_free, NULL);
|
kt_register(STNode, __STNode_free, NULL);
|
||||||
kt_register(STNode*, ktId_STNodePtr, __STNode_free, NULL);
|
|
||||||
|
|
||||||
// KeyValuePair
|
// KeyValuePair
|
||||||
kt_register(KVPair, ktId_KVPair, __KVPair_free, NULL);
|
kt_register(KVPair, __KVPair_free, NULL);
|
||||||
kt_register(KVPair*, ktId_KVPairPtr, __KVPair_free, NULL);
|
kt_register(Autoarr_KVPair, ____Autoarr_free_KVPair_, 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
|
// replacing autogenerated freear() function to custom
|
||||||
Autoarr_KVPair* _kvpar=Autoarr_create(KVPair, 1, 1);
|
Autoarr_KVPair* _kvpar=Autoarr_create(KVPair, 1, 1);
|
||||||
_kvpar->functions->freear=__Autoarr_free_KVPair_;
|
_kvpar->functions->freear=__Autoarr_free_KVPair_;
|
||||||
Autoarr_free(_kvpar, true);
|
Autoarr_free(_kvpar, true);
|
||||||
|
|
||||||
// Hashtable
|
// Hashtable
|
||||||
kt_register(Hashtable, ktId_Hashtable, __Hashtable_free, NULL);
|
kt_register(Hashtable, __Hashtable_free, NULL);
|
||||||
kt_register(Hashtable*, ktId_HashtablePtr, __Hashtable_free, NULL);
|
|
||||||
|
|
||||||
// string
|
// string
|
||||||
kt_register(string, ktId_string, NULL, NULL);
|
kt_register(string, NULL, NULL);
|
||||||
kt_register(string*, ktId_stringPtr, NULL, NULL);
|
kt_register(string, ____Autoarr_free_string, NULL);
|
||||||
kt_register(string, ktId_AutoarrString, ____Autoarr_free_string, NULL);
|
|
||||||
kt_register(string*, ktId_AutoarrStringPtr, ____Autoarr_free_string, NULL);
|
|
||||||
// StringBuilder
|
// StringBuilder
|
||||||
kt_register(StringBuilder, ktId_StringBuilder, __StringBuilder_free, NULL);
|
kt_register(StringBuilder, __StringBuilder_free, NULL);
|
||||||
kt_register(StringBuilder*, ktId_StringBuilderPtr, __StringBuilder_free, NULL);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,13 +5,13 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../std.h"
|
#include "../std.h"
|
||||||
#include "ktId.h"
|
#include "ktid.h"
|
||||||
|
|
||||||
typedef void (*freeMembers_t)(void*);
|
typedef void (*freeMembers_t)(void*);
|
||||||
typedef char* (*toString_t)(void* obj, uint32 fmt);
|
typedef char* (*toString_t)(void* obj, uint32 fmt);
|
||||||
typedef struct ktDescriptor{
|
typedef struct ktDescriptor{
|
||||||
char* name;
|
char* name;
|
||||||
ktId id;
|
ktid id;
|
||||||
uint16 size;
|
uint16 size;
|
||||||
freeMembers_t freeMembers; // NULL or function which frees all struct members
|
freeMembers_t freeMembers; // NULL or function which frees all struct members
|
||||||
toString_t toString; // NULL or function which generates string representaion of object
|
toString_t toString; // NULL or function which generates string representaion of object
|
||||||
|
|||||||
@ -5,12 +5,18 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../std.h"
|
#include "../std.h"
|
||||||
typedef uint16 ktId;
|
typedef uint16 ktid;
|
||||||
|
|
||||||
#define ktId_declare(TYPE_NAME)\
|
#define ktid_name(TYPE) ktid_##TYPE
|
||||||
extern ktId ktId_##TYPE_NAME
|
#define ktid_ptrName(TYPE) ktid_##TYPE##_Ptr
|
||||||
#define ktId_define(TYPE_NAME)\
|
|
||||||
ktId ktId_##TYPE_NAME=-1
|
#define ktid_declare(TYPE)\
|
||||||
|
extern ktid ktid_##TYPE;\
|
||||||
|
extern ktid ktid_##TYPE##_Ptr;
|
||||||
|
|
||||||
|
#define ktid_define(TYPE)\
|
||||||
|
ktid ktid_##TYPE=-1;\
|
||||||
|
ktid ktid_##TYPE##_Ptr=-1;
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,42 +3,28 @@
|
|||||||
Autoarr_declare(ktDescriptor)
|
Autoarr_declare(ktDescriptor)
|
||||||
Autoarr_define(ktDescriptor)
|
Autoarr_define(ktDescriptor)
|
||||||
|
|
||||||
ktId_define(Null);
|
ktid ktid_Null=-1;
|
||||||
|
|
||||||
ktId_define(Char);
|
ktid_define(char);
|
||||||
ktId_define(Bool);
|
ktid_define(bool);
|
||||||
ktId_define(Float32);
|
ktid_define(float32);
|
||||||
ktId_define(Float64);
|
ktid_define(float64);
|
||||||
ktId_define(Int8);
|
ktid_define(int8);
|
||||||
ktId_define(UInt8);
|
ktid_define(uint8);
|
||||||
ktId_define(Int16);
|
ktid_define(int16);
|
||||||
ktId_define(UInt16);
|
ktid_define(uint16);
|
||||||
ktId_define(Int32);
|
ktid_define(int32);
|
||||||
ktId_define(UInt32);
|
ktid_define(uint32);
|
||||||
ktId_define(Int64);
|
ktid_define(int64);
|
||||||
ktId_define(UInt64);
|
ktid_define(uint64);
|
||||||
|
|
||||||
ktId_define(CharPtr);
|
ktid_define(ktDescriptor);
|
||||||
ktId_define(BoolPtr);
|
|
||||||
ktId_define(Float32Ptr);
|
|
||||||
ktId_define(Float64Ptr);
|
|
||||||
ktId_define(Int8Ptr);
|
|
||||||
ktId_define(UInt8Ptr);
|
|
||||||
ktId_define(Int16Ptr);
|
|
||||||
ktId_define(UInt16Ptr);
|
|
||||||
ktId_define(Int32Ptr);
|
|
||||||
ktId_define(UInt32Ptr);
|
|
||||||
ktId_define(Int64Ptr);
|
|
||||||
ktId_define(UInt64Ptr);
|
|
||||||
|
|
||||||
ktId_define(ktDescriptor);
|
|
||||||
ktId_define(ktDescriptorPtr);
|
|
||||||
|
|
||||||
// type descriptors are stored here during initialization
|
// type descriptors are stored here during initialization
|
||||||
Autoarr(ktDescriptor)* __ktDescriptors=NULL;
|
Autoarr(ktDescriptor)* __ktDescriptors=NULL;
|
||||||
// here type descriptors are stored when initialization is complited
|
// here type descriptors are stored when initialization is complited
|
||||||
ktDescriptor* typeDescriptors=NULL;
|
ktDescriptor* typeDescriptors=NULL;
|
||||||
ktId ktId_last=-1;
|
ktid ktid_last=-1;
|
||||||
|
|
||||||
typedef enum{
|
typedef enum{
|
||||||
NotInitialized, Initializing, Initialized
|
NotInitialized, Initializing, Initialized
|
||||||
@ -55,22 +41,22 @@ void ktDescriptors_endInit(){
|
|||||||
typeDescriptors=Autoarr_toArray(__ktDescriptors);
|
typeDescriptors=Autoarr_toArray(__ktDescriptors);
|
||||||
Autoarr_free(__ktDescriptors,true);
|
Autoarr_free(__ktDescriptors,true);
|
||||||
if(typeDescriptors==NULL) throw(ERR_NULLPTR);
|
if(typeDescriptors==NULL) throw(ERR_NULLPTR);
|
||||||
kprintf("\e[92minitialized %u type descriptors\n", ktId_last);
|
kprintf("\e[92minitialized %u type descriptors\n", ktid_last);
|
||||||
}
|
}
|
||||||
|
|
||||||
void __kt_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, uint32)){
|
void __kt_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, uint32)){
|
||||||
ktDescriptor typeDesc={
|
ktDescriptor typeDesc={
|
||||||
.name=name,
|
.name=name,
|
||||||
.size=size,
|
.size=size,
|
||||||
.id=++ktId_last,
|
.id=++ktid_last,
|
||||||
.freeMembers=freeMembers,
|
.freeMembers=freeMembers,
|
||||||
.toString=toString
|
.toString=toString
|
||||||
};
|
};
|
||||||
Autoarr_add(__ktDescriptors, typeDesc);
|
Autoarr_add(__ktDescriptors, typeDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
ktDescriptor ktDescriptor_get(ktId id){
|
ktDescriptor ktDescriptor_get(ktid id){
|
||||||
if(id>ktId_last) {
|
if(id>ktid_last) {
|
||||||
kprintf("\ntype id: %u\n",id);
|
kprintf("\ntype id: %u\n",id);
|
||||||
throw("invalid type id");
|
throw("invalid type id");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,55 +5,43 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../std.h"
|
#include "../std.h"
|
||||||
#include "ktId.h"
|
#include "ktid.h"
|
||||||
#include "ktDescriptor.h"
|
#include "ktDescriptor.h"
|
||||||
|
|
||||||
extern ktId ktId_last;
|
extern ktid ktid_last;
|
||||||
void __kt_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, uint32));
|
void __kt_register(char* name, int16 size, void (*freeMembers)(void*), char* (*toString)(void*, uint32));
|
||||||
|
|
||||||
#define kt_register(TYPE, ID_VAR_NAME, FREE_MEMBERS_FUNC, TO_STRING_FUNC)\
|
#define kt_register(TYPE, FREE_MEMBERS_FUNC, TO_STRING_FUNC)\
|
||||||
__kt_register(#ID_VAR_NAME, sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\
|
__kt_register(#TYPE, sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\
|
||||||
ID_VAR_NAME=ktId_last;
|
ktid_##TYPE=ktid_last;\
|
||||||
|
__kt_register(#TYPE "*", sizeof(TYPE), FREE_MEMBERS_FUNC, TO_STRING_FUNC);\
|
||||||
|
ktid_##TYPE##_Ptr=ktid_last;
|
||||||
|
|
||||||
void ktDescriptors_beginInit();
|
void ktDescriptors_beginInit();
|
||||||
void ktDescriptors_endInit();
|
void ktDescriptors_endInit();
|
||||||
|
|
||||||
/// @param id id of registered type
|
/// @param id id of registered type
|
||||||
ktDescriptor ktDescriptor_get(ktId id);
|
ktDescriptor ktDescriptor_get(ktid id);
|
||||||
|
|
||||||
// call it to free heap-allocated ktDescriptors array
|
// call it to free heap-allocated ktDescriptors array
|
||||||
void ktDescriptors_free();
|
void ktDescriptors_free();
|
||||||
|
|
||||||
ktId_declare(Null);
|
extern ktid ktid_Null;
|
||||||
|
|
||||||
ktId_declare(Char);
|
ktid_declare(char);
|
||||||
ktId_declare(Bool);
|
ktid_declare(bool);
|
||||||
ktId_declare(Float32);
|
ktid_declare(float32);
|
||||||
ktId_declare(Float64);
|
ktid_declare(float64);
|
||||||
ktId_declare(Int8);
|
ktid_declare(int8);
|
||||||
ktId_declare(UInt8);
|
ktid_declare(uint8);
|
||||||
ktId_declare(Int16);
|
ktid_declare(int16);
|
||||||
ktId_declare(UInt16);
|
ktid_declare(uint16);
|
||||||
ktId_declare(Int32);
|
ktid_declare(int32);
|
||||||
ktId_declare(UInt32);
|
ktid_declare(uint32);
|
||||||
ktId_declare(Int64);
|
ktid_declare(int64);
|
||||||
ktId_declare(UInt64);
|
ktid_declare(uint64);
|
||||||
|
|
||||||
ktId_declare(CharPtr);
|
ktid_declare(ktDescriptor);
|
||||||
ktId_declare(BoolPtr);
|
|
||||||
ktId_declare(Float32Ptr);
|
|
||||||
ktId_declare(Float64Ptr);
|
|
||||||
ktId_declare(Int8Ptr);
|
|
||||||
ktId_declare(UInt8Ptr);
|
|
||||||
ktId_declare(Int16Ptr);
|
|
||||||
ktId_declare(UInt16Ptr);
|
|
||||||
ktId_declare(Int32Ptr);
|
|
||||||
ktId_declare(UInt32Ptr);
|
|
||||||
ktId_declare(Int64Ptr);
|
|
||||||
ktId_declare(UInt64Ptr);
|
|
||||||
|
|
||||||
ktId_declare(ktDescriptor);
|
|
||||||
ktId_declare(ktDescriptorPtr);
|
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#include "init.h"
|
#include "init.h"
|
||||||
#include "ktId.h"
|
#include "ktid.h"
|
||||||
#include "ktDescriptor.h"
|
#include "ktDescriptor.h"
|
||||||
#include "kt_functions.h"
|
#include "kt_functions.h"
|
||||||
#include "unitype.h"
|
#include "unitype.h"
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#include "../base.h"
|
#include "../base.h"
|
||||||
|
|
||||||
ktId_define(Unitype);
|
ktid_define(Unitype);
|
||||||
ktId_define(UnitypePtr);
|
|
||||||
|
|
||||||
void Unitype_free(Unitype u){
|
void Unitype_free(Unitype u){
|
||||||
ktDescriptor type=ktDescriptor_get(u.typeId);
|
ktDescriptor type=ktDescriptor_get(u.typeId);
|
||||||
@ -29,15 +28,15 @@ char* toString_Unitype(void* _u, uint32 fmt){
|
|||||||
char* sprintuni(Unitype v){
|
char* sprintuni(Unitype v){
|
||||||
char* buf=malloc(BUFSIZE);
|
char* buf=malloc(BUFSIZE);
|
||||||
ktDescriptor type=ktDescriptor_get(v.typeId);
|
ktDescriptor type=ktDescriptor_get(v.typeId);
|
||||||
if(v.typeId==ktId_Null)
|
if(v.typeId==ktid_Null)
|
||||||
sprintf_s(buf, BUFSIZE, "{Null}");
|
sprintf_s(buf, BUFSIZE, "{Null}");
|
||||||
else if(v.typeId==ktId_Float64)
|
else if(v.typeId==ktid_name(float64))
|
||||||
sprintf_s(buf, BUFSIZE, "{%s : %lf}", type.name,v.Float64);
|
sprintf_s(buf, BUFSIZE, "{%s : %lf}", type.name,v.Float64);
|
||||||
else if(v.typeId==ktId_Bool || v.typeId==ktId_UInt64)
|
else if(v.typeId==ktid_name(bool) || v.typeId==ktid_name(uint64))
|
||||||
sprintf_s(buf, BUFSIZE, "{%s : " IFWIN("%llu", "%lu") "}", type.name,v.UInt64);
|
sprintf_s(buf, BUFSIZE, "{%s : " IFWIN("%llu", "%lu") "}", type.name,v.UInt64);
|
||||||
else if(v.typeId==ktId_Int64)
|
else if(v.typeId==ktid_name(int64))
|
||||||
sprintf_s(buf, BUFSIZE, "{%s : " IFWIN("%lld", "%ld") "}", type.name,v.Int64);
|
sprintf_s(buf, BUFSIZE, "{%s : " IFWIN("%lld", "%ld") "}", type.name,v.Int64);
|
||||||
else if(v.typeId==ktId_CharPtr){
|
else if(v.typeId==ktid_ptrName(char)){
|
||||||
size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2;
|
size_t newBUFSIZE=cptr_length(v.VoidPtr) + BUFSIZE/2;
|
||||||
buf=realloc(buf, newBUFSIZE);
|
buf=realloc(buf, newBUFSIZE);
|
||||||
sprintf_s(buf, BUFSIZE, "{%s : \"%s\"}", type.name,(char*)v.VoidPtr);
|
sprintf_s(buf, BUFSIZE, "{%s : \"%s\"}", type.name,(char*)v.VoidPtr);
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ktId.h"
|
#include "ktid.h"
|
||||||
|
|
||||||
typedef struct Unitype{
|
typedef struct Unitype{
|
||||||
union {
|
union {
|
||||||
@ -15,27 +15,26 @@ typedef struct Unitype{
|
|||||||
void* VoidPtr;
|
void* VoidPtr;
|
||||||
char Bytes[8];
|
char Bytes[8];
|
||||||
};
|
};
|
||||||
ktId typeId;
|
ktid typeId;
|
||||||
bool allocatedInHeap; // should Unitype_free call free() to VoidPtr*
|
bool allocatedInHeap; // should Unitype_free call free() to VoidPtr*
|
||||||
} Unitype;
|
} Unitype;
|
||||||
ktId_declare(Unitype);
|
ktid_declare(Unitype);
|
||||||
ktId_declare(UnitypePtr);
|
|
||||||
|
|
||||||
|
|
||||||
#define __UniDef(TYPE, VAL) (Unitype){\
|
#define __UniDef(FIELD, TYPE, VAL) (Unitype){\
|
||||||
.TYPE=VAL, .typeId=ktId_##TYPE, .allocatedInHeap=false}
|
.FIELD=VAL, .typeId=ktid_name(TYPE), .allocatedInHeap=false}
|
||||||
|
|
||||||
#define UniInt64(VAL) __UniDef(Int64, VAL)
|
#define UniInt64(VAL) __UniDef(Int64, int64, VAL)
|
||||||
#define UniUInt64(VAL) __UniDef(UInt64, VAL)
|
#define UniUInt64(VAL) __UniDef(UInt64, uint64, VAL)
|
||||||
#define UniFloat64(VAL) __UniDef(Float64, VAL)
|
#define UniFloat64(VAL) __UniDef(Float64, float64, VAL)
|
||||||
#define UniBool(VAL) __UniDef(Bool, VAL)
|
#define UniBool(VAL) __UniDef(Bool, bool, VAL)
|
||||||
|
|
||||||
#define UniStack(ID_VAR_NAME, VAL) (Unitype){\
|
#define UniStackPtr(TYPE, VAL) (Unitype){\
|
||||||
.VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=false}
|
.VoidPtr=VAL, .typeId=ktid_ptrName(TYPE), .allocatedInHeap=false}
|
||||||
#define UniHeap(ID_VAR_NAME, VAL) (Unitype){\
|
#define UniHeapPtr(TYPE, VAL) (Unitype){\
|
||||||
.VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=true}
|
.VoidPtr=VAL, .typeId=ktid_ptrName(TYPE), .allocatedInHeap=true}
|
||||||
|
|
||||||
#define UniNull UniStack(ktId_Null, NULL)
|
#define UniNull (Unitype){.Int64=0, .typeId=ktid_Null, .allocatedInHeap=false}
|
||||||
#define UniTrue UniBool(true)
|
#define UniTrue UniBool(true)
|
||||||
#define UniFalse UniBool(false)
|
#define UniFalse UniBool(false)
|
||||||
|
|
||||||
|
|||||||
@ -13,11 +13,11 @@ I don't really like printf function (and its variants), so i made safer and more
|
|||||||
## how to use it:
|
## how to use it:
|
||||||
+ **format construction:**
|
+ **format construction:**
|
||||||
```
|
```
|
||||||
kprint_format fmt= kprint_fgColor | kprint_bgColor | kprint_fdataFmt | flags | ktId;
|
kprint_format fmt= kprint_fgColor | kprint_bgColor | kprint_fdataFmt | flags | ktid;
|
||||||
```
|
```
|
||||||
[more about `kprint_format`](kprint_format.md)
|
[more about `kprint_format`](kprint_format.md)
|
||||||
+ fgColor and bgColor can be set to change console output color
|
+ fgColor and bgColor can be set to change console output color
|
||||||
+ you should set dataFormat for `int`/`uint`/`float`/`char*` arguments and ktId 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
|
+ flags can be set to modify TypeDescriptor.toString() behavior
|
||||||
+ don't forget to set TypeDescriptor.toString when registering type, or kprint will crash
|
+ don't forget to set TypeDescriptor.toString when registering type, or kprint will crash
|
||||||
|
|
||||||
@ -31,6 +31,6 @@ I don't really like printf function (and its variants), so i made safer and more
|
|||||||
should be sent as pointers
|
should be sent as pointers
|
||||||
```
|
```
|
||||||
Maybe m=MaybeNull;
|
Maybe m=MaybeNull;
|
||||||
kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | ktId_MaybePtr, &m);
|
kprint(kprint_fgBlue | kprint_fmtString, "Maybe: ", kprint_fgGreen | ktid_MaybePtr, &m);
|
||||||
```
|
```
|
||||||
output: <span style="color:blue">Maybe:</span> <span style="color:lightgreen">{value={0, ktId_Null}}</span>
|
output: <span style="color:blue">Maybe:</span> <span style="color:lightgreen">{value={0, ktid_Null}}</span>
|
||||||
@ -1,23 +1,23 @@
|
|||||||
#include "../String/StringBuilder.h"
|
#include "../String/StringBuilder.h"
|
||||||
#include "kprint.h"
|
#include "kprint.h"
|
||||||
|
|
||||||
ktId __typeFromFormat(kprint_format f){
|
ktid __typeFromFormat(kprint_format f){
|
||||||
ktId typeId=kprint_format_ktId(f);
|
ktid typeId=kprint_format_ktid(f);
|
||||||
if(typeId)
|
if(typeId)
|
||||||
return typeId;
|
return typeId;
|
||||||
switch(kprint_format_dataFormat(f)){
|
switch(kprint_format_dataFormat(f)){
|
||||||
case kprint_fmtInt:
|
case kprint_fmtInt:
|
||||||
case kprint_fmtHex:
|
case kprint_fmtHex:
|
||||||
case kprint_fmtBin:
|
case kprint_fmtBin:
|
||||||
return ktId_Int64;
|
return ktid_name(int64);
|
||||||
case kprint_fmtUInt:
|
case kprint_fmtUInt:
|
||||||
return ktId_UInt64;
|
return ktid_name(uint64);
|
||||||
case kprint_fmtFloat:
|
case kprint_fmtFloat:
|
||||||
return ktId_Float64;
|
return ktid_name(float64);
|
||||||
case kprint_fmtChar:
|
case kprint_fmtChar:
|
||||||
return ktId_Char;
|
return ktid_char;
|
||||||
case kprint_fmtString:
|
case kprint_fmtString:
|
||||||
return ktId_CharPtr;
|
return ktid_ptrName(char);
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -25,13 +25,13 @@ ktId __typeFromFormat(kprint_format f){
|
|||||||
|
|
||||||
Maybe __next_toString(kprint_format f, __kprint_value_union* object){
|
Maybe __next_toString(kprint_format f, __kprint_value_union* object){
|
||||||
// detecting type
|
// detecting type
|
||||||
ktId typeId=__typeFromFormat(f);
|
ktid typeId=__typeFromFormat(f);
|
||||||
if(typeId==-1)
|
if(typeId==-1)
|
||||||
safethrow("typeId is not set, can't autodetect type",;);
|
safethrow("typeId is not set, can't autodetect type",;);
|
||||||
ktDescriptor typeDesc=ktDescriptor_get(typeId);
|
ktDescriptor typeDesc=ktDescriptor_get(typeId);
|
||||||
if(!typeDesc.toString)
|
if(!typeDesc.toString)
|
||||||
safethrow("type descriptor doesnt have toString() func",;);
|
safethrow("type descriptor doesnt have toString() func",;);
|
||||||
return SUCCESS(UniHeap(ktId_CharPtr, typeDesc.toString(object, f)));
|
return SUCCESS(UniHeapPtr(char, typeDesc.toString(object, f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||||
@ -43,7 +43,7 @@ Maybe __ksprint(uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
|||||||
Unitype_free(mStr.value);
|
Unitype_free(mStr.value);
|
||||||
}
|
}
|
||||||
char* rezult=StringBuilder_build(strb).ptr;
|
char* rezult=StringBuilder_build(strb).ptr;
|
||||||
return SUCCESS(UniHeap(ktId_CharPtr, rezult));
|
return SUCCESS(UniHeapPtr(char, rezult));
|
||||||
}
|
}
|
||||||
|
|
||||||
Maybe __kfprint(FILE* file, uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
Maybe __kfprint(FILE* file, uint8 n, kprint_format* formats, __kprint_value_union* objects){
|
||||||
@ -150,7 +150,7 @@ void kprint_setColor(kprint_format f){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Maybe ksprint_ar(uint32 count, kprint_format format, ktId typeId, void* array){
|
/* Maybe ksprint_ar(uint32 count, kprint_format format, ktid typeId, void* array){
|
||||||
ktDescriptor typeDesc=ktDescriptor_get(format.typeId);
|
ktDescriptor typeDesc=ktDescriptor_get(format.typeId);
|
||||||
if(!typeDesc.toString)
|
if(!typeDesc.toString)
|
||||||
safethrow("type descriptor doesnt have toString() func",;);
|
safethrow("type descriptor doesnt have toString() func",;);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../base/std.h"
|
#include "../base/std.h"
|
||||||
#include "../base/type_system/ktId.h"
|
#include "../base/type_system/ktid.h"
|
||||||
|
|
||||||
typedef enum kprint_dataFormat{
|
typedef enum kprint_dataFormat{
|
||||||
// 00000000 00000000 00000000 00000000
|
// 00000000 00000000 00000000 00000000
|
||||||
@ -41,7 +41,7 @@ typedef uint32 kprint_format;
|
|||||||
#define kprint_format_fgColor(FMT) (kprint_fgColor)(FMT&0x8f000000)
|
#define kprint_format_fgColor(FMT) (kprint_fgColor)(FMT&0x8f000000)
|
||||||
#define kprint_format_bgColor(FMT) (kprint_bgColor)(FMT&0x40f00000)
|
#define kprint_format_bgColor(FMT) (kprint_bgColor)(FMT&0x40f00000)
|
||||||
#define kprint_format_dataFormat(FMT) (kprint_dataFormat)(FMT&0x000f0000)
|
#define kprint_format_dataFormat(FMT) (kprint_dataFormat)(FMT&0x000f0000)
|
||||||
#define kprint_format_ktId(FMT) (kprint_dataFormat)(FMT&0x0000ffff)
|
#define kprint_format_ktid(FMT) (kprint_dataFormat)(FMT&0x0000ffff)
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
```
|
```
|
||||||
00000000 00000000 00000000 00000000
|
00000000 00000000 00000000 00000000
|
||||||
fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ ktId
|
fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ ktid
|
||||||
bgColorSet─┘││ │ bgColor └data format
|
bgColorSet─┘││ │ bgColor └data format
|
||||||
prefix┬────┘│ └fgColor
|
prefix┬────┘│ └fgColor
|
||||||
postfix └uppercase
|
postfix └uppercase
|
||||||
|
|||||||
@ -20,9 +20,8 @@ int main(){
|
|||||||
ktDescriptors_initKerepTypes();
|
ktDescriptors_initKerepTypes();
|
||||||
ktDescriptors_endInit();
|
ktDescriptors_endInit();
|
||||||
kprintf("\e[97mkerep tests are starting!\n");
|
kprintf("\e[97mkerep tests are starting!\n");
|
||||||
//optime("test_all",1,test_all());
|
optime("test_all",1,test_all());
|
||||||
ktDescriptors_free();
|
ktDescriptors_free();
|
||||||
kprintf("ъъъъ");
|
|
||||||
kprintf("\e[0m\n");
|
kprintf("\e[0m\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,7 @@ void print_dtsod(Hashtable* dtsod){
|
|||||||
kprintf("\e[92m");
|
kprintf("\e[92m");
|
||||||
Hashtable_foreach(dtsod, p,({
|
Hashtable_foreach(dtsod, p,({
|
||||||
printkvp(p);
|
printkvp(p);
|
||||||
if(p.value.typeId==ktId_HashtablePtr){
|
if(p.value.typeId==ktid_ptrName(Hashtable)){
|
||||||
kprintf(": {\n");
|
kprintf(": {\n");
|
||||||
Hashtable* sub=p.value.VoidPtr;
|
Hashtable* sub=p.value.VoidPtr;
|
||||||
Hashtable_foreach(sub, _p,({
|
Hashtable_foreach(sub, _p,({
|
||||||
|
|||||||
@ -4,7 +4,7 @@ EXPORT void CALL test_marshalling(char* text, KVPair** kptr){
|
|||||||
KVPair* k=malloc(sizeof(KVPair));
|
KVPair* k=malloc(sizeof(KVPair));
|
||||||
k->key="message";
|
k->key="message";
|
||||||
char* tc=cptr_copy(text);
|
char* tc=cptr_copy(text);
|
||||||
Unitype u=UniHeap(ktId_CharPtr,tc);
|
Unitype u=UniHeapPtr(char,tc);
|
||||||
k->value=u;
|
k->value=u;
|
||||||
*kptr=k;
|
*kptr=k;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,11 +44,11 @@ void test_searchtree(){
|
|||||||
printuni(u);
|
printuni(u);
|
||||||
ST_push(node,"channel_id", u);
|
ST_push(node,"channel_id", u);
|
||||||
kprintf(" -> channel_id\n ");
|
kprintf(" -> channel_id\n ");
|
||||||
u=UniHeap(ktId_CharPtr, cptr_copy("32.2004"));
|
u=UniHeapPtr(char, cptr_copy("32.2004"));
|
||||||
printuni(u);
|
printuni(u);
|
||||||
ST_push(node,"message_id", u);
|
ST_push(node,"message_id", u);
|
||||||
kprintf(" -> message_id\n ");
|
kprintf(" -> message_id\n ");
|
||||||
u=UniStack(ktId_CharPtr,"some text UwU");
|
u=UniStackPtr(char,"some text UwU");
|
||||||
printuni(u);
|
printuni(u);
|
||||||
ST_push(node,"text", u);
|
ST_push(node,"text", u);
|
||||||
kprintf(" -> text\n");
|
kprintf(" -> text\n");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user