Start working on codegen implementation in C

This commit is contained in:
Abdelrahman Said 2025-09-07 06:09:43 +01:00
parent 509d6c912f
commit f09d759b05
7 changed files with 2200 additions and 2 deletions

View File

@ -43,9 +43,9 @@ ifeq ($(CC),gcc)
export ASAN_OPTIONS=verify_asan_link_order=0
endif
.PHONY: help full prng testing uuid core primitives all clean builddir build-test run-test codegen install build-lib
.PHONY: help full prng testing uuid core primitives all clean builddir build-test run-test codegen install build-lib ccodegen
all: clean builddir codegen run-c-test full run-cc-test
all: clean builddir codegen run-c-test full run-cc-test ccodegen
help:
@echo "Available build variables:"
@ -126,3 +126,6 @@ build-lib: builddir
$(CC) -c $(CSTD) $(CFLAGS) $(LIBFLAGS) $(LIB_SRC) -o $(OBJ_OUT)
$(AR) r $(LIB_OUT) $(OBJ_OUT)
@rm $(OBJ_OUT)
ccodegen:
$(CC) $(CSTD) $(CFLAGS) $(LIBFLAGS) -Isrc/core src/core/wapp_core.c ccodegen/*.c -o ccgen

120
ccodegen/datatypes.c Normal file
View File

@ -0,0 +1,120 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "datatypes.h"
#include "type_enums.h"
#include "wapp_core.h"
#define ERR_MSG "Not enough capacity in dst buffer"
internal inline void ctype_to_string(Str8 *dst, CType ctype);
internal inline void cqualifier_to_string(Str8 *dst, CQualifier cqualifier);
internal inline void cpointertype_to_string(Str8 *dst, CPointerType cpointertype);
internal inline void cpointer_to_string(Str8 *dst, const CPointer *cpointer);
internal inline void cenumval_to_string(Str8 *dst, const CEnumVal *cenumval);
internal inline void cmacro_to_string(Str8 *dst, const CMacro *cmacro);
void cobject_to_string(Str8 *dst, const CObject *object) {
wapp_debug_assert(dst != NULL object != NULL, "`allocator`, `dst` and `object` should not be NULL");
if (object->kind >= COUNT_COBJECTKIND) {
return;
}
switch (object->kind) {
case COBJECT_CTYPE:
ctype_to_string(dst, object->object.c_type);
break;
case COBJECT_CQUALIFIER:
cqualifier_to_string(dst, object->object.c_qualifier);
break;
case COBJECT_CPOINTERTYPE:
cpointertype_to_string(dst, object->object.c_pointertype);
break;
case COBJECT_CPOINTER:
cpointer_to_string(dst, &(object->object.c_pointer));
break;
case COBJECT_CENUMVAL:
cenumval_to_string(dst, &(object->object.c_enumval));
break;
case COBJECT_CENUM:
break;
case COBJECT_CMACRO:
cmacro_to_string(dst, &(object->object.c_macro));
break;
case COBJECT_CSTRUCT:
break;
case COBJECT_CUSERTYPE:
break;
case COBJECT_CDATATYPE:
break;
case COBJECT_CARG:
break;
case COBJECT_CFUNC:
break;
case COBJECT_CINCULDE:
break;
case COBJECT_CHEADER:
break;
case COBJECT_CSOURCE:
break;
default:
break;
}
}
internal inline void ctype_to_string(Str8 *dst, CType ctype) {
wapp_runtime_assert(ctypes[ctype].size <= dst->capacity, ERR_MSG);
wapp_str8_copy_str8_capped(dst, &ctypes[ctype]);
}
internal inline void cqualifier_to_string(Str8 *dst, CQualifier cqualifier) {
wapp_runtime_assert(cqualifiers[cqualifier].size <= dst->capacity, ERR_MSG);
wapp_str8_copy_str8_capped(dst, &cqualifiers[cqualifier]);
}
internal inline void cpointertype_to_string(Str8 *dst, CPointerType cpointertype) {
wapp_runtime_assert(cpointertypes[cpointertype].size <= dst->capacity, ERR_MSG);
wapp_str8_copy_str8_capped(dst, &cpointertypes[cpointertype]);
}
internal inline void cpointer_to_string(Str8 *dst, const CPointer *cpointer) {
wapp_debug_assert(dst != NULL && cpointer != NULL, "`dst` and `cpointer` should not be NULL");
u64 total_size = cpointertypes[cpointer->type].size + cqualifiers[cpointer->qualifier].size;
wapp_runtime_assert(total_size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst,
WAPP_STR8_SPEC WAPP_STR8_SPEC,
wapp_str8_varg(cpointertypes[cpointer->type]),
wapp_str8_varg(cqualifiers[cpointer->qualifier]));
}
internal inline void cenumval_to_string(Str8 *dst, const CEnumVal *cenumval) {
wapp_debug_assert(dst != NULL && cenumval != NULL, "`dst` and `cenumval` should not be NULL");
Str8 tmp = wapp_str8_buf(32);
u64 tmp_size = 0;
if (cenumval->value != NULL) {
wapp_str8_format(&tmp, " = %d", *(cenumval->value));
tmp_size = tmp.size;
}
u64 total_size = cenumval->name.size + tmp_size;
wapp_runtime_assert(total_size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst,
WAPP_STR8_SPEC WAPP_STR8_SPEC,
wapp_str8_varg(cenumval->name),
wapp_str8_varg(tmp));
}
internal inline void cmacro_to_string(Str8 *dst, const CMacro *cmacro) {
wapp_debug_assert(dst != NULL && cenumval != NULL, "`dst` and `cmacro` should not be NULL");
Str8 def = wapp_str8_lit("#define ");
u64 total_size = def.size + cmacro->name.size + cmacro->value.size + 1; // Add 1 for newline
wapp_runtime_assert(total_size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst,
WAPP_STR8_SPEC WAPP_STR8_SPEC " " WAPP_STR8_SPEC "\n",
wapp_str8_varg(def),
wapp_str8_varg(cmacro->name),
wapp_str8_varg(cmacro->value));
}

236
ccodegen/datatypes.h Normal file
View File

@ -0,0 +1,236 @@
// vim:fileencoding=utf-8:foldmethod=marker
#ifndef DATATYPES_H
#define DATATYPES_H
#include "wapp_core.h"
#include "dbl_list.h"
#include "type_enums.h"
#define CENUM(NAME, VALUES, TYPEDEF) ((CEnum){ .name = (NAME), .values = (VALUES), .add_typedef = (TYPEDEF) })
#define CSTRUCT(NAME, ARGS, TYPEDEF_NAME_PTR) ((CStruct){ .name = (NAME), .args = (ARGS), .typedef_name = (TYPEDEF_NAME_PTR) })
#define CUSERTYPE_ENUM(ENUM) ((CUserType){ .kind = CUSERTYPE_CENUM, .type.c_enum = ENUM })
#define CUSERTYPE_STRUCT(STRUCT) ((CUserType){ .kind = CUSERTYPE_CSTRUCT, .type.c_struct = STRUCT })
#define CDATATYPE_CTYPE(VALUE) ((CDataType){ .kind = CDATATYPE_CTYPE, .type.c_type = (VALUE) })
#define CDATATYPE_USERTYPE(USERTYPE) ((CDataType){ .kind = CDATATYPE_CUSERTYPE, .type.c_usertype = (USERTYPE) })
#define CDATATYPE_STR(STR) ((CDataType){ .kind = CDATATYPE_STR, .type.str = (STR) })
#define CHEADERINCLUDE_STR(NAME) ((CHeaderInclude){ .kind = C_HEADER_INCLUDE_STR, .header.name = (NAME) })
#define CHEADERINCLUDE_CHEADER(CHEADER) ((CHeaderInclude){ .kind = C_HEADER_INCLUDE_HEADER, .header.header = (CHEADER) })
#define COBJECT_TYPE(VALUE) \
((CObject){ .kind = COBJECT_CTYPE, .object.c_type = (VALUE) })
#define COBJECT_QUALIFIER(VALUE) \
((CObject){ .kind = COBJECT_CQUALIFIER, .object.c_qualifier = (VALUE) })
#define COBJECT_POINTERTYPE(VALUE) \
((CObject){ .kind = COBJECT_CPOINTERTYPE, .object.c_pointertype = (VALUE) })
#define COBJECT_POINTER(CPOINTER) \
((CObject){ .kind = COBJECT_CPOINTER, .object.c_pointer = (CPOINTER) })
#define COBJECT_ENUMVAL(CENUMVAL) \
((CObject){ .kind = COBJECT_CENUMVAL, .object.c_enumval = (CENUMVAL) })
#define COBJECT_ENUM(ENUM) \
((CObject){ .kind = COBJECT_CENUM, .object.c_enum = (ENUM) })
#define COBJECT_MACRO(CMACRO) \
((CObject){ .kind = COBJECT_CMACRO, .object.c_macro = (CMACRO) })
#define COBJECT_STRUCT(STRUCT) \
((CObject){ .kind = COBJECT_CSTRUCT, .object.c_struct = STRUCT })
#define COBJECT_USERTYPE(USERTYPE) \
((CObject){ .kind = COBJECT_CUSERTYPE, .object.c_usertype = (USERTYPE) })
#define COBJECT_DATATYPE(DATATYPE) \
((CObject){ .kind = COBJECT_CDATATYPE, .object.c_datatype = (DATATYPE) })
#define COBJECT_ARG(CARG) \
((CObject){ .kind = COBJECT_CARG, .object.c_arg = (CARG) })
#define COBJECT_FUNC(CFUNC) \
((CObject){ .kind = COBJECT_CFUNC, .object.c_func = (CFUNC) })
#define COBJECT_INCULDE(CINCLUDE) \
((CObject){ .kind = COBJECT_CINCULDE, .object.c_include = (CINCLUDE) })
#define COBJECT_HEADER(CHEADER) \
((CObject){ .kind = COBJECT_CHEADER, .object.c_header = (CHEADER) })
#define COBJECT_SOURCE(CSOURCE) \
((CObject){ .kind = COBJECT_CSOURCE, .object.c_source = (CSOURCE) })
typedef enum {
CUSERTYPE_CENUM,
CUSERTYPE_CSTRUCT,
COUNT_CUSERTYPEKIND,
} CUserTypeKind;
typedef enum {
CDATATYPE_CTYPE,
CDATATYPE_CUSERTYPE,
CDATATYPE_STR,
COUNT_CDATATYPEKIND,
} CDataTypeKind;
typedef enum {
CFILE_EXT_H,
CFILE_EXT_C,
COUNT_CFILE_EXT,
} CFileExtension;
typedef enum {
C_HEADER_INCLUDE_STR,
C_HEADER_INCLUDE_HEADER,
COUNT_CHEADERINCLUDEKIND,
} CHeaderIncludeKind;
typedef enum {
COBJECT_CTYPE,
COBJECT_CQUALIFIER,
COBJECT_CPOINTERTYPE,
COBJECT_CPOINTER,
COBJECT_CENUMVAL,
COBJECT_CENUM,
COBJECT_CMACRO,
COBJECT_CSTRUCT,
COBJECT_CUSERTYPE,
COBJECT_CDATATYPE,
COBJECT_CARG,
COBJECT_CFUNC,
COBJECT_CINCULDE,
COBJECT_CHEADER,
COBJECT_CSOURCE,
COUNT_COBJECTKIND,
} CObjectKind;
typedef struct cpointer CPointer;
typedef struct cenumval CEnumVal;
typedef struct cenum CEnum;
typedef struct cmacro CMacro;
typedef struct cstruct CStruct;
typedef struct cusertype CUserType;
typedef struct cdatatype CDataType;
typedef struct carg CArg;
typedef struct cfunc CFunc;
typedef struct cheader_include CHeaderInclude;
typedef struct cinclude CInclude;
typedef struct cheader CHeader;
typedef struct csource CSource;
typedef struct cobject CObject;
struct cpointer {
CPointerType type;
CQualifier qualifier;
};
struct cenumval {
Str8 name;
i32 *value;
};
struct cenum {
Str8 name;
CEnumValList values;
b32 add_typedef;
};
struct cmacro {
Str8 name;
Str8 value;
};
struct cstruct {
Str8 name;
CArgList args;
Str8 *typedef_name;
};
struct cusertype {
CUserTypeKind kind;
union {
CEnum c_enum;
CStruct c_struct;
} type;
};
struct cdatatype {
CDataTypeKind kind;
union {
CType c_type;
CUserType c_usertype;
Str8 str;
} type;
};
struct carg {
Str8 name;
CDataType type;
CPointer pointer;
CQualifier qualifier;
b32 is_array;
};
struct cfunc {
Str8 name;
CDataType ret_type;
CArgList args;
Str8 body;
CPointer pointer;
CQualifierList qualifiers;
};
#define CFILE_ARGS \
Str8 name; \
CFileExtension extension; \
CIncludeList includes; \
CUserTypeList types; \
CFuncList funcs; \
CStructList decl_types; \
CMacroList macros; \
CMacroList c_macros; \
CMacroList cpp_macros \
struct cheader {
CFILE_ARGS;
};
struct csource {
CFILE_ARGS;
CFuncList internal_funcs;
};
struct cheader_include {
CHeaderIncludeKind kind;
union {
Str8 name;
CHeader header;
} header;
};
struct cinclude {
CHeaderInclude header;
b32 is_local;
b32 same_dir;
};
struct cobject {
CObjectKind kind;
union {
CType c_type;
CQualifier c_qualifier;
CPointerType c_pointertype;
CPointer c_pointer;
CEnumVal c_enumval;
CEnum c_enum;
CMacro c_macro;
CStruct c_struct;
CUserType c_usertype;
CDataType c_datatype;
CArg c_arg;
CFunc c_func;
CInclude c_include;
CHeader c_header;
CSource c_source;
} object;
};
void cobject_to_string(Str8 *dst, const CObject *object);
#endif // !DATATYPES_H

1526
ccodegen/dbl_list.c Normal file

File diff suppressed because it is too large Load Diff

222
ccodegen/dbl_list.h Normal file
View File

@ -0,0 +1,222 @@
// vim:fileencoding=utf-8:foldmethod=marker
#ifndef CCGEN_DBL_LIST_H
#define CCGEN_DBL_LIST_H
#include "wapp_core.h"
#include "type_enums.h"
#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#ifdef WAPP_PLATFORM_CPP
#define wapp_cenumval_list_node(ITEM_PTR) CEnumValNode{ITEM_PTR, nullptr, nullptr}
#define wapp_carg_list_node(ITEM_PTR) CArgNode{ITEM_PTR, nullptr, nullptr}
#define wapp_cqualifier_list_node(ITEM_PTR) CQualifierNode{ITEM_PTR, nullptr, nullptr}
#define wapp_cinclude_list_node(ITEM_PTR) CIncludeNode{ITEM_PTR, nullptr, nullptr}
#define wapp_cusertype_list_node(ITEM_PTR) CUserTypeNode{ITEM_PTR, nullptr, nullptr}
#define wapp_cfunc_list_node(ITEM_PTR) CFuncNode{ITEM_PTR, nullptr, nullptr}
#define wapp_cstruct_list_node(ITEM_PTR) CStructNode{ITEM_PTR, nullptr, nullptr}
#define wapp_cmacro_list_node(ITEM_PTR) CMacroNode{ITEM_PTR, nullptr, nullptr}
#else
#define wapp_cenumval_list_node(ITEM_PTR) ((CEnumValNode){.item = ITEM_PTR})
#define wapp_carg_list_node(ITEM_PTR) ((CArgNode){.item = ITEM_PTR})
#define wapp_cqualifier_list_node(ITEM_PTR) ((CQualifierNode){.item = ITEM_PTR})
#define wapp_cinclude_list_node(ITEM_PTR) ((CIncludeNode){.item = ITEM_PTR})
#define wapp_cusertype_list_node(ITEM_PTR) ((CUserTypeNode){.item = ITEM_PTR})
#define wapp_cfunc_list_node(ITEM_PTR) ((CFuncNode){.item = ITEM_PTR})
#define wapp_cstruct_list_node(ITEM_PTR) ((CStructNode){.item = ITEM_PTR})
#define wapp_cmacro_list_node(ITEM_PTR) ((CMacroNode){.item = ITEM_PTR})
#endif // !WAPP_PLATFORM_CPP
typedef struct cenumval CEnumVal;
typedef struct carg CArg;
typedef struct cinclude CInclude;
typedef struct cusertype CUserType;
typedef struct cfunc CFunc;
typedef struct cstruct CStruct;
typedef struct cmacro CMacro;
typedef struct CEnumValNode CEnumValNode;
struct CEnumValNode {
CEnumVal *item;
CEnumValNode *prev;
CEnumValNode *next;
};
typedef struct CEnumValList CEnumValList;
struct CEnumValList {
CEnumValNode *first;
CEnumValNode *last;
u64 node_count;
};
typedef struct CArgNode CArgNode;
struct CArgNode {
CArg *item;
CArgNode *prev;
CArgNode *next;
};
typedef struct CArgList CArgList;
struct CArgList {
CArgNode *first;
CArgNode *last;
u64 node_count;
};
typedef struct CQualifierNode CQualifierNode;
struct CQualifierNode {
CQualifier *item;
CQualifierNode *prev;
CQualifierNode *next;
};
typedef struct CQualifierList CQualifierList;
struct CQualifierList {
CQualifierNode *first;
CQualifierNode *last;
u64 node_count;
};
typedef struct CIncludeNode CIncludeNode;
struct CIncludeNode {
CInclude *item;
CIncludeNode *prev;
CIncludeNode *next;
};
typedef struct CIncludeList CIncludeList;
struct CIncludeList {
CIncludeNode *first;
CIncludeNode *last;
u64 node_count;
};
typedef struct CUserTypeNode CUserTypeNode;
struct CUserTypeNode {
CUserType *item;
CUserTypeNode *prev;
CUserTypeNode *next;
};
typedef struct CUserTypeList CUserTypeList;
struct CUserTypeList {
CUserTypeNode *first;
CUserTypeNode *last;
u64 node_count;
};
typedef struct CFuncNode CFuncNode;
struct CFuncNode {
CFunc *item;
CFuncNode *prev;
CFuncNode *next;
};
typedef struct CFuncList CFuncList;
struct CFuncList {
CFuncNode *first;
CFuncNode *last;
u64 node_count;
};
typedef struct CStructNode CStructNode;
struct CStructNode {
CStruct *item;
CStructNode *prev;
CStructNode *next;
};
typedef struct CStructList CStructList;
struct CStructList {
CStructNode *first;
CStructNode *last;
u64 node_count;
};
typedef struct CMacroNode CMacroNode;
struct CMacroNode {
CMacro *item;
CMacroNode *prev;
CMacroNode *next;
};
typedef struct CMacroList CMacroList;
struct CMacroList {
CMacroNode *first;
CMacroNode *last;
u64 node_count;
};
CEnumValNode *wapp_cenumval_list_get(const CEnumValList *list, u64 index);
void wapp_cenumval_list_push_front(CEnumValList *list, CEnumValNode *node);
void wapp_cenumval_list_push_back(CEnumValList *list, CEnumValNode *node);
void wapp_cenumval_list_insert(CEnumValList *list, CEnumValNode *node, u64 index);
CEnumValNode *wapp_cenumval_list_pop_front(CEnumValList *list);
CEnumValNode *wapp_cenumval_list_pop_back(CEnumValList *list);
CEnumValNode *wapp_cenumval_list_remove(CEnumValList *list, u64 index);
void wapp_cenumval_list_empty(CEnumValList *list);
CArgNode *wapp_carg_list_get(const CArgList *list, u64 index);
void wapp_carg_list_push_front(CArgList *list, CArgNode *node);
void wapp_carg_list_push_back(CArgList *list, CArgNode *node);
void wapp_carg_list_insert(CArgList *list, CArgNode *node, u64 index);
CArgNode *wapp_carg_list_pop_front(CArgList *list);
CArgNode *wapp_carg_list_pop_back(CArgList *list);
CArgNode *wapp_carg_list_remove(CArgList *list, u64 index);
void wapp_carg_list_empty(CArgList *list);
CQualifierNode *wapp_cqualifier_list_get(const CQualifierList *list, u64 index);
void wapp_cqualifier_list_push_front(CQualifierList *list, CQualifierNode *node);
void wapp_cqualifier_list_push_back(CQualifierList *list, CQualifierNode *node);
void wapp_cqualifier_list_insert(CQualifierList *list, CQualifierNode *node, u64 index);
CQualifierNode *wapp_cqualifier_list_pop_front(CQualifierList *list);
CQualifierNode *wapp_cqualifier_list_pop_back(CQualifierList *list);
CQualifierNode *wapp_cqualifier_list_remove(CQualifierList *list, u64 index);
void wapp_cqualifier_list_empty(CQualifierList *list);
CIncludeNode *wapp_cinclude_list_get(const CIncludeList *list, u64 index);
void wapp_cinclude_list_push_front(CIncludeList *list, CIncludeNode *node);
void wapp_cinclude_list_push_back(CIncludeList *list, CIncludeNode *node);
void wapp_cinclude_list_insert(CIncludeList *list, CIncludeNode *node, u64 index);
CIncludeNode *wapp_cinclude_list_pop_front(CIncludeList *list);
CIncludeNode *wapp_cinclude_list_pop_back(CIncludeList *list);
CIncludeNode *wapp_cinclude_list_remove(CIncludeList *list, u64 index);
void wapp_cinclude_list_empty(CIncludeList *list);
CUserTypeNode *wapp_cusertype_list_get(const CUserTypeList *list, u64 index);
void wapp_cusertype_list_push_front(CUserTypeList *list, CUserTypeNode *node);
void wapp_cusertype_list_push_back(CUserTypeList *list, CUserTypeNode *node);
void wapp_cusertype_list_insert(CUserTypeList *list, CUserTypeNode *node, u64 index);
CUserTypeNode *wapp_cusertype_list_pop_front(CUserTypeList *list);
CUserTypeNode *wapp_cusertype_list_pop_back(CUserTypeList *list);
CUserTypeNode *wapp_cusertype_list_remove(CUserTypeList *list, u64 index);
void wapp_cusertype_list_empty(CUserTypeList *list);
CFuncNode *wapp_cfunc_list_get(const CFuncList *list, u64 index);
void wapp_cfunc_list_push_front(CFuncList *list, CFuncNode *node);
void wapp_cfunc_list_push_back(CFuncList *list, CFuncNode *node);
void wapp_cfunc_list_insert(CFuncList *list, CFuncNode *node, u64 index);
CFuncNode *wapp_cfunc_list_pop_front(CFuncList *list);
CFuncNode *wapp_cfunc_list_pop_back(CFuncList *list);
CFuncNode *wapp_cfunc_list_remove(CFuncList *list, u64 index);
void wapp_cfunc_list_empty(CFuncList *list);
CStructNode *wapp_cstruct_list_get(const CStructList *list, u64 index);
void wapp_cstruct_list_push_front(CStructList *list, CStructNode *node);
void wapp_cstruct_list_push_back(CStructList *list, CStructNode *node);
void wapp_cstruct_list_insert(CStructList *list, CStructNode *node, u64 index);
CStructNode *wapp_cstruct_list_pop_front(CStructList *list);
CStructNode *wapp_cstruct_list_pop_back(CStructList *list);
CStructNode *wapp_cstruct_list_remove(CStructList *list, u64 index);
void wapp_cstruct_list_empty(CStructList *list);
CMacroNode *wapp_cmacro_list_get(const CMacroList *list, u64 index);
void wapp_cmacro_list_push_front(CMacroList *list, CMacroNode *node);
void wapp_cmacro_list_push_back(CMacroList *list, CMacroNode *node);
void wapp_cmacro_list_insert(CMacroList *list, CMacroNode *node, u64 index);
CMacroNode *wapp_cmacro_list_pop_front(CMacroList *list);
CMacroNode *wapp_cmacro_list_pop_back(CMacroList *list);
CMacroNode *wapp_cmacro_list_remove(CMacroList *list, u64 index);
void wapp_cmacro_list_empty(CMacroList *list);
#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#endif // !DBL_LIST_H

7
ccodegen/main.c Normal file
View File

@ -0,0 +1,7 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include <stdio.h>
int main(void) {
return 0;
}

84
ccodegen/type_enums.h Normal file
View File

@ -0,0 +1,84 @@
// vim:fileencoding=utf-8:foldmethod=marker
#ifndef TYPE_ENUMS_H
#define TYPE_ENUMS_H
#include "wapp_core.h"
typedef enum {
CTYPE_VOID,
CTYPE_BOOL,
CTYPE_CHAR,
CTYPE_C8,
CTYPE_C16,
CTYPE_C32,
CTYPE_I8,
CTYPE_I16,
CTYPE_I32,
CTYPE_I64,
CTYPE_U8,
CTYPE_U16,
CTYPE_U32,
CTYPE_U64,
CTYPE_F32,
CTYPE_F64,
CTYPE_F128,
CTYPE_IPTR,
CTYPE_UPTR,
COUNT_CTYPE,
} CType;
internal Str8RO ctypes[COUNT_CTYPE] = {
[CTYPE_VOID] = wapp_str8_lit_ro("void"),
[CTYPE_BOOL] = wapp_str8_lit_ro("b32"),
[CTYPE_CHAR] = wapp_str8_lit_ro("char"),
[CTYPE_C8] = wapp_str8_lit_ro("c8"),
[CTYPE_C16] = wapp_str8_lit_ro("c16"),
[CTYPE_C32] = wapp_str8_lit_ro("c32"),
[CTYPE_I8] = wapp_str8_lit_ro("i8"),
[CTYPE_I16] = wapp_str8_lit_ro("i16"),
[CTYPE_I32] = wapp_str8_lit_ro("i32"),
[CTYPE_I64] = wapp_str8_lit_ro("i64"),
[CTYPE_U8] = wapp_str8_lit_ro("u8"),
[CTYPE_U16] = wapp_str8_lit_ro("u16"),
[CTYPE_U32] = wapp_str8_lit_ro("u32"),
[CTYPE_U64] = wapp_str8_lit_ro("u64"),
[CTYPE_F32] = wapp_str8_lit_ro("f32"),
[CTYPE_F64] = wapp_str8_lit_ro("f64"),
[CTYPE_F128] = wapp_str8_lit_ro("f128"),
[CTYPE_IPTR] = wapp_str8_lit_ro("iptr"),
[CTYPE_UPTR] = wapp_str8_lit_ro("uptr"),
};
typedef enum {
CQUALIFIER_NONE,
CQUALIFIER_CONST,
CQUALIFIER_EXTERNAL,
CQUALIFIER_INTERNAL,
CQUALIFIER_PERSISTENT,
COUNT_CQUALIFIER,
} CQualifier;
internal Str8RO cqualifiers[COUNT_CQUALIFIER] = {
[CQUALIFIER_NONE] = wapp_str8_lit_ro(""),
[CQUALIFIER_CONST] = wapp_str8_lit_ro("const "),
[CQUALIFIER_EXTERNAL] = wapp_str8_lit_ro("external "),
[CQUALIFIER_INTERNAL] = wapp_str8_lit_ro("internal "),
[CQUALIFIER_PERSISTENT] = wapp_str8_lit_ro("persistent "),
};
typedef enum {
CPOINTERTYPE_NONE,
CPOINTERTYPE_SINGLE,
CPOINTERTYPE_DOUBLE,
COUNT_CPOINTERTYPE,
} CPointerType;
internal Str8RO cpointertypes[COUNT_CPOINTERTYPE] = {
[CPOINTERTYPE_NONE] = wapp_str8_lit_ro(""),
[CPOINTERTYPE_SINGLE] = wapp_str8_lit_ro("*"),
[CPOINTERTYPE_DOUBLE] = wapp_str8_lit_ro("**"),
};
#endif // !TYPE_ENUMS_H