Fix default #foo args.

This commit is contained in:
Christoffer Lerno
2025-01-02 15:23:14 +01:00
parent 55cdcbb39b
commit 1994cba73e
5 changed files with 10 additions and 2 deletions

View File

@@ -1724,6 +1724,7 @@ struct SemaContext_
Decl** locals;
DynamicScope active_scope;
Expr *return_expr;
bool is_temp;
};
typedef struct

View File

@@ -60,7 +60,7 @@ void gencontext_begin_module(GenContext *c)
ASSERT0(!c->module && "Expected no module");
codegen_setup_object_names(c->code_module, &c->ir_filename, &c->asm_filename, &c->object_filename);
DEBUG_LOG("Emit module %s.", c->code_module->name->module);
c->panic_var = compiler.context.panic_var;
c->panicf = compiler.context.panicf;
c->module = LLVMModuleCreateWithNameInContext(c->code_module->name->module, c->context);

View File

@@ -1362,6 +1362,12 @@ static bool sema_analyse_parameter(SemaContext *context, Expr *arg, Decl *param,
break;
case VARDECL_PARAM_EXPR:
// #foo
if (context->is_temp)
{
SemaContext *temp = context;
context = MALLOCS(SemaContext);
*context = *temp;
}
param->var.hash_var.context = context;
param->var.hash_var.span = arg->span;
break;

View File

@@ -529,6 +529,7 @@ SemaContext *context_transform_for_eval(SemaContext *context, SemaContext *temp_
temp_context->compilation_unit = context->compilation_unit;
temp_context->call_env = context->call_env;
temp_context->current_macro = context->current_macro;
temp_context->is_temp = true;
return temp_context;
}

View File

@@ -343,7 +343,7 @@ static inline void* expand_(void *vec, size_t element_size)
#define CONCAT(a, b) CONCAT_INNER(a, b)
#define FOREACH(type__, name__, vec__) \
type__* CONCAT(foreach_vec_, __LINE__) = (vec__); type__* CONCAT(foreach_vecend_, __LINE__) = CONCAT(foreach_vec_, __LINE__) + vec_size(CONCAT(foreach_vec_, __LINE__)); \
type__* CONCAT(foreach_vec_, __LINE__) = (vec__); type__* CONCAT(foreach_vecend_, __LINE__) = CONCAT(foreach_vec_, __LINE__) ? CONCAT(foreach_vec_, __LINE__) + vec_size(CONCAT(foreach_vec_, __LINE__)) : NULL; \
type__* CONCAT(foreach_it_, __LINE__) = CONCAT(foreach_vec_, __LINE__); \
for (type__ name__ ; CONCAT(foreach_it_, __LINE__) < CONCAT(foreach_vecend_, __LINE__) ? (name__ = *CONCAT(foreach_it_, __LINE__), true) : false; CONCAT(foreach_it_, __LINE__)++)