commit 327b03d58b8ba6d5d928c338ea8c32e27a2f9c94
parent e0614afe4458a7fdabc4da686bae925552e4be3e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 22 Apr 2014 08:32:14 +0200
Eval expressions in arithmetic
arithmetic cannot deals with comparisions, so they must be
evaluated before of doing anything.
Diffstat:
| M | expr.c |  |  | 18 | ++++++++++-------- | 
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/expr.c b/expr.c
@@ -59,6 +59,14 @@ typeconv(Node **p1, Node **p2)
 }
 
 static Node *
+eval(Node *np)
+{
+	if (!ISNODECMP(np))
+		return np;
+	return ternarycode(np, symcode(one), symcode(zero));
+}
+
+static Node *
 integerop(char op, Node *np1, Node *np2)
 {
 	if (np1->typeop != INT || np2->typeop != INT)
@@ -172,6 +180,8 @@ incorrect:
 static Node *
 arithmetic(char op, Node *np1, Node *np2)
 {
+	np1 = eval(np1);
+	np2 = eval(np2);
 	switch (np1->typeop) {
 	case INT: case FLOAT:
 		switch (np2->typeop) {
@@ -296,14 +306,6 @@ iszero(Node *np)
 }
 
 static Node *
-eval(Node *np)
-{
-	if (!ISNODECMP(np))
-		return np;
-	return ternarycode(np, symcode(one), symcode(zero));
-}
-
-static Node *
 assignop(char op, Node *np1, Node *np2)
 {
 	if ((np2 = convert(np2, np1->type, 0)) == NULL)