summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-10-10 20:11:31 +0200
committerlemon <lsof@mailbox.org>2022-10-10 20:11:31 +0200
commit72d64e806dc460641cc7f32ff9d1e64677ea1cc3 (patch)
tree1fe8dbba89d909d181e5a971d69e87776282a769
parentdbf6b2d3eedf1bdffb398254ef365a33aacb0e82 (diff)
SEL[*] gather operator
-rw-r--r--pez.c19
-rw-r--r--test.pez7
2 files changed, 23 insertions, 3 deletions
diff --git a/pez.c b/pez.c
index 3a37815..d894bc0 100644
--- a/pez.c
+++ b/pez.c
@@ -1043,6 +1043,7 @@ fixtrunc(fixnum f) { return f & ~(uint32_t)0xFFF; }
_(close, 0) \
_(argc, 1) \
_(vararg, 0) \
+ _(gather, 1) \
_(global, 0) \
_(setglo,-2) \
_(putglo,-2) \
@@ -1654,6 +1655,13 @@ exefn(PezContext *cx, Fn *fn, uint nargs)
}
TRY(push(cx, idx >= nargs ? VOID : args[idx]));
}
+ CASE(Ogather) {
+ int n = nargs - pr->nparams;
+ Array *arr = newarr(cx, n);
+ TRY(arr);
+ TRY(push(cx, box_obj(arr)));
+ TRY(arrpushn(cx, arr, args + pr->nparams, n));
+ }
CASE(Oglobal) {
Val k = pop(cx), *v;
if ((v = getglobal(cx, k))) {
@@ -2662,9 +2670,14 @@ primaryexpr(Comp *cm)
return compop(cm, Oargc);
} else if (!strcmp(buf, "SEL")) {
TRY(expectspchr(cm, '['));
- TRY(expr(cm));
- TRY(expectspchr(cm, ']'));
- TRY(compop(cm, Ovararg));
+ if (matchspchr(cm, '*')) {
+ TRY(expectspchr(cm, ']'));
+ TRY(compop(cm, Ogather));
+ } else {
+ TRY(expr(cm));
+ TRY(expectspchr(cm, ']'));
+ TRY(compop(cm, Ovararg));
+ }
return 1;
}
if (reserved(buf)) {
diff --git a/test.pez b/test.pez
index b6dcd8c..47a59ae 100644
--- a/test.pez
+++ b/test.pez
@@ -34,4 +34,11 @@ printf["%a == %a\n", m[3,7], 3^7]
acc
}
+
printf["4+1+3: %a\n", add[4,1,3]]
+
+@gather: {[*]
+ SEL[*]
+}
+
+printf["test %a\n", gather[-1, (), 'x]]