Compiler: Fix empty return compound codegen
This commit is contained in:
@@ -9,11 +9,7 @@ Pop :: (a: *Array($T)): T
|
|||||||
if a.len > 0
|
if a.len > 0
|
||||||
a.len -= 1
|
a.len -= 1
|
||||||
return a.data[a.len]
|
return a.data[a.len]
|
||||||
// @reproduction: c compile error, probably because of compound expression (Array){}
|
return {}
|
||||||
// return {}
|
|
||||||
|
|
||||||
result: T
|
|
||||||
return result
|
|
||||||
|
|
||||||
Contains :: (a: *Array($T), item: *T): bool
|
Contains :: (a: *Array($T), item: *T): bool
|
||||||
result := item >= a.data && item < a.data + a.len
|
result := item >= a.data && item < a.data + a.len
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*@language_refactor: Remove tuples and simplify, Make var unpacking general*/
|
||||||
|
|
||||||
|
/*@language_todo: make polymorphism checking more robust*/
|
||||||
|
|
||||||
/*@language_todo: labeled block
|
/*@language_todo: labeled block
|
||||||
|
|
||||||
It acts just like a scope in C.
|
It acts just like a scope in C.
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ GetRandomUnblockedP :: (m: *Map): V2I
|
|||||||
return p
|
return p
|
||||||
|
|
||||||
Assert(false, "Invalid codepath")
|
Assert(false, "Invalid codepath")
|
||||||
r: V2I; return r
|
return {}
|
||||||
|
|
||||||
Init :: ()
|
Init :: ()
|
||||||
CurrentMap.x = WinX / RectX
|
CurrentMap.x = WinX / RectX
|
||||||
|
|||||||
@@ -11,6 +11,9 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
global S32 global_indent;
|
global S32 global_indent;
|
||||||
global S32 is_inside_struct;
|
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 void gen_ast(Ast *ast);
|
||||||
CORE_Static bool gen_expr(Ast_Expr *ast);
|
CORE_Static bool gen_expr(Ast_Expr *ast);
|
||||||
@@ -304,7 +307,6 @@ gen_pointer(Ast_Expr *expr) {
|
|||||||
|
|
||||||
CORE_Static void
|
CORE_Static void
|
||||||
gen_try_any_or_slice(Ast_Expr *expr, Ast_Type *decl_type) {
|
gen_try_any_or_slice(Ast_Expr *expr, Ast_Type *decl_type) {
|
||||||
|
|
||||||
// We want normal values to get boxed as Any pointers
|
// We want normal values to get boxed as Any pointers
|
||||||
// but other then that we shouldn't box other Any values
|
// 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)) {
|
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) {
|
CASE(COMPOUND, Call) {
|
||||||
|
bool generated_anything = false;
|
||||||
bool is_global_variable = node->parent_scope->kind == AST_FILE;
|
bool is_global_variable = node->parent_scope->kind == AST_FILE;
|
||||||
if (!is_global_variable) {
|
if (!is_global_variable) {
|
||||||
gen("(");
|
gen("(");
|
||||||
@@ -514,6 +517,7 @@ gen_expr(Ast_Expr *ast) {
|
|||||||
// We need to double wrap it because Any is a pointer
|
// We need to double wrap it because Any is a pointer
|
||||||
// We need to pass it a compound array
|
// We need to pass it a compound array
|
||||||
if (is_slice(node->resolved_type)) {
|
if (is_slice(node->resolved_type)) {
|
||||||
|
generated_anything = true;
|
||||||
gen(".len = %d, ", node->exprs.len);
|
gen(".len = %d, ", node->exprs.len);
|
||||||
gen(".data = (");
|
gen(".data = (");
|
||||||
gen_simple_decl(node->resolved_type->base);
|
gen_simple_decl(node->resolved_type->base);
|
||||||
@@ -523,6 +527,7 @@ gen_expr(Ast_Expr *ast) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
For(node->exprs) {
|
For(node->exprs) {
|
||||||
|
generated_anything = true;
|
||||||
if (is_struct(node->resolved_type) || is_union(node->resolved_type))
|
if (is_struct(node->resolved_type) || is_union(node->resolved_type))
|
||||||
gen(".%Q = ", it->resolved_name);
|
gen(".%Q = ", it->resolved_name);
|
||||||
else if (is_array(node->resolved_type))
|
else if (is_array(node->resolved_type))
|
||||||
@@ -533,6 +538,7 @@ gen_expr(Ast_Expr *ast) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_slice(node->resolved_type)) gen("}");
|
if (is_slice(node->resolved_type)) gen("}");
|
||||||
|
if (!generated_anything) gen("0");
|
||||||
gen("}");
|
gen("}");
|
||||||
BREAK();
|
BREAK();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -595,6 +595,7 @@ struct Ast_Scope : Ast {
|
|||||||
uint32_t scope_id;
|
uint32_t scope_id;
|
||||||
Ast_Scope *file; // Self referential for file and module
|
Ast_Scope *file; // Self referential for file and module
|
||||||
Ast_Module *module;
|
Ast_Module *module;
|
||||||
|
Ast_Decl *parent_decl; // @language_todo: add parent decl
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Ast_Module_State {
|
enum Ast_Module_State {
|
||||||
|
|||||||
Reference in New Issue
Block a user