summaryrefslogtreecommitdiff
path: root/6/simp.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-12-21 00:14:33 -0800
committerOri Bernstein <ori@eigenstate.org>2015-12-21 00:14:33 -0800
commit67e077fe5811a7bc218cb58de5a32e337417268c (patch)
tree5004a1a3fe49808839d2bbf65cdcf431acef42fe /6/simp.c
parent8bcba75efd9dd84da2ba9d9634d456d960580f68 (diff)
downloadmc-67e077fe5811a7bc218cb58de5a32e337417268c.tar.gz
Iterable traits pass the frontend.
The backend still needs to lower them, but this is relatively easy.
Diffstat (limited to '6/simp.c')
-rw-r--r--6/simp.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/6/simp.c b/6/simp.c
index 273baae..618e33e 100644
--- a/6/simp.c
+++ b/6/simp.c
@@ -449,7 +449,7 @@ static void simploop(Simp *s, Node *n)
* cjmp (match) :body :step
* :end
*/
-static void simpiter(Simp *s, Node *n)
+static void simpidxiter(Simp *s, Node *n)
{
Node *lbody, *lload, *lstep, *lcond, *lmatch, *lend;
Node *idx, *len, *dcl, *seq, *val, *done;
@@ -510,6 +510,36 @@ static void simpiter(Simp *s, Node *n)
s->nloopexit--;
}
+/* for pat in seq
+ * body;;
+ * =>
+ * .seq = seq
+ * .elt = elt
+ * :body
+ * ..body..
+ * __iterfin__(&seq, &elt)
+ * :step
+ * cond = __iternext__(&seq, &eltout)
+ * cjmp (cond) :match :end
+ * :match
+ * ...match...
+ * cjmp (match) :body :step
+ * :end
+ */
+static void simptraititer(Simp *s, Node *n)
+{
+ die("unimplemented");
+}
+
+static void simpiter(Simp *s, Node *n)
+{
+ switch (tybase(exprtype(n->iterstmt.seq))->type) {
+ case Tyarray: simpidxiter(s, n); break;
+ case Tyslice: simpidxiter(s, n); break;
+ default: simptraititer(s, n); break;
+ }
+}
+
static Node *uconid(Simp *s, Node *n)
{
Ucon *uc;