lang: codegen: implement for-loop code generation
This commit is contained in:
@@ -18,6 +18,24 @@
|
||||
* mie_value for its parent generator to use.
|
||||
*/
|
||||
|
||||
static struct code_generator_state *get_current_generator_state(
|
||||
struct ivy_codegen *gen)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&gen->c_state);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct code_generator_state, entry, s_entry);
|
||||
}
|
||||
|
||||
static void code_generator_state_inherit(
|
||||
struct code_generator_state *parent, struct code_generator_state *child)
|
||||
{
|
||||
child->s_loop_break_target = parent->s_loop_break_target;
|
||||
child->s_loop_repeat_target = parent->s_loop_repeat_target;
|
||||
}
|
||||
|
||||
enum ivy_status codegen_push_generator(
|
||||
struct ivy_codegen *gen, enum code_generator_type gen_type,
|
||||
uintptr_t argv, void *argp)
|
||||
@@ -42,6 +60,13 @@ enum ivy_status codegen_push_generator(
|
||||
|
||||
enum ivy_status status = IVY_OK;
|
||||
|
||||
struct code_generator_state *parent_state
|
||||
= get_current_generator_state(gen);
|
||||
|
||||
if (parent_state) {
|
||||
code_generator_state_inherit(parent_state, state);
|
||||
}
|
||||
|
||||
if (generator->g_state_init) {
|
||||
status = generator->g_state_init(gen, state, argv, argp);
|
||||
}
|
||||
@@ -111,6 +136,7 @@ enum ivy_status codegen_define_variable(
|
||||
return IVY_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
#if 0
|
||||
enum ivy_status resolve_global_variable(
|
||||
struct ivy_codegen *gen, const char *ident, struct codegen_var *out)
|
||||
{
|
||||
@@ -124,6 +150,7 @@ enum ivy_status resolve_global_variable(
|
||||
|
||||
return IVY_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
enum ivy_status codegen_resolve_variable(
|
||||
struct ivy_codegen *gen, const char *ident, struct codegen_var *out)
|
||||
@@ -153,9 +180,11 @@ enum ivy_status codegen_resolve_variable(
|
||||
entry = b_queue_prev(entry);
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (!resolved) {
|
||||
return resolve_global_variable(gen, ident, out);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (entry) {
|
||||
entry = b_queue_next(entry);
|
||||
@@ -192,15 +221,14 @@ struct mie_value *codegen_load_variable(
|
||||
return var->v_value;
|
||||
}
|
||||
|
||||
static struct code_generator_state *get_current_generator_state(
|
||||
struct ivy_codegen *gen)
|
||||
void codegen_store_variable(
|
||||
struct ivy_codegen *gen, struct codegen_var *var, struct mie_value *val)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_last(&gen->c_state);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
if (!(var->v_flags & CODEGEN_VAR_F_PTR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return b_unbox(struct code_generator_state, entry, s_entry);
|
||||
mie_builder_store(gen->c_builder, val, var->v_value);
|
||||
}
|
||||
|
||||
enum ivy_status ivy_codegen_create(struct mie_ctx *ctx, struct ivy_codegen **out)
|
||||
@@ -317,6 +345,9 @@ static bool node_is_expr(struct ivy_ast_node *node)
|
||||
case IVY_AST_DISCARD:
|
||||
case IVY_AST_INT:
|
||||
case IVY_AST_DOUBLE:
|
||||
case IVY_AST_C_TRUE:
|
||||
case IVY_AST_C_FALSE:
|
||||
case IVY_AST_C_NULL:
|
||||
case IVY_AST_STRING:
|
||||
case IVY_AST_FSTRING:
|
||||
case IVY_AST_ATOM:
|
||||
@@ -389,6 +420,10 @@ enum ivy_status ivy_codegen_push_node(
|
||||
|
||||
result = func(gen, state, node, node_depth);
|
||||
|
||||
if (result.r_status != IVY_OK) {
|
||||
return result.r_status;
|
||||
}
|
||||
|
||||
if (result.r_flags & CODEGEN_R_REPEAT_NODE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user