added binary op reduction to comparison and boolean operators
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 10 Aug 2020 20:43:29 +0000 (15:43 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 10 Aug 2020 20:43:29 +0000 (15:43 -0500)
onyx
src/onyxchecker.c
src/onyxutils.c

diff --git a/onyx b/onyx
index 0481c589a8dd8e84b14463b082c3c9af6d809eb6..1234b0255ab602b1de965ce85577d7e1c6429f09 100755 (executable)
Binary files a/onyx and b/onyx differ
index 8354c39182bf873026bd076c2473b70f060d3982..7a468ef918d87c175058de39d62719761c425c70 100644 (file)
@@ -473,6 +473,11 @@ CHECK(binaryop_compare, AstBinaryOp** pbinop) {
     }
 
     binop->type = &basic_types[Basic_Kind_Bool];
+    if (binop->flags & Ast_Flag_Comptime) {
+        // NOTE: Not a binary op
+        *pbinop = (AstBinaryOp *) ast_reduce(semstate.node_allocator, (AstTyped *) binop);
+    }
+    
     return 0;
 }
 
@@ -501,6 +506,11 @@ CHECK(binaryop_bool, AstBinaryOp** pbinop) {
     }
 
     binop->type = &basic_types[Basic_Kind_Bool];
+
+    if (binop->flags & Ast_Flag_Comptime) {
+        // NOTE: Not a binary op
+        *pbinop = (AstBinaryOp *) ast_reduce(semstate.node_allocator, (AstTyped *) binop);
+    }
     return 0;
 }
 
@@ -621,7 +631,6 @@ CHECK(binaryop, AstBinaryOp** pbinop, b32 assignment_is_ok) {
         // NOTE: Not a binary op
         *pbinop = (AstBinaryOp *) ast_reduce(semstate.node_allocator, (AstTyped *) binop);
     }
-
     return 0;
 }
 
index 72dde5fdba65d04243b41acb2a1621c2bfb55d18..9bb20b3849d7a87e68a330c4a1bba057d025f281 100644 (file)
@@ -206,9 +206,6 @@ AstNode* symbol_resolve(Scope* start_scope, OnyxToken* tkn) {
     } \
     break;
 
-
-AstTyped* ast_reduce(bh_allocator a, AstTyped* node);
-
 AstNumLit* ast_reduce_binop(bh_allocator a, AstBinaryOp* node) {
     AstNumLit* left =  (AstNumLit *) ast_reduce(a, node->left);
     AstNumLit* right = (AstNumLit *) ast_reduce(a, node->right);