6 Commits

24 changed files with 2722 additions and 87 deletions

View File

@@ -1,4 +1,4 @@
.PHONY: help full base os prng testing uuid all clean builddir build-test run-test install build-lib
.PHONY: help full base os prng testing uuid all clean builddir build-test run-test install build-lib ccodegen
# External variables
CC = clang
@@ -175,3 +175,6 @@ build-lib: builddir
$(CC) -c $(CSTD) $(CFLAGS) $(BUILD_FLAGS) $(LIBFLAGS) $(LIB_SRC) -o "$(OBJ_OUT)"
$(AR) r "$(LIB_OUT)" "$(OBJ_OUT)"
@rm "$(OBJ_OUT)"
ccodegen:
$(CC) $(CSTD) $(CFLAGS) $(BUILD_FLAGS) $(LIBFLAGS) -Isrc/os src/os/wapp_os.c ccodegen/*.c -o ccgen

View File

@@ -1,3 +1,3 @@
# Wizard Apprentice Standard Library
A group of utilities for C/C++ projects
A base layer for C/C++ projects

BIN
ccgen Executable file

Binary file not shown.

522
ccodegen/datatypes.c Normal file
View File

@@ -0,0 +1,522 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "datatypes.h"
#include "dbl_list.h"
#include "type_enums.h"
#include "wapp_core.h"
#define ERR_MSG "Not enough capacity in dst buffer"
#define CFILE_DISCLAIMER "/**\n" \
" * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN.\n" \
" */\n\n"
void cobject_to_string(Str8 *dst, const CObject *object) {
wapp_debug_assert(dst != NULL && object != NULL, "`allocator`, `dst` and `object` should not be NULL");
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:
cenum_to_string(dst, &(object->object.c_enum));
break;
case COBJECT_CMACRO:
cmacro_to_string(dst, &(object->object.c_macro));
break;
case COBJECT_CSTRUCT:
cstruct_to_string(dst, &(object->object.c_struct));
break;
case COBJECT_CUSERTYPE:
cusertype_to_string(dst, &(object->object.c_usertype));
break;
case COBJECT_CDATATYPE:
cdatatype_to_string(dst, &(object->object.c_datatype));
break;
case COBJECT_CARG:
carg_to_string(dst, &(object->object.c_arg));
break;
case COBJECT_CFUNC:
cfunc_to_string(dst, &(object->object.c_func));
break;
case COBJECT_CINCULDE:
cinclude_to_string(dst, &(object->object.c_include));
break;
case COBJECT_CHEADER:
cheader_to_string(dst, &(object->object.c_header));
break;
case COBJECT_CSOURCE:
csource_to_string(dst, &(object->object.c_source));
break;
default:
break;
}
}
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]);
}
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]);
}
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]);
}
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]));
}
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(CCGEN_BUF_TINY);
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));
}
void cenum_to_string(Str8 *dst, const CEnum *cenum) {
wapp_debug_assert(dst != NULL && cenum != NULL, "`dst` and `cenum` should not be NULL");
Str8 header = wapp_str8_buf(CCGEN_BUF_LARGE);
Str8 values = wapp_str8_buf(CCGEN_BUF_MAX);
Str8 footer = wapp_str8_buf(CCGEN_BUF_LARGE);
Str8 tmp = wapp_str8_buf(CCGEN_BUF_LARGE);
if (cenum->add_typedef) {
wapp_str8_copy_cstr_capped(&header, "typedef enum {\n");
wapp_str8_format(&footer, "} " WAPP_STR8_SPEC ";\n", wapp_str8_varg(cenum->name));
} else {
wapp_str8_format(&header, "enum " WAPP_STR8_SPEC " {\n", wapp_str8_varg(cenum->name));
wapp_str8_copy_cstr_capped(&footer, "};\n");
}
for (u64 i = 0; i < cenum->values.node_count; ++i) {
cenumval_to_string(&tmp, wapp_cenumval_list_get(&(cenum->values), i)->item);
// Add 4 for extra characters
wapp_runtime_assert(tmp.size + 4 <= values.capacity - values.size, ERR_MSG);
wapp_str8_concat_capped(&values, &wapp_str8_lit_ro(" "));
wapp_str8_concat_capped(&values, &tmp);
wapp_str8_concat_capped(&values, &wapp_str8_lit_ro(",\n"));
}
u64 total_size = header.size + values.size + footer.size;
wapp_runtime_assert(total_size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst,
WAPP_STR8_SPEC WAPP_STR8_SPEC WAPP_STR8_SPEC,
wapp_str8_varg(header),
wapp_str8_varg(values),
wapp_str8_varg(footer));
}
void cmacro_to_string(Str8 *dst, const CMacro *cmacro) {
wapp_debug_assert(dst != NULL && cmacro != 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));
}
void cstruct_to_string(Str8 *dst, const CStruct *cstruct) {
wapp_debug_assert(dst != NULL && cstruct != NULL, "`dst` and `cstruct` should not be NULL");
Str8 declaration = wapp_str8_buf(CCGEN_BUF_LARGE);
Str8 definition = wapp_str8_buf(CCGEN_BUF_MAX);
declare_cstruct(&declaration, cstruct);
define_cstruct(&definition, cstruct);
u64 total_size = declaration.size + definition.size;
wapp_runtime_assert(total_size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst, WAPP_STR8_SPEC WAPP_STR8_SPEC,
wapp_str8_varg(declaration), wapp_str8_varg(definition));
}
void declare_cstruct(Str8 *dst, const CStruct *cstruct) {
wapp_debug_assert(dst != NULL && cstruct != NULL, "`dst` and `cstruct` should not be NULL");
Str8 tmp = wapp_str8_buf(CCGEN_BUF_MAX);
wapp_str8_format(&tmp,
"typedef struct " WAPP_STR8_SPEC " " WAPP_STR8_SPEC ";\n",
wapp_str8_varg(cstruct->name),
wapp_str8_varg(cstruct->typedef_name.size > 0 ? cstruct->typedef_name : cstruct->name));
wapp_runtime_assert(tmp.size <= dst->capacity, ERR_MSG);
wapp_str8_copy_str8_capped(dst, &tmp);
}
void define_cstruct(Str8 *dst, const CStruct *cstruct) {
wapp_debug_assert(dst != NULL && cstruct != NULL, "`dst` and `cstruct` should not be NULL");
Str8 definition = wapp_str8_buf(CCGEN_BUF_LARGE);
Str8 args = wapp_str8_buf(CCGEN_BUF_MAX);
Str8 footer = wapp_str8_lit_ro("};\n");
Str8 tmp = wapp_str8_buf(CCGEN_BUF_MEDIUM);
wapp_str8_format(&definition, "struct " WAPP_STR8_SPEC " {\n", wapp_str8_varg(cstruct->name));
for (u64 i = 0; i < cstruct->args.node_count; ++i) {
carg_to_string(&tmp, wapp_carg_list_get(&(cstruct->args), i)->item);
// Add 4 for extra characters
wapp_runtime_assert(tmp.size + 4 <= args.capacity - args.size, ERR_MSG);
wapp_str8_concat_capped(&args, &wapp_str8_lit_ro(" "));
wapp_str8_concat_capped(&args, &tmp);
wapp_str8_concat_capped(&args, &wapp_str8_lit_ro(";\n"));
}
u64 total_size = definition.size + args.size + footer.size;
wapp_runtime_assert(total_size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst,
WAPP_STR8_SPEC WAPP_STR8_SPEC WAPP_STR8_SPEC,
wapp_str8_varg(definition),
wapp_str8_varg(args),
wapp_str8_varg(footer));
}
void cusertype_to_string(Str8 *dst, const CUserType *cusertype) {
wapp_debug_assert(dst != NULL && cusertype != NULL, "`dst` and `cusertype` should not be NULL");
switch (cusertype->kind) {
case CUSERTYPE_CENUM:
cenum_to_string(dst, &(cusertype->type.c_enum));
break;
case CUSERTYPE_CSTRUCT:
cstruct_to_string(dst, &(cusertype->type.c_struct));
break;
default:
break;
}
}
void cdatatype_to_string(Str8 *dst, const CDataType *cdatatype) {
wapp_debug_assert(dst != NULL && cdatatype != NULL, "`dst` and `cdatatype` should not be NULL");
switch (cdatatype->kind) {
case CDATATYPE_CTYPE:
ctype_to_string(dst, cdatatype->type.c_type);
break;
case CDATATYPE_CUSERTYPE:
cusertype_to_string(dst, &(cdatatype->type.c_usertype));
break;
case CDATATYPE_STR:
wapp_runtime_assert(cdatatype->type.str.size <= dst->capacity, ERR_MSG);
wapp_str8_copy_str8_capped(dst, &(cdatatype->type.str));
break;
default:
break;
}
}
void carg_to_string(Str8 *dst, const CArg *carg) {
wapp_debug_assert(dst != NULL && carg != NULL, "`dst` and `carg` should not be NULL");
Str8 qualifier = wapp_str8_buf(CCGEN_BUF_MEDIUM);
Str8 type = wapp_str8_buf(CCGEN_BUF_LARGE);
Str8 pointer = wapp_str8_buf(CCGEN_BUF_MEDIUM);
Str8 array = wapp_str8_buf(CCGEN_BUF_MEDIUM);
cqualifier_to_string(&qualifier, carg->qualifier);
cdatatype_to_string(&type, &(carg->type));
wapp_str8_concat_capped(&type, &wapp_str8_lit_ro(" "));
cpointer_to_string(&pointer, &(carg->pointer));
if (carg->is_array) { wapp_str8_copy_cstr_capped(&array, "[]"); }
u64 total_size = qualifier.size + type.size + pointer.size + array.size + carg->name.size;
wapp_runtime_assert(total_size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst, WAPP_STR8_SPEC WAPP_STR8_SPEC WAPP_STR8_SPEC WAPP_STR8_SPEC WAPP_STR8_SPEC,
wapp_str8_varg(qualifier), wapp_str8_varg(type), wapp_str8_varg(pointer),
wapp_str8_varg(carg->name), wapp_str8_varg(array));
}
void cfunc_to_string(Str8 *dst, const CFunc *cfunc) {
wapp_debug_assert(dst != NULL && cfunc != NULL, "`dst` and `cfunc` should not be NULL");
Str8 qualifiers = wapp_str8_buf(CCGEN_BUF_LARGE);
Str8 args = wapp_str8_buf(CCGEN_BUF_LARGE);
Str8 ret_type = wapp_str8_buf(CCGEN_BUF_SMALL);
Str8 pointer = wapp_str8_buf(CCGEN_BUF_SMALL);
Str8 tmp = wapp_str8_buf(CCGEN_BUF_MEDIUM);
CQualifier *qf = NULL;
CArg *arg = NULL;
for (u64 i = 0; i < cfunc->qualifiers.node_count; ++i) {
qf = wapp_cqualifier_list_get(&(cfunc->qualifiers), i)->item;
if (*qf == CQUALIFIER_NONE) { continue; }
cqualifier_to_string(&tmp, *qf);
wapp_runtime_assert(tmp.size + 1 <= qualifiers.capacity - qualifiers.size, ERR_MSG);
if (qualifiers.size > 0) { wapp_str8_concat_capped(&qualifiers, &wapp_str8_lit_ro(" ")); }
wapp_str8_concat_capped(&qualifiers, &tmp);
}
for (u64 i = 0; i < cfunc->args.node_count; ++i) {
arg = wapp_carg_list_get(&(cfunc->args), i)->item;
carg_to_string(&tmp, arg);
wapp_runtime_assert(tmp.size + 2 <= args.capacity - args.size, ERR_MSG);
wapp_str8_concat_capped(&args, &tmp);
if (i + 1 < cfunc->args.node_count) { wapp_str8_concat_capped(&args, &wapp_str8_lit_ro(", ")); }
}
cdatatype_to_string(&ret_type, &(cfunc->ret_type));
cpointer_to_string(&pointer, &(cfunc->pointer));
u64 total_size = cfunc->name.size + qualifiers.size + args.size + ret_type.size + pointer.size + 4;
wapp_runtime_assert(total_size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst,
WAPP_STR8_SPEC WAPP_STR8_SPEC " " WAPP_STR8_SPEC WAPP_STR8_SPEC "(" WAPP_STR8_SPEC ")",
wapp_str8_varg(qualifiers),
wapp_str8_varg(ret_type),
wapp_str8_varg(pointer),
wapp_str8_varg(cfunc->name),
wapp_str8_varg(args));
}
void declare_cfunc(Str8 *dst, const CFunc *cfunc) {
wapp_debug_assert(dst != NULL && cfunc != NULL, "`dst` and `cfunc` should not be NULL");
Str8 tmp = wapp_str8_buf(CCGEN_BUF_MAX);
cfunc_to_string(&tmp, cfunc);
wapp_runtime_assert(tmp.size + 2 <= dst->capacity, ERR_MSG);
wapp_str8_format(dst, WAPP_STR8_SPEC ";\n", wapp_str8_varg(tmp));
}
void define_cfunc(Str8 *dst, const CFunc *cfunc) {
wapp_debug_assert(dst != NULL && cfunc != NULL, "`dst` and `cfunc` should not be NULL");
Str8 tmp = wapp_str8_buf(CCGEN_BUF_MAX);
cfunc_to_string(&tmp, cfunc);
wapp_runtime_assert(tmp.size + cfunc->body.size + 8 <= dst->capacity, ERR_MSG);
wapp_str8_format(dst, WAPP_STR8_SPEC " {\n" WAPP_STR8_SPEC "\n}\n\n",
wapp_str8_varg(tmp), wapp_str8_varg(cfunc->body));
}
void cinclude_to_string(Str8 *dst, const CInclude *cinclude) {
wapp_debug_assert(dst != NULL && cinclude != NULL, "`dst` and `cinclude` should not be NULL");
Str8 header_str = wapp_str8_buf(CCGEN_BUF_LARGE);
if (!cheaderinclude_to_string(&header_str, &(cinclude->header))) { return; }
Str8 inc = wapp_str8_lit("#include ");
Str8 open_symbol = wapp_str8_buf(CCGEN_BUF_MIN);
Str8 close_symbol = wapp_str8_buf(CCGEN_BUF_MIN);
if (cinclude->is_local) {
wapp_str8_concat_capped(&open_symbol, &wapp_str8_lit_ro("\""));
wapp_str8_concat_capped(&close_symbol, &wapp_str8_lit_ro("\""));
if (cinclude->same_dir) { wapp_str8_concat_capped(&open_symbol, &wapp_str8_lit_ro("./")); }
} else {
wapp_str8_concat_capped(&open_symbol, &wapp_str8_lit_ro("<"));
wapp_str8_concat_capped(&close_symbol, &wapp_str8_lit_ro(">"));
}
u64 total_size = header_str.size + inc.size + open_symbol.size + close_symbol.size;
wapp_runtime_assert(total_size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst,
WAPP_STR8_SPEC WAPP_STR8_SPEC WAPP_STR8_SPEC WAPP_STR8_SPEC "\n",
wapp_str8_varg(inc),
wapp_str8_varg(open_symbol),
wapp_str8_varg(header_str),
wapp_str8_varg(close_symbol));
}
void cheader_to_string(Str8 *dst, const CHeader *cheader) {
wapp_debug_assert(dst != NULL && cheader != NULL, "`dst` and `cheader` should not be NULL");
Allocator arena = wapp_mem_arena_allocator_init(MB(64));
Str8 *output = wapp_str8_alloc_buf(&arena, KB(32));
wapp_runtime_assert(output != NULL, "Failed to allocate buffer");
Str8 header_guard_name = wapp_str8_buf(CCGEN_BUF_SMALL);
Str8 tmp = wapp_str8_buf(CCGEN_BUF_MAX);
// ADD HEADER GUARD AND START C LINKAGE
wapp_str8_to_upper(&header_guard_name, &(cheader->name));
wapp_str8_concat_capped(&header_guard_name, &wapp_str8_lit_ro("_H"));
wapp_str8_format(&tmp, "#ifndef " WAPP_STR8_SPEC "\n#define " WAPP_STR8_SPEC "\n\n"
"#ifdef WAPP_PLATFORM_CPP\nBEGIN_C_LINKAGE\n#endif // !WAPP_PLATFORM_CPP\n\n",
wapp_str8_varg(header_guard_name), wapp_str8_varg(header_guard_name));
wapp_str8_alloc_concat(&arena, output, &tmp);
for (u64 i = 0; i < cheader->includes.node_count; ++i) {
cinclude_to_string(&tmp, wapp_cinclude_list_get(&(cheader->includes), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
if (cheader->includes.node_count > 0) { wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("\n")); }
for (u64 i = 0; i < cheader->macros.node_count; ++i) {
cmacro_to_string(&tmp, wapp_cmacro_list_get(&(cheader->macros), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
if (cheader->macros.node_count > 0) { wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("\n")); }
if (cheader->cpp_macros.node_count > 0) {
wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("#ifdef WAPP_PLATFORM_CPP\n"));
for (u64 i = 0; i < cheader->cpp_macros.node_count; ++i) {
cmacro_to_string(&tmp, wapp_cmacro_list_get(&(cheader->cpp_macros), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("#else\n"));
for (u64 i = 0; i < cheader->c_macros.node_count; ++i) {
cmacro_to_string(&tmp, wapp_cmacro_list_get(&(cheader->c_macros), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("#endif // !WAPP_PLATFORM_CPP\n\n"));
}
for (u64 i = 0; i < cheader->decl_types.node_count; ++i) {
declare_cstruct(&tmp, wapp_cstruct_list_get(&(cheader->decl_types), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
if (cheader->decl_types.node_count > 0) { wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("\n")); }
for (u64 i = 0; i < cheader->types.node_count; ++i) {
cusertype_to_string(&tmp, wapp_cusertype_list_get(&(cheader->types), i)->item);
wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("\n"));
wapp_str8_alloc_concat(&arena, output, &tmp);
}
for (u64 i = 0; i < cheader->funcs.node_count; ++i) {
declare_cfunc(&tmp, wapp_cfunc_list_get(&(cheader->funcs), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
// END C LINKAGE AND CLOSE HEADER GUARD
wapp_str8_format(&tmp, "\n#ifdef WAPP_PLATFORM_CPP\nEND_C_LINKAGE\n#endif // !WAPP_PLATFORM_CPP\n\n"
"#endif // !" WAPP_STR8_SPEC "\n", wapp_str8_varg(header_guard_name));
wapp_str8_alloc_concat(&arena, output, &tmp);
wapp_runtime_assert(output->size <= dst->capacity, ERR_MSG);
wapp_str8_copy_str8_capped(dst, output);
wapp_mem_arena_allocator_destroy(&arena);
}
void csource_to_string(Str8 *dst, const CSource *csource) {
wapp_debug_assert(dst != NULL && csource != NULL, "`dst` and `csource` should not be NULL");
Allocator arena = wapp_mem_arena_allocator_init(MB(64));
Str8 *output = wapp_str8_alloc_buf(&arena, KB(32));
Str8 *internal_funcs_def = wapp_str8_alloc_buf(&arena, KB(16));
wapp_runtime_assert(output != NULL && internal_funcs_def != NULL, "Failed to allocate buffer");
Str8 tmp = wapp_str8_buf(CCGEN_BUF_MAX);
for (u64 i = 0; i < csource->includes.node_count; ++i) {
cinclude_to_string(&tmp, wapp_cinclude_list_get(&(csource->includes), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
if (csource->includes.node_count > 0) { wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("\n")); }
for (u64 i = 0; i < csource->macros.node_count; ++i) {
cmacro_to_string(&tmp, wapp_cmacro_list_get(&(csource->macros), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
if (csource->macros.node_count > 0) { wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("\n")); }
for (u64 i = 0; i < csource->decl_types.node_count; ++i) {
declare_cstruct(&tmp, wapp_cstruct_list_get(&(csource->decl_types), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
if (csource->decl_types.node_count > 0) { wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("\n")); }
for (u64 i = 0; i < csource->types.node_count; ++i) {
cusertype_to_string(&tmp, wapp_cusertype_list_get(&(csource->types), i)->item);
wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("\n"));
wapp_str8_alloc_concat(&arena, output, &tmp);
}
Str8RO _wapp_intern = wapp_str8_lit_ro("wapp_intern ");
for (u64 i = 0; i < csource->internal_funcs.node_count; ++i) {
declare_cfunc(&tmp, wapp_cfunc_list_get(&(csource->internal_funcs), i)->item);
wapp_str8_alloc_concat(&arena, output, &_internal);
wapp_str8_alloc_concat(&arena, output, &tmp);
define_cfunc(&tmp, wapp_cfunc_list_get(&(csource->internal_funcs), i)->item);
wapp_str8_alloc_concat(&arena, internal_funcs_def, &_internal);
wapp_str8_alloc_concat(&arena, internal_funcs_def, &tmp);
}
if (csource->internal_funcs.node_count > 0) { wapp_str8_alloc_concat(&arena, output, &wapp_str8_lit_ro("\n")); }
for (u64 i = 0; i < csource->funcs.node_count; ++i) {
define_cfunc(&tmp, wapp_cfunc_list_get(&(csource->funcs), i)->item);
wapp_str8_alloc_concat(&arena, output, &tmp);
}
wapp_runtime_assert(output->size + internal_funcs_def->size <= dst->capacity, ERR_MSG);
wapp_str8_copy_str8_capped(dst, output);
wapp_str8_concat_capped(dst, internal_funcs_def);
wapp_mem_arena_allocator_destroy(&arena);
}
b8 cheaderinclude_to_string(Str8 *dst, const CHeaderInclude *cheaderinclude) {
wapp_debug_assert(dst != NULL && cheaderinclude != NULL, "`dst` and `cheaderinclude` should not be NULL");
switch (cheaderinclude->kind) {
case C_HEADER_INCLUDE_STR:
wapp_runtime_assert(cheaderinclude->header.name.size <= dst->capacity, ERR_MSG);
wapp_str8_format(dst, WAPP_STR8_SPEC, wapp_str8_varg(cheaderinclude->header.name));
return true;
case C_HEADER_INCLUDE_HEADER:
// Take extension into account
wapp_runtime_assert(cheaderinclude->header.header.name.size + 2 <= dst->capacity, ERR_MSG);
wapp_str8_format(
dst,
WAPP_STR8_SPEC ".%s",
wapp_str8_varg(cheaderinclude->header.header.name),
cheaderinclude->header.header.extension == CFILE_EXT_H ? "h" : "c"
);
return true;
default:
return false;
}
return false;
}

280
ccodegen/datatypes.h Normal file
View File

@@ -0,0 +1,280 @@
// vim:fileencoding=utf-8:foldmethod=marker
#ifndef DATATYPES_H
#define DATATYPES_H
#include "wapp_core.h"
#include "dbl_list.h"
#include "type_enums.h"
#ifndef CCGEN_BUF_MIN
#define CCGEN_BUF_MIN 16
#endif // !CCGEN_BUF_MIN
#ifndef CCGEN_BUF_TINY
#define CCGEN_BUF_TINY 32
#endif // !CCGEN_BUF_TINY
#ifndef CCGEN_BUF_SMALL
#define CCGEN_BUF_SMALL 512
#endif // !CCGEN_BUF_SMALL
#ifndef CCGEN_BUF_MEDIUM
#define CCGEN_BUF_MEDIUM 1024
#endif // !CCGEN_BUF_MEDIUM
#ifndef CCGEN_BUF_LARGE
#define CCGEN_BUF_LARGE 4096
#endif // !CCGEN_BUF_LARGE
#ifndef CCGEN_BUF_MAX
#define CCGEN_BUF_MAX 8192
#endif // !CCGEN_BUF_MAX
#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;
b8 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;
b8 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;
b8 is_local;
b8 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);
void ctype_to_string(Str8 *dst, CType ctype);
void cqualifier_to_string(Str8 *dst, CQualifier cqualifier);
void cpointertype_to_string(Str8 *dst, CPointerType cpointertype);
void cpointer_to_string(Str8 *dst, const CPointer *cpointer);
void cenumval_to_string(Str8 *dst, const CEnumVal *cenumval);
void cenum_to_string(Str8 *dst, const CEnum *cenum);
void cmacro_to_string(Str8 *dst, const CMacro *cmacro);
void cstruct_to_string(Str8 *dst, const CStruct *cstruct);
void declare_cstruct(Str8 *dst, const CStruct *cstruct);
void define_cstruct(Str8 *dst, const CStruct *cstruct);
void cusertype_to_string(Str8 *dst, const CUserType *cusertype);
void cdatatype_to_string(Str8 *dst, const CDataType *cdatatype);
void carg_to_string(Str8 *dst, const CArg *carg);
void cfunc_to_string(Str8 *dst, const CFunc *cfunc);
void declare_cfunc(Str8 *dst, const CFunc *cfunc);
void define_cfunc(Str8 *dst, const CFunc *cfunc);
void cinclude_to_string(Str8 *dst, const CInclude *cinclude);
void cheader_to_string(Str8 *dst, const CHeader *cheader);
void csource_to_string(Str8 *dst, const CSource *csource);
b8 cheaderinclude_to_string(Str8 *dst, const CHeaderInclude *cheaderinclude);
#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

10
ccodegen/main.c Normal file
View File

@@ -0,0 +1,10 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "datatypes.h"
#include "type_enums.h"
#include "wapp_core.h"
#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_B8,
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;
wapp_intern Str8RO ctypes[COUNT_CTYPE] = {
[CTYPE_VOID] = wapp_str8_lit_ro("void"),
[CTYPE_B8] = wapp_str8_lit_ro("b8"),
[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;
wapp_intern Str8RO cqualifiers[COUNT_CQUALIFIER] = {
[CQUALIFIER_NONE] = wapp_str8_lit_ro(""),
[CQUALIFIER_CONST] = wapp_str8_lit_ro("const "),
[CQUALIFIER_EXTERNAL] = wapp_str8_lit_ro("wapp_extern "),
[CQUALIFIER_INTERNAL] = wapp_str8_lit_ro("wapp_intern "),
[CQUALIFIER_PERSISTENT] = wapp_str8_lit_ro("wapp_persist "),
};
typedef enum {
CPOINTERTYPE_NONE,
CPOINTERTYPE_SINGLE,
CPOINTERTYPE_DOUBLE,
COUNT_CPOINTERTYPE,
} CPointerType;
wapp_intern 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

View File

@@ -9,11 +9,10 @@
#define _offset_pointer(PTR, OFFSET) ((void *)((uptr)(PTR) + (OFFSET)))
wapp_persist inline void _array_validate(const GenericArray *array, u64 item_size);
void *_array_get(GenericArray *array, u64 index, u64 item_size) {
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
_array_validate(array, item_size);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
wapp_runtime_assert(index < array->count, "`index` is out of bounds");
return _offset_pointer(array->items, array->item_size * index);
@@ -26,7 +25,8 @@ void _array_set(GenericArray *array, u64 index, void *value, u64 item_size) {
void _array_append_capped(GenericArray *array, void *value, u64 item_size) {
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
_array_validate(array, item_size);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
if (array->count >= array->capacity) { return; }
@@ -36,8 +36,9 @@ void _array_append_capped(GenericArray *array, void *value, u64 item_size) {
void _array_extend_capped(GenericArray *dst, const GenericArray *src, u64 item_size) {
wapp_runtime_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
_array_validate(dst, item_size);
_array_validate(src, item_size);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
wapp_runtime_assert(item_size == dst->item_size && item_size == src->item_size, "Invalid item type provided");
u64 remaining_capacity = dst->capacity - dst->count;
@@ -49,8 +50,9 @@ void _array_extend_capped(GenericArray *dst, const GenericArray *src, u64 item_s
void _array_copy_capped(GenericArray *dst, const GenericArray *src, u64 item_size) {
wapp_runtime_assert(dst != NULL && src != NULL, "`dst` and `src` should not be NULL");
_array_validate(dst, item_size);
_array_validate(src, item_size);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
wapp_runtime_assert(item_size == dst->item_size && item_size == src->item_size, "Invalid item type provided");
_array_clear(dst, item_size);
u64 copy_count = src->count < dst->capacity ? src->count : dst->capacity;
@@ -60,7 +62,8 @@ void _array_copy_capped(GenericArray *dst, const GenericArray *src, u64 item_siz
GenericArray *_array_append_alloc(const Allocator *allocator, GenericArray *array, void *value, u64 item_size) {
wapp_runtime_assert(allocator != NULL && array != NULL, "`allocator` and `array` should not be NULL");
_array_validate(array, item_size);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
GenericArray *output = array;
@@ -82,8 +85,9 @@ RETURN_ARRAY_APPEND_ALLOC:
GenericArray *_array_extend_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size) {
wapp_runtime_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
_array_validate(dst, item_size);
_array_validate(src, item_size);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
wapp_runtime_assert(item_size == dst->item_size && item_size == src->item_size, "Invalid item type provided");
GenericArray *output = dst;
@@ -106,8 +110,9 @@ RETURN_ARRAY_EXTEND_ALLOC:
GenericArray *_array_copy_alloc(const Allocator *allocator, GenericArray *dst, const GenericArray *src, u64 item_size) {
wapp_runtime_assert(allocator != NULL && dst != NULL && src != NULL, "`allocator`, `dst` and `src` should not be NULL");
_array_validate(dst, item_size);
_array_validate(src, item_size);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == dst->magic, "`dst` is not a valid wapp array");
wapp_runtime_assert(WAPP_ARRAY_MAGIC == src->magic, "`src` is not a valid wapp array");
wapp_runtime_assert(item_size == dst->item_size && item_size == src->item_size, "Invalid item type provided");
GenericArray *output = dst;
@@ -128,7 +133,8 @@ RETURN_ARRAY_COPY_ALLOC:
void *_array_pop(GenericArray *array, u64 item_size) {
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
_array_validate(array, item_size);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
if (array->count == 0) { return NULL; }
@@ -140,7 +146,8 @@ void *_array_pop(GenericArray *array, u64 item_size) {
void _array_clear(GenericArray *array, u64 item_size) {
wapp_runtime_assert(array != NULL, "`array` should not be NULL");
_array_validate(array, item_size);
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
array->count = 0;
}
@@ -166,8 +173,3 @@ GenericArray *_array_alloc_capacity(const Allocator *allocator, u64 capacity, u6
RETURN_ARRAY_ALLOC:
return output;
}
wapp_persist inline void _array_validate(const GenericArray *array, u64 item_size) {
wapp_runtime_assert(WAPP_ARRAY_MAGIC == array->magic, "`array` is not a valid wapp array");
wapp_runtime_assert(item_size == array->item_size, "Invalid item type provided");
}

View File

@@ -1,5 +1,3 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "./dbl_list.h"
#include "../mem/allocator/mem_allocator.h"
#include "../../common/assert/assert.h"
@@ -7,9 +5,9 @@
#include "../../common/platform/platform.h"
#include <stddef.h>
wapp_intern inline GenericList _node_to_list(GenericNode *node, u64 item_size);
wapp_intern inline void _dbl_list_validate(const GenericList *list, u64 item_size);
wapp_intern inline void _dbl_list_node_validate(const GenericList *list, const GenericNode *node, u64 item_size);
wapp_intern GenericList _node_to_list(GenericNode *node, u64 item_size);
wapp_intern void _dbl_list_validate(const GenericList *list, u64 item_size);
wapp_intern void _dbl_list_node_validate(const GenericNode *node, u64 item_size);
GenericList *_dbl_list_alloc(const Allocator *allocator, u64 item_size) {
wapp_debug_assert(allocator != NULL, "`allocator` should not be NULL");
@@ -58,7 +56,7 @@ GenericNode *_dbl_list_get(const GenericList *list, u64 index, u64 item_size) {
void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
_dbl_list_validate(list, item_size);
_dbl_list_node_validate(list, node, item_size);
_dbl_list_node_validate(node, item_size);
GenericList node_list = _node_to_list(node, item_size);
@@ -81,7 +79,7 @@ void _dbl_list_push_front(GenericList *list, GenericNode *node, u64 item_size) {
void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
_dbl_list_validate(list, item_size);
_dbl_list_node_validate(list, node, item_size);
_dbl_list_node_validate(node, item_size);
GenericList node_list = _node_to_list(node, item_size);
@@ -104,7 +102,7 @@ void _dbl_list_push_back(GenericList *list, GenericNode *node, u64 item_size) {
void _dbl_list_insert(GenericList *list, GenericNode *node, u64 index, u64 item_size) {
wapp_debug_assert(list != NULL && node != NULL && (node->item) != NULL, "`list`, `node` and `node->item` should not be NULL");
_dbl_list_validate(list, item_size);
_dbl_list_node_validate(list, node, item_size);
_dbl_list_node_validate(node, item_size);
if (index == 0) {
_dbl_list_push_front(list, node, item_size);
@@ -145,7 +143,7 @@ GenericNode *_dbl_list_pop_front(GenericList *list, u64 item_size) {
output = list->first;
if (list->node_count == 1) {
*list = (GenericList){.magic = WAPP_DBL_LIST_MAGIC, .item_size = item_size};
*list = (GenericList){0};
goto RETURN_I32_LIST_POP_FRONT;
}
@@ -251,8 +249,7 @@ wapp_intern void _dbl_list_validate(const GenericList *list, u64 item_size) {
wapp_runtime_assert(list->item_size == item_size, "Invalid item provided");
}
wapp_intern void _dbl_list_node_validate(const GenericList *list, const GenericNode *node, u64 item_size) {
wapp_intern void _dbl_list_node_validate(const GenericNode *node, u64 item_size) {
wapp_runtime_assert(node->magic == WAPP_DBL_NODE_MAGIC, "`node` isn't a valid wapp node type");
wapp_runtime_assert(list->item_size == node->item_size, "Mismatched `list` and `node` types");
wapp_runtime_assert(node->item_size == item_size, "Invalid item provided");
}

View File

@@ -1,5 +1,3 @@
// vim:fileencoding=utf-8:foldmethod=marker
#ifndef DBL_LIST_H
#define DBL_LIST_H

View File

@@ -9,19 +9,10 @@
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP
#define KiB(SIZE) (((u64)SIZE) << 10)
#define MiB(SIZE) (((u64)SIZE) << 20)
#define GiB(SIZE) (((u64)SIZE) << 30)
#define TiB(SIZE) (((u64)SIZE) << 40)
#define PiB(SIZE) (((u64)SIZE) << 50)
#define EiB(SIZE) (((u64)SIZE) << 60)
#define KB(SIZE) (((u64)SIZE) * 1000llu)
#define MB(SIZE) (KB(SIZE) * 1000llu)
#define GB(SIZE) (MB(SIZE) * 1000llu)
#define TB(SIZE) (GB(SIZE) * 1000llu)
#define PB(SIZE) (TB(SIZE) * 1000llu)
#define EB(SIZE) (PB(SIZE) * 1000llu)
#define KB(SIZE) (SIZE * 1024ull)
#define MB(SIZE) (KB(SIZE) * 1024)
#define GB(SIZE) (MB(SIZE) * 1024)
#define TB(SIZE) (GB(SIZE) * 1024)
#define wapp_misc_utils_padding_size(SIZE) u8 reserved_padding[sizeof(void *) - ((SIZE) % sizeof(void *))]

View File

@@ -15,7 +15,7 @@
#define DEFAULT_ALIGNMENT (2 * sizeof(void *))
#endif /* ifndef DEFAULT_ALIGNMENT */
#define ARENA_MINIMUM_CAPACITY KiB(16) // Allocate minimum of 4 pages
#define ARENA_MINIMUM_CAPACITY KB(16) // Allocate minimum of 4 pages
struct arena {
u8 *buf;

View File

@@ -87,7 +87,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
goto RETURN_DIRUP;
}
Allocator tmp_arena = wapp_mem_arena_allocator_init(MiB(8));
Allocator tmp_arena = wapp_mem_arena_allocator_init(MB(8));
if (wapp_mem_allocator_invalid(&tmp_arena)) {
goto RETURN_DIRUP;
}

View File

@@ -25,7 +25,7 @@ CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_bu
return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS);
}
Allocator arena = wapp_mem_arena_allocator_init(KiB(500));
Allocator arena = wapp_mem_arena_allocator_init(KB(500));
Str8 *cmd_str = wapp_str8_join(&arena, cmd, &wapp_str8_lit_ro(" "));
if (!cmd_str) {

View File

@@ -2,7 +2,7 @@
#include "wapp.h"
#include <stdlib.h>
#define ARENA_CAPACITY KiB(16)
#define ARENA_CAPACITY KB(16)
wapp_intern Arena *arena = NULL;
wapp_intern i32 count = 20;
@@ -16,7 +16,7 @@ TestFuncResult test_arena_init(void) {
TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) {
Arena *large_arena = NULL;
u64 capacity = GiB(512);
u64 capacity = GB(512);
b8 result = wapp_mem_arena_init(&large_arena, capacity);
if (result) {
wapp_mem_arena_destroy(&large_arena);

View File

@@ -2,7 +2,7 @@
#include "wapp.h"
#include <stdlib.h>
#define ARENA_CAPACITY KiB(16)
#define ARENA_CAPACITY KB(16)
wapp_intern Arena *arena = nullptr;
wapp_intern i32 count = 20;
@@ -16,7 +16,7 @@ TestFuncResult test_arena_init(void) {
TestFuncResult test_arena_init_succeeds_when_reserving_very_large_size(void) {
Arena *large_arena = nullptr;
u64 capacity = GiB(512);
u64 capacity = GB(512);
b8 result = wapp_mem_arena_init(&large_arena, capacity);
if (result) {
wapp_mem_arena_destroy(&large_arena);

View File

@@ -145,7 +145,7 @@ TestFuncResult test_i32_array_copy_capped(void) {
TestFuncResult test_i32_array_alloc_capacity(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
u64 capacity = 32;
I32Array *array = wapp_array_alloc_capacity(i32, I32Array, &allocator, capacity);
@@ -159,7 +159,7 @@ TestFuncResult test_i32_array_alloc_capacity(void) {
TestFuncResult test_i32_array_append_alloc(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
I32Array array1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6, 7, 8);
I32Array array2 = wapp_array(i32, I32Array, 1, 2);
@@ -186,7 +186,7 @@ TestFuncResult test_i32_array_append_alloc(void) {
TestFuncResult test_i32_array_extend_alloc(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
I32Array array1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6, 7, 8);
I32Array array2 = wapp_array(i32, I32Array, 1, 2);
I32Array array3 = wapp_array(i32, I32Array, 1, 2, 3, 4);
@@ -205,7 +205,7 @@ TestFuncResult test_i32_array_extend_alloc(void) {
TestFuncResult test_i32_array_copy_alloc(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
I32Array src = wapp_array(i32, I32Array, 1, 2, 3, 4, 5);
I32Array dst1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6);
I32Array dst2 = wapp_array(i32, I32Array, 1, 2);

View File

@@ -147,7 +147,7 @@ TestFuncResult test_i32_array_copy_capped(void) {
TestFuncResult test_i32_array_alloc_capacity(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
u64 capacity = 32;
I32Array *array = wapp_array_alloc_capacity(i32, I32Array, &allocator, capacity);
@@ -161,7 +161,7 @@ TestFuncResult test_i32_array_alloc_capacity(void) {
TestFuncResult test_i32_array_append_alloc(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
I32Array array1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6, 7, 8);
I32Array array2 = wapp_array(i32, I32Array, 1, 2);
@@ -189,7 +189,7 @@ TestFuncResult test_i32_array_append_alloc(void) {
TestFuncResult test_i32_array_extend_alloc(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
I32Array array1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6, 7, 8);
I32Array array2 = wapp_array(i32, I32Array, 1, 2);
I32Array array3 = wapp_array(i32, I32Array, 1, 2, 3, 4);
@@ -208,7 +208,7 @@ TestFuncResult test_i32_array_extend_alloc(void) {
TestFuncResult test_i32_array_copy_alloc(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(MiB(4));
Allocator allocator = wapp_mem_arena_allocator_init(MB(4));
I32Array src = wapp_array(i32, I32Array, 1, 2, 3, 4, 5);
I32Array dst1 = wapp_array(i32, I32Array, 1, 2, 3, 4, 5, 6);
I32Array dst2 = wapp_array(i32, I32Array, 1, 2);

View File

@@ -81,7 +81,7 @@ TestFuncResult test_cpath_join_path(void) {
}
TestFuncResult test_cpath_dirname(void) {
Allocator arena = wapp_mem_arena_allocator_init(MiB(8));
Allocator arena = wapp_mem_arena_allocator_init(MB(8));
if (wapp_mem_allocator_invalid(&arena)) {
return wapp_tester_result(false);
}
@@ -129,7 +129,7 @@ TestFuncResult test_cpath_dirname(void) {
}
TestFuncResult test_cpath_dirup(void) {
Allocator arena = wapp_mem_arena_allocator_init(MiB(8));
Allocator arena = wapp_mem_arena_allocator_init(MB(8));
if (wapp_mem_allocator_invalid(&arena)) {
return wapp_tester_result(false);
}

View File

@@ -102,7 +102,7 @@ TestFuncResult test_cpath_join_path(void) {
}
TestFuncResult test_cpath_dirname(void) {
Allocator arena = wapp_mem_arena_allocator_init(MiB(8));
Allocator arena = wapp_mem_arena_allocator_init(MB(8));
if (wapp_mem_allocator_invalid(&arena)) {
return wapp_tester_result(false);
}
@@ -152,7 +152,7 @@ TestFuncResult test_cpath_dirname(void) {
}
TestFuncResult test_cpath_dirup(void) {
Allocator arena = wapp_mem_arena_allocator_init(MiB(8));
Allocator arena = wapp_mem_arena_allocator_init(MB(8));
if (wapp_mem_allocator_invalid(&arena)) {
return wapp_tester_result(false);
}

View File

@@ -77,7 +77,7 @@ TestFuncResult test_str8_buf(void) {
TestFuncResult test_str8_alloc_buf(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
Allocator allocator = wapp_mem_arena_allocator_init(KB(100));
if (wapp_mem_allocator_invalid(&allocator)) {
return wapp_tester_result(false);
}
@@ -105,7 +105,7 @@ TEST_ALLOC_BUF_CLEANUP:
TestFuncResult test_str8_alloc_cstr(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
Allocator allocator = wapp_mem_arena_allocator_init(KB(100));
if (wapp_mem_allocator_invalid(&allocator)) {
return wapp_tester_result(false);
}
@@ -126,7 +126,7 @@ TestFuncResult test_str8_alloc_cstr(void) {
TestFuncResult test_str8_alloc_str8(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
Allocator allocator = wapp_mem_arena_allocator_init(KB(100));
if (wapp_mem_allocator_invalid(&allocator)) {
return wapp_tester_result(false);
}
@@ -146,7 +146,7 @@ TestFuncResult test_str8_alloc_str8(void) {
TestFuncResult test_str8_alloc_substr(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
Allocator allocator = wapp_mem_arena_allocator_init(KB(100));
if (wapp_mem_allocator_invalid(&allocator)) {
return wapp_tester_result(false);
}
@@ -289,7 +289,7 @@ TestFuncResult test_str8_slice(void) {
TestFuncResult test_str8_alloc_concat(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("Hello world");
Str8 suffix1 = wapp_str8_lit(" from me.");
@@ -410,7 +410,7 @@ TestFuncResult test_str8_rfind(void) {
TestFuncResult test_str8_split(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim1 = wapp_str8_lit(" ");
@@ -467,7 +467,7 @@ TestFuncResult test_str8_split(void) {
TestFuncResult test_str8_split_with_max(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim = wapp_str8_lit(" ");
@@ -502,7 +502,7 @@ TestFuncResult test_str8_split_with_max(void) {
TestFuncResult test_str8_rsplit(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim1 = wapp_str8_lit(" ");
@@ -559,7 +559,7 @@ TestFuncResult test_str8_rsplit(void) {
TestFuncResult test_str8_rsplit_with_max(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim = wapp_str8_lit(" ");
@@ -594,7 +594,7 @@ TestFuncResult test_str8_rsplit_with_max(void) {
TestFuncResult test_str8_join(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim1 = wapp_str8_lit(" ");

View File

@@ -77,7 +77,7 @@ TestFuncResult test_str8_buf(void) {
TestFuncResult test_str8_alloc_buf(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
Allocator allocator = wapp_mem_arena_allocator_init(KB(100));
if (wapp_mem_allocator_invalid(&allocator)) {
return wapp_tester_result(false);
}
@@ -105,7 +105,7 @@ TestFuncResult test_str8_alloc_buf(void) {
TestFuncResult test_str8_alloc_cstr(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
Allocator allocator = wapp_mem_arena_allocator_init(KB(100));
if (wapp_mem_allocator_invalid(&allocator)) {
return wapp_tester_result(false);
}
@@ -126,7 +126,7 @@ TestFuncResult test_str8_alloc_cstr(void) {
TestFuncResult test_str8_alloc_str8(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
Allocator allocator = wapp_mem_arena_allocator_init(KB(100));
if (wapp_mem_allocator_invalid(&allocator)) {
return wapp_tester_result(false);
}
@@ -146,7 +146,7 @@ TestFuncResult test_str8_alloc_str8(void) {
TestFuncResult test_str8_alloc_substr(void) {
b8 result;
Allocator allocator = wapp_mem_arena_allocator_init(KiB(100));
Allocator allocator = wapp_mem_arena_allocator_init(KB(100));
if (wapp_mem_allocator_invalid(&allocator)) {
return wapp_tester_result(false);
}
@@ -289,7 +289,7 @@ TestFuncResult test_str8_slice(void) {
TestFuncResult test_str8_alloc_concat(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("Hello world");
Str8 suffix1 = wapp_str8_lit(" from me.");
@@ -410,7 +410,7 @@ TestFuncResult test_str8_rfind(void) {
TestFuncResult test_str8_split(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim1 = wapp_str8_lit(" ");
@@ -467,7 +467,7 @@ TestFuncResult test_str8_split(void) {
TestFuncResult test_str8_split_with_max(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim = wapp_str8_lit(" ");
@@ -502,7 +502,7 @@ TestFuncResult test_str8_split_with_max(void) {
TestFuncResult test_str8_rsplit(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim1 = wapp_str8_lit(" ");
@@ -559,7 +559,7 @@ TestFuncResult test_str8_rsplit(void) {
TestFuncResult test_str8_rsplit_with_max(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim = wapp_str8_lit(" ");
@@ -594,7 +594,7 @@ TestFuncResult test_str8_rsplit_with_max(void) {
TestFuncResult test_str8_join(void) {
b8 result;
Allocator arena = wapp_mem_arena_allocator_init(KiB(100));
Allocator arena = wapp_mem_arena_allocator_init(KB(100));
Str8 str = wapp_str8_lit("hello world from me");
Str8 delim1 = wapp_str8_lit(" ");