lang: codegen: replace codegen_value with a new system for passing different types of values between code generators
This commit is contained in:
@@ -57,7 +57,7 @@ enum ivy_status codegen_push_generator(
|
||||
}
|
||||
|
||||
enum ivy_status codegen_pop_generator(
|
||||
struct ivy_codegen *gen, struct mie_value **result)
|
||||
struct ivy_codegen *gen, struct code_generator_value *result)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_back(&gen->c_state);
|
||||
if (!entry) {
|
||||
@@ -81,42 +81,6 @@ enum ivy_status codegen_pop_generator(
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
struct codegen_value *codegen_value_create(
|
||||
struct ivy_ast_node *node, struct mie_value *val)
|
||||
{
|
||||
struct codegen_value *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->v_node = node;
|
||||
out->v_value = val;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void codegen_value_destroy(struct codegen_value *val)
|
||||
{
|
||||
free(val);
|
||||
}
|
||||
|
||||
void codegen_push_value(struct ivy_codegen *gen, struct codegen_value *value)
|
||||
{
|
||||
b_queue_push_back(&gen->c_values, &value->v_entry);
|
||||
}
|
||||
|
||||
struct codegen_value *codegen_pop_value(struct ivy_codegen *gen)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_back(&gen->c_values);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return b_unbox(struct codegen_value, entry, v_entry);
|
||||
}
|
||||
|
||||
enum ivy_status codegen_define_variable(
|
||||
struct ivy_codegen *gen, const char *ident, const struct codegen_var *var)
|
||||
{
|
||||
@@ -305,9 +269,15 @@ struct mie_module *ivy_codegen_get_current_module(struct ivy_codegen *gen)
|
||||
static enum ivy_status pop_generator_recurse(
|
||||
struct ivy_codegen *gen, size_t node_depth)
|
||||
{
|
||||
enum ivy_status status;
|
||||
|
||||
while (1) {
|
||||
struct mie_value *value = NULL;
|
||||
codegen_pop_generator(gen, &value);
|
||||
struct code_generator_value value = {0};
|
||||
status = codegen_pop_generator(gen, &value);
|
||||
if (status != IVY_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
struct code_generator_state *state
|
||||
= get_current_generator_state(gen);
|
||||
|
||||
@@ -320,7 +290,7 @@ static enum ivy_status pop_generator_recurse(
|
||||
};
|
||||
|
||||
if (state->s_gen->g_value_received) {
|
||||
state->s_gen->g_value_received(gen, state, value);
|
||||
state->s_gen->g_value_received(gen, state, &value);
|
||||
}
|
||||
|
||||
bool should_pop = ((result.r_flags & CODEGEN_R_POP_GENERATOR) != 0)
|
||||
@@ -431,11 +401,18 @@ enum ivy_status ivy_codegen_push_node(
|
||||
|
||||
enum ivy_status ivy_codegen_push_eof(struct ivy_codegen *gen)
|
||||
{
|
||||
struct code_generator_result result;
|
||||
enum ivy_status status = IVY_OK;
|
||||
struct code_generator_result result = {
|
||||
.r_status = IVY_OK,
|
||||
};
|
||||
|
||||
while (!b_queue_empty(&gen->c_state)) {
|
||||
struct mie_value *value = NULL;
|
||||
codegen_pop_generator(gen, &value);
|
||||
struct code_generator_value value = {0};
|
||||
status = codegen_pop_generator(gen, &value);
|
||||
if (status != IVY_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
struct code_generator_state *state
|
||||
= get_current_generator_state(gen);
|
||||
|
||||
@@ -443,7 +420,7 @@ enum ivy_status ivy_codegen_push_eof(struct ivy_codegen *gen)
|
||||
continue;
|
||||
}
|
||||
|
||||
result = state->s_gen->g_value_received(gen, state, value);
|
||||
result = state->s_gen->g_value_received(gen, state, &value);
|
||||
|
||||
if (result.r_status != IVY_OK) {
|
||||
break;
|
||||
@@ -452,3 +429,36 @@ enum ivy_status ivy_codegen_push_eof(struct ivy_codegen *gen)
|
||||
|
||||
return result.r_status;
|
||||
}
|
||||
|
||||
struct mie_value *code_generator_value_get_mie_value(struct code_generator_value *vp)
|
||||
{
|
||||
if (vp->v_type != CODE_GENERATOR_VALUE_MIE_VALUE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return vp->v_value.mie_value;
|
||||
}
|
||||
|
||||
void code_generator_value_set_mie_value(
|
||||
struct code_generator_value *vp, struct mie_value *value)
|
||||
{
|
||||
vp->v_type = CODE_GENERATOR_VALUE_MIE_VALUE;
|
||||
vp->v_value.mie_value = value;
|
||||
}
|
||||
|
||||
extern struct mie_phi_edge *code_generator_value_get_phi_edge(
|
||||
struct code_generator_value *vp)
|
||||
{
|
||||
if (vp->v_type != CODE_GENERATOR_VALUE_PHI_EDGE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return vp->v_value.phi_edge;
|
||||
}
|
||||
|
||||
void code_generator_value_set_phi_edge(
|
||||
struct code_generator_value *vp, struct mie_phi_edge *edge)
|
||||
{
|
||||
vp->v_type = CODE_GENERATOR_VALUE_PHI_EDGE;
|
||||
vp->v_value.phi_edge = edge;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user