From: Dale Weiler Date: Tue, 30 Jul 2013 17:27:54 +0000 (+0000) Subject: I'm in a state of confusion as to why constant folding was never done on comparisions... X-Git-Tag: v0.3.0~56 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2c975fe48feaa8a78792510e5ef09c6f4cd9f655;p=xonotic%2Fgmqcc.git I'm in a state of confusion as to why constant folding was never done on comparisions, now it is ;) --- diff --git a/parser.c b/parser.c index 00e7299..9f53b42 100644 --- 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('='):