added 'null_proc' to builtin.onyx
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 31 Dec 2020 17:32:33 +0000 (11:32 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 31 Dec 2020 17:32:33 +0000 (11:32 -0600)
represents a procedure that matches every type; used for having a 'null' procedure when one isn't necessary

bin/onyx
core/builtin.onyx
include/onyxastnodes.h
src/onyx.c
src/onyxparser.c
src/onyxutils.c

index 9117f73bf5b83c3ee10bc304e1952eae8e6ff18b..297704e57c3bf140828b5b1e883f1fafe5bd0bc3 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 0a7df2d1dab0728787eb810e228ba3f3b587d636..9e4dbeb80f9534577123026c658345112e814c92 100644 (file)
@@ -24,7 +24,9 @@ vararg_get :: proc (va: vararg, ret: ^$T) -> bool {
     return true;
 }
 
-null :: cast(rawptr) 0;
+// HACK: NullProcHack
+null_proc :: proc () #null ---
+null      :: cast(rawptr) 0;
 
 OnyxContext :: struct {
     allocator      : Allocator;
index 578518d93af033b18100ef9aabdbd50866f7bcd4..d94d8e5ec14e8dd3b0b8f13f5ff5edc492d2d0dd 100644 (file)
@@ -197,6 +197,9 @@ typedef enum AstFlags {
     Ast_Flag_Cannot_Take_Addr      = BH_BIT(20),
 
     Ast_Flag_Struct_Mem_Used       = BH_BIT(21),
+
+    // HACK: NullProcHack
+    Ast_Flag_Proc_Is_Null          = BH_BIT(22),
 } AstFlags;
 
 typedef enum UnaryOp {
index b1e6c3627cd4c1711e0bb5df1cd7b90554a56b4a..1f743b27211dd131dabf9950a51e32dd74ef9da5 100644 (file)
@@ -517,7 +517,7 @@ static i32 onyx_compile(CompilerState* compiler_state) {
 
             if (ent.expr->token) {
                 OnyxFilePos pos = ent.expr->token->pos;
-                printf("\e[0K%s on %s:%d:%d\n", entity_state_strings[ent.state], pos.filename, pos.line, pos.column);
+                printf("\e[0K%s on %s in %s:%d:%d\n", entity_state_strings[ent.state], entity_type_strings[ent.type], pos.filename, pos.line, pos.column);
             }
         }
 
index d7633124184322b0b2252951b68520d9ea460e63..2c11b7c9eadaf538be409e4f07edf595e3430ce5 100644 (file)
@@ -1846,6 +1846,11 @@ static AstFunction* parse_function_definition(OnyxParser* parser) {
             }
         }
 
+        // HACK: NullProcHack
+        else if (parse_possible_directive(parser, "null")) {
+            func_def->flags |= Ast_Flag_Proc_Is_Null;
+        }
+
         else {
             OnyxToken* directive_token = expect_token(parser, '#');
             OnyxToken* symbol_token = expect_token(parser, Token_Type_Symbol);
index 2042a8b1728148b661cf050a6776cb9181a53602..9308525eb71f4f3d271fe2ff3aca490e6cfa526f 100644 (file)
@@ -924,6 +924,9 @@ b32 type_check_or_auto_cast(AstTyped** pnode, Type* type) {
         node = *pnode;
     }
 
+    // HACK: NullProcHack
+    if (type->kind == Type_Kind_Function && (node->flags & Ast_Flag_Proc_Is_Null) != 0) return 1;
+
     if (types_are_compatible(node->type, type)) return 1;
     if (node_is_auto_cast((AstNode *) node)) {
         // If the node is an auto cast, we convert it to a cast node which will reports errors if