use errMd more

This commit is contained in:
dzaima 2025-06-11 18:03:40 +03:00
parent 634cf82fbe
commit d9007c3136
4 changed files with 15 additions and 20 deletions

View File

@ -208,7 +208,7 @@ B fold_c1(Md1D* d, B x) { B f = d->f;
thrM("𝔽´𝕩: Identity not found"); thrM("𝔽´𝕩: Identity not found");
} }
} }
if (RARE(!isFun(f))) { decG(x); if (isMd(f)) thrM("Calling a modifier"); return inc(f); } if (RARE(!isFun(f))) { decG(x); return inc(errMd(f)); }
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
if (RTID(f) != RTID_NONE) { if (RTID(f) != RTID_NONE) {
u8 rtid = RTID(f); u8 rtid = RTID(f);
@ -279,7 +279,7 @@ B fold_c2(Md1D* d, B w, B x) { B f = d->f;
if (isAtm(x) || RNK(x)!=1) thrF("𝕨𝔽´𝕩: 𝕩 must be a list (%H ≡ ≢𝕩)", x); if (isAtm(x) || RNK(x)!=1) thrF("𝕨𝔽´𝕩: 𝕩 must be a list (%H ≡ ≢𝕩)", x);
usz ia = IA(x); usz ia = IA(x);
if (RARE(ia==0)) { decG(x); return w; } if (RARE(ia==0)) { decG(x); return w; }
if (RARE(!isFun(f))) { dec(w); decG(x); if (isMd(f)) thrM("Calling a modifier"); return inc(f); } if (RARE(!isFun(f))) { dec(w); decG(x); return inc(errMd(f)); }
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
if (RTID(f) != RTID_NONE) { if (RTID(f) != RTID_NONE) {
@ -477,7 +477,7 @@ B insert_c1(Md1D* d, B x) { B f = d->f;
thrM("𝔽˝𝕩: Identity not found"); thrM("𝔽˝𝕩: Identity not found");
} }
if (len==1) return C1(select, x); if (len==1) return C1(select, x);
if (RARE(!isFun(f))) { decG(x); if (isMd(f)) thrM("Calling a modifier"); return inc(f); } if (RARE(!isFun(f))) { decG(x); return inc(errMd(f)); }
if (isPervasiveDyExt(f)) { if (isPervasiveDyExt(f)) {
if (xr==1) return m_unit(fold_c1(d, x)); if (xr==1) return m_unit(fold_c1(d, x));
usz xia = IA(x); usz xia = IA(x);
@ -521,7 +521,7 @@ B insert_c2(Md1D* d, B w, B x) { B f = d->f;
if (isAtm(x) || (xr=RNK(x))==0) thrM("𝕨˝𝕩: 𝕩 must have rank at least 1"); if (isAtm(x) || (xr=RNK(x))==0) thrM("𝕨˝𝕩: 𝕩 must have rank at least 1");
usz len = *SH(x); usz len = *SH(x);
if (len==0) { decG(x); return w; } if (len==0) { decG(x); return w; }
if (RARE(!isFun(f))) { dec(w); decG(x); if (isMd(f)) thrM("Calling a modifier"); return inc(f); } if (RARE(!isFun(f))) { dec(w); decG(x); return inc(errMd(f)); }
if (isPervasiveDyExt(f)) { if (isPervasiveDyExt(f)) {
usz xia = IA(x); usz xia = IA(x);
ur rr = xr - 1; ur rr = xr - 1;

View File

@ -247,7 +247,7 @@ B scan_c1(Md1D* d, B x) { B f = d->f;
usz ia = IA(x); if (ia <= 1) { if (ia==1 && RNK(x)==0) goto unit; return x; } usz ia = IA(x); if (ia <= 1) { if (ia==1 && RNK(x)==0) goto unit; return x; }
usz n = *SH(x); if (n <= 1) return x; usz n = *SH(x); if (n <= 1) return x;
if (RARE(!isFun(f))) { if (RARE(!isFun(f))) {
if (isMd(f)) thrM("Calling a modifier"); errMd(f);
B xf = getFillR(x); B xf = getFillR(x);
MAKE_MUT(rm, ia); MAKE_MUT(rm, ia);
usz csz = arr_csz(x); usz csz = arr_csz(x);
@ -367,8 +367,7 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f;
if (isArr(w)? !ptr_eqShape(SH(w), RNK(w), xsh+1, xr-1) : xr!=1) thrF("𝕨𝔽`𝕩: Shape of 𝕨 must match the cell of 𝕩 (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x); if (isArr(w)? !ptr_eqShape(SH(w), RNK(w), xsh+1, xr-1) : xr!=1) thrF("𝕨𝔽`𝕩: Shape of 𝕨 must match the cell of 𝕩 (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
if (ia==0) { dec(w); return x; } if (ia==0) { dec(w); return x; }
if (RARE(!isFun(f))) { if (RARE(!isFun(f))) {
if (isMd(f)) thrM("Calling a modifier"); Arr* ra = arr_shCopy(reshape_one(ia, inc(errMd(f))), x);
Arr* ra = arr_shCopy(reshape_one(ia, inc(f)), x);
B xf = getFillR(x); B xf = getFillR(x);
decG(x); decG(x);
return withFill(taga(ra), xf); return withFill(taga(ra), xf);

View File

@ -40,12 +40,10 @@ NORETURN NOINLINE void fatal(char* s) {
exit(1); exit(1);
} }
NOINLINE B c1F(B f, B x) { dec(x); NOINLINE B c1F(B f, B x) { dec(x); errMd(f);
if (isMd(f)) thrM("Calling a modifier");
return inc(VALIDATE(f)); return inc(VALIDATE(f));
} }
NOINLINE B c2F(B f, B w, B x) { dec(w); dec(x); NOINLINE B c2F(B f, B w, B x) { dec(w); dec(x); errMd(f);
if (isMd(f)) thrM("Calling a modifier");
return inc(VALIDATE(f)); return inc(VALIDATE(f));
} }
NOINLINE void value_freeF(Value* x) { value_free(x); } NOINLINE void value_freeF(Value* x) { value_free(x); }

16
src/h.h
View File

@ -705,27 +705,25 @@ static B c2(B f, B w, B x) { // BQN-call f dyadically; consumes w,x
if (isFun(f)) return VALIDATE(VRES(c(Fun,f)->c2(f, VRES(w), VRES(x)))); if (isFun(f)) return VALIDATE(VRES(c(Fun,f)->c2(f, VRES(w), VRES(x))));
return c2F(f, w, x); return c2F(f, w, x);
} }
static void errMd(B x) { if(RARE(isMd(x))) thrM("Calling a modifier"); } static B errMd(B x) { if (RARE(isMd(x))) thrM("Calling a modifier"); return x; }
// like c1/c2, but with less overhead on non-functions // like c1/c2, but with less overhead on non-functions
SHOULD_INLINE B c1I(B f, B x) { SHOULD_INLINE B c1I(B f, B x) {
if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, x)); if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, x));
dec(x); errMd(f); dec(x);
return inc(f); return inc(errMd(f));
} }
SHOULD_INLINE B c2I(B f, B w, B x) { SHOULD_INLINE B c2I(B f, B w, B x) {
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, w, x)); if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, w, x));
dec(w); dec(x); errMd(f); dec(w); dec(x);
return inc(f); return inc(errMd(f));
} }
static B c1iX(B f, B x) { // c1 with inc(x) static B c1iX(B f, B x) { // c1 with inc(x)
if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, inc(x))); if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, inc(x)));
errMd(f); return inc(errMd(f));
return inc(f);
} }
static B c2iWX(B f, B w, B x) { // c2 with inc(w), inc(x) static B c2iWX(B f, B w, B x) { // c2 with inc(w), inc(x)
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, inc(w), inc(x))); if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, inc(w), inc(x)));
errMd(f); return inc(errMd(f));
return inc(f);
} }
static B c1G(B f, B x) { assert(isFun(f)); return c(Fun,f)->c1(f, x); } static B c1G(B f, B x) { assert(isFun(f)); return c(Fun,f)->c1(f, x); }