lang: codegen: implement message-send code generation and global var references
This commit is contained in:
@@ -21,6 +21,7 @@ struct expr_item {
|
||||
struct expr_codegen_state {
|
||||
struct code_generator_state s_base;
|
||||
struct ivy_ast_node *s_expr_root;
|
||||
uintptr_t s_flags;
|
||||
b_queue s_item_queue;
|
||||
};
|
||||
|
||||
@@ -107,6 +108,24 @@ static struct code_generator_result gen_op(
|
||||
return CODEGEN_RESULT_OK(0);
|
||||
}
|
||||
|
||||
static struct code_generator_result gen_msg(
|
||||
struct ivy_codegen *gen, struct code_generator_state *state,
|
||||
struct ivy_ast_node *node, size_t depth)
|
||||
{
|
||||
debug_printf("codegen: got msg\n");
|
||||
struct expr_codegen_state *expr = (struct expr_codegen_state *)state;
|
||||
|
||||
int flags = 0;
|
||||
if (b_queue_empty(&expr->s_item_queue)
|
||||
&& (expr->s_flags & CODEGEN_F_IGNORE_RESULT)) {
|
||||
flags |= CODEGEN_F_IGNORE_RESULT;
|
||||
}
|
||||
|
||||
codegen_push_generator(gen, CODE_GENERATOR_MSG, flags, NULL);
|
||||
|
||||
return CODEGEN_RESULT_OK(CODEGEN_R_REPEAT_NODE);
|
||||
}
|
||||
|
||||
static struct code_generator_result gen_var_reference(
|
||||
struct ivy_codegen *gen, struct code_generator_state *state,
|
||||
struct ivy_ast_node *node, size_t depth)
|
||||
@@ -124,7 +143,8 @@ static struct code_generator_result gen_var_reference(
|
||||
var_ptr = var->v_ptr;
|
||||
} else {
|
||||
/* this is a global variable, and needs to be loaded via a data ptr */
|
||||
/* TODO */
|
||||
var_ptr = mie_builder_get_data_ptr(
|
||||
gen->c_builder, ident->n_content->t_str);
|
||||
}
|
||||
|
||||
struct mie_type *id = mie_ctx_get_type(gen->c_ctx, MIE_TYPE_ID);
|
||||
@@ -257,7 +277,8 @@ static struct code_generator_result cancel_expr(
|
||||
#endif
|
||||
|
||||
static enum ivy_status state_init(
|
||||
struct ivy_codegen *gen, struct code_generator_state *state)
|
||||
struct ivy_codegen *gen, struct code_generator_state *state,
|
||||
uintptr_t argv, void *argp)
|
||||
{
|
||||
debug_printf("codegen: start of expression\n");
|
||||
return IVY_OK;
|
||||
@@ -339,14 +360,31 @@ static enum ivy_status state_fini(
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
static struct code_generator_result value_received(
|
||||
struct ivy_codegen *gen, struct code_generator_state *state,
|
||||
struct mie_value *value)
|
||||
{
|
||||
struct expr_codegen_state *expr = (struct expr_codegen_state *)state;
|
||||
|
||||
debug_printf("codegen: got sub-expr\n");
|
||||
enum ivy_status status = push_operand(expr, NULL, value);
|
||||
if (status != IVY_OK) {
|
||||
return CODEGEN_RESULT_ERR(status);
|
||||
}
|
||||
|
||||
return CODEGEN_RESULT_OK(0);
|
||||
}
|
||||
|
||||
struct code_generator expr_generator = {
|
||||
.g_type = CODE_GENERATOR_EXPR,
|
||||
.g_state_size = sizeof(struct expr_codegen_state),
|
||||
.g_state_init = state_init,
|
||||
.g_state_fini = state_fini,
|
||||
.g_value_received = value_received,
|
||||
.g_node_generators = {
|
||||
[IVY_AST_INT] = gen_int,
|
||||
[IVY_AST_OP] = gen_op,
|
||||
[IVY_AST_IDENT] = gen_var_reference,
|
||||
NODE_CODEGEN(INT, gen_int),
|
||||
NODE_CODEGEN(OP, gen_op),
|
||||
NODE_CODEGEN(MSG, gen_msg),
|
||||
NODE_CODEGEN(IDENT, gen_var_reference),
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user