Skip to content

Commit

Permalink
0.5.4: Hash variables accept designated initializers. @safemacro over…
Browse files Browse the repository at this point in the history
…rides the need for `@` in macro names. Fixes to macro context evaluation. Updated allocator api. Removed install_win_reqs.bat. Deterministic @init for MacOS. Fixed temp memory issue with formatter. Support LLVM 19. Add support to compare bitstructs using == and !=. Support Windows `.def` files. Removed invalid grammar from grammar.y. Support compile time folding of &|^~ for bitstructs. `output` project setting now respected. Fix issue where constants were not properly constant folded. Add temp_push/pop. Aliased declarations caused errors when used in initializers. Fix export output. Fix of const ternary #1118. Fix of $$MODULE in nested macros #1117.
  • Loading branch information
lerno committed Feb 10, 2024
1 parent f6599c5 commit 4cf57bc
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- Aliased consts used as constant initializers caused errors.
- Exported module names replace `::` by `_`.
- Const ternary would evaluate incorrectly for ?:
- `$$MODULE` would report the incorrect module name in macros.

### Stdlib changes
- Deprecated `Allocator` helper functions.
Expand Down
1 change: 1 addition & 0 deletions src/compiler/compiler_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,7 @@ struct SemaContext_
struct
{
uint32_t original_inline_line;
Module *original_module;
Decl **yield_params;
Ast *yield_body;
BlockExit** block_exit_ref;
Expand Down
11 changes: 10 additions & 1 deletion src/compiler/sema_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ INLINE bool sema_call_expand_arguments(SemaContext *context, CalledDecl *callee,
bool success;
SCOPE_START
new_context->original_inline_line = context->original_inline_line ? context->original_inline_line : call->span.row;
new_context->original_module = context->original_module ? context->original_module : context->core_module;
success = sema_analyse_expr_rhs(new_context, param->type, arg, true, no_match_ref);
SCOPE_END;
sema_context_destroy(&default_context);
Expand Down Expand Up @@ -1955,6 +1956,7 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s
FOREACH_END();
macro_context.macro_varargs = call_expr->call_expr.varargs;
macro_context.original_inline_line = context->original_inline_line ? context->original_inline_line : call_expr->span.row;
macro_context.original_module = context->original_module ? context->original_module : context->compilation_unit->module;
macro_context.macro_params = params;
BlockExit** block_exit_ref = CALLOCS(BlockExit*);
macro_context.block_exit_ref = block_exit_ref;
Expand Down Expand Up @@ -6825,7 +6827,14 @@ static inline bool sema_expr_analyse_compiler_const(SemaContext *context, Expr *
expr_rewrite_to_string(expr, context->compilation_unit->file->full_path);
return true;
case BUILTIN_DEF_MODULE:
expr_rewrite_to_string(expr, context->compilation_unit->module->name->module);
if (context->original_module)
{
expr_rewrite_to_string(expr, context->original_module->name->module);
}
else
{
expr_rewrite_to_string(expr, context->compilation_unit->module->name->module);
}
return true;
case BUILTIN_DEF_LINE:
if (context->original_inline_line)
Expand Down
1 change: 1 addition & 0 deletions src/compiler/sema_stmts.c
Original file line number Diff line number Diff line change
Expand Up @@ -3066,6 +3066,7 @@ bool sema_analyse_function_body(SemaContext *context, Decl *func)
FunctionPrototype *prototype = func->type->function.prototype;
assert(prototype);
context->original_inline_line = 0;
context->original_module = NULL;
context->call_env = (CallEnv) {
.current_function = func,
.kind = CALL_ENV_FUNCTION,
Expand Down
22 changes: 22 additions & 0 deletions test/unit/regression/file_line_func_module_builtins.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module test::module_a;
import std::io;

macro line() => $$LINE;
macro func() => $$FUNC;
macro mod() => $$MODULE;

macro line_indirect() => line();
macro func_indirect() => func();
macro mod_indirect() => mod();

module test @test;

fn void test_builtins()
{
assert(module_a::line() == module_a::line_indirect());
assert(module_a::line() == $$LINE);
assert(module_a::func() == module_a::func_indirect());
assert(module_a::func() == $$FUNC);
assert(module_a::mod() == module_a::mod_indirect());
assert(module_a::mod() == $$MODULE);
}

0 comments on commit 4cf57bc

Please sign in to comment.