cleaner ¨
This commit is contained in:
parent
b31865b0f4
commit
9f824483eb
2
src/h.h
2
src/h.h
@ -451,6 +451,8 @@ B c1_modifier(B f, B w, B x) {
|
||||
dec(w); dec(x);
|
||||
thrM("Calling a modifier");
|
||||
}
|
||||
BB2B c1fn(B f);
|
||||
BBB2B c2fn(B f);
|
||||
|
||||
|
||||
typedef struct Md1 {
|
||||
|
||||
@ -66,7 +66,7 @@ void mut_pfree(Mut* m, usz n) { // free the first n elements
|
||||
else mm_free((Value*) m->val);
|
||||
}
|
||||
|
||||
// doesn't consume x; fills m[ms…ms+l] with x
|
||||
// doesn't consume; fills m[ms…ms+l] with x
|
||||
void mut_fill(Mut* m, usz ms, B x, usz l) {
|
||||
again:
|
||||
#define AGAIN(T) { mut_to(m, T); goto again; }
|
||||
|
||||
23
src/sfns.c
23
src/sfns.c
@ -127,31 +127,20 @@ B eachm_fn(BB2B f, B fo, B x) { // consumes x; x must be array
|
||||
for (; i < ia; i++) rH.a[i] = f(fo, xget(x,i));
|
||||
return harr_fcd(rH, x);
|
||||
}
|
||||
B eachm(B f, B x) { // complete F¨ x
|
||||
B eachm(B f, B x) { // complete F¨ x without fills
|
||||
if (!isArr(x)) return m_hunit(c1(f, x));
|
||||
if (isFun(f)) return eachm_fn(c(Fun,f)->c1, f, x);
|
||||
if (isMd(f)) if (!isArr(x) || a(x)->ia) { decR(x); thrM("Calling a modifier"); }
|
||||
|
||||
usz ia = a(x)->ia;
|
||||
dec(x);
|
||||
HArr_p r = m_harrUv(ia);
|
||||
for(usz i = 0; i < ia; i++) r.a[i] = inc(f);
|
||||
return r.b;
|
||||
MAKE_MUT(r, ia);
|
||||
mut_fill(r, 0, f, ia);
|
||||
return mut_fcd(r, x);
|
||||
}
|
||||
|
||||
B eachd(B f, B w, B x) { // complete w F¨ x
|
||||
B eachd(B f, B w, B x) { // complete w F¨ x without fills
|
||||
if (!isArr(w) & !isArr(x)) return m_hunit(c2(f, w, x));
|
||||
if (isFun(f)) return eachd_fn(c(Fun,f)->c2, f, w, x);
|
||||
if (isArr(w) && isArr(x)) {
|
||||
ur mr = rnk(w); if(rnk(w)<mr) mr = rnk(w);
|
||||
if(!eqShPrefix(a(w)->sh, a(x)->sh, mr)) { decR(x); thrM("Mapping: Expected equal shape prefix"); }
|
||||
}
|
||||
if (isMd(f)) if ((isArr(w)&&a(w)->ia) || (isArr(x)&&a(x)->ia)) { decR(x); thrM("Calling a modifier"); } // case where both are units has already been taken care of
|
||||
|
||||
HArr_p r = m_harrUc(!isArr(w)? x : rnk(w)>rnk(x)? w : x);
|
||||
for(usz i = 0; i < r.c->ia; i++) r.a[i] = inc(f);
|
||||
dec(w); dec(x);
|
||||
return r.b;
|
||||
return eachd_fn(c2fn(f), f, w, x);
|
||||
}
|
||||
B shape_c1(B t, B x) {
|
||||
if (!isArr(x)) thrM("⥊: deshaping non-array");
|
||||
|
||||
15
src/stuff.c
15
src/stuff.c
@ -209,6 +209,21 @@ static inline void hdr_init() {
|
||||
assert((MD1_TAG>>1) == (MD2_TAG>>1)); // just to be sure it isn't changed incorrectly, `isMd` depends on this
|
||||
}
|
||||
|
||||
B md_c1(B t, B x) { thrM("Cannot call a modifier"); }
|
||||
B md_c2(B t, B w, B x) { thrM("Cannot call a modifier"); }
|
||||
B arr_c1(B t, B x) { return inc(t); }
|
||||
B arr_c2(B t, B w, B x) { return inc(t); }
|
||||
BB2B c1fn(B f) {
|
||||
if (isFun(f)) return c(Fun,f)->c1;
|
||||
if (isMd(f)) return md_c1;
|
||||
return arr_c1;
|
||||
}
|
||||
BBB2B c2fn(B f) {
|
||||
if (isFun(f)) return c(Fun,f)->c2;
|
||||
if (isMd(f)) return md_c2;
|
||||
return arr_c2;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ALLOC_STAT
|
||||
u64* ctr_a = 0;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user