From: Brendan Hansen Date: Thu, 31 Dec 2020 17:32:33 +0000 (-0600) Subject: added 'null_proc' to builtin.onyx X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=6104baddf4c1710411e48a096a092e813b00a67b;p=onyx.git added 'null_proc' to builtin.onyx represents a procedure that matches every type; used for having a 'null' procedure when one isn't necessary --- diff --git a/bin/onyx b/bin/onyx index 9117f73b..297704e5 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/builtin.onyx b/core/builtin.onyx index 0a7df2d1..9e4dbeb8 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -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; diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 578518d9..d94d8e5e 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -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 { diff --git a/src/onyx.c b/src/onyx.c index b1e6c362..1f743b27 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -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); } } diff --git a/src/onyxparser.c b/src/onyxparser.c index d7633124..2c11b7c9 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -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); diff --git a/src/onyxutils.c b/src/onyxutils.c index 2042a8b1..9308525e 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -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