improvement

This commit is contained in:
Krzosa Karol
2025-01-21 18:02:30 +01:00
parent adb30cf24d
commit 02638f80f0
6 changed files with 37 additions and 43 deletions

View File

@@ -33,7 +33,6 @@ struct sb8_t {
// WARNING: remember to update typeinfo after editing this
i32 indent;
void *user_data;
};
typedef i32 s8_seek_t;

View File

@@ -149,7 +149,6 @@ gb_read_only type_t type__sb8_t = { type_kind_struct, s8_const_lit("sb8_t"), siz
{s8_const_lit("first"), &POINTER(sb8_node_t), .offset = offsetof(sb8_t, first)},
{s8_const_lit("last"), &POINTER(sb8_node_t), .offset = offsetof(sb8_t, last)},
{s8_const_lit("indent"), &type__i32, .offset = offsetof(sb8_t, indent)},
{s8_const_lit("user_data"), &POINTER(void), .offset = offsetof(sb8_t, user_data)},
}
};

View File

@@ -29,6 +29,7 @@ struct ast_t {
ast_flag_t flags;
lex_t *pos;
ast_t *tag;
ast_t *next;
ast_t *first;
ast_t *last;

View File

@@ -1,3 +1,24 @@
/* Table format
**
** DATA:
** { windows linux macos }
** { win32 unix unix }
** { msvc gcc clang }
**
** AST (represented in key value format):
** table {
** row {
** windows { win32 }
** linux { unix }
** macos { unix }
** }
** row {
** windows { msvc }
** linux { gcc }
** macos { clang }
** }
** }
*/
fn void mtt__parse_row(parser_t *par, ast_t *parent) {
parser_match(par, lex_kind_open_brace);
while (par->at->kind != lex_kind_eof) {
@@ -26,26 +47,6 @@ fn void mtt__parse_row(parser_t *par, ast_t *parent) {
}
}
/*
** DATA:
** { windows linux macos }
** { win32 unix unix }
** { msvc gcc clang }
**
** AST (represented in key value format):
** table {
** row {
** windows { win32 }
** linux { unix }
** macos { unix }
** }
** row {
** windows { msvc }
** linux { gcc }
** macos { clang }
** }
** }
*/
fn ast_t *mtt_parse(ma_arena_t *arena, char *file, s8_t code) {
lex_array_t tokens = lex_tokens(arena, file, code);
parser_t *par = parser_make(arena, tokens.data);
@@ -105,7 +106,6 @@ fn s8_t mt_templatize_string(ma_arena_t *arena, s8_t string, lex_array_t tokens,
if (token->kind == lex_kind_tag && char_is_alphanumeric(string.str[i])) {
lex_t *ident = parser_expect(par, lex_kind_ident); i += ident->len;
sb8_append(sb, mtt_gets(n, ident->string));
} else {
sb8_append(sb, token->string);
}
@@ -132,28 +132,27 @@ fn s8_t mt_printf(ma_arena_t *arena, ast_t *n, char *str, ...) {
return result;
}
fn s8_t mt_sbprint(sb8_t *sb, s8_t string) {
assert(sb->user_data);
fn s8_t mt_sbprint(sb8_t *sb, ast_t *n, s8_t string) {
ma_temp_t scratch = ma_begin_scratch1(sb->arena);
s8_t result = mt_print(sb->arena, (ast_t *)sb->user_data, string);
s8_t result = mt_print(sb->arena, n, string);
sb8_append(sb, result);
ma_end_scratch(scratch);
return result;
}
fn s8_t mt_sbprintf(sb8_t *sb, char *str, ...) {
fn s8_t mt_sbprintf(sb8_t *sb, ast_t *n, char *str, ...) {
ma_temp_t scratch = ma_begin_scratch1(sb->arena);
S8_FMT(scratch.arena, str, string);
s8_t result = mt_sbprint(sb, string);
s8_t result = mt_sbprint(sb, n, string);
ma_end_scratch(scratch);
return result;
}
fn s8_t mt_stmtf(sb8_t *sb, char *str, ...) {
fn s8_t mt_stmtf(sb8_t *sb, ast_t *n, char *str, ...) {
sb8_indent(sb);
ma_temp_t scratch = ma_begin_scratch1(sb->arena);
S8_FMT(scratch.arena, str, string);
s8_t result = mt_sbprint(sb, string);
s8_t result = mt_sbprint(sb, n, string);
ma_end_scratch(scratch);
return result;
}

View File

@@ -41,8 +41,7 @@ void mt_ui(ma_arena_t *arena) {
if (s8_are_equal(mtts(it, "type"), mtts(prev, "type"))) goto type_already_gened;
}
h->user_data = it;
mt_stmtf(h, "typedef struct @node @node; struct @node { @type value; @node *next; };");
mt_stmtf(h, it, "typedef struct @node @node; struct @node { @type value; @node *next; };");
type_already_gened:;
}
@@ -52,31 +51,27 @@ void mt_ui(ma_arena_t *arena) {
sb8_stmtf(h, "#define UI_DECL_BOX_MEMBERS \\");
for (ast_t *it = table->first; it; it = it->next) {
if (mtt(it, "skip_box_member")->integer) continue;
h->user_data = it;
mt_stmtf(h, "@type @name;\\");
mt_stmtf(h, it, "@type @name;\\");
}
sb8_printf(h, "\n");
sb8_stmtf(h, "#define UI_DECL_STACKS \\");
for (ast_t *it = table->first; it; it = it->next) {
h->user_data = it;
mt_stmtf(h, "@node *@stack;\\");
mt_stmtf(h, it, "@node *@stack;\\");
}
sb8_printf(h, "\n");
///////////////////////////////
// generate stack functions
for (ast_t *it = table->first; it; it = it->next) {
c->user_data = it;
mt_sbprintf(c, "fn void ui_push_@name(@type v) { @node *n = ma_push_type(tcx.temp, @node); n->value = v; SLLS_PUSH(ui->@stack, n); }\n"
"fn void ui_pop_@name(void) { SLLS_POP(ui->@stack); }\n"
"#define ui_set_@name(x) defer_block(ui_push_@name(x), ui_pop_@name())\n");
mt_sbprintf(c, it, "fn void ui_push_@name(@type v) { @node *n = ma_push_type(tcx.temp, @node); n->value = v; SLLS_PUSH(ui->@stack, n); }\n"
"fn void ui_pop_@name(void) { SLLS_POP(ui->@stack); }\n"
"#define ui_set_@name(x) defer_block(ui_push_@name(x), ui_pop_@name())\n");
}
sb8_stmtf(c, "fn void ui_assert_stacks_are_null(void) {");
for (ast_t *it = table->first; it; it = it->next) {
c->user_data = it;
mt_stmtf(c, "assert(ui->@stack == NULL);");
mt_stmtf(c, it, "assert(ui->@stack == NULL);");
}
sb8_stmtf(c, "}");

View File

@@ -29,8 +29,9 @@
[ ] core
[x] remove dates and time from core
[ ] meta
[ ] prototype something like templates, readable string generation
[x] prototype something like templates, readable string generation
[ ] mt_tag syntax // f32 value; mt_tag(min = 0, min = 10) // mt_tag(something)
[ ] remove flags
[x] search for python snippets and execute meta.py script on that file
[x] simplify logging!!!!
[x] somehow index properly the meta files and ignore generated files