diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2024-11-25 14:05:27 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2024-11-25 14:05:27 +0100 |
commit | 5e6dddee0b116e50654ab5d6c87c5908da1b7b20 (patch) | |
tree | 101e2ffef9c445c3a852982f9a171b2a213b8d23 | |
parent | 53eed017eb1260877c15f66c2d9910f118b64d29 (diff) | |
download | bxgen-5e6dddee0b116e50654ab5d6c87c5908da1b7b20.zip |
Control flow
-rwxr-xr-x | bxgen.c | 431 |
1 files changed, 291 insertions, 140 deletions
@@ -200,6 +200,16 @@ enum { OP_F64, OP_ADD, OP_SUB, + OR_NEG, + OP_UMUL, + OP_IMUL, + OP_UDIV, + OP_IDIV, + OP_AND, + OP_OR, + OP_XOR, + OP_NOT, + OP_IF, OP_ADDRESS, OP_CALL, OP_RET, @@ -279,6 +289,10 @@ typedef struct { typedef i64 Var; typedef struct { + Var condition; +} If; + +typedef struct { Chunk_Handle vals; } Ret; @@ -302,9 +316,16 @@ typedef struct { union { Chunk_Handle lit; Var ref; - Ret ret; - Call call; - Var bin_op[2]; + struct { + i64 ctrl_previous; + i64 ctrl_index; + union { + If if_; + Ret ret; + Call call; + Var bin_op[2]; + }; + }; }; } Node; @@ -439,8 +460,8 @@ extern "C" { #endif void dispatch_assert(b8 condition, c8 *message, u32 line, c8 *file); -void dispatch_log(i32 log_level, u32 line, c8 *file, c8 *format, ...); -void dispatch_io(u16 op, i64 *id, i64 *size, void *data, void *user_data); +void dispatch_log (i32 log_level, u32 line, c8 *file, c8 *format, ...); +void dispatch_io (u16 op, i64 *id, i64 *size, void *data, void *user_data); // ================================================================ // @@ -448,48 +469,51 @@ void dispatch_io(u16 op, i64 *id, i64 *size, void *data, void *user_data); // // ================================================================ -i64 pool_add(Pool *pool, Entity data); +i64 pool_add (Pool *pool, Entity data); void pool_remove(Pool *pool, i64 entity, u16 type); -i64 node_init(Pool *pool, Node data); +i64 node_init (Pool *pool, Node data); void node_destroy(Pool *pool, i64 node); + i64 node_data_reference(Pool *pool, i64 node); -i64 node_data_array_c8(Pool *pool, i64 size, c8 *data); -i64 node_data_ptr(Pool *pool, u64 address); -i64 node_data_i32(Pool *pool, i32 value); -i64 node_data_i64(Pool *pool, i64 value); -i64 node_data_add(Pool *pool, Var x, Var y); -i64 node_data_sub(Pool *pool, Var x, Var y); -i64 node_ctrl_call(Pool *pool, i64 target_proc, i64 num_args, Var *args); -i64 node_ctrl_call_by_name(Pool *pool, i64 name_size, c8 *name, i64 num_args, Var *args); -i64 node_ctrl_ret(Pool *pool, i64 num_values, Var *values); - -i64 proc_init(Pool *pool); -void proc_destroy(Pool *pool, i64 proc); +i64 node_data_array_c8 (Pool *pool, i64 size, c8 *data); +i64 node_data_ptr (Pool *pool, u64 address); +i64 node_data_i32 (Pool *pool, i32 value); +i64 node_data_i64 (Pool *pool, i64 value); +i64 node_data_add (Pool *pool, Var x, Var y); +i64 node_data_sub (Pool *pool, Var x, Var y); + +i64 node_ctrl_call (Pool *pool, i64 previous, i64 index, i64 target_proc, i64 num_args, Var *args); +i64 node_ctrl_call_by_name(Pool *pool, i64 previous, i64 index, i64 name_size, c8 *name, i64 num_args, Var *args); +i64 node_ctrl_if (Pool *pool, i64 previous, i64 index, Var condition); +i64 node_ctrl_ret (Pool *pool, i64 previous, i64 index, i64 num_values, Var *values); + +i64 proc_initi (Pool *pool); +void proc_destroy (Pool *pool, i64 proc); void proc_set_convention(Pool *pool, i64 proc, u16 convention); -void proc_set_name(Pool *pool, i64 proc, i64 name_size, c8 *name); -void proc_node_add(Pool *pool, i64 proc, i64 node); -void proc_node_remove(Pool *pool, i64 proc, i64 node); - -i64 unit_init(Pool *pool, u16 type); -void unit_destroy(Pool *pool, i64 unit); -void unit_proc_add(Pool *pool, i64 unit, i64 proc); -void unit_proc_remove(Pool *pool, i64 unit, i64 proc); -void unit_link_add(Pool *pool, i64 unit, i64 link_unit); -void unit_link_remove(Pool *pool, i64 unit, i64 link_unit); -void unit_set_name(Pool *pool, i64 unit, i64 name_size, c8 *name); +void proc_set_name (Pool *pool, i64 proc, i64 name_size, c8 *name); +void proc_node_add (Pool *pool, i64 proc, i64 node); +void proc_node_remove (Pool *pool, i64 proc, i64 node); + +i64 unit_init (Pool *pool, u16 type); +void unit_destroy (Pool *pool, i64 unit); +void unit_proc_add (Pool *pool, i64 unit, i64 proc); +void unit_proc_remove (Pool *pool, i64 unit, i64 proc); +void unit_link_add (Pool *pool, i64 unit, i64 link_unit); +void unit_link_remove (Pool *pool, i64 unit, i64 link_unit); +void unit_set_name (Pool *pool, i64 unit, i64 name_size, c8 *name); void unit_set_entry_point(Pool *pool, i64 unit, i64 entry_point_proc); i64 unit_write_in_memory(Pool *pool, Codegen_Context *codegen, Linker_Context *linker, i64 unit, u16 format, u16 arch); -b8 unit_write(Pool *pool, i64 unit, u16 format, u16 arch, i64 io_id, void *io_user_data); +b8 unit_write (Pool *pool, i64 unit, u16 format, u16 arch, i64 io_id, void *io_user_data); -i64 io_open_read(i64 name_size, c8 *name, void *user_data); +i64 io_open_read (i64 name_size, c8 *name, void *user_data); i64 io_open_write(i64 name_size, c8 *name, void *user_data); -void io_close(i64 f, void *user_data); -b8 io_seek(i64 f, i64 offset, u16 origin, void *user_data); -i64 io_tell(i64 f, void *user_data); -i64 io_read(i64 f, i64 size, void *data, void *user_data); -i64 io_write(i64 f, i64 size, void *data, void *user_data); -void io_chmod_exe(i64 f, void *user_data); +void io_close (i64 f, void *user_data); +b8 io_seek (i64 f, i64 offset, u16 origin, void *user_data); +i64 io_tell (i64 f, void *user_data); +i64 io_read (i64 f, i64 size, void *data, void *user_data); +i64 io_write (i64 f, i64 size, void *data, void *user_data); +void io_chmod_exe (i64 f, void *user_data); // ================================================================ // @@ -504,11 +528,13 @@ i64 n_ptr(i64 proc, u64 address); i64 n_str(i64 proc, c8 *value); i64 n_i32(i64 proc, i32 value); i64 n_i64(i64 proc, i64 value); -i64 n_call(i64 proc, i64 target_proc, i64 num_args, Var *args); -i64 n_call_by_name(i64 proc, c8 *name, i64 num_args, Var *args); i64 n_add(i64 proc, Var x, Var y); i64 n_sub(i64 proc, Var x, Var y); -i64 n_ret(i64 proc, i64 num_vals, Var *vals); + +i64 n_call (i64 proc, i64 ctrl_previous, i64 ctrl_index, i64 target_proc, i64 num_args, Var *args); +i64 n_call_by_name(i64 proc, i64 ctrl_previous, i64 ctrl_index, c8 *name, i64 num_args, Var *args); +i64 n_if (i64 proc, i64 ctrl_previous, i64 ctrl_index, Var condition); +i64 n_ret (i64 proc, i64 ctrl_previous, i64 ctrl_index, i64 num_vals, Var *vals); i64 p_new(i64 unit, c8 *name); i64 p_new_entry(i64 unit); @@ -527,9 +553,9 @@ c8 * l_find(c8 *name, b8 silent); #define ARGS(...) \ (sizeof((Var[]) { __VA_ARGS__ }) / sizeof(Var)), \ (Var[]) { __VA_ARGS__ } -#define N_CALL(proc, target_proc, ...) n_call((proc), (target_proc), ARGS(__VA_ARGS__)) -#define N_CALL_BY_NAME(proc, name, ...) n_call_by_name((proc), (name), ARGS(__VA_ARGS__)) -#define N_RET(proc, ...) n_ret((proc), ARGS(__VA_ARGS__)) +#define N_CALL(proc, prev_, index_, target_proc, ...) n_call ((proc), (prev_), (index_), (target_proc), ARGS(__VA_ARGS__)) +#define N_CALL_BY_NAME(proc, prev_, index_, name, ...) n_call_by_name((proc), (prev_), (index_), (name), ARGS(__VA_ARGS__)) +#define N_RET(proc, prev_, index_, ...) n_ret ((proc), (prev_), (index_), ARGS(__VA_ARGS__)) #endif @@ -1018,9 +1044,11 @@ u16 resolve_calling_convention(Pool *pool, i64 proc) { return p->convention; } -i64 node_ctrl_call(Pool *pool, i64 target_proc, i64 num_args, Var *args) { +i64 node_ctrl_call(Pool *pool, i64 previous, i64 index, i64 target_proc, i64 num_args, Var *args) { return node_init(pool, (Node) { - .op = OP_CALL, + .op = OP_CALL, + .ctrl_previous = previous, + .ctrl_index = index, .call = { .convention = resolve_calling_convention(pool, target_proc), .target_proc = target_proc, @@ -1029,9 +1057,11 @@ i64 node_ctrl_call(Pool *pool, i64 target_proc, i64 num_args, Var *args) { }); } -i64 node_ctrl_call_by_name(Pool *pool, i64 name_size, c8 *name, i64 num_args, Var *args) { +i64 node_ctrl_call_by_name(Pool *pool, i64 previous, i64 index, i64 name_size, c8 *name, i64 num_args, Var *args) { return node_init(pool, (Node) { - .op = OP_CALL, + .op = OP_CALL, + .ctrl_previous = previous, + .ctrl_index = index, .call = { .convention = CONV_CDECL, .target_proc = UNDEFINED, @@ -1041,11 +1071,24 @@ i64 node_ctrl_call_by_name(Pool *pool, i64 name_size, c8 *name, i64 num_args, Va }); } -i64 node_ctrl_ret(Pool *pool, i64 num_values, Var *values) { +i64 node_ctrl_if(Pool *pool, i64 previous, i64 index, Var condition) { + return node_init(pool, (Node) { + .op = OP_IF, + .ctrl_previous = previous, + .ctrl_index = index, + .if_ = { + .condition = condition, + }, + }); +} + +i64 node_ctrl_ret(Pool *pool, i64 previous, i64 index, i64 num_values, Var *values) { return node_init(pool, (Node) { - .op = OP_RET, + .op = OP_RET, + .ctrl_previous = previous, + .ctrl_index = index, .ret = { - .vals = chunk_add(pool, num_values * sizeof *values, values) + .vals = chunk_add(pool, num_values * sizeof *values, values), }, }); } @@ -4698,32 +4741,38 @@ i64 n_i64(i64 proc, i64 value) { return n; } -i64 n_call(i64 proc, i64 target_proc, i64 num_args, Var *args) { - i64 n = node_ctrl_call(&g_pool, target_proc, num_args, args); +i64 n_add(i64 proc, Var x, Var y) { + i64 n = node_data_add(&g_pool, x, y); + p_add(proc, n); + return n; +} + +i64 n_sub(i64 proc, Var x, Var y) { + i64 n = node_data_sub(&g_pool, x, y); p_add(proc, n); return n; } -i64 n_call_by_name(i64 proc, c8 *name, i64 num_args, Var *args) { - i64 n = node_ctrl_call_by_name(&g_pool, str_len(name, name + MAX_STRING_SIZE), name, num_args, args); +i64 n_call(i64 proc, i64 ctrl_previous, i64 ctrl_index, i64 target_proc, i64 num_args, Var *args) { + i64 n = node_ctrl_call(&g_pool, ctrl_previous, ctrl_index, target_proc, num_args, args); p_add(proc, n); return n; } -i64 n_add(i64 proc, Var x, Var y) { - i64 n = node_data_add(&g_pool, x, y); +i64 n_call_by_name(i64 proc, i64 ctrl_previous, i64 ctrl_index, c8 *name, i64 num_args, Var *args) { + i64 n = node_ctrl_call_by_name(&g_pool, ctrl_previous, ctrl_index, str_len(name, name + MAX_STRING_SIZE), name, num_args, args); p_add(proc, n); return n; } -i64 n_sub(i64 proc, Var x, Var y) { - i64 n = node_data_sub(&g_pool, x, y); +i64 n_if(i64 proc, i64 ctrl_previous, i64 ctrl_index, Var condition) { + i64 n = node_ctrl_if(&g_pool, ctrl_previous, ctrl_index, condition); p_add(proc, n); return n; } -i64 n_ret(i64 proc, i64 num_vals, Var *vals) { - i64 n = node_ctrl_ret(&g_pool, num_vals, vals); +i64 n_ret(i64 proc, i64 ctrl_previous, i64 ctrl_index, i64 num_vals, Var *vals) { + i64 n = node_ctrl_ret(&g_pool, ctrl_previous, ctrl_index, num_vals, vals); p_add(proc, n); return n; } @@ -4901,19 +4950,21 @@ c8 *l_find(c8 *name, b8 silent) { ADD_TEST_(link_with_libc, 42, // Add the main proc. - i64 mainproc = p_new(u, "main"); + i64 p = p_new(u, "main"); { // Call puts N_CALL_BY_NAME( - mainproc, + p, + 0, 0, "puts", // proc name - n_str(mainproc, "hello sailor") // the first argument + n_str(p, "hello sailor") // the first argument ); // Return 42 N_RET( - mainproc, - n_i32(mainproc, 42) // the return value + p, + 0, 0, + n_i32(p, 42) // the return value ); } @@ -4927,162 +4978,258 @@ ADD_TEST_(link_with_libc, 42, ) ADD_TEST_(math_two_plus_two, 4, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); N_RET( - mainproc, - n_add(mainproc, n_i32(mainproc, 2), n_i32(mainproc, 2)) + p, + 0, 0, + n_add(p, n_i32(p, 2), n_i32(p, 2)) ); ) ADD_TEST_(math_sixty_nine, 69, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); N_RET( - mainproc, - n_add(mainproc, n_i32(mainproc, 27), n_i32(mainproc, 42)) + p, + 0, 0, + n_add(p, n_i32(p, 27), n_i32(p, 42)) ); ) ADD_TEST_(math_add_3, 1+2+3, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); - i64 a = n_add(mainproc, n_i32(mainproc, 1), n_i32(mainproc, 2)); - i64 b = n_i32(mainproc, 3); + i64 a = n_add(p, n_i32(p, 1), n_i32(p, 2)); + i64 b = n_i32(p, 3); N_RET( - mainproc, - n_add(mainproc, a, b) + p, + 0, 0, + n_add(p, a, b) ); ) ADD_TEST_(math_add_4a, 1+2+3+4, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); - i64 a = n_add(mainproc, n_i32(mainproc, 1), n_i32(mainproc, 2)); - i64 b = n_add(mainproc, n_i32(mainproc, 3), n_i32(mainproc, 4)); + i64 a = n_add(p, n_i32(p, 1), n_i32(p, 2)); + i64 b = n_add(p, n_i32(p, 3), n_i32(p, 4)); N_RET( - mainproc, - n_add(mainproc, a, b) + p, + 0, 0, + n_add(p, a, b) ); ) ADD_TEST_(math_add_5, 1+2+3+4+5, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); - i64 a = n_add(mainproc, n_i32(mainproc, 1), n_i32(mainproc, 2)); - i64 b = n_add(mainproc, n_i32(mainproc, 3), n_i32(mainproc, 4)); - i64 c = n_i32(mainproc, 5); - i64 a_b = n_add(mainproc, a, b); + i64 a = n_add(p, n_i32(p, 1), n_i32(p, 2)); + i64 b = n_add(p, n_i32(p, 3), n_i32(p, 4)); + i64 c = n_i32(p, 5); + i64 a_b = n_add(p, a, b); N_RET( - mainproc, - n_add(mainproc, a_b, c) + p, + 0, 0, + n_add(p, a_b, c) ); ) ADD_TEST_(math_add_6, 1+2+3+4+5+6, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); - i64 a = n_add(mainproc, n_i32(mainproc, 1), n_i32(mainproc, 2)); - i64 b = n_add(mainproc, n_i32(mainproc, 3), n_i32(mainproc, 4)); - i64 c = n_add(mainproc, n_i32(mainproc, 5), n_i32(mainproc, 6)); - i64 a_b = n_add(mainproc, a, b); + i64 a = n_add(p, n_i32(p, 1), n_i32(p, 2)); + i64 b = n_add(p, n_i32(p, 3), n_i32(p, 4)); + i64 c = n_add(p, n_i32(p, 5), n_i32(p, 6)); + i64 a_b = n_add(p, a, b); N_RET( - mainproc, - n_add(mainproc, a_b, c) + p, + 0, 0, + n_add(p, a_b, c) ); ) ADD_TEST_(math_add_7, 1+2+3+4+5+6+7, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); - i64 a = n_add(mainproc, n_i32(mainproc, 1), n_i32(mainproc, 2)); - i64 b = n_add(mainproc, n_i32(mainproc, 3), n_i32(mainproc, 4)); - i64 c = n_add(mainproc, n_i32(mainproc, 5), n_i32(mainproc, 6)); - i64 d = n_i32(mainproc, 7); - i64 a_b = n_add(mainproc, a, b); - i64 c_d = n_add(mainproc, c, d); + i64 a = n_add(p, n_i32(p, 1), n_i32(p, 2)); + i64 b = n_add(p, n_i32(p, 3), n_i32(p, 4)); + i64 c = n_add(p, n_i32(p, 5), n_i32(p, 6)); + i64 d = n_i32(p, 7); + i64 a_b = n_add(p, a, b); + i64 c_d = n_add(p, c, d); N_RET( - mainproc, - n_add(mainproc, a_b, c_d) + p, + 0, 0, + n_add(p, a_b, c_d) ); ) ADD_TEST_(math_add_4b, 5+6+7+8, - i64 mainproc = p_new_entry(u); - - i64 a = n_add(mainproc, n_i32(mainproc, 1), n_i32(mainproc, 2)); - i64 b = n_add(mainproc, n_i32(mainproc, 3), n_i32(mainproc, 4)); - i64 c = n_add(mainproc, n_i32(mainproc, 5), n_i32(mainproc, 6)); - i64 d = n_add(mainproc, n_i32(mainproc, 7), n_i32(mainproc, 8)); - i64 a_b = n_add(mainproc, a, b); - i64 c_d = n_add(mainproc, c, d); + i64 p = p_new_entry(u); + + i64 a = n_add(p, n_i32(p, 1), n_i32(p, 2)); + i64 b = n_add(p, n_i32(p, 3), n_i32(p, 4)); + i64 c = n_add(p, n_i32(p, 5), n_i32(p, 6)); + i64 d = n_add(p, n_i32(p, 7), n_i32(p, 8)); + i64 a_b = n_add(p, a, b); + i64 c_d = n_add(p, c, d); (void) a_b; N_RET( - mainproc, + p, + 0, 0, c_d ); ) ADD_TEST_(math_add_8, 1+2+3+4+5+6+7+8, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); - i64 a = n_add(mainproc, n_i32(mainproc, 1), n_i32(mainproc, 2)); - i64 b = n_add(mainproc, n_i32(mainproc, 3), n_i32(mainproc, 4)); - i64 c = n_add(mainproc, n_i32(mainproc, 5), n_i32(mainproc, 6)); - i64 d = n_add(mainproc, n_i32(mainproc, 7), n_i32(mainproc, 8)); - i64 a_b = n_add(mainproc, a, b); - i64 c_d = n_add(mainproc, c, d); + i64 a = n_add(p, n_i32(p, 1), n_i32(p, 2)); + i64 b = n_add(p, n_i32(p, 3), n_i32(p, 4)); + i64 c = n_add(p, n_i32(p, 5), n_i32(p, 6)); + i64 d = n_add(p, n_i32(p, 7), n_i32(p, 8)); + i64 a_b = n_add(p, a, b); + i64 c_d = n_add(p, c, d); N_RET( - mainproc, - n_add(mainproc, a_b, c_d) + p, + 0, 0, + n_add(p, a_b, c_d) ); ) ADD_TEST_(math_sub_3, 3-2-1, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); - i64 a = n_sub(mainproc, n_i32(mainproc, 3), n_i32(mainproc, 2)); - i64 b = n_i32(mainproc, 1); + i64 a = n_sub(p, n_i32(p, 3), n_i32(p, 2)); + i64 b = n_i32(p, 1); N_RET( - mainproc, - n_sub(mainproc, a, b) + p, + 0, 0, + n_sub(p, a, b) ); ) ADD_TEST_(math_sub_4, (4-3)-(2-1), - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); - i64 a = n_sub(mainproc, n_i32(mainproc, 4), n_i32(mainproc, 3)); - i64 b = n_sub(mainproc, n_i32(mainproc, 2), n_i32(mainproc, 1)); + i64 a = n_sub(p, n_i32(p, 4), n_i32(p, 3)); + i64 b = n_sub(p, n_i32(p, 2), n_i32(p, 1)); N_RET( - mainproc, - n_sub(mainproc, a, b) + p, + 0, 0, + n_sub(p, a, b) ); ) ADD_TEST_(math_sub_5, ((5-3)-(1-4))-2, - i64 mainproc = p_new_entry(u); + i64 p = p_new_entry(u); + + i64 a = n_sub(p, n_i32(p, 5), n_i32(p, 3)); + i64 b = n_sub(p, n_i32(p, 1), n_i32(p, 4)); + i64 c = n_i32(p, 2); + i64 a_b = n_sub(p, a, b); + + N_RET( + p, + 0, 0, + n_sub(p, a_b, c) + ); +) + +ADD_TEST_(math_sub_6, ((6-1)-(5-4))-(3-2), + i64 p = p_new_entry(u); + + i64 a = n_sub(p, n_i32(p, 6), n_i32(p, 1)); + i64 b = n_sub(p, n_i32(p, 5), n_i32(p, 4)); + i64 c = n_sub(p, n_i32(p, 3), n_i32(p, 2)); + i64 a_b = n_sub(p, a, b); + + N_RET( + p, + 0, 0, + n_sub(p, a_b, c) + ); +) + +ADD_TEST_(math_sub_7, ((7-2)-(2-3))-((4-5)-1), + i64 p = p_new_entry(u); + + i64 a = n_sub(p, n_i32(p, 7), n_i32(p, 2)); + i64 b = n_sub(p, n_i32(p, 2), n_i32(p, 3)); + i64 c = n_sub(p, n_i32(p, 4), n_i32(p, 5)); + i64 d = n_i32(p, 1); + i64 a_b = n_sub(p, a, b); + i64 c_d = n_sub(p, c, d); + + N_RET( + p, + 0, 0, + n_sub(p, a_b, c_d) + ); +) - i64 a = n_sub(mainproc, n_i32(mainproc, 5), n_i32(mainproc, 3)); - i64 b = n_sub(mainproc, n_i32(mainproc, 1), n_i32(mainproc, 4)); - i64 c = n_i32(mainproc, 2); - i64 a_b = n_sub(mainproc, a, b); +ADD_TEST_(math_sub_8, ((8-1)-(2-3))-((4-5)-(7-6)), + i64 p = p_new_entry(u); + + i64 a = n_sub(p, n_i32(p, 8), n_i32(p, 1)); + i64 b = n_sub(p, n_i32(p, 2), n_i32(p, 3)); + i64 c = n_sub(p, n_i32(p, 4), n_i32(p, 5)); + i64 d = n_sub(p, n_i32(p, 7), n_i32(p, 6)); + i64 a_b = n_sub(p, a, b); + i64 c_d = n_sub(p, c, d); N_RET( - mainproc, - n_sub(mainproc, a_b, c) + p, + 0, 0, + n_sub(p, a_b, c_d) ); ) +ADD_TEST_(math_reg_reuse, (1+2+3+4+5+6+7+8+9+10), + i64 p = p_new_entry(u); + + i64 a = n_i32(p, 1); + i64 b = n_add(p, a, n_i32(p, 2)); + i64 c = n_add(p, b, n_i32(p, 3)); + i64 d = n_add(p, c, n_i32(p, 4)); + i64 e = n_add(p, d, n_i32(p, 5)); + i64 f = n_add(p, e, n_i32(p, 6)); + i64 g = n_add(p, f, n_i32(p, 7)); + i64 h = n_add(p, g, n_i32(p, 8)); + i64 i = n_add(p, h, n_i32(p, 9)); + i64 j = n_add(p, i, n_i32(p, 10)); + + N_RET(p, 0, 0, j); +) + +ADD_TEST_(cond_1, 1, + i64 p = p_new_entry(u); + + i64 a = n_i32(p, 1); + i64 b = n_if(p, 0, 0, a); + N_RET(p, b, 0, 1); + N_RET(p, b, 1, 2); +) + +ADD_TEST_(cond_2, 2, + i64 p = p_new_entry(u); + + i64 a = n_i32(p, 0); + i64 b = n_if(p, 0, 0, a); + N_RET(p, b, 0, 1); + N_RET(p, b, 1, 2); +) + #endif // HELPERS i32 main(i32 argc, c8 **argv) { @@ -5163,6 +5310,10 @@ i32 main(i32 argc, c8 **argv) { RUN_TEST_(math_sub_3); RUN_TEST_(math_sub_4); RUN_TEST_(math_sub_5); + RUN_TEST_(math_sub_6); + RUN_TEST_(math_sub_7); + RUN_TEST_(math_sub_8); + RUN_TEST_(math_reg_reuse); #endif #undef RUN_TEST_ |