diff options
| author | 2022-10-10 20:11:31 +0200 | |
|---|---|---|
| committer | 2022-10-10 20:11:31 +0200 | |
| commit | 72d64e806dc460641cc7f32ff9d1e64677ea1cc3 (patch) | |
| tree | 1fe8dbba89d909d181e5a971d69e87776282a769 /pez.c | |
| parent | dbf6b2d3eedf1bdffb398254ef365a33aacb0e82 (diff) | |
SEL[*] gather operator
Diffstat (limited to 'pez.c')
| -rw-r--r-- | pez.c | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -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)) { |