•_while_

This commit is contained in:
dzaima 2021-10-04 15:13:39 +03:00
parent e0b987930f
commit dc535763bc
3 changed files with 15 additions and 2 deletions

View File

@ -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;

View File

@ -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() {

View File

@ -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);