bugfix: `#callsite` did not work in macros
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 19 Apr 2023 01:13:44 +0000 (20:13 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 19 Apr 2023 01:13:44 +0000 (20:13 -0500)
compiler/include/astnodes.h
compiler/src/checker.c
core/container/optional.onyx

index b622186d5eac67270d83b3c002e0a467f5a36eac..7f2c8e10ff3178f34f063a4974c76e3180745a02 100644 (file)
@@ -1421,6 +1421,8 @@ struct AstCallSite {
     AstStrLit* filename;
     AstNumLit* line;
     AstNumLit* column;
+
+    b32 collapsed : 1;
 };
 
 // Represents a "pastable" block of code.
index 90b5e5b455ff926faff43c4738fa757f760e77e5..9d30c0775f3b8ab963b3e7d755bccc9d5d22f2e3 100644 (file)
@@ -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;
         }
     }
index d6d773e3d96613d2325169661d7fa6cc29fc84eb..35ad5d4fed52a783a89ef13bf130c891da958600 100644 (file)
@@ -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.