From: Brendan Hansen Date: Tue, 14 Jul 2020 15:41:57 +0000 (-0500) Subject: Added parsing of boolean not X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=e24913ee9f6f57b66110920a9164604bd16cce7f;p=onyx.git Added parsing of boolean not --- diff --git a/onyx b/onyx index 5fd9c1d9..30458373 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/basic.onyx b/progs/basic.onyx index 5b4ad454..f97d4cfd 100644 --- a/progs/basic.onyx +++ b/progs/basic.onyx @@ -6,12 +6,14 @@ pointer_test :: proc { print :: foreign "host" "print" proc (val: i32) --- -test :: proc (a: bool) -> i32 { - return 0; +test :: proc (a: bool) -> bool { + return !a; } export main :: proc { a : i32 = 0; - print(a); + cond :: true; + + print(test(cond) as i32); } diff --git a/src/onyxparser.c b/src/onyxparser.c index 6744d477..978d17b1 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -149,6 +149,21 @@ static AstTyped* parse_factor(OnyxParser* parser) { break; } + case '!': + { + AstUnaryOp* not_node = make_node(AstUnaryOp, Ast_Kind_Unary_Op); + not_node->operation = Unary_Op_Not; + not_node->base.token = expect(parser, '!'); + not_node->expr = parse_factor(parser); + + if ((not_node->expr->flags & Ast_Flag_Comptime) != 0) { + not_node->base.flags |= Ast_Flag_Comptime; + } + + retval = (AstTyped *) not_node; + break; + } + case Token_Type_Symbol: { OnyxToken* sym_token = expect(parser, Token_Type_Symbol);