some type_system changes

This commit is contained in:
Timerix22 2023-05-22 03:06:46 +06:00
parent f32306a6d5
commit 27be5beacd
3 changed files with 15 additions and 16 deletions

View File

@ -13,21 +13,21 @@ extern "C" {
extern ktDescriptor ktDescriptor_##TYPE; \
extern ktDescriptor ktDescriptor_##TYPE##_Ptr;
#define kt_define(TYPE, FREE_FUNC, TOSTRING_FUNC)\
#define kt_define(TYPE, FREE_MEMBERS_F, TOSTRING_F)\
ktid_define(TYPE); \
ktDescriptor ktDescriptor_##TYPE={ \
.name=#TYPE, \
.id=ktid_undefined, \
.size=sizeof(TYPE), \
.freeMembers=FREE_FUNC, \
.toString=TOSTRING_FUNC \
.freeMembers=FREE_MEMBERS_F, \
.toString=TOSTRING_F \
}; \
ktDescriptor ktDescriptor_##TYPE##_Ptr={\
.name=#TYPE "_Ptr", \
.id=ktid_undefined, \
.size=sizeof(TYPE), \
.freeMembers=FREE_FUNC, \
.toString=TOSTRING_FUNC \
.freeMembers=FREE_MEMBERS_F, \
.toString=TOSTRING_F \
};
typedef void (*freeMembers_t)(void*);

View File

@ -34,11 +34,11 @@ ktDescriptorsState initState=NotInitialized;
void kt_beginInit(){
kprintf("\e[94mtype descriptors initializing...\n");
__descriptorPointers=Autoarr_create(Pointer, 256, 256);
if(__descriptorPointers==NULL)
throw(ERR_NULLPTR);
}
void kt_endInit(){
if(__descriptorPointers==NULL)
throw(ERR_NULLPTR);
typeDescriptors=(ktDescriptor**)Autoarr_toArray(__descriptorPointers);
Autoarr_free(__descriptorPointers,true);
if(typeDescriptors==NULL) throw(ERR_NULLPTR);

View File

@ -21,25 +21,24 @@ STRUCT(Unitype,
)
#define __UniDef(FIELD, TYPE, VAL) (Unitype){ \
.FIELD=VAL, .typeId=ktid_name(TYPE), .allocatedInHeap=false}
#define __UniDef(FIELD, TYPE, VAL) ((Unitype){ \
.FIELD=VAL, .typeId=ktid_name(TYPE), .allocatedInHeap=false})
#define UniInt64(VAL) __UniDef(Int64, i64, VAL)
#define UniUInt64(VAL) __UniDef(UInt64, u64, VAL)
#define UniFloat64(VAL) __UniDef(Float64, f64, VAL)
#define UniBool(VAL) __UniDef(Bool, bool, VAL)
#define UniStackPtr(TYPE, VAL) (Unitype){ \
.VoidPtr=VAL, .typeId=ktid_ptrName(TYPE), .allocatedInHeap=false}
#define UniHeapPtr(TYPE, VAL) (Unitype){ \
.VoidPtr=VAL, .typeId=ktid_ptrName(TYPE), .allocatedInHeap=true}
#define UniPtr(TYPE_ID, VAL, ALLOCATED_ON_HEAP)((Unitype){ \
.VoidPtr=VAL, .typeId=TYPE_ID, .allocatedInHeap=ALLOCATED_ON_HEAP })
#define UniStackPtr(TYPE, VAL) UniPtr(ktid_ptrName(TYPE), VAL, false)
#define UniHeapPtr(TYPE, VAL) UniPtr(ktid_ptrName(TYPE), VAL, true)
// 0==ktid_Pointer
#define UniNull (Unitype){.Int64=0, .typeId=0, .allocatedInHeap=false}
#define UniNull ((Unitype){.Int64=0, .typeId=0, .allocatedInHeap=false})
#define UniTrue UniBool(true)
#define UniFalse UniBool(false)
#define Unitype_isUniNull(UNI) (UNI.typeId==ktid_Pointer && UNI.VoidPtr==NULL)
#define Unitype_isUniNull(UNI) (UNI.typeId==0 && UNI.Int64==0)
// frees VoidPtr value or does nothing if type isn't pointer
void Unitype_free(Unitype u);