kerepType -> kt
This commit is contained in:
parent
dc6a52608a
commit
67e1328ee7
@ -13,35 +13,35 @@ Autoarr_define(int32)
|
|||||||
Autoarr_define(uint64)
|
Autoarr_define(uint64)
|
||||||
Autoarr_define(int64)
|
Autoarr_define(int64)
|
||||||
|
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrChar);
|
ktId_define(ktId_AutoarrChar);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrBool);
|
ktId_define(ktId_AutoarrBool);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrFloat32);
|
ktId_define(ktId_AutoarrFloat32);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrFloat64);
|
ktId_define(ktId_AutoarrFloat64);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrInt8);
|
ktId_define(ktId_AutoarrInt8);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUInt8);
|
ktId_define(ktId_AutoarrUInt8);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrInt16);
|
ktId_define(ktId_AutoarrInt16);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUInt16);
|
ktId_define(ktId_AutoarrUInt16);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrInt32);
|
ktId_define(ktId_AutoarrInt32);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUInt32);
|
ktId_define(ktId_AutoarrUInt32);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrInt64);
|
ktId_define(ktId_AutoarrInt64);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUInt64);
|
ktId_define(ktId_AutoarrUInt64);
|
||||||
|
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrCharPtr);
|
ktId_define(ktId_AutoarrCharPtr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrBoolPtr);
|
ktId_define(ktId_AutoarrBoolPtr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrFloat32Ptr);
|
ktId_define(ktId_AutoarrFloat32Ptr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrFloat64Ptr);
|
ktId_define(ktId_AutoarrFloat64Ptr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrInt8Ptr);
|
ktId_define(ktId_AutoarrInt8Ptr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUInt8Ptr);
|
ktId_define(ktId_AutoarrUInt8Ptr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrInt16Ptr);
|
ktId_define(ktId_AutoarrInt16Ptr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUInt16Ptr);
|
ktId_define(ktId_AutoarrUInt16Ptr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrInt32Ptr);
|
ktId_define(ktId_AutoarrInt32Ptr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUInt32Ptr);
|
ktId_define(ktId_AutoarrUInt32Ptr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrInt64Ptr);
|
ktId_define(ktId_AutoarrInt64Ptr);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUInt64Ptr);
|
ktId_define(ktId_AutoarrUInt64Ptr);
|
||||||
|
|
||||||
Autoarr_define(Unitype)
|
Autoarr_define(Unitype)
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUnitype);
|
ktId_define(ktId_AutoarrUnitype);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrUnitypePtr);
|
ktId_define(ktId_AutoarrUnitypePtr);
|
||||||
|
|
||||||
// right func to clear array of unitype values
|
// right func to clear array of unitype values
|
||||||
void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr){
|
void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr){
|
||||||
|
|||||||
@ -20,35 +20,35 @@ Autoarr_declare(uint32)
|
|||||||
Autoarr_declare(int64)
|
Autoarr_declare(int64)
|
||||||
Autoarr_declare(uint64)
|
Autoarr_declare(uint64)
|
||||||
|
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrChar);
|
ktId_declare(ktId_AutoarrChar);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrBool);
|
ktId_declare(ktId_AutoarrBool);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrFloat32);
|
ktId_declare(ktId_AutoarrFloat32);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrFloat64);
|
ktId_declare(ktId_AutoarrFloat64);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrInt8);
|
ktId_declare(ktId_AutoarrInt8);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUInt8);
|
ktId_declare(ktId_AutoarrUInt8);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrInt16);
|
ktId_declare(ktId_AutoarrInt16);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUInt16);
|
ktId_declare(ktId_AutoarrUInt16);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrInt32);
|
ktId_declare(ktId_AutoarrInt32);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUInt32);
|
ktId_declare(ktId_AutoarrUInt32);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrInt64);
|
ktId_declare(ktId_AutoarrInt64);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUInt64);
|
ktId_declare(ktId_AutoarrUInt64);
|
||||||
|
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrCharPtr);
|
ktId_declare(ktId_AutoarrCharPtr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrBoolPtr);
|
ktId_declare(ktId_AutoarrBoolPtr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrFloat32Ptr);
|
ktId_declare(ktId_AutoarrFloat32Ptr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrFloat64Ptr);
|
ktId_declare(ktId_AutoarrFloat64Ptr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrInt8Ptr);
|
ktId_declare(ktId_AutoarrInt8Ptr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUInt8Ptr);
|
ktId_declare(ktId_AutoarrUInt8Ptr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrInt16Ptr);
|
ktId_declare(ktId_AutoarrInt16Ptr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUInt16Ptr);
|
ktId_declare(ktId_AutoarrUInt16Ptr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrInt32Ptr);
|
ktId_declare(ktId_AutoarrInt32Ptr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUInt32Ptr);
|
ktId_declare(ktId_AutoarrUInt32Ptr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrInt64Ptr);
|
ktId_declare(ktId_AutoarrInt64Ptr);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUInt64Ptr);
|
ktId_declare(ktId_AutoarrUInt64Ptr);
|
||||||
|
|
||||||
Autoarr_declare(Unitype)
|
Autoarr_declare(Unitype)
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUnitype);
|
ktId_declare(ktId_AutoarrUnitype);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrUnitypePtr);
|
ktId_declare(ktId_AutoarrUnitypePtr);
|
||||||
|
|
||||||
// this function is injected in kerep_init()
|
// this function is injected in kerep_init()
|
||||||
void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr);
|
void __Autoarr_free_Unitype_(Autoarr(Unitype)* ar, bool freePtr);
|
||||||
|
|||||||
@ -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(kerepTypeId_CharPtr,NULL));
|
return SUCCESS(UniHeap(ktId_CharPtr,NULL));
|
||||||
case ':':
|
case ':':
|
||||||
return SUCCESS(UniHeap(kerepTypeId_CharPtr,string_extract(nameStr)));
|
return SUCCESS(UniHeap(ktId_CharPtr,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(kerepTypeId_CharPtr,NULL));
|
return SUCCESS(UniHeap(ktId_CharPtr,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(kerepTypeId_CharPtr,str));
|
return SUCCESS(UniHeap(ktId_CharPtr,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==kerepTypeId_Null)
|
if(val.value.typeId==ktId_Null)
|
||||||
Autoarr_pop(list);
|
Autoarr_pop(list);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCESS(UniHeap(kerepTypeId_AutoarrUnitypePtr,list));
|
return SUCCESS(UniHeap(ktId_AutoarrUnitypePtr,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!=kerepTypeId_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(kerepTypeId_AutoarrUnitypePtr,list));
|
Hashtable_add(dict,nameCPtr,UniHeap(ktId_AutoarrUnitypePtr,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(kerepTypeId_HashtablePtr,dict));
|
return SUCCESS(UniHeap(ktId_HashtablePtr,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==kerepTypeId_Int64){
|
if(u.typeId==ktId_Int64){
|
||||||
StringBuilder_append_int64(b,u.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);
|
StringBuilder_append_uint64(b,u.UInt64);
|
||||||
addc('u');
|
addc('u');
|
||||||
}
|
}
|
||||||
else if(u.typeId==kerepTypeId_Float64){
|
else if(u.typeId==ktId_Float64){
|
||||||
StringBuilder_append_float64(b,u.Float64);
|
StringBuilder_append_float64(b,u.Float64);
|
||||||
addc('f');
|
addc('f');
|
||||||
}
|
}
|
||||||
else if(u.typeId==kerepTypeId_CharPtr){
|
else if(u.typeId==ktId_CharPtr){
|
||||||
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==kerepTypeId_Bool){
|
else if(u.typeId==ktId_Bool){
|
||||||
StringBuilder_append_cptr(b, u.Bool ? "true" : "false");
|
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",;);
|
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)))){
|
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==kerepTypeId_HashtablePtr){
|
else if(u.typeId==ktId_HashtablePtr){
|
||||||
// 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(kerepTypeId_CharPtr, str));
|
return SUCCESS(UniHeap(ktId_CharPtr, str));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include "Hashtable.h"
|
#include "Hashtable.h"
|
||||||
|
|
||||||
kerepTypeId_define(kerepTypeId_Hashtable);
|
ktId_define(ktId_Hashtable);
|
||||||
kerepTypeId_define(kerepTypeId_HashtablePtr);
|
ktId_define(ktId_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 +96,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!=kerepTypeId_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,8 @@ 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;
|
||||||
kerepTypeId_declare(kerepTypeId_Hashtable);
|
ktId_declare(ktId_Hashtable);
|
||||||
kerepTypeId_declare(kerepTypeId_HashtablePtr);
|
ktId_declare(ktId_HashtablePtr);
|
||||||
|
|
||||||
Hashtable* Hashtable_create();
|
Hashtable* Hashtable_create();
|
||||||
void Hashtable_free(Hashtable* ht);
|
void Hashtable_free(Hashtable* ht);
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
#include "KeyValuePair.h"
|
#include "KeyValuePair.h"
|
||||||
|
|
||||||
kerepTypeId_define(kerepTypeId_KVPair);
|
ktId_define(ktId_KVPair);
|
||||||
kerepTypeId_define(kerepTypeId_KVPairPtr);
|
ktId_define(ktId_KVPairPtr);
|
||||||
|
|
||||||
Autoarr_define(KVPair)
|
Autoarr_define(KVPair)
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrKVPair);
|
ktId_define(ktId_AutoarrKVPair);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrKVPairPtr);
|
ktId_define(ktId_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,12 @@ typedef struct KVPair{
|
|||||||
char* key;
|
char* key;
|
||||||
Unitype value;
|
Unitype value;
|
||||||
} KVPair;
|
} KVPair;
|
||||||
kerepTypeId_declare(kerepTypeId_KVPair);
|
ktId_declare(ktId_KVPair);
|
||||||
kerepTypeId_declare(kerepTypeId_KVPairPtr);
|
ktId_declare(ktId_KVPairPtr);
|
||||||
|
|
||||||
Autoarr_declare(KVPair)
|
Autoarr_declare(KVPair)
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrKVPair);
|
ktId_declare(ktId_AutoarrKVPair);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrKVPairPtr);
|
ktId_declare(ktId_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,12 @@
|
|||||||
#include "SearchTree.h"
|
#include "SearchTree.h"
|
||||||
|
|
||||||
kerepTypeId_define(kerepTypeId_STNode);
|
ktId_define(ktId_STNode);
|
||||||
kerepTypeId_define(kerepTypeId_STNodePtr);
|
ktId_define(ktId_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=kerepTypeId_Null;
|
node->value.typeId=ktId_Null;
|
||||||
node->value.UInt64=0;
|
node->value.UInt64=0;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,8 +11,8 @@ typedef struct SearchTreeNode{
|
|||||||
struct SearchTreeNode**** branches; // *STNode[8][8][4]
|
struct SearchTreeNode**** branches; // *STNode[8][8][4]
|
||||||
Unitype value;
|
Unitype value;
|
||||||
} STNode;
|
} STNode;
|
||||||
kerepTypeId_declare(kerepTypeId_STNode);
|
ktId_declare(ktId_STNode);
|
||||||
kerepTypeId_declare(kerepTypeId_STNodePtr);
|
ktId_declare(ktId_STNodePtr);
|
||||||
|
|
||||||
STNode* STNode_create();
|
STNode* STNode_create();
|
||||||
void STNode_free(STNode* node);
|
void STNode_free(STNode* node);
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
#include "StringBuilder.h"
|
#include "StringBuilder.h"
|
||||||
|
|
||||||
Autoarr_define(string)
|
Autoarr_define(string)
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrString);
|
ktId_define(ktId_AutoarrString);
|
||||||
kerepTypeId_define(kerepTypeId_AutoarrStringPtr);
|
ktId_define(ktId_AutoarrStringPtr);
|
||||||
|
|
||||||
kerepTypeId_define(kerepTypeId_StringBuilder);
|
ktId_define(ktId_StringBuilder);
|
||||||
kerepTypeId_define(kerepTypeId_StringBuilderPtr);
|
ktId_define(ktId_StringBuilderPtr);
|
||||||
|
|
||||||
#define BL_C 32
|
#define BL_C 32
|
||||||
#define BL_L 1024
|
#define BL_L 1024
|
||||||
|
|||||||
@ -8,15 +8,15 @@ extern "C" {
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
Autoarr_declare(string)
|
Autoarr_declare(string)
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrString);
|
ktId_declare(ktId_AutoarrString);
|
||||||
kerepTypeId_declare(kerepTypeId_AutoarrStringPtr);
|
ktId_declare(ktId_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;
|
||||||
kerepTypeId_declare(kerepTypeId_StringBuilder);
|
ktId_declare(ktId_StringBuilder);
|
||||||
kerepTypeId_declare(kerepTypeId_StringBuilderPtr);
|
ktId_declare(ktId_StringBuilderPtr);
|
||||||
|
|
||||||
StringBuilder* StringBuilder_create(void);
|
StringBuilder* StringBuilder_create(void);
|
||||||
void StringBuilder_free(StringBuilder* b);
|
void StringBuilder_free(StringBuilder* b);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
kerepTypeId_define(kerepTypeId_string);
|
ktId_define(ktId_string);
|
||||||
kerepTypeId_define(kerepTypeId_stringPtr);
|
ktId_define(ktId_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,8 @@ 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;
|
||||||
kerepTypeId_declare(kerepTypeId_string);
|
ktId_declare(ktId_string);
|
||||||
kerepTypeId_declare(kerepTypeId_stringPtr);
|
ktId_declare(ktId_stringPtr);
|
||||||
|
|
||||||
static const string stringNull={NULL,0};
|
static const string stringNull={NULL,0};
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,7 @@ extern "C" {
|
|||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
#include "cptr.h"
|
#include "cptr.h"
|
||||||
#include "optime.h"
|
#include "optime.h"
|
||||||
#include "type_system/types.h"
|
#include "type_system/type_system.h"
|
||||||
#include "type_system/unitype.h"
|
|
||||||
#include "init.h"
|
|
||||||
#include "kprint/kprint.h"
|
#include "kprint/kprint.h"
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|||||||
103
src/base/init.c
103
src/base/init.c
@ -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);
|
|
||||||
}
|
|
||||||
@ -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
|
|
||||||
@ -10,11 +10,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_fbgColor | kprint_fdataFmt | flags | kerepTypeId;
|
kprint_format fmt= kprint_fgColor | kprint_fbgColor | 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 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
|
+ 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
|
||||||
|
|
||||||
@ -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
|
should be sent as pointers
|
||||||
```
|
```
|
||||||
Maybe m=MaybeNull;
|
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: <span style="color:blue">Maybe:</span> <span style="color:lightgreen">{value={0, kerepTypeId_Null}}</span>
|
output: <span style="color:blue">Maybe:</span> <span style="color:lightgreen">{value={0, ktId_Null}}</span>
|
||||||
@ -7,20 +7,20 @@ Maybe __next_toString(kprint_format format, void* object){
|
|||||||
case kprint_fmtInt:
|
case kprint_fmtInt:
|
||||||
case kprint_fmtHex:
|
case kprint_fmtHex:
|
||||||
case kprint_fmtBin:
|
case kprint_fmtBin:
|
||||||
format.typeId=kerepTypeId_Int64; break;
|
format.typeId=ktId_Int64; break;
|
||||||
case kprint_fmtUInt:
|
case kprint_fmtUInt:
|
||||||
format.typeId=kerepTypeId_UInt64; break;
|
format.typeId=ktId_UInt64; break;
|
||||||
case kprint_fmtFloat:
|
case kprint_fmtFloat:
|
||||||
format.typeId=kerepTypeId_Float64; break;
|
format.typeId=ktId_Float64; break;
|
||||||
case kprint_fmtChar:
|
case kprint_fmtChar:
|
||||||
format.typeId=kerepTypeId_Char; break;
|
format.typeId=ktId_Char; break;
|
||||||
case kprint_fmtString:
|
case kprint_fmtString:
|
||||||
format.typeId=kerepTypeId_CharPtr; break;
|
format.typeId=ktId_CharPtr; break;
|
||||||
default:
|
default:
|
||||||
safethrow("typeId is not set, can't autodetect type",;);
|
safethrow("typeId is not set, can't autodetect type",;);
|
||||||
}
|
}
|
||||||
try(kerepTypeDescriptor_get(format.typeId),mtd,;);
|
try(ktDescriptor_get(format.typeId),mtd,;);
|
||||||
kerepTypeDescriptor typeDesc=*(kerepTypeDescriptor*)mtd.value.VoidPtr;
|
ktDescriptor typeDesc=*(ktDescriptor*)mtd.value.VoidPtr;
|
||||||
if(!typeDesc.toString)
|
if(!typeDesc.toString)
|
||||||
safethrow("type descriptor doesnt have toString() func",;);
|
safethrow("type descriptor doesnt have toString() func",;);
|
||||||
try(typeDesc.toString(object, &format), mStr,;);
|
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);
|
StringBuilder_append_cptr(strb, mStr.value.VoidPtr);
|
||||||
}
|
}
|
||||||
char* rezult=StringBuilder_build(strb).ptr;
|
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){
|
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){
|
Maybe ksprint_ar(uint32 count, kprint_format format, ktId typeId, void* array){
|
||||||
try(kerepTypeDescriptor_get(format.typeId),mtd,;);
|
try(ktDescriptor_get(format.typeId),mtd,;);
|
||||||
kerepTypeDescriptor typeDesc=*(kerepTypeDescriptor*)mtd.value.VoidPtr;
|
ktDescriptor typeDesc=*(ktDescriptor*)mtd.value.VoidPtr;
|
||||||
if(!typeDesc.toString)
|
if(!typeDesc.toString)
|
||||||
safethrow("type descriptor doesnt have toString() func",;);
|
safethrow("type descriptor doesnt have toString() func",;);
|
||||||
StringBuilder* strb=StringBuilder_create();
|
StringBuilder* strb=StringBuilder_create();
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../type_system/kerepTypeId.h"
|
#include "../type_system/ktId.h"
|
||||||
|
|
||||||
typedef enum kprint_dataFormat{
|
typedef enum kprint_dataFormat{
|
||||||
// 00000000 00000000 00000000 00000000
|
// 00000000 00000000 00000000 00000000
|
||||||
@ -39,7 +39,7 @@ typedef struct {
|
|||||||
unsigned char fgColor : 4;
|
unsigned char fgColor : 4;
|
||||||
unsigned char bgColor : 4;
|
unsigned char bgColor : 4;
|
||||||
unsigned char dataFmt : 4;
|
unsigned char dataFmt : 4;
|
||||||
kerepTypeId typeId;
|
ktId typeId;
|
||||||
} kprint_format;
|
} kprint_format;
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
```
|
```
|
||||||
00000000 00000000 00000000 00000000
|
00000000 00000000 00000000 00000000
|
||||||
fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ kerepTypeId
|
fgColorSet┘│││└┼┴┘ └┼┴┘└┴┴┤ ktId
|
||||||
bgColorSet─┘││ │ bgColor └data format
|
bgColorSet─┘││ │ bgColor └data format
|
||||||
prefix┬────┘│ └fgColor
|
prefix┬────┘│ └fgColor
|
||||||
postfix └uppercase
|
postfix └uppercase
|
||||||
|
|||||||
103
src/base/type_system/init.c
Normal file
103
src/base/type_system/init.c
Normal file
@ -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);
|
||||||
|
}
|
||||||
12
src/base/type_system/init.h
Normal file
12
src/base/type_system/init.h
Normal file
@ -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
|
||||||
@ -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
|
|
||||||
@ -6,16 +6,16 @@ extern "C" {
|
|||||||
|
|
||||||
#include "../std.h"
|
#include "../std.h"
|
||||||
#include "../errors.h"
|
#include "../errors.h"
|
||||||
#include "kerepTypeId.h"
|
#include "ktId.h"
|
||||||
|
|
||||||
typedef struct kerepTypeDescriptor{
|
typedef struct ktDescriptor{
|
||||||
char* name;
|
char* name;
|
||||||
kerepTypeId id;
|
ktId id;
|
||||||
uint16 size;
|
uint16 size;
|
||||||
void (*freeMembers)(void*); // NULL or function which frees all struct members
|
void (*freeMembers)(void*); // NULL or function which frees all struct members
|
||||||
///@return Maybe<char*>
|
///@return Maybe<char*>
|
||||||
Maybe (*toString)(void*, int32); // NULL or function which generates string representaion of object
|
Maybe (*toString)(void*, int32); // NULL or function which generates string representaion of object
|
||||||
} kerepTypeDescriptor;
|
} ktDescriptor;
|
||||||
|
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}
|
}
|
||||||
17
src/base/type_system/ktId.h
Normal file
17
src/base/type_system/ktId.h
Normal file
@ -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
|
||||||
75
src/base/type_system/kt_functions.c
Normal file
75
src/base/type_system/kt_functions.c
Normal file
@ -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]));
|
||||||
|
}
|
||||||
59
src/base/type_system/kt_functions.h
Normal file
59
src/base/type_system/kt_functions.h
Normal file
@ -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<ktDescriptor*>
|
||||||
|
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
|
||||||
4
src/base/type_system/type_system.h
Normal file
4
src/base/type_system/type_system.h
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
#include "init.h"
|
||||||
|
#include "kt_functions.h"
|
||||||
|
#include "unitype.h"
|
||||||
@ -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]));
|
|
||||||
}
|
|
||||||
@ -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<kerepTypeDescriptor*>
|
|
||||||
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
|
|
||||||
@ -1,11 +1,11 @@
|
|||||||
#include "../base.h"
|
#include "../base.h"
|
||||||
|
|
||||||
kerepTypeId_define(kerepTypeId_Unitype);
|
ktId_define(ktId_Unitype);
|
||||||
kerepTypeId_define(kerepTypeId_UnitypePtr);
|
ktId_define(ktId_UnitypePtr);
|
||||||
|
|
||||||
void Unitype_free(Unitype u){
|
void Unitype_free(Unitype u){
|
||||||
tryLast(kerepTypeDescriptor_get(u.typeId), mType);
|
tryLast(ktDescriptor_get(u.typeId), mType);
|
||||||
kerepTypeDescriptor type=*(kerepTypeDescriptor*)mType.value.VoidPtr;
|
ktDescriptor type=*(ktDescriptor*)mType.value.VoidPtr;
|
||||||
if(type.freeMembers)
|
if(type.freeMembers)
|
||||||
type.freeMembers(u.VoidPtr);
|
type.freeMembers(u.VoidPtr);
|
||||||
if(u.allocatedInHeap)
|
if(u.allocatedInHeap)
|
||||||
@ -16,17 +16,17 @@ void __UnitypePtr_free(void* u) { Unitype_free(*(Unitype*)u); }
|
|||||||
#define BUFSIZE 64
|
#define BUFSIZE 64
|
||||||
char* sprintuni(Unitype v){
|
char* sprintuni(Unitype v){
|
||||||
char* buf=malloc(BUFSIZE);
|
char* buf=malloc(BUFSIZE);
|
||||||
tryLast(kerepTypeDescriptor_get(v.typeId), mType);
|
tryLast(ktDescriptor_get(v.typeId), mType);
|
||||||
kerepTypeDescriptor type=*(kerepTypeDescriptor*)mType.value.VoidPtr;
|
ktDescriptor type=*(ktDescriptor*)mType.value.VoidPtr;
|
||||||
if(v.typeId==kerepTypeId_Null)
|
if(v.typeId==ktId_Null)
|
||||||
sprintf_s(buf, BUFSIZE, "{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);
|
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);
|
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);
|
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;
|
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 "kerepTypeId.h"
|
#include "ktId.h"
|
||||||
|
|
||||||
typedef struct Unitype{
|
typedef struct Unitype{
|
||||||
union {
|
union {
|
||||||
@ -15,15 +15,15 @@ typedef struct Unitype{
|
|||||||
void* VoidPtr;
|
void* VoidPtr;
|
||||||
char Bytes[8];
|
char Bytes[8];
|
||||||
};
|
};
|
||||||
kerepTypeId typeId;
|
ktId typeId;
|
||||||
bool allocatedInHeap; // should Unitype_free call free() to VoidPtr*
|
bool allocatedInHeap; // should Unitype_free call free() to VoidPtr*
|
||||||
} Unitype;
|
} Unitype;
|
||||||
kerepTypeId_declare(kerepTypeId_Unitype);
|
ktId_declare(ktId_Unitype);
|
||||||
kerepTypeId_declare(kerepTypeId_UnitypePtr);
|
ktId_declare(ktId_UnitypePtr);
|
||||||
|
|
||||||
|
|
||||||
#define __UniDef(TYPE, VAL) (Unitype){\
|
#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 UniInt64(VAL) __UniDef(Int64, VAL)
|
||||||
#define UniUInt64(VAL) __UniDef(UInt64, VAL)
|
#define UniUInt64(VAL) __UniDef(UInt64, VAL)
|
||||||
@ -35,7 +35,7 @@ kerepTypeId_declare(kerepTypeId_UnitypePtr);
|
|||||||
#define UniHeap(ID_VAR_NAME, VAL) (Unitype){\
|
#define UniHeap(ID_VAR_NAME, VAL) (Unitype){\
|
||||||
.VoidPtr=VAL, .typeId=ID_VAR_NAME, .allocatedInHeap=true}
|
.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 UniTrue UniBool(true)
|
||||||
#define UniFalse UniBool(false)
|
#define UniFalse UniBool(false)
|
||||||
|
|
||||||
|
|||||||
@ -13,9 +13,9 @@ void test_all(){
|
|||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
setlocale(LC_ALL, "en-US.Unicode");
|
setlocale(LC_ALL, "en-US.Unicode");
|
||||||
kerepTypeDescriptors_beginInit();
|
ktDescriptors_beginInit();
|
||||||
kerepTypeDescriptors_initKerepTypes();
|
ktDescriptors_initKerepTypes();
|
||||||
kerepTypeDescriptors_endInit();
|
ktDescriptors_endInit();
|
||||||
printf("\e[97mkerep tests are starting!\n");
|
printf("\e[97mkerep tests are starting!\n");
|
||||||
optime("test_all",1,test_all());
|
optime("test_all",1,test_all());
|
||||||
printf("\e[0m\n");
|
printf("\e[0m\n");
|
||||||
|
|||||||
@ -18,7 +18,7 @@ void print_dtsod(Hashtable* dtsod){
|
|||||||
printf("\e[92m");
|
printf("\e[92m");
|
||||||
Hashtable_foreach(dtsod, p,({
|
Hashtable_foreach(dtsod, p,({
|
||||||
printkvp(p);
|
printkvp(p);
|
||||||
if(p.value.typeId==kerepTypeId_HashtablePtr){
|
if(p.value.typeId==ktId_HashtablePtr){
|
||||||
printf(": {\n");
|
printf(": {\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(kerepTypeId_CharPtr,tc);
|
Unitype u=UniHeap(ktId_CharPtr,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);
|
||||||
printf(" -> channel_id\n ");
|
printf(" -> channel_id\n ");
|
||||||
u=UniHeap(kerepTypeId_CharPtr, cptr_copy("32.2004"));
|
u=UniHeap(ktId_CharPtr, cptr_copy("32.2004"));
|
||||||
printuni(u);
|
printuni(u);
|
||||||
ST_push(node,"message_id", u);
|
ST_push(node,"message_id", u);
|
||||||
printf(" -> message_id\n ");
|
printf(" -> message_id\n ");
|
||||||
u=UniStack(kerepTypeId_CharPtr,"some text UwU");
|
u=UniStack(ktId_CharPtr,"some text UwU");
|
||||||
printuni(u);
|
printuni(u);
|
||||||
ST_push(node,"text", u);
|
ST_push(node,"text", u);
|
||||||
printf(" -> text\n");
|
printf(" -> text\n");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user