meta refactorings
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
void mt_ui(ma_arena_t *arena) {
|
||||
typedef struct cg_ui_stacks_t cg_ui_stacks_t;
|
||||
struct cg_ui_stacks_t {
|
||||
typedef struct mt_ui_stacks_t mt_ui_stacks_t;
|
||||
struct mt_ui_stacks_t {
|
||||
s8_t type;
|
||||
s8_t name;
|
||||
b32 skip_box_member;
|
||||
@@ -9,7 +9,7 @@ void mt_ui(ma_arena_t *arena) {
|
||||
s8_t node;
|
||||
};
|
||||
|
||||
cg_ui_stacks_t stacks[] = {
|
||||
mt_ui_stacks_t stacks[] = {
|
||||
{s8_lit("ui_id_t") , s8_lit("id") , .skip_box_member = true} ,
|
||||
{s8_lit("ui_lop_t") , s8_lit("lop") , .skip_box_member = true} ,
|
||||
{s8_lit("f32") , s8_lit("border_thickness")} ,
|
||||
@@ -22,7 +22,7 @@ void mt_ui(ma_arena_t *arena) {
|
||||
|
||||
///////////////////////////////
|
||||
// fill stack and node
|
||||
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
for (mt_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
s8_t core_type = it->type;
|
||||
if (s8_ends_with(core_type, s8_lit("_t"), false)) core_type = s8_chop(core_type, 2);
|
||||
it->stack = s8_printf(arena, "%S_stack", it->name);
|
||||
@@ -35,8 +35,8 @@ void mt_ui(ma_arena_t *arena) {
|
||||
|
||||
///////////////////////////////
|
||||
// generate types
|
||||
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
for (cg_ui_stacks_t *jt = it - 1; jt >= stacks; jt -= 1) if (s8_are_equal(it->type, jt->type)) goto type_already_gened;
|
||||
for (mt_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
for (mt_ui_stacks_t *jt = it - 1; jt >= stacks; jt -= 1) if (s8_are_equal(it->type, jt->type)) goto type_already_gened;
|
||||
sb8_stmtf(h_sb, "typedef struct %S %S; struct %S { %S value; %S *next; };", it->node, it->node, it->node, it->type, it->node);
|
||||
type_already_gened:;
|
||||
}
|
||||
@@ -45,33 +45,34 @@ void mt_ui(ma_arena_t *arena) {
|
||||
///////////////////////////////
|
||||
// generate field embeds
|
||||
sb8_stmtf(h_sb, "#define UI_DECL_BOX_MEMBERS \\");
|
||||
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
for (mt_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
if (it->skip_box_member) continue;
|
||||
sb8_stmtf(h_sb, "%S %S;\\", it->type, it->name);
|
||||
}
|
||||
sb8_printf(h_sb, "\n");
|
||||
|
||||
sb8_stmtf(h_sb, "#define UI_DECL_STACKS \\");
|
||||
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
for (mt_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
sb8_stmtf(h_sb, "%S *%S;\\", it->node, it->stack);
|
||||
}
|
||||
sb8_printf(h_sb, "\n");
|
||||
|
||||
///////////////////////////////
|
||||
// generate stack functions
|
||||
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
for (mt_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
sb8_stmtf(c_sb, "fn void ui_push_%S(%S v) { %S *n = ma_push_type(tcx.temp, %S); n->value = v; SLLS_PUSH(ui->%S, n); }", it->name, it->type, it->node, it->node, it->stack);
|
||||
sb8_stmtf(c_sb, "fn void ui_pop_%S(void) { SLLS_POP(ui->%S); }", it->name, it->stack);
|
||||
sb8_stmtf(c_sb, "#define ui_set_%S(x) defer_block(ui_push_%S(x), ui_pop_%S())", it->name, it->name, it->name);
|
||||
}
|
||||
|
||||
sb8_stmtf(c_sb, "fn void ui_assert_stacks_are_null(void) {");
|
||||
for (cg_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
for (mt_ui_stacks_t *it = stacks; it < stacks + lengthof(stacks); it += 1) {
|
||||
sb8_stmtf(c_sb, "assert(ui->%S == NULL);", it->stack);
|
||||
}
|
||||
sb8_stmtf(c_sb, "}");
|
||||
|
||||
|
||||
os_write_file(cg_cpath(arena), sb8_serial_end(arena, c_sb));
|
||||
os_write_file(cg_hpath(arena), sb8_serial_end(arena, h_sb));
|
||||
///////////////////////////////
|
||||
// write to disk
|
||||
os_write_file(mt_cpath(arena), sb8_serial_end(arena, c_sb));
|
||||
os_write_file(mt_hpath(arena), sb8_serial_end(arena, h_sb));
|
||||
}
|
||||
Reference in New Issue
Block a user