ref: 10fc3c6fb48ebc45f6322d86d6692e7d568545a1
parent: 18825e0e1a0f70ab8673407f47a7d886f01d09e3
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Apr 15 11:21:05 EDT 2014
Add evaluation of logical 'and' and logical 'or' The code before this commit was only an stub and it was no even call.
--- a/cc.h
+++ b/cc.h
@@ -245,5 +245,6 @@
#define OP(s) ((union unode) {.op = s})
#define TYP(s) ((union unode) {.type = s})
#define ISNODESYM(n) ((n)->code == emitsym)
+#define ISNODEBIN(n) ((n)->code == emitbin)
#endif
--- a/code.c
+++ b/code.c
@@ -41,6 +41,8 @@
[OADDR] = "a",
[ONEG] = "_",
[OCPL] = "~",
+ [OAND] = "m",
+ [OOR] = "s"
};
Node *
--- a/expr.c
+++ b/expr.c
@@ -37,12 +37,6 @@
}
static Node *
-logic(char op, Node *np1, Node *np2)
-{
- return np1;
-}
-
-static Node *
bitlogic(char op, Node *np1, Node *np2)
{
Type *tp1, *tp2;
@@ -230,6 +224,26 @@
}
static Node *
+exp2cond(Node *np)
+{
+ if (ISNODEBIN(np)) {
+ switch (np->u.op) {
+ case OLT: case OGT: case OGE: case OLE: case OEQ: case ONE:
+ return np;
+ }
+ }
+ return compare(ONE, np, constcode(zero));
+}
+
+static Node *
+logic(char op, Node *np1, Node *np2)
+{
+ np1 = exp2cond(np1);
+ np2 = exp2cond(np2);
+ return bincode(op, inttype, np1, np2);
+}
+
+static Node *
array(Node *np1, Node *np2)
{
Type *tp;
@@ -633,7 +647,7 @@
{
register Node *cond, *ifyes, *ifno;
- cond = bit_or();
+ cond = or();
while (accept('?')) {
ifyes = expr();
expect(':');