lang: codegen: implement for-loop code generation
This commit is contained in:
@@ -98,6 +98,28 @@ static struct code_generator_result gen_expr(
|
||||
return CODEGEN_RESULT_OK(CODEGEN_R_REPEAT_NODE);
|
||||
}
|
||||
|
||||
static struct code_generator_result gen_for_loop(
|
||||
struct ivy_codegen *gen, struct code_generator_state *state,
|
||||
struct ivy_ast_node *node, size_t depth)
|
||||
{
|
||||
struct unit_codegen_state *unit = (struct unit_codegen_state *)state;
|
||||
struct mie_builder *builder = gen->c_builder;
|
||||
struct mie_func *current = mie_builder_get_current_func(builder);
|
||||
|
||||
enum ivy_status status = IVY_OK;
|
||||
if (!current || current != unit->s_immediate) {
|
||||
status = switch_to_immediate_func(gen, unit, ENSURE_OPEN_BLOCK);
|
||||
}
|
||||
|
||||
if (status != IVY_OK) {
|
||||
return CODEGEN_RESULT_ERR(status);
|
||||
}
|
||||
|
||||
codegen_push_generator(
|
||||
gen, CODE_GENERATOR_FOR_LOOP, CODEGEN_F_IGNORE_RESULT, NULL);
|
||||
return CODEGEN_RESULT_OK(CODEGEN_R_REPEAT_NODE);
|
||||
}
|
||||
|
||||
static void serialise_package_name(b_queue *parts, b_stringstream *out)
|
||||
{
|
||||
b_stringstream_add(out, "_ZN");
|
||||
@@ -251,6 +273,7 @@ struct code_generator unit_generator = {
|
||||
.g_state_fini = state_fini,
|
||||
.g_node_generators = {
|
||||
NODE_CODEGEN(RETURN, gen_return),
|
||||
NODE_CODEGEN(FOR_LOOP, gen_for_loop),
|
||||
NODE_CODEGEN(UNIT_PACKAGE, gen_unit_package),
|
||||
NODE_CODEGEN(UNIT_IMPORT, gen_unit_import),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user