]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Actually generate an ast_call for __builtin_pow for the ** operator, otherwise the...
authorDale Weiler <killfieldengine@gmail.com>
Thu, 7 Mar 2013 23:05:40 +0000 (23:05 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Thu, 7 Mar 2013 23:05:40 +0000 (23:05 +0000)
parser.c
tests/exponentiation.qc [new file with mode: 0644]
tests/exponentiation.tmpl [new file with mode: 0644]

index b97d92c3896ee0d26fb9c3a240afc7da2e02bf9b..6ab55e33116a0745f5de8a789fcab43fccb2c03a 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -1086,7 +1086,10 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             if (CanConstFold(exprs[0], exprs[1])) {
                 out = (ast_expression*)parser_const_float(parser, powf(ConstF(0), ConstF(1)));
             } else {
             if (CanConstFold(exprs[0], exprs[1])) {
                 out = (ast_expression*)parser_const_float(parser, powf(ConstF(0), ConstF(1)));
             } else {
-                out = parser_builtin_pow(parser);
+                ast_call *gencall = ast_call_new(parser_ctx(parser), parser_builtin_pow(parser));
+                vec_push(gencall->params, exprs[0]);
+                vec_push(gencall->params, exprs[1]);
+                out = (ast_expression*)gencall;
             }
             break;
 
             }
             break;
 
@@ -1435,7 +1438,8 @@ static bool parser_sy_apply_operator(parser_t *parser, shunt *sy)
             if(CanConstFold1(exprs[0]))
                 out = (ast_expression*)parser_const_float(parser, ~(qcint)ConstF(0));
             else
             if(CanConstFold1(exprs[0]))
                 out = (ast_expression*)parser_const_float(parser, ~(qcint)ConstF(0));
             else
-                out = (ast_expression*)ast_binary_new(ctx, INSTR_SUB_F, (ast_expression*)parser_const_float_neg1(parser), exprs[0]);
+                out = (ast_expression*)
+                    ast_binary_new(ctx, INSTR_SUB_F, (ast_expression*)parser_const_float_neg1(parser), exprs[0]);
             break;
     }
 #undef NotSameType
             break;
     }
 #undef NotSameType
diff --git a/tests/exponentiation.qc b/tests/exponentiation.qc
new file mode 100644 (file)
index 0000000..f3ab7d3
--- /dev/null
@@ -0,0 +1,11 @@
+float pow(float x, float y) {
+    return __builtin_pow(x, y);
+}
+
+void main() {
+    float hundy = pow(10, 2); // 10^2 == 100
+    print(ftos(hundy), "\n");      // prints: 100
+
+    hundy -= 90; // 100-90 = 10
+    print(ftos(hundy ** 2), "\n"); // prints: 100
+}
diff --git a/tests/exponentiation.tmpl b/tests/exponentiation.tmpl
new file mode 100644 (file)
index 0000000..47741ea
--- /dev/null
@@ -0,0 +1,8 @@
+# used to test the builtins
+I: exponentiation.qc
+D: test exponentiation operator and __builtin_pow
+T: -execute
+C: -std=gmqcc
+E: $null
+M: 100
+M: 100