diff options
author | Ori Bernstein <ori@eigenstate.org> | 2018-03-06 11:47:45 -0800 |
---|---|---|
committer | Ori Bernstein <ori@markovcorp.com> | 2018-03-06 11:47:45 -0800 |
commit | 7b024df82962f4bfe24db5b74fe2a92aac26cf8e (patch) | |
tree | 71c499cbc5964b8a9823fef21d1e8b09ee98c0b3 /mi | |
parent | 27b4f894b3b7456b64908ad8c2d50ba66ebb513a (diff) | |
download | mc-7b024df82962f4bfe24db5b74fe2a92aac26cf8e.tar.gz |
Add ternary operator.
Diffstat (limited to 'mi')
-rw-r--r-- | mi/flatten.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/mi/flatten.c b/mi/flatten.c index 37b59e5..aba73cd 100644 --- a/mi/flatten.c +++ b/mi/flatten.c @@ -277,6 +277,33 @@ flattencond(Flattenctx *s, Node *n, Node *ltrue, Node *lfalse) } } +static Node* +flattentern(Flattenctx *s, Node *n) +{ + Node *l1, *l2, *l3; + Node *res, *t; + + l1 = genlbl(n->loc); + l2 = genlbl(n->loc); + l3 = genlbl(n->loc); + + res = temp(s, n); + flattencond(s, n->expr.args[0], l1, l2); + + append(s, l1); + t = assign(s, res, rval(s, n->expr.args[1])); + append(s, t); + jmp(s, l3); + + append(s, l2); + t = assign(s, res, rval(s, n->expr.args[2])); + append(s, t); + + append(s, l3); + + return res; +} + /* flatten * a || b * to @@ -588,6 +615,9 @@ rval(Flattenctx *s, Node *n) if (exitscope(s, NULL, Zloc, Xret)) append(s, mkexpr(n->loc, Oret, s->tret, NULL)); break; + case Otern: + r = flattentern(s, n); + break; case Oasn: r = assign(s, args[0], args[1]); break; |