parser+codegen: Handle function epilogue

Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
2026-02-15 23:11:52 -05:00
parent 87f0cfcdb0
commit 07db3ee834
3 changed files with 28 additions and 5 deletions

View File

@@ -13,6 +13,10 @@ resolve_func(struct rifle_state *state, struct ast_node *root)
return -1;
}
if (root->epilogue) {
return mu_gen_ret(state);
}
if ((symbol = root->symbol) == NULL) {
trace_error(state, "internal: no symbol associated with func node\n");
return -1;

View File

@@ -495,6 +495,9 @@ parse_func(struct rifle_state *state, struct token *tok, struct ast_node **res)
static int
parse_rbrace(struct rifle_state *state, struct token *tok, struct ast_node **res)
{
struct ast_node *root = NULL;
tt_t scope;
if (state == NULL || tok == NULL) {
return -1;
}
@@ -507,7 +510,21 @@ parse_rbrace(struct rifle_state *state, struct token *tok, struct ast_node **res
return -1;
}
scope_pop(state);
scope = scope_pop(state);
switch (scope) {
case TT_F:
if (ast_alloc_node(state, AST_FUNC, &root) < 0) {
trace_error(state, "failed to allocate AST_FUNC\n");
return -1;
}
root->epilogue = 1;
break;
default:
break;
}
*res = root;
return 0;
}
@@ -537,11 +554,11 @@ parse_begin(struct rifle_state *state)
utok1(state, &tok);
return -1;
}
}
if (root != NULL) {
if (cg_resolve_node(state, root) < 0)
return -1;
if (root != NULL) {
if (cg_resolve_node(state, root) < 0)
return -1;
}
}
return 0;