From 72d64e806dc460641cc7f32ff9d1e64677ea1cc3 Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 10 Oct 2022 20:11:31 +0200 Subject: SEL[*] gather operator --- pez.c | 19 ++++++++++++++++--- test.pez | 7 +++++++ 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]] -- cgit v1.2.3