From a6ebab98676c1674b145af1118ef6e691d13f8a2 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 18 Apr 2023 20:13:44 -0500 Subject: [PATCH] bugfix: `#callsite` did not work in macros --- compiler/include/astnodes.h | 2 ++ compiler/src/checker.c | 3 +++ core/container/optional.onyx | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/compiler/include/astnodes.h b/compiler/include/astnodes.h index b622186d..7f2c8e10 100644 --- a/compiler/include/astnodes.h +++ b/compiler/include/astnodes.h @@ -1421,6 +1421,8 @@ struct AstCallSite { AstStrLit* filename; AstNumLit* line; AstNumLit* column; + + b32 collapsed : 1; }; // Represents a "pastable" block of code. diff --git a/compiler/src/checker.c b/compiler/src/checker.c index 90b5e5b4..9d30c077 100644 --- a/compiler/src/checker.c +++ b/compiler/src/checker.c @@ -722,6 +722,8 @@ CheckStatus check_call(AstCall** pcall) { if ((*arg_value)->kind == Ast_Kind_Call_Site) { AstCallSite* callsite = (AstCallSite *) ast_clone(context.ast_alloc, *arg_value); + if (callsite->collapsed) continue; + callsite->callsite_token = call->token; // HACK CLEANUP @@ -747,6 +749,7 @@ CheckStatus check_call(AstCall** pcall) { convert_numlit_to_type(callsite->line, &basic_types[Basic_Kind_U32]); convert_numlit_to_type(callsite->column, &basic_types[Basic_Kind_U32]); + callsite->collapsed = 1; *arg_value = (AstTyped *) callsite; } } diff --git a/core/container/optional.onyx b/core/container/optional.onyx index d6d773e3..35ad5d4f 100644 --- a/core/container/optional.onyx +++ b/core/container/optional.onyx @@ -29,6 +29,16 @@ package core """ empty :: macro (T: type_expr) => (?T).{}; + #doc """ + Converts a pointer to an optional by defining `null` to be `None`, + and a non-null pointer to be `Some`. This dereferences the valid + pointer to return the data stored at the pointer's address. + """ + from_ptr :: macro (p: &$T) -> ?T { + if p do return *p; + return .{}; + } + #doc """ Extracts the value from the Optional, or uses a default if no value is present. -- 2.25.1