From dc535763bc949c3db0f6cc5f11a00fb223725790 Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 4 Oct 2021 15:13:39 +0300 Subject: [PATCH] =?UTF-8?q?=E2=80=A2=5Fwhile=5F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins.h | 6 ++++-- src/builtins/md2.c | 10 ++++++++++ src/builtins/sysfn.c | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/builtins.h b/src/builtins.h index d50d48b0..d4b0f82b 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -20,7 +20,9 @@ #define FOR_PM2(A,M,D) \ /*md2.c*/ A(val,"⊘") A(repeat,"⍟") A(fillBy,"•_fillBy_") A(catch,"⎊") \ - /*md2.c*/ A(atop,"∘") A(over,"○") A(before,"⊸") A(after,"⟜") A(cond,"◶") A(under,"⌾") + /*md2.c*/ A(atop,"∘") A(over,"○") A(before,"⊸") A(after,"⟜") A(cond,"◶") A(under,"⌾") \ +/* everything before the definition of •_while_ is defined to be pure, and everything after is not */ \ + /*md2.c*/ A(while,"•_while_") enum PrimFns { pf_none, #define F(N,X) pf_##N, @@ -39,7 +41,7 @@ enum PrimMd2 { pm2_none, }; static const i32 firstImpurePFN = pf_type; static const i32 firstImpurePM1 = pm1_timed; -static const i32 firstImpurePM2 = I32_MAX; +static const i32 firstImpurePM2 = pm2_while; static inline bool isImpureBuiltin(B x) { if (isFun(x)) return !v(x)->extra || v(x)->extra>=firstImpurePFN; diff --git a/src/builtins/md2.c b/src/builtins/md2.c index bfc2eb15..c305195c 100644 --- a/src/builtins/md2.c +++ b/src/builtins/md2.c @@ -148,6 +148,16 @@ B before_uc1(B t, B o, B f, B g, B x) { } +B while_c1(Md2D* d, B x) { B f=d->f; B g=d->g; + while (o2b(c1(g,inc(x)))) x = c1(f, x); + return x; +} +B while_c2(Md2D* d, B w, B x) { B f=d->f; B g=d->g; + while (o2b(c2(g,inc(w),inc(x)))) x = c2(f, inc(w), x); + dec(w); + return x; +} + static void print_md2BI(B x) { printf("%s", pm2_repr(c(Md1,x)->extra)); } void md2_init() { diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 600b6df5..e1ef16df 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -740,6 +740,7 @@ B sys_c1(B t, B x) { else if (eqStr(c, U"type")) r.a[i] = incG(bi_type); else if (eqStr(c, U"sh")) r.a[i] = incG(bi_sh); else if (eqStr(c, U"decompose")) r.a[i] = incG(bi_decp); + else if (eqStr(c, U"while")) r.a[i] = incG(bi_while); else if (eqStr(c, U"primind")) r.a[i] = incG(bi_primInd); else if (eqStr(c, U"bqn")) r.a[i] = incG(bi_bqn); else if (eqStr(c, U"cmp")) r.a[i] = incG(bi_cmp);