getFill shouldn't consume
This commit is contained in:
parent
6740e680a9
commit
0192bdb987
@ -2,15 +2,15 @@
|
||||
#include <math.h>
|
||||
|
||||
static inline B arith_recm(BB2B f, B x) {
|
||||
B fx = getFill(inc(x));
|
||||
B fx = getFillQ(x);
|
||||
B r = eachm_fn(f, bi_N, x);
|
||||
return withFill(r, fx);
|
||||
}
|
||||
#ifdef CATCH_ERRORS
|
||||
static inline B arith_recd(BBB2B f, B w, B x) {
|
||||
B fx = getFill(inc(x));
|
||||
B fx = getFillQ(x);
|
||||
if (noFill(fx)) return eachd_fn(f, bi_N, w, x);
|
||||
B fw = getFill(inc(w));
|
||||
B fw = getFillQ(w);
|
||||
B r = eachd_fn(f, bi_N, w, x);
|
||||
if (noFill(fw)) return r;
|
||||
if (CATCH) { dec(catchMessage); return r; }
|
||||
|
||||
@ -22,28 +22,27 @@ B asFill(B x) { // consumes
|
||||
dec(x);
|
||||
return bi_noFill;
|
||||
}
|
||||
B getFill(B x) { // consumes; can return bi_noFill
|
||||
B getFillQ(B x) { // doesn't consume; can return bi_noFill
|
||||
bool defZero = true;
|
||||
#ifdef CATCH_ERRORS
|
||||
defZero = false;
|
||||
#endif
|
||||
if (isArr(x)) {
|
||||
u8 t = v(x)->type;
|
||||
if (t==t_fillarr ) { B r = inc(c(FillArr,x )->fill); dec(x); return r; }
|
||||
if (t==t_fillslice) { B r = inc(c(FillArr,c(Slice,x)->p)->fill); dec(x); return r; }
|
||||
if (t==t_c32arr || t==t_c32slice) { dec(x); return m_c32(' '); }
|
||||
if (t==t_i32arr || t==t_i32slice) { dec(x); return m_f64(0 ); }
|
||||
if (t==t_f64arr || t==t_f64slice) { dec(x); return m_f64(0 ); }
|
||||
dec(x);
|
||||
if (t==t_fillarr ) { B r = inc(c(FillArr,x )->fill); return r; }
|
||||
if (t==t_fillslice) { B r = inc(c(FillArr,c(Slice,x)->p)->fill); return r; }
|
||||
if (t==t_c32arr || t==t_c32slice) return m_c32(' ');
|
||||
if (t==t_i32arr || t==t_i32slice) return m_f64(0 );
|
||||
if (t==t_f64arr || t==t_f64slice) return m_f64(0 );
|
||||
return defZero? m_f64(0) : bi_noFill;
|
||||
}
|
||||
if (isF64(x)|isI32(x)) return m_i32(0);
|
||||
if (isC32(x)) return m_c32(' ');
|
||||
dec(x);
|
||||
|
||||
return defZero? m_f64(0) : bi_noFill;
|
||||
}
|
||||
B getFillE(B x) { // errors if there's no fill
|
||||
B xf = getFill(x);
|
||||
B xf = getFillQ(x);
|
||||
if (noFill(xf)) {
|
||||
if (PROPER_FILLS) thrM("No fill found");
|
||||
else return m_f64(0);
|
||||
@ -150,9 +149,9 @@ B fill_or(B wf, B xf) { // consumes
|
||||
}
|
||||
|
||||
B fill_both(B w, B x) { // doesn't consume
|
||||
B wf = getFill(inc(w));
|
||||
B wf = getFillQ(w);
|
||||
if (noFill(wf)) return bi_noFill;
|
||||
B xf = getFill(inc(x));
|
||||
B xf = getFillQ(x);
|
||||
return fill_or(wf, xf);
|
||||
}
|
||||
|
||||
|
||||
16
src/md1.c
16
src/md1.c
@ -46,13 +46,13 @@ B homFil2(B f, B r, B wf, B xf) {
|
||||
|
||||
B tbl_c1(B d, B x) { B f = c(Md1D,d)->f;
|
||||
if (!EACH_FILLS) return eachm(f, x);
|
||||
B xf = getFill(inc(x));
|
||||
B xf = getFillQ(x);
|
||||
return homFil1(f, eachm(f, x), xf);
|
||||
}
|
||||
B tbl_c2(B d, B w, B x) { B f = c(Md1D,d)->f;
|
||||
B wf, xf;
|
||||
if (EACH_FILLS) wf = getFill(inc(w));
|
||||
if (EACH_FILLS) xf = getFill(inc(x));
|
||||
if (EACH_FILLS) wf = getFillQ(w);
|
||||
if (EACH_FILLS) xf = getFillQ(x);
|
||||
if (isAtm(w)) w = m_atomUnit(w);
|
||||
if (isAtm(x)) x = m_atomUnit(x);
|
||||
usz wia = a(w)->ia; ur wr = rnk(w);
|
||||
@ -84,20 +84,20 @@ B tbl_c2(B d, B w, B x) { B f = c(Md1D,d)->f;
|
||||
|
||||
B each_c1(B d, B x) { B f = c(Md1D,d)->f;
|
||||
if (!EACH_FILLS) return eachm(f, x);
|
||||
B xf = getFill(inc(x));
|
||||
B xf = getFillQ(x);
|
||||
return homFil1(f, eachm(f, x), xf);
|
||||
}
|
||||
B each_c2(B d, B w, B x) { B f = c(Md1D,d)->f;
|
||||
if (!EACH_FILLS) return eachd(f, w, x);
|
||||
B wf = getFill(inc(w));
|
||||
B xf = getFill(inc(x));
|
||||
B wf = getFillQ(w);
|
||||
B xf = getFillQ(x);
|
||||
return homFil2(f, eachd(f, w, x), wf, xf);
|
||||
}
|
||||
|
||||
|
||||
B scan_c1(B d, B x) { B f = c(Md1D,d)->f;
|
||||
if (isAtm(x) || rnk(x)==0) thrM("`: Argument cannot have rank 0");
|
||||
B xf = getFill(inc(x));
|
||||
B xf = getFillQ(x);
|
||||
ur xr = rnk(x);
|
||||
usz ia = a(x)->ia;
|
||||
if (ia==0) return x;
|
||||
@ -121,7 +121,7 @@ B scan_c1(B d, B x) { B f = c(Md1D,d)->f;
|
||||
B scan_c2(B d, B w, B x) { B f = c(Md1D,d)->f;
|
||||
if (isAtm(x) || rnk(x)==0) thrM("`: 𝕩 cannot have rank 0");
|
||||
ur xr = rnk(x); usz* xsh = a(x)->sh; usz ia = a(x)->ia;
|
||||
B wf = getFill(inc(w));
|
||||
B wf = getFillQ(w);
|
||||
bool reuse = (v(x)->type==t_harr && reusable(x)) | !ia;
|
||||
usz i = 0;
|
||||
HArr_p r = reuse? harr_parts(x) : m_harrs(a(x)->ia, &i);
|
||||
|
||||
@ -8,7 +8,7 @@ B val_c2(B d, B w, B x) { return c2(c(Md2D,d)->g, w,x); }
|
||||
|
||||
#ifdef CATCH_ERRORS
|
||||
B fillBy_c1(B d, B x) {
|
||||
B xf=getFill(inc(x));
|
||||
B xf=getFillQ(x);
|
||||
B r = c1(c(Md2D,d)->f, x);
|
||||
if(isAtm(r) || noFill(xf)) { dec(xf); return r; }
|
||||
if (CATCH) { dec(catchMessage); return r; }
|
||||
@ -17,7 +17,7 @@ B fillBy_c1(B d, B x) {
|
||||
return withFill(r, fill);
|
||||
}
|
||||
B fillBy_c2(B d, B w, B x) {
|
||||
B wf=getFill(inc(w)); B xf=getFill(inc(x));
|
||||
B wf=getFillQ(w); B xf=getFillQ(x);
|
||||
B r = c2(c(Md2D,d)->f, w,x);
|
||||
if(isAtm(r) || noFill(xf)) { dec(xf); dec(wf); return r; }
|
||||
if (CATCH) { dec(catchMessage); return r; }
|
||||
|
||||
19
src/sfns.c
19
src/sfns.c
@ -174,7 +174,8 @@ B shape_c2(B t, B w, B x) {
|
||||
B pick_c1(B t, B x) {
|
||||
if (isAtm(x)) return x;
|
||||
if (a(x)->ia==0) {
|
||||
B r = getFill(x);
|
||||
B r = getFillQ(x);
|
||||
dec(x);
|
||||
if (noFill(r)) thrM("⊑: called on empty array without fill");
|
||||
return r;
|
||||
}
|
||||
@ -224,7 +225,7 @@ B select_c2(B t, B w, B x) {
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
B xf = getFill(inc(x));
|
||||
B xf = getFillQ(x);
|
||||
BS2B xget = TI(x).get;
|
||||
usz wia = a(w)->ia;
|
||||
|
||||
@ -330,7 +331,7 @@ B slash_c2(B t, B w, B x) {
|
||||
if (isArr(w) && isArr(x) && rnk(w)==1 && rnk(x)==1 && depth(w)==1) {
|
||||
usz wia = a(w)->ia;
|
||||
usz xia = a(x)->ia;
|
||||
B xf = getFill(inc(x));
|
||||
B xf = getFillQ(x);
|
||||
if (wia!=xia) thrM("/: Lengths of components of 𝕨 must match 𝕩");
|
||||
i64 wsum = isum(w); if (wsum>USZ_MAX) thrM("/: Result too large");
|
||||
usz ria = wsum;
|
||||
@ -380,11 +381,11 @@ B join_c1(B t, B x) {
|
||||
if (rnk(x)==1) {
|
||||
usz xia = a(x)->ia;
|
||||
if (xia==0) {
|
||||
B xf = getFillE(x);
|
||||
B xf = getFillE(x); dec(x);
|
||||
if (isAtm(xf)) thrM("∾: Empty vector 𝕩 cannot have an atom fill element");
|
||||
ur ir = rnk(xf);
|
||||
if (ir==0) thrM("∾: Empty vector 𝕩 cannot have a unit fill element");
|
||||
B xff = getFill(inc(xf));
|
||||
B xff = getFillQ(xf);
|
||||
HArr_p r = m_harrUp(0);
|
||||
usz* sh = arr_shAllocR(r.b, ir);
|
||||
if (sh) {
|
||||
@ -397,7 +398,7 @@ B join_c1(B t, B x) {
|
||||
BS2B xgetU = TI(x).getU;
|
||||
|
||||
B x0 = xgetU(x,0);
|
||||
B rf; if(SFNS_FILLS) rf = getFill(inc(x0));
|
||||
B rf; if(SFNS_FILLS) rf = getFillQ(x0);
|
||||
if (isAtm(x0)) thrM("∾: Rank of items must be equal or greater than rank of argument");
|
||||
usz ir = rnk(x0);
|
||||
usz* x0sh = a(x0)->sh;
|
||||
@ -411,7 +412,7 @@ B join_c1(B t, B x) {
|
||||
usz* csh = a(c)->sh;
|
||||
if (ir>1) for (usz j = 1; j < ir; j++) if (csh[j]!=x0sh[j]) thrM("∾: Item trailing shapes must be equal");
|
||||
cam+= a(c)->sh[0];
|
||||
if (SFNS_FILLS && !noFill(rf)) rf = fill_or(rf, getFill(inc(c)));
|
||||
if (SFNS_FILLS && !noFill(rf)) rf = fill_or(rf, getFillQ(c));
|
||||
}
|
||||
|
||||
MAKE_MUT(r, cam*csz);
|
||||
@ -517,7 +518,7 @@ B shiftb_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("»: Argument cannot be a scalar");
|
||||
usz ia = a(x)->ia;
|
||||
if (ia==0) return x;
|
||||
B xf = getFillE(inc(x));
|
||||
B xf = getFillE(x);
|
||||
usz csz = arr_csz(x);
|
||||
|
||||
MAKE_MUT(r, ia); mut_to(r, TI(x).elType);
|
||||
@ -544,7 +545,7 @@ B shifta_c1(B t, B x) {
|
||||
if (isAtm(x) || rnk(x)==0) thrM("«: Argument cannot be a scalar");
|
||||
usz ia = a(x)->ia;
|
||||
if (ia==0) return x;
|
||||
B xf = getFillE(inc(x));
|
||||
B xf = getFillE(x);
|
||||
usz csz = arr_csz(x);
|
||||
MAKE_MUT(r, ia); mut_to(r, TI(x).elType);
|
||||
mut_copy(r, 0, x, csz, ia-csz);
|
||||
|
||||
@ -33,7 +33,9 @@ B glyph_c1(B t, B x) {
|
||||
}
|
||||
|
||||
B fill_c1(B t, B x) {
|
||||
return getFillE(x);
|
||||
B r = getFillE(x);
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
B fill_c2(B t, B w, B x) { // TODO not set fill for typed arrays
|
||||
if (isArr(x)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user