Fix of multiple returns in macros retaining ct values. Correctly require ; after endfor etc.

This commit is contained in:
Christoffer Lerno
2022-12-06 20:09:40 +01:00
parent 5721fcc224
commit 963b8f28ef
5 changed files with 15 additions and 14 deletions

View File

@@ -939,6 +939,7 @@ static inline Ast* parse_ct_foreach_stmt(ParseContext *c)
*current = astid(stmt);
current = &stmt->next;
}
CONSUME_EOS_OR_RET(poisoned_ast);
return ast;
}
@@ -980,6 +981,7 @@ static inline Ast* parse_ct_for_stmt(ParseContext *c)
*current = astid(stmt);
current = &stmt->next;
}
CONSUME_EOS_OR_RET(poisoned_ast);
return ast;
}

View File

@@ -1528,7 +1528,7 @@ static inline Type *context_unify_returns(SemaContext *context)
if (!max)
{
SEMA_ERROR(return_stmt, "Cannot find a common parent type of %s and %s",
rtype, common_type);
type_quoted_error_string(rtype), type_quoted_error_string(common_type));
Ast *prev = context->returns[i - 1];
assert(prev);
SEMA_NOTE(prev, "The previous return was here.");
@@ -1840,20 +1840,19 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s
{
is_no_return = true;
}
if (returns_found == 1)
if (returns_found)
{
Ast *ret = macro_context.returns[0];
Expr *result = ret ? ret->return_stmt.expr : NULL;
if (result && expr_is_constant_eval(result, CONSTANT_EVAL_CONSTANT_VALUE))
if (!result) goto NOT_CT;
if (!expr_is_constant_eval(result, CONSTANT_EVAL_CONSTANT_VALUE)) goto NOT_CT;
if (ast_is_compile_time(body))
{
if (ast_is_compile_time(body))
{
expr_replace(call_expr, result);
goto EXIT;
}
expr_replace(call_expr, result);
goto EXIT;
}
}
NOT_CT:
call_expr->expr_kind = EXPR_MACRO_BLOCK;
call_expr->macro_block.first_stmt = body->compound_stmt.first_stmt;
call_expr->macro_block.params = params;

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.3.106"
#define COMPILER_VERSION "0.3.107"

View File

@@ -9,7 +9,7 @@ macro print_args($Type)
var $params = $Type.params;
$foreach ($param : $params):
io::println($param.nameof);
$endforeach
$endforeach;
}
bitstruct Bark : ulong
@@ -37,7 +37,7 @@ macro print_fields($Type)
var $params = $Type.membersof;
$foreach ($param : $params):
io::printfln("%s: %s", $param.nameof, $param.typeid.nameof);
$endforeach
$endforeach;
}
fn void hello(int a, double b, int[4] d, args...) {}

View File

@@ -9,7 +9,7 @@ macro print_args($Type)
var $params = $Type.params;
$foreach ($param : $params):
io::println($param.nameof);
$endforeach
$endforeach;
}
bitstruct Bark : ulong
@@ -37,7 +37,7 @@ macro print_fields($Type)
var $params = $Type.membersof;
$foreach ($param : $params):
io::printfln("%s: %s", $param.nameof, $param.typeid.nameof);
$endforeach
$endforeach;
}
fn void hello(int a, double b, int[4] d, args...) {}