cgen, stb_truetype defines
This commit is contained in:
@@ -31,5 +31,7 @@ f32 f32_round(f32 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_roundf(x), roundf
|
||||
f64 f64_round(f64 x) { return IF_PLATFORM_CLANG_ELSE(__builtin_round(x), round(x)); }
|
||||
f64 f64_mod(f64 a, f64 b) { return IF_PLATFORM_CLANG_ELSE(__builtin_fmod(a, b), fmod(a, b)); }
|
||||
f32 f32_mod(f32 a, f32 b) { return IF_PLATFORM_CLANG_ELSE(__builtin_fmodf(a, b), fmodf(a, b)); }
|
||||
f32 f32_pow(f32 a, f32 b) { return IF_PLATFORM_CLANG_ELSE(__builtin_powf(a, b), powf(a, b)); }
|
||||
f64 f64_pow(f64 a, f64 b) { return IF_PLATFORM_CLANG_ELSE(__builtin_pow(a, b), pow(a, b)); }
|
||||
|
||||
|
||||
|
||||
@@ -352,7 +352,6 @@ fn lex_t lex_token(lexer_t *lex) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// @todo: use s8_t instead
|
||||
fn lex_array_t lex_tokens(ma_arena_t *arena, char *file_name, s8_t stream) {
|
||||
usize align = arena->align;
|
||||
arena->align = 0;
|
||||
|
||||
@@ -122,6 +122,7 @@ fn s8_t s8_printf(ma_arena_t *ma, const char *str, ...);
|
||||
|
||||
//
|
||||
// string builder
|
||||
#define sb8(ARENA) &(sb8_t){.arena = arena}
|
||||
#define sb8_serial_begin(ARENA) &(sb8_t){.arena = ARENA}
|
||||
#define sb8_serial_end(ARENA, SB) sb8_merge(ARENA, SB)
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "core/core_inc.h"
|
||||
#include "core/core_inc.c"
|
||||
#include "core/core_clexer.c"
|
||||
|
||||
void test_s8(void) {
|
||||
ma_arena_t *arena = ma_create(ma_default_reserve_size);
|
||||
|
||||
98
src/meta/cgen.c
Normal file
98
src/meta/cgen.c
Normal file
@@ -0,0 +1,98 @@
|
||||
typedef struct cg_file_t cg_file_t;
|
||||
struct cg_file_t {
|
||||
cg_file_t *next;
|
||||
s8_t path;
|
||||
s8_t content;
|
||||
lex_array_t tokens;
|
||||
};
|
||||
|
||||
typedef struct cg_files_t cg_files_t;
|
||||
struct cg_files_t {
|
||||
cg_file_t *first;
|
||||
cg_file_t *last;
|
||||
};
|
||||
|
||||
fn s8_t cg_resolve_path(ma_arena_t *arena, sb8_t *include_paths, s8_t filename, s8_t parent_file, b32 is_system_include) {
|
||||
if (OS_IsAbsolute(filename) && os_file_exists(filename)) {
|
||||
return filename;
|
||||
}
|
||||
|
||||
// 1) (QUOTED_FORM) In the same directory as the file that contains the #include statement.
|
||||
if (!is_system_include && parent_file.len) {
|
||||
s8_t path = s8_printf(arena, "%S/%S", s8_chop_last_slash(parent_file), filename);
|
||||
if (os_file_exists(path)) {
|
||||
return OS_GetAbsolutePath(&Perm, path);
|
||||
}
|
||||
}
|
||||
|
||||
// 2) (QUOTED FORM) In the directories of the currently opened include files, in the reverse order in which they were opened. The search begins in the directory of the parent include file and continues upward through the directories of any grandparent include files.
|
||||
|
||||
|
||||
// 3) (BOTH FORMS) Along the path that's specified by each /I (or INCLUDE enviroment variable) compiler option.
|
||||
for (sb8_node_t *it = include_paths->first; it; it = it->next) {
|
||||
s8_t path = s8_printf(arena, "%S/%S", it->string, filename);
|
||||
if (os_file_exists(path)) {
|
||||
return OS_GetAbsolutePath(&Perm, path);
|
||||
}
|
||||
}
|
||||
|
||||
return s8_null;
|
||||
}
|
||||
|
||||
fn cg_file_t *cg_find_file_exact(cg_files_t *root, s8_t path) {
|
||||
for (cg_file_t *it = root->first; it; it = it->next) {
|
||||
if (s8_are_equal(path, it->path)) return it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fn cg_file_t *cg_find_file(cg_files_t *root, s8_t name) {
|
||||
for (cg_file_t *it = root->first; it; it = it->next) {
|
||||
if (s8_ends_with(name, it->path, false)) return it;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fn void cg__lex_files(ma_arena_t *arena, cg_files_t *root, s8_t path, sb8_t *include_paths) {
|
||||
s8_t content = OS_ReadFile(&Perm, path);
|
||||
if (content.len == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
lex_array_t array = lex_tokens(arena, path.str, content);
|
||||
cg_file_t *file = ma_push_type(arena, cg_file_t);
|
||||
file->tokens = array;
|
||||
file->content = content;
|
||||
file->path = path;
|
||||
SLLQ_APPEND(root->first, root->last, file);
|
||||
|
||||
for (i32 i = 0; i < array.len; i += 1) {
|
||||
lex_t *token = array.data + i;
|
||||
if (token->kind != lex_kind_preproc_include) {
|
||||
continue;
|
||||
}
|
||||
|
||||
s8_t inc_path = cg_resolve_path(arena, include_paths, token->string, s8_from_char(token->file), token->system_include);
|
||||
if (inc_path.len && cg_find_file_exact(root, inc_path) == NULL) {
|
||||
// debugf("%s:%d %S, %S", token->file, token->line + 1, token->string, inc_path);
|
||||
cg__lex_files(arena, root, inc_path, include_paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn cg_files_t cg_lex_files(ma_arena_t *arena, s8_t path, sb8_t *include_paths) {
|
||||
cg_files_t files = {0};
|
||||
path = OS_GetAbsolutePath(&Perm, path);
|
||||
cg__lex_files(arena, &files, path, include_paths);
|
||||
return files;
|
||||
}
|
||||
|
||||
fn void cg_list_files_recursive(sb8_t *sb, s8_t path) {
|
||||
for (OS_FileIter iter = OS_IterateFiles(&Perm, path); OS_IsValid(iter); OS_Advance(&iter)) {
|
||||
if (iter.is_directory) {
|
||||
cg_list_files_recursive(sb, iter.absolute_path);
|
||||
} else {
|
||||
sb8_append(sb, iter.absolute_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,20 @@
|
||||
#include "app/app.c"
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#define STBTT_ifloor(x) ((int)f64_floor(x))
|
||||
#define STBTT_iceil(x) ((int)f64_ceil(x))
|
||||
#define STBTT_sqrt(x) (f64_sqrt(x))
|
||||
#define STBTT_pow(x,y) (f64_pow(x,y))
|
||||
#define STBTT_fmod(x,y) (f64_mod(x,y))
|
||||
#define STBTT_cos(x) (f64_cos(x))
|
||||
#define STBTT_acos(x) (f64_acos(x))
|
||||
#define STBTT_fabs(x) (f64_abs(x))
|
||||
#define STBTT_assert(x) (assert(x))
|
||||
#define STBTT_malloc(x,u) (ma_push_size(tcx.temp, x))
|
||||
#define STBTT_free(x,u)
|
||||
#define STBTT_strlen(x) (str_len(x))
|
||||
#define STBTT_memcpy memory_copy
|
||||
#define STBTT_memset memory_set
|
||||
#include "render/stb_truetype.h"
|
||||
#include "render/backup_font.c"
|
||||
#include "render/font.c"
|
||||
|
||||
Reference in New Issue
Block a user