TO_GET helper
This commit is contained in:
parent
10671c446d
commit
4eb632a48d
@ -658,7 +658,7 @@ B rank_c1(Md2D* d, B x) { B f = d->f; B g = d->g;
|
||||
kf = req_whole(o2fG(g));
|
||||
} else {
|
||||
usz gia = check_rank_vec(g);
|
||||
kf = IGetU(g, gia==2).f;
|
||||
kf = o2fG(IGetU(g, gia==2));
|
||||
decA(gi);
|
||||
}
|
||||
if (isAtm(x)) return c1wrap(f, x);
|
||||
@ -697,9 +697,7 @@ SHOULD_INLINE bool unpack_unit(B* r) {
|
||||
B x = *r;
|
||||
if (isAtm(x)) return true;
|
||||
if (RNK(x)!=0) return false;
|
||||
B x2 = IGet(x,0);
|
||||
decG(x);
|
||||
*r = x2;
|
||||
*r = TO_GET(x,0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -780,7 +778,7 @@ NOINLINE B for_cells_SA(B f, B w, B x, ur xcr, ur xr, u32 chr) { // w⊸F⎉xcr
|
||||
if (xcr==0) break;
|
||||
if (!(xsh[xk]==1 || shProd(xsh, xk+1, xr)==1)) break;
|
||||
}
|
||||
if (isArr(w)) { B w0=w; w = IGet(w,0); decG(w0); }
|
||||
if (isArr(w)) w = TO_GET(w, 0);
|
||||
return shift_cells(w, x, cam, xsh[xk], el_or(TI(x,elType), selfElType(w)), rtid);
|
||||
} break;
|
||||
case n_take: case n_drop: {
|
||||
|
||||
@ -190,9 +190,7 @@ B fold_c1(Md1D* d, B x) { B f = d->f;
|
||||
decG(x);
|
||||
return c2(f, x0, x1);
|
||||
} else if (ia==1) {
|
||||
B r = IGet(x,0);
|
||||
decG(x);
|
||||
return r;
|
||||
return TO_GET(x,0);
|
||||
} else {
|
||||
decG(x);
|
||||
if (isFun(f)) {
|
||||
@ -206,8 +204,8 @@ B fold_c1(Md1D* d, B x) { B f = d->f;
|
||||
u8 xe = TI(x,elType);
|
||||
if (v(f)->flags) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
if (rtid==n_ltack) { B r = IGet(x, 0 ); decG(x); return r; }
|
||||
if (rtid==n_rtack) { B r = IGet(x, ia-1); decG(x); return r; }
|
||||
if (rtid==n_ltack) return TO_GET(x, 0);
|
||||
if (rtid==n_rtack) return TO_GET(x, ia-1);
|
||||
if (xe>el_f64) goto base;
|
||||
if (xe==el_bit) {
|
||||
u64* xp = bitany_ptr(x);
|
||||
@ -279,8 +277,8 @@ B fold_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
if (v(f)->flags) {
|
||||
u8 rtid = v(f)->flags-1;
|
||||
if (rtid==n_ltack) {
|
||||
B r = IGet(x, 0);
|
||||
dec(w); decG(x); return r;
|
||||
dec(w);
|
||||
return TO_GET(x, 0);
|
||||
}
|
||||
if (rtid==n_rtack) { decG(x); return w; }
|
||||
if (!isF64(w) || xe>el_f64) goto base;
|
||||
@ -457,7 +455,7 @@ B insert_c2(Md1D* d, B w, B x) { B f = d->f;
|
||||
if (isArr(w)) {
|
||||
if (IA(w) != 1) goto skip;
|
||||
ur wr = RNK(w); if (wr>rr) rr = wr;
|
||||
B w0=w; w = IGet(w,0); decG(w0);
|
||||
w = TO_GET(w, 0);
|
||||
}
|
||||
if (xr > 1) x = C1(shape, x);
|
||||
B r = m_unit(fold_c2(d, w, x));
|
||||
|
||||
@ -373,9 +373,7 @@ B memberOf_c2(B t, B w, B x) {
|
||||
ur wr = RNK(w);
|
||||
if (wr>0) goto many;
|
||||
|
||||
B w0 = IGet(w, 0);
|
||||
dec(w);
|
||||
w = w0;
|
||||
w = TO_GET(w, 0);
|
||||
goto single;
|
||||
|
||||
B r;
|
||||
|
||||
@ -188,9 +188,7 @@ B shape_c1(B t, B x) {
|
||||
if (RNK(x)==1) return x;
|
||||
usz ia = IA(x);
|
||||
if (ia==1 && TI(x,elType)<el_B) {
|
||||
B n = IGet(x,0);
|
||||
decG(x);
|
||||
return m_vec1(n);
|
||||
return m_vec1(TO_GET(x,0));
|
||||
}
|
||||
if (reusable(x)) { FL_KEEP(x, fl_squoze);
|
||||
decSh(v(x)); arr_shVec(a(x));
|
||||
@ -271,9 +269,7 @@ B shape_c2(B t, B w, B x) {
|
||||
} else {
|
||||
if (xia <= 1) {
|
||||
if (RARE(xia == 0)) thrM("⥊: Empty 𝕩 and non-empty result");
|
||||
B n = IGet(x,0);
|
||||
decG(x);
|
||||
x = n;
|
||||
x = TO_GET(x, 0);
|
||||
goto unit;
|
||||
}
|
||||
if (xia <= nia/2) x = any_squeeze(x);
|
||||
@ -359,9 +355,7 @@ B pick_c1(B t, B x) {
|
||||
// dec(x);
|
||||
// return r;
|
||||
}
|
||||
B r = IGet(x, 0);
|
||||
decG(x);
|
||||
return r;
|
||||
return TO_GET(x, 0);
|
||||
}
|
||||
|
||||
static NOINLINE void checkIndexList(B w, ur xr) {
|
||||
@ -438,9 +432,7 @@ B pick_c2(B t, B w, B x) {
|
||||
if (isNum(w)) {
|
||||
if (RNK(x)!=1) thrF("⊑: 𝕩 must be a list when 𝕨 is a number (%H ≡ ≢𝕩)", x);
|
||||
usz p = WRAP(o2i64(w), IA(x), thrF("⊑: indexing out-of-bounds (𝕨≡%R, %s≡≠𝕩)", w, iaW));
|
||||
B r = IGet(x, p);
|
||||
decG(x);
|
||||
return r;
|
||||
return TO_GET(x, p);
|
||||
}
|
||||
if (!isArr(w)) thrM("⊑: 𝕨 must be a numeric array");
|
||||
B r = recPick(w, x);
|
||||
@ -960,8 +952,8 @@ B join_c2(B t, B w, B x) {
|
||||
ur c = wr>xr?wr:xr;
|
||||
if (c==0) {
|
||||
HArr_p r = m_harrUv(2);
|
||||
r.a[0] = IGet(w,0); decG(w);
|
||||
r.a[1] = IGet(x,0); decG(x);
|
||||
r.a[0] = TO_GET(w, 0);
|
||||
r.a[1] = TO_GET(x, 0);
|
||||
NOGC_E;
|
||||
return qWithFill(r.b, f);
|
||||
}
|
||||
@ -1482,16 +1474,12 @@ B reverse_ix(B t, B w, B x) {
|
||||
|
||||
NOINLINE B enclose_im(B t, B x) {
|
||||
if (isAtm(x) || RNK(x)!=0) thrM("<⁼: Argument wasn't a rank 0 array");
|
||||
B r = IGet(x, 0);
|
||||
dec(x);
|
||||
return r;
|
||||
return TO_GET(x, 0);
|
||||
}
|
||||
|
||||
NOINLINE B pair_im(B t, B x) {
|
||||
if (isAtm(x) || RNK(x)!=1 || IA(x)!=1) thrM("⋈⁼: Argument wasn't a length-1 list");
|
||||
B r = IGet(x, 0);
|
||||
dec(x);
|
||||
return r;
|
||||
return TO_GET(x, 0);
|
||||
}
|
||||
|
||||
B select_c1(B,B);
|
||||
|
||||
@ -621,7 +621,7 @@ B slash_c2(B t, B w, B x) {
|
||||
if (depth(w)>1) goto base;
|
||||
ur wr = RNK(w);
|
||||
if (wr>1) thrF("/: Simple 𝕨 must have rank 0 or 1 (%i≡=𝕨)", wr);
|
||||
if (wr<1) { B v=IGet(w, 0); decG(w); w=v; goto atom; }
|
||||
if (wr<1) { w = TO_GET(w, 0); goto atom; }
|
||||
wia = IA(w);
|
||||
if (wia==0) { decG(w); return isArr(x)? x : m_unit(x); }
|
||||
} else {
|
||||
|
||||
1
src/h.h
1
src/h.h
@ -592,6 +592,7 @@ typedef B (*D2C2)(Md2D*, B, B);
|
||||
#define SGet(X) Arr* X##_arr = a(X); AS2B X##_get = TIv(X##_arr,get);
|
||||
#define IGet(X,N) ({ Arr* x_ = a(X); TIv(x_,get)(x_,N); })
|
||||
#define Get(X,N) X##_get(X##_arr,N)
|
||||
#define TO_GET(X,N) ({ B x_2 = (X); B r = IGet(x_2,N); decG(x_2); r; })
|
||||
|
||||
|
||||
enum Flags {
|
||||
|
||||
@ -438,8 +438,7 @@ B nc_parseBlock(B tokens, usz i0, u32 end, bool isBlock, B* objs, u32* varCount)
|
||||
#endif
|
||||
i1 = nc_skipSeparators(tokens, i1);
|
||||
if (i1 != IA(tokens)) thrM("Native compiler: Code present after block end");
|
||||
B r = IGet(r0, 1);
|
||||
decG(r0);
|
||||
B r = TO_GET(r0, 1);
|
||||
decG(toFree);
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ static inline B hmv(HArr_p p, usz n) { B r = p.a[n]; p.a[n] = m_f64(0); return r
|
||||
|
||||
B eachd_fn(B fo, B w, B x, FC2 f) {
|
||||
ur wr, xr; // if rank is 0, respective w/x will be disclosed
|
||||
if (isArr(w)) { wr=RNK(w); if (wr==0) { B c=IGet(w, 0); decG(w); w=c; } } else wr=0;
|
||||
if (isArr(x)) { xr=RNK(x); if (xr==0) { B c=IGet(x, 0); decG(x); x=c; } } else xr=0;
|
||||
if (isArr(w)) { wr=RNK(w); if (wr==0) w = TO_GET(w,0); } else wr=0;
|
||||
if (isArr(x)) { xr=RNK(x); if (xr==0) x = TO_GET(x,0); } else xr=0;
|
||||
bool wg = wr>xr;
|
||||
ur rM = wg? wr : xr;
|
||||
ur rm = wg? xr : wr;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user