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

@@ -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, "}");