]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
I'm in a state of confusion as to why constant folding was never done on comparisions...
authorDale Weiler <killfieldengine@gmail.com>
Tue, 30 Jul 2013 17:27:54 +0000 (17:27 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Tue, 30 Jul 2013 17:27:54 +0000 (17:27 +0000)
parser.c

index 00e729925d3067cd03273a10577f9a30336ca00e..9f53b428e7a6033b4114040f1ad31c2deeed1db9 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1326,7 +1326,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                               type_name[exprs[1]->vtype]);
                 return false;
             }
-            out = (ast_expression*)ast_binary_new(ctx, type_ne_instr[exprs[0]->vtype], exprs[0], exprs[1]);
+            out = CanConstFold(exprs[0], exprs[1])
+                ? (ast_expression*)parser_const_float(parser, ConstF(0) != ConstF(1))
+                : (ast_expression*)ast_binary_new(ctx, type_ne_instr[exprs[0]->vtype], exprs[0], exprs[1]);
             break;
         case opid2('=', '='):
             if (exprs[0]->vtype != exprs[1]->vtype) {
@@ -1335,7 +1337,9 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
                               type_name[exprs[1]->vtype]);
                 return false;
             }
-            out = (ast_expression*)ast_binary_new(ctx, type_eq_instr[exprs[0]->vtype], exprs[0], exprs[1]);
+            out = CanConstFold(exprs[0], exprs[1])
+                ? (ast_expression*)parser_const_float(parser, ConstF(0) == ConstF(1))
+                : (ast_expression*)ast_binary_new(ctx, type_eq_instr[exprs[0]->vtype], exprs[0], exprs[1]);
             break;
 
         case opid1('='):