Compiler: Fix empty return compound codegen

This commit is contained in:
Krzosa Karol
2023-04-21 09:06:48 +02:00
parent 3207a390c8
commit 1e12f51451
5 changed files with 16 additions and 7 deletions

View File

@@ -11,6 +11,9 @@
} while (0)
global S32 global_indent;
global S32 is_inside_struct;
/*@language_refactor: Add context to typechecking and codegen, use arrays to construct stacks
instead of passing arguments to functions you use the context stacks
*/
CORE_Static void gen_ast(Ast *ast);
CORE_Static bool gen_expr(Ast_Expr *ast);
@@ -304,7 +307,6 @@ gen_pointer(Ast_Expr *expr) {
CORE_Static void
gen_try_any_or_slice(Ast_Expr *expr, Ast_Type *decl_type) {
// We want normal values to get boxed as Any pointers
// but other then that we shouldn't box other Any values
if (expr->kind != AST_COMPOUND && is_any(decl_type) && !is_any(expr->resolved_type)) {
@@ -503,6 +505,7 @@ gen_expr(Ast_Expr *ast) {
}
CASE(COMPOUND, Call) {
bool generated_anything = false;
bool is_global_variable = node->parent_scope->kind == AST_FILE;
if (!is_global_variable) {
gen("(");
@@ -514,6 +517,7 @@ gen_expr(Ast_Expr *ast) {
// We need to double wrap it because Any is a pointer
// We need to pass it a compound array
if (is_slice(node->resolved_type)) {
generated_anything = true;
gen(".len = %d, ", node->exprs.len);
gen(".data = (");
gen_simple_decl(node->resolved_type->base);
@@ -523,6 +527,7 @@ gen_expr(Ast_Expr *ast) {
}
For(node->exprs) {
generated_anything = true;
if (is_struct(node->resolved_type) || is_union(node->resolved_type))
gen(".%Q = ", it->resolved_name);
else if (is_array(node->resolved_type))
@@ -533,6 +538,7 @@ gen_expr(Ast_Expr *ast) {
}
if (is_slice(node->resolved_type)) gen("}");
if (!generated_anything) gen("0");
gen("}");
BREAK();
}