actually use TY(x) / PTY(x) more
This commit is contained in:
parent
5112796cfd
commit
aa95b6add4
@ -92,7 +92,7 @@ B select_c2(B t, B w, B x) {
|
||||
case el_B:; \
|
||||
} \
|
||||
M_HARR(r, wia); \
|
||||
if (v(x)->type==t_harr || v(x)->type==t_hslice) { \
|
||||
if (TY(x)==t_harr || TY(x)==t_hslice) { \
|
||||
B* xp = hany_ptr(x); \
|
||||
for (usz i=0; i < wia; i++) HARR_ADD(r, i, inc(xp[WRAP(wp[i], xia, thrF("⊏: Indexing out-of-bounds (%i∊𝕨, %s≡≠𝕩)", wp[i], xia))])); \
|
||||
decG(x); return HARR_FCD(r, w); \
|
||||
@ -250,7 +250,7 @@ B select_ucw(B t, B o, B w, B x) {
|
||||
} else UD;
|
||||
}
|
||||
if (reusable(x) && xe==re) {
|
||||
if (v(x)->type==t_harr) {
|
||||
if (TY(x)==t_harr) {
|
||||
B* xp = harr_ptr(REUSE(x));
|
||||
SGet(rep)
|
||||
for (usz i = 0; i < wia; i++) {
|
||||
|
||||
@ -1502,12 +1502,12 @@ B pick_ucw(B t, B o, B w, B x) {
|
||||
else if (TI(x,elType)==el_i16) { i16* xp = i16any_ptr(x); xp[wi] = o2iu(rep); return x; }
|
||||
else if (TI(x,elType)==el_i32) { i32* xp = i32any_ptr(x); xp[wi] = o2iu(rep); return x; }
|
||||
else if (TI(x,elType)==el_f64) { f64* xp = f64any_ptr(x); xp[wi] = o2fu(rep); return x; }
|
||||
else if (v(x)->type==t_harr) {
|
||||
else if (TY(x)==t_harr) {
|
||||
B* xp = harr_ptr(x);
|
||||
dec(xp[wi]);
|
||||
xp[wi] = rep;
|
||||
return x;
|
||||
} else if (v(x)->type==t_fillarr) {
|
||||
} else if (TY(x)==t_fillarr) {
|
||||
B* xp = fillarr_ptr(a(x));
|
||||
dec(xp[wi]);
|
||||
xp[wi] = rep;
|
||||
@ -1536,7 +1536,7 @@ B slash_ucw(B t, B o, B w, B x) {
|
||||
SGet(x)
|
||||
SGet(rep)
|
||||
usz repI = 0;
|
||||
if (a(w)->type == t_bitarr) {
|
||||
if (TY(w) == t_bitarr) {
|
||||
u64* d = bitarr_ptr(w);
|
||||
if (TI(x,elType)<=el_i32 && TI(rep,elType)<=el_i32) {
|
||||
if (r->fns->elType!=el_i32) mut_to(r, el_i32);
|
||||
|
||||
@ -71,7 +71,7 @@ B glyph_c1(B t, B x) {
|
||||
decG(x);
|
||||
return r;
|
||||
}
|
||||
u8 ty = v(x)->type;
|
||||
u8 ty = TY(x);
|
||||
if (ty==t_funBI) { B r = utf8Decode0(pfn_repr(c(Fun,x)->extra)); decG(x); return r; }
|
||||
if (ty==t_md1BI) { B r = utf8Decode0(pm1_repr(c(Md1,x)->extra)); decG(x); return r; }
|
||||
if (ty==t_md2BI) { B r = utf8Decode0(pm2_repr(c(Md2,x)->extra)); decG(x); return r; }
|
||||
@ -1044,7 +1044,7 @@ static CastType getCastType(B e, B v) {
|
||||
usz s; bool c;
|
||||
if (isNum(e)) {
|
||||
s = o2s(e);
|
||||
c = q_N(v) ? 0 : isCharType(v(v)->type);
|
||||
c = q_N(v) ? 0 : isCharType(TY(v));
|
||||
} else {
|
||||
if (!isArr(e) || RNK(e)!=1 || IA(e)!=2) thrM("•bit._cast: 𝕗 elements must be numbers or two-element lists");
|
||||
SGetU(e)
|
||||
@ -1103,7 +1103,7 @@ B bitcast_impl(B el0, B el1, B x) {
|
||||
// Convert to input type
|
||||
B r = convert(xt, x);
|
||||
u8 rt = typeOfCast(zt);
|
||||
if (rt==t_bitarr && (v(r)->refc!=1 || IS_SLICE(v(r)->type))) {
|
||||
if (rt==t_bitarr && (v(r)->refc!=1 || IS_SLICE(TY(r)))) {
|
||||
r = taga(copy(xt, r));
|
||||
} else if (v(r)->refc!=1) {
|
||||
B pr = r;
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
static B* arr_bptr(B x) { assert(isArr(x));
|
||||
if (v(x)->type==t_harr) return harr_ptr(x);
|
||||
if (v(x)->type==t_fillarr) return fillarr_ptr(a(x));
|
||||
if (v(x)->type==t_hslice) return c(HSlice,x)->a;
|
||||
if (v(x)->type==t_fillslice) return c(FillSlice,x)->a;
|
||||
if (TY(x)==t_harr) return harr_ptr(x);
|
||||
if (TY(x)==t_fillarr) return fillarr_ptr(a(x));
|
||||
if (TY(x)==t_hslice) return c(HSlice,x)->a;
|
||||
if (TY(x)==t_fillslice) return c(FillSlice,x)->a;
|
||||
return NULL;
|
||||
}
|
||||
static B* arrV_bptr(Arr* x) {
|
||||
if (x->type==t_harr) return ((HArr*)x)->a;
|
||||
if (x->type==t_fillarr) return fillarr_ptr(x);
|
||||
if (x->type==t_hslice) return ((HSlice*)x)->a;
|
||||
if (x->type==t_fillslice) return ((FillSlice*)x)->a;
|
||||
if (PTY(x)==t_harr) return ((HArr*)x)->a;
|
||||
if (PTY(x)==t_fillarr) return fillarr_ptr(x);
|
||||
if (PTY(x)==t_hslice) return ((HSlice*)x)->a;
|
||||
if (PTY(x)==t_fillslice) return ((FillSlice*)x)->a;
|
||||
return NULL;
|
||||
}
|
||||
static void* tyarr_ptr(B x) { assert(IS_ARR(v(x)->type)); return c(TyArr,x)->a; }
|
||||
static void* tyslice_ptr(B x) { assert(IS_SLICE(v(x)->type)); return c(TySlice,x)->a; }
|
||||
static void* tyany_ptr(B x) { assert(IS_ARR(v(x)->type) || IS_SLICE(v(x)->type));
|
||||
u8 t = v(x)->type;
|
||||
static void* tyarr_ptr(B x) { assert(IS_ARR(TY(x))); return c(TyArr,x)->a; }
|
||||
static void* tyslice_ptr(B x) { assert(IS_SLICE(TY(x))); return c(TySlice,x)->a; }
|
||||
static void* tyany_ptr(B x) { assert(IS_ARR(TY(x)) || IS_SLICE(TY(x)));
|
||||
u8 t = TY(x);
|
||||
return IS_SLICE(t)? c(TySlice,x)->a : c(TyArr,x)->a;
|
||||
}
|
||||
|
||||
|
||||
@ -31,10 +31,10 @@ C16Arr* cpyC16Arr(B x); // consumes
|
||||
C32Arr* cpyC32Arr(B x); // consumes
|
||||
|
||||
// all consume x
|
||||
static C8Arr* toC8Arr (B x) { return v(x)->type==t_c8arr ? c(C8Arr, x) : cpyC8Arr (x); }
|
||||
static C16Arr* toC16Arr(B x) { return v(x)->type==t_c16arr? c(C16Arr,x) : cpyC16Arr(x); }
|
||||
static C32Arr* toC32Arr(B x) { return v(x)->type==t_c32arr? c(C32Arr,x) : cpyC32Arr(x); }
|
||||
static C8Arr* toC8Arr (B x) { return TY(x)==t_c8arr ? c(C8Arr, x) : cpyC8Arr (x); }
|
||||
static C16Arr* toC16Arr(B x) { return TY(x)==t_c16arr? c(C16Arr,x) : cpyC16Arr(x); }
|
||||
static C32Arr* toC32Arr(B x) { return TY(x)==t_c32arr? c(C32Arr,x) : cpyC32Arr(x); }
|
||||
|
||||
static B toC8Any (B x) { u8 t=v(x)->type; return t==t_c8arr || t==t_c8slice ? x : taga(cpyC8Arr (x)); }
|
||||
static B toC16Any(B x) { u8 t=v(x)->type; return t==t_c16arr || t==t_c16slice? x : taga(cpyC16Arr(x)); }
|
||||
static B toC32Any(B x) { u8 t=v(x)->type; return t==t_c32arr || t==t_c32slice? x : taga(cpyC32Arr(x)); }
|
||||
static B toC8Any (B x) { u8 t=TY(x); return t==t_c8arr || t==t_c8slice ? x : taga(cpyC8Arr (x)); }
|
||||
static B toC16Any(B x) { u8 t=TY(x); return t==t_c16arr || t==t_c16slice? x : taga(cpyC16Arr(x)); }
|
||||
static B toC32Any(B x) { u8 t=TY(x); return t==t_c32arr || t==t_c32slice? x : taga(cpyC32Arr(x)); }
|
||||
|
||||
@ -64,10 +64,10 @@ static B md2D_uc1(B t, B o, B x) {
|
||||
|
||||
static B toConstant(B x) { // doesn't consume x
|
||||
if (!isCallable(x)) return inc(x);
|
||||
if (v(x)->type == t_md1D) {
|
||||
if (TY(x) == t_md1D) {
|
||||
Md1D* d = c(Md1D,x);
|
||||
Md1* m1 = d->m1;
|
||||
if (m1->type==t_md1BI && m1->flags==n_const) return inc(d->f);
|
||||
if (PTY(m1)==t_md1BI && m1->flags==n_const) return inc(d->f);
|
||||
}
|
||||
return bi_N;
|
||||
}
|
||||
|
||||
@ -40,10 +40,10 @@ static Arr* m_fillslice(Arr* p, B* ptr, usz ia, B fill) {
|
||||
static Arr* fillarr_slice (B x, usz s, usz ia) { FillArr* a=c(FillArr ,x); return m_fillslice((Arr*)a, a->a+s, ia, inc(a->fill)); }
|
||||
static Arr* fillslice_slice(B x, usz s, usz ia) { FillSlice* a=c(FillSlice,x); Arr* r=m_fillslice(ptr_inc(a->p), a->a+s, ia, inc(a->fill)); decG(x); return r; }
|
||||
|
||||
static B fillarr_get (Arr* x, usz n) { assert(x->type==t_fillarr ); return inc(((FillArr* )x)->a[n]); }
|
||||
static B fillslice_get (Arr* x, usz n) { assert(x->type==t_fillslice); return inc(((FillSlice*)x)->a[n]); }
|
||||
static B fillarr_getU (Arr* x, usz n) { assert(x->type==t_fillarr ); return ((FillArr* )x)->a[n] ; }
|
||||
static B fillslice_getU(Arr* x, usz n) { assert(x->type==t_fillslice); return ((FillSlice*)x)->a[n] ; }
|
||||
static B fillarr_get (Arr* x, usz n) { assert(PTY(x)==t_fillarr ); return inc(((FillArr* )x)->a[n]); }
|
||||
static B fillslice_get (Arr* x, usz n) { assert(PTY(x)==t_fillslice); return inc(((FillSlice*)x)->a[n]); }
|
||||
static B fillarr_getU (Arr* x, usz n) { assert(PTY(x)==t_fillarr ); return ((FillArr* )x)->a[n] ; }
|
||||
static B fillslice_getU(Arr* x, usz n) { assert(PTY(x)==t_fillslice); return ((FillSlice*)x)->a[n] ; }
|
||||
DEF_FREE(fillarr) {
|
||||
decSh(x);
|
||||
B* p = ((FillArr*)x)->a;
|
||||
@ -51,7 +51,7 @@ DEF_FREE(fillarr) {
|
||||
usz ia = PIA((Arr*)x);
|
||||
for (usz i = 0; i < ia; i++) dec(p[i]);
|
||||
}
|
||||
static void fillarr_visit(Value* x) { assert(x->type == t_fillarr);
|
||||
static void fillarr_visit(Value* x) { assert(PTY(x) == t_fillarr);
|
||||
usz ia = PIA((Arr*)x); B* p = ((FillArr*)x)->a;
|
||||
mm_visit(((FillArr*)x)->fill);
|
||||
for (usz i = 0; i < ia; i++) mm_visit(p[i]);
|
||||
@ -114,7 +114,7 @@ B withFill(B x, B fill) { // consumes both
|
||||
#ifdef DEBUG
|
||||
validateFill(fill);
|
||||
#endif
|
||||
u8 xt = v(x)->type;
|
||||
u8 xt = TY(x);
|
||||
if (noFill(fill) && xt!=t_fillarr && xt!=t_fillslice) return x;
|
||||
switch(xt) {
|
||||
case t_f64arr: case t_f64slice: case t_bitarr:
|
||||
@ -145,7 +145,7 @@ B withFill(B x, B fill) { // consumes both
|
||||
B* xbp = arr_bptr(x);
|
||||
if (xbp!=NULL) {
|
||||
Arr* xa = a(x);
|
||||
if (IS_SLICE(xa->type)) xa = ptr_inc(((Slice*)xa)->p);
|
||||
if (IS_SLICE(PTY(xa))) xa = ptr_inc(((Slice*)xa)->p);
|
||||
else ptr_inc(xa);
|
||||
r = m_fillslice(xa, xbp, ia, fill);
|
||||
} else {
|
||||
|
||||
@ -33,7 +33,7 @@ static B getFillR(B x) { // doesn't consume; can return bi_noFill
|
||||
case el_i8: case el_i16: case el_i32: case el_f64: case el_bit: return m_i32(0);
|
||||
case el_c8: case el_c16: case el_c32: return m_c32(' ');
|
||||
case el_B:;
|
||||
u8 t = v(x)->type;
|
||||
u8 t = TY(x);
|
||||
if (t==t_fillarr ) return inc(c(FillArr, x)->fill);
|
||||
if (t==t_fillslice) return inc(c(FillSlice,x)->fill);
|
||||
return bi_noFill;
|
||||
@ -64,8 +64,8 @@ static Arr* m_fillarrp(usz ia) {
|
||||
CHECK_IA(ia, sizeof(B));
|
||||
return m_arr(fsizeof(FillArr,a,B,ia), t_fillarr, ia);
|
||||
}
|
||||
static void fillarr_setFill(Arr* x, B fill) { assert(x->type==t_fillarr); ((FillArr*)x)->fill = fill; } // consumes fill
|
||||
static B* fillarr_ptr(Arr* x) { assert(x->type==t_fillarr); return ((FillArr*)x)->a; }
|
||||
static void fillarr_setFill(Arr* x, B fill) { assert(PTY(x)==t_fillarr); ((FillArr*)x)->fill = fill; } // consumes fill
|
||||
static B* fillarr_ptr(Arr* x) { assert(PTY(x)==t_fillarr); return ((FillArr*)x)->a; }
|
||||
|
||||
static B m_emptyFVec(B f) { // consumes f
|
||||
Arr* r = arr_shVec(m_fillarrp(0));
|
||||
|
||||
@ -65,7 +65,7 @@ NOINLINE B m_caB(usz ia, B* a) {
|
||||
}
|
||||
|
||||
NOINLINE void harr_pfree(B x, usz am) { // am - item after last written
|
||||
assert(v(x)->type==t_harr);
|
||||
assert(TY(x)==t_harr);
|
||||
B* p = harr_ptr(x);
|
||||
for (usz i = 0; i < am; i++) dec(p[i]);
|
||||
if (RNK(x)>1) ptr_dec(shObj(x));
|
||||
@ -83,10 +83,10 @@ static Arr* m_hslice(Arr* p, B* ptr, usz ia) {
|
||||
static Arr* harr_slice (B x, usz s, usz ia) { return m_hslice(a(x), c(HArr,x)->a+s, ia); }
|
||||
static Arr* hslice_slice(B x, usz s, usz ia) { Arr* p = ptr_inc(c(Slice,x)->p); Arr* r = m_hslice(p, c(HSlice,x)->a+s, ia); decG(x); return r; }
|
||||
|
||||
static B harr_get (Arr* x, usz n) { assert(x->type==t_harr ); return inc(((HArr* )x)->a[n]); }
|
||||
static B hslice_get (Arr* x, usz n) { assert(x->type==t_hslice); return inc(((HSlice*)x)->a[n]); }
|
||||
static B harr_getU (Arr* x, usz n) { assert(x->type==t_harr ); return ((HArr* )x)->a[n] ; }
|
||||
static B hslice_getU(Arr* x, usz n) { assert(x->type==t_hslice); return ((HSlice*)x)->a[n] ; }
|
||||
static B harr_get (Arr* x, usz n) { assert(PTY(x)==t_harr ); return inc(((HArr* )x)->a[n]); }
|
||||
static B hslice_get (Arr* x, usz n) { assert(PTY(x)==t_hslice); return inc(((HSlice*)x)->a[n]); }
|
||||
static B harr_getU (Arr* x, usz n) { assert(PTY(x)==t_harr ); return ((HArr* )x)->a[n] ; }
|
||||
static B hslice_getU(Arr* x, usz n) { assert(PTY(x)==t_hslice); return ((HSlice*)x)->a[n] ; }
|
||||
DEF_FREE(harr) {
|
||||
decSh(x);
|
||||
B* p = ((HArr*)x)->a; // don't use harr_ptr so type isn't checked
|
||||
@ -101,17 +101,17 @@ static bool harr_canStore(B x) { return true; }
|
||||
|
||||
|
||||
|
||||
DEF_FREE(harrP) { assert(x->type==t_harrPartial|x->type==t_freed);
|
||||
DEF_FREE(harrP) { assert(PTY(x)==t_harrPartial|PTY(x)==t_freed);
|
||||
B* p = ((HArr*)x)->a;
|
||||
usz am = PIA((HArr*)x);
|
||||
for (usz i = 0; i < am; i++) dec(p[i]);
|
||||
}
|
||||
void harr_abandon_impl(HArr* p) { assert(p->type == t_harrPartial);
|
||||
void harr_abandon_impl(HArr* p) { assert(PTY(p) == t_harrPartial);
|
||||
gsPop();
|
||||
harrP_freeO((Value*) p);
|
||||
mm_free((Value*) p);
|
||||
}
|
||||
static void harrP_visit(Value* x) { assert(x->type == t_harrPartial);
|
||||
static void harrP_visit(Value* x) { assert(PTY(x) == t_harrPartial);
|
||||
B* p = ((HArr*)x)->a;
|
||||
usz am = PIA((HArr*)x);
|
||||
for (usz i = 0; i < am; i++) mm_visit(p[i]);
|
||||
|
||||
@ -102,10 +102,10 @@ static B m_hunit(B x) { // consumes
|
||||
}
|
||||
|
||||
static B* harr_ptr(B x) { VTY(x,t_harr); return c(HArr,x)->a; }
|
||||
static B* hany_ptr(B x) { return v(x)->type==t_hslice? c(HSlice,x)->a : harr_ptr(x); }
|
||||
static B* hany_ptr(B x) { return TY(x)==t_hslice? c(HSlice,x)->a : harr_ptr(x); }
|
||||
|
||||
HArr* cpyHArr(B x); // consumes
|
||||
static HArr* toHArr(B x) { return v(x)->type==t_harr? c(HArr,x) : cpyHArr(x); }
|
||||
static HArr* toHArr(B x) { return TY(x)==t_harr? c(HArr,x) : cpyHArr(x); }
|
||||
B m_caB(usz ia, B* a);
|
||||
|
||||
// consumes all
|
||||
|
||||
@ -46,9 +46,9 @@ void heapVerify() {
|
||||
static u64 heap_PICounts[t_COUNT];
|
||||
static u64 heap_PISizes[t_COUNT];
|
||||
|
||||
void heap_PIFn(Value* v) {
|
||||
heap_PICounts[v->type]++;
|
||||
heap_PISizes[v->type]+= mm_size(v);
|
||||
NOINLINE void heap_PIFn(Value* v) {
|
||||
heap_PICounts[PTY(v)]++;
|
||||
heap_PISizes[PTY(v)]+= mm_size(v);
|
||||
}
|
||||
|
||||
static u64 heap_PIFreed[128];
|
||||
|
||||
@ -73,16 +73,16 @@ F64Arr* cpyF64Arr(B x); // consumes
|
||||
BitArr* cpyBitArr(B x); // consumes
|
||||
|
||||
// all consume x
|
||||
static I8Arr* toI8Arr (B x) { return v(x)->type==t_i8arr ? c(I8Arr, x) : cpyI8Arr (x); }
|
||||
static I16Arr* toI16Arr(B x) { return v(x)->type==t_i16arr? c(I16Arr,x) : cpyI16Arr(x); }
|
||||
static I32Arr* toI32Arr(B x) { return v(x)->type==t_i32arr? c(I32Arr,x) : cpyI32Arr(x); }
|
||||
static F64Arr* toF64Arr(B x) { return v(x)->type==t_f64arr? c(F64Arr,x) : cpyF64Arr(x); }
|
||||
static BitArr* toBitArr(B x) { return v(x)->type==t_bitarr? c(BitArr,x) : cpyBitArr(x); }
|
||||
static I8Arr* toI8Arr (B x) { return TY(x)==t_i8arr ? c(I8Arr, x) : cpyI8Arr (x); }
|
||||
static I16Arr* toI16Arr(B x) { return TY(x)==t_i16arr? c(I16Arr,x) : cpyI16Arr(x); }
|
||||
static I32Arr* toI32Arr(B x) { return TY(x)==t_i32arr? c(I32Arr,x) : cpyI32Arr(x); }
|
||||
static F64Arr* toF64Arr(B x) { return TY(x)==t_f64arr? c(F64Arr,x) : cpyF64Arr(x); }
|
||||
static BitArr* toBitArr(B x) { return TY(x)==t_bitarr? c(BitArr,x) : cpyBitArr(x); }
|
||||
|
||||
static B toI8Any (B x) { u8 t=v(x)->type; return t==t_i8arr || t==t_i8slice ? x : taga(cpyI8Arr (x)); }
|
||||
static B toI16Any(B x) { u8 t=v(x)->type; return t==t_i16arr || t==t_i16slice? x : taga(cpyI16Arr(x)); }
|
||||
static B toI32Any(B x) { u8 t=v(x)->type; return t==t_i32arr || t==t_i32slice? x : taga(cpyI32Arr(x)); }
|
||||
static B toF64Any(B x) { u8 t=v(x)->type; return t==t_f64arr || t==t_f64slice? x : taga(cpyF64Arr(x)); }
|
||||
static B toI8Any (B x) { u8 t=TY(x); return t==t_i8arr || t==t_i8slice ? x : taga(cpyI8Arr (x)); }
|
||||
static B toI16Any(B x) { u8 t=TY(x); return t==t_i16arr || t==t_i16slice? x : taga(cpyI16Arr(x)); }
|
||||
static B toI32Any(B x) { u8 t=TY(x); return t==t_i32arr || t==t_i32slice? x : taga(cpyI32Arr(x)); }
|
||||
static B toF64Any(B x) { u8 t=TY(x); return t==t_f64arr || t==t_f64slice? x : taga(cpyF64Arr(x)); }
|
||||
|
||||
|
||||
B m_cai32(usz ia, i32* a);
|
||||
|
||||
@ -137,8 +137,8 @@ void fprint(FILE* f, B x) {
|
||||
else fprintf(f, "\\x0%x", (u32)x.u);
|
||||
} else if (isVal(x)) {
|
||||
#ifdef DEBUG
|
||||
if (isVal(x) && (v(x)->type==t_freed || v(x)->type==t_empty)) {
|
||||
u8 t = v(x)->type;
|
||||
if (isVal(x) && (TY(x)==t_freed || TY(x)==t_empty)) {
|
||||
u8 t = TY(x);
|
||||
v(x)->type = v(x)->flags;
|
||||
fprintf(f, t==t_freed?"FREED:":"EMPTY:");
|
||||
TI(x,print)(f, x);
|
||||
@ -399,7 +399,7 @@ NOINLINE i32 compareF(B w, B x) {
|
||||
#undef CMP
|
||||
|
||||
NOINLINE bool atomEqualF(B w, B x) {
|
||||
if (v(w)->type!=v(x)->type) return false;
|
||||
if (TY(w)!=TY(x)) return false;
|
||||
B2B dcf = TI(w,decompose);
|
||||
if (dcf == def_decompose) return false;
|
||||
B wd=dcf(inc(w)); B* wdp = harr_ptr(wd);
|
||||
@ -509,7 +509,7 @@ bool atomEEqual(B w, B x) { // doesn't consume (not that that matters really cur
|
||||
#endif
|
||||
if(isF64(w)|isF64(x)) return false;
|
||||
if (!isVal(w) | !isVal(x)) return false;
|
||||
if (v(w)->type!=v(x)->type) return false;
|
||||
if (TY(w)!=TY(x)) return false;
|
||||
B2B dcf = TI(w,decompose);
|
||||
if (dcf == def_decompose) return false;
|
||||
B wd=dcf(inc(w)); B* wdp = harr_ptr(wd);
|
||||
|
||||
@ -60,7 +60,7 @@ static Arr* bitarr_slice(B x, usz s, usz ia) {
|
||||
return r;
|
||||
}
|
||||
|
||||
static B bitarr_get(Arr* x, usz n) { assert(x->type==t_bitarr); return bitp_get((u64*)((BitArr*)x)->a, n)? m_f64(1) : m_f64(0); }
|
||||
static B bitarr_get(Arr* x, usz n) { assert(PTY(x)==t_bitarr); return bitp_get((u64*)((BitArr*)x)->a, n)? m_f64(1) : m_f64(0); }
|
||||
static bool bitarr_canStore(B x) { return q_bit(x); }
|
||||
|
||||
static void bitarr_init() {
|
||||
|
||||
@ -11,8 +11,8 @@ static Arr* TP(m_,slice) (Arr* p, TEl* ptr, usz ia) {
|
||||
static Arr* TP(,arr_slice) (B x, usz s, usz ia) { return TP(m_,slice) (a(x), ((TEl*)c(TyArr,x)->a)+s, ia); }
|
||||
static Arr* TP(,slice_slice) (B x, usz s, usz ia) { Arr* p = ptr_inc(c(Slice,x)->p); Arr* r = TP(m_,slice) (p, ((TEl*)c(TySlice,x)->a)+s, ia); dec(x); return r; }
|
||||
|
||||
static B TP(,arr_get) (Arr* x, usz n) { assert(x->type==T_ARR ); return TP(m_,) (((TEl*)((TyArr* )x)->a)[n]); }
|
||||
static B TP(,slice_get) (Arr* x, usz n) { assert(x->type==T_SLICE); return TP(m_,) (((TEl*)((TySlice*)x)->a)[n]); }
|
||||
static B TP(,arr_get) (Arr* x, usz n) { assert(PTY(x)==T_ARR ); return TP(m_,) (((TEl*)((TyArr* )x)->a)[n]); }
|
||||
static B TP(,slice_get) (Arr* x, usz n) { assert(PTY(x)==T_SLICE); return TP(m_,) (((TEl*)((TySlice*)x)->a)[n]); }
|
||||
static bool TP(,arr_canStore) (B x) { return TP(q_,) (x); }
|
||||
|
||||
static void TP(,arr_init)() {
|
||||
|
||||
@ -28,7 +28,7 @@ static Arr* TP(m_,arrp) (TEl** p, usz ia) {
|
||||
static TEl* TP(,arrv_ptr) (TyArr* x) { return (TEl*)x->a; }
|
||||
|
||||
static TEl* TP(,arr_ptr) (B x) { VTY(x, T_ARR); return (TEl*)c(TyArr,x)->a; }
|
||||
static TEl* TP(,any_ptr) (B x) { assert(isArr(x)); u8 t=v(x)->type; if(t==T_ARR) return (TEl*)c(TyArr,x)->a; assert(t==T_SLICE); return (TEl*)c(TySlice,x)->a; }
|
||||
static TEl* TP(,any_ptr) (B x) { assert(isArr(x)); u8 t=TY(x); if(t==T_ARR) return (TEl*)c(TyArr,x)->a; assert(t==T_SLICE); return (TEl*)c(TySlice,x)->a; }
|
||||
|
||||
#undef TEl
|
||||
#undef TU
|
||||
|
||||
@ -302,19 +302,19 @@ static OptRes opt(u32* bc0) {
|
||||
break;
|
||||
}
|
||||
case FN1C: case FN1O: { S(f,0)
|
||||
if (!isFun(f.v) || v(f.v)->type!=t_funBI) goto defIns;
|
||||
if (!isFun(f.v) || TY(f.v)!=t_funBI) goto defIns;
|
||||
RM(f.p); cact = 3;
|
||||
TSADD(data, (u64) c(Fun, f.v)->c1);
|
||||
goto defIns;
|
||||
}
|
||||
case FN2C: { S(f,1)
|
||||
if (!isFun(f.v) || v(f.v)->type!=t_funBI) goto defIns;
|
||||
if (!isFun(f.v) || TY(f.v)!=t_funBI) goto defIns;
|
||||
cact = 3; RM(f.p);
|
||||
TSADD(data, (u64) c(Fun, f.v)->c2);
|
||||
goto defIns;
|
||||
}
|
||||
case FN2O: { S(f,1)
|
||||
if (!isFun(f.v) || v(f.v)->type!=t_funBI) goto defIns;
|
||||
if (!isFun(f.v) || TY(f.v)!=t_funBI) goto defIns;
|
||||
cact = 4; RM(f.p);
|
||||
TSADD(data, (u64) c(Fun, f.v)->c1);
|
||||
TSADD(data, (u64) c(Fun, f.v)->c2);
|
||||
|
||||
@ -102,7 +102,7 @@ static NOINLINE void asm_free() {
|
||||
|
||||
assert(asm_depth>0);
|
||||
B v = gsPop();
|
||||
assert(v(v)->type==t_customObj);
|
||||
assert(TY(v)==t_customObj);
|
||||
decG(v);
|
||||
}
|
||||
|
||||
|
||||
@ -18,8 +18,8 @@ B eachd_fn(B fo, B w, B x, BBB2B f) {
|
||||
return m_unit(r);
|
||||
}
|
||||
if (rm && !eqShPart(SH(w), SH(x), rm)) thrF("Mapping: Expected equal shape prefix (%H ≡ ≢𝕨, %H ≡ ≢𝕩)", w, x);
|
||||
bool rw = rM==wr && ((v(w)->type==t_harr) & reusable(w)); // v(…) is safe as rank>0
|
||||
bool rx = rM==xr && ((v(x)->type==t_harr) & reusable(x));
|
||||
bool rw = rM==wr && ((TY(w)==t_harr) & reusable(w)); // v(…) is safe as rank>0
|
||||
bool rx = rM==xr && ((TY(x)==t_harr) & reusable(x));
|
||||
if (rw|rx && (wr==xr | rm==0)) {
|
||||
HArr_p r = harr_parts(REUSE(rw? w : x));
|
||||
usz ria = r.c->ia;
|
||||
@ -60,7 +60,7 @@ B eachm_fn(B fo, B x, BB2B f) { // TODO definitely rewrite this. Probably still
|
||||
HArr_p rH;
|
||||
if (TI(x,canStore)(cr)) {
|
||||
bool reuse = reusable(x);
|
||||
if (v(x)->type==t_harr) {
|
||||
if (TY(x)==t_harr) {
|
||||
B* xp = harr_ptr(x);
|
||||
if (reuse) {
|
||||
dec(xp[i]); xp[i++] = cr;
|
||||
@ -75,7 +75,7 @@ B eachm_fn(B fo, B x, BB2B f) { // TODO definitely rewrite this. Probably still
|
||||
} else if (TI(x,elType)==el_i32) {
|
||||
i32* xp = i32any_ptr(x);
|
||||
B r; i32* rp;
|
||||
if (reuse && v(x)->type==t_i32arr) { r=incG(REUSE(x)); rp = xp; }
|
||||
if (reuse && TY(x)==t_i32arr) { r=incG(REUSE(x)); rp = xp; }
|
||||
else r = m_i32arrc(&rp, x);
|
||||
rp[i++] = o2iu(cr);
|
||||
for (; i < ia; i++) {
|
||||
@ -93,7 +93,7 @@ B eachm_fn(B fo, B x, BB2B f) { // TODO definitely rewrite this. Probably still
|
||||
} else if (TI(x,elType)==el_f64) {
|
||||
f64* xp = f64any_ptr(x);
|
||||
B r; f64* rp;
|
||||
if (reuse && v(x)->type==t_f64arr) { r=incG(REUSE(x)); rp = xp; }
|
||||
if (reuse && TY(x)==t_f64arr) { r=incG(REUSE(x)); rp = xp; }
|
||||
else r = m_f64arrc(&rp, x);
|
||||
rp[i++] = o2fu(cr);
|
||||
for (; i < ia; i++) {
|
||||
@ -108,7 +108,7 @@ B eachm_fn(B fo, B x, BB2B f) { // TODO definitely rewrite this. Probably still
|
||||
}
|
||||
decG(x);
|
||||
return num_squeeze(r);
|
||||
} else if (v(x)->type==t_fillarr) {
|
||||
} else if (TY(x)==t_fillarr) {
|
||||
B* xp = fillarr_ptr(a(x));
|
||||
if (reuse) {
|
||||
dec(c(FillArr,x)->fill);
|
||||
|
||||
@ -118,9 +118,9 @@ DEF_G(void, fill, B , (void* a, usz ms, B x, usz l), ms, x, l) {
|
||||
|
||||
|
||||
#if SINGELI
|
||||
#define DEF_COPY(TY, BODY) DEF0(void, copy, TY, u8 xe=TI(x,elType); u8 ne=el_or(xe,el_##TY);, ne==el_##TY, ne, (void* a, usz ms, B x, usz xs, usz l), ms, x, xs, l)
|
||||
#define DEF_COPY(T, BODY) DEF0(void, copy, T, u8 xe=TI(x,elType); u8 ne=el_or(xe,el_##T);, ne==el_##T, ne, (void* a, usz ms, B x, usz xs, usz l), ms, x, xs, l)
|
||||
#else
|
||||
#define DEF_COPY(TY, BODY) DEF(void, copy, TY, u8 xe=TI(x,elType); u8 ne=el_or(xe,el_##TY);, ne==el_##TY, ne, (void* a, usz ms, B x, usz xs, usz l), ms, x, xs, l) { u8 xt=v(x)->type; (void)xt; BODY }
|
||||
#define DEF_COPY(T, BODY) DEF(void, copy, T, u8 xe=TI(x,elType); u8 ne=el_or(xe,el_##T);, ne==el_##T, ne, (void* a, usz ms, B x, usz xs, usz l), ms, x, xs, l) { u8 xt=TY(x); (void)xt; BODY }
|
||||
#endif
|
||||
|
||||
|
||||
@ -177,7 +177,7 @@ NOINLINE void m_copyG_B_generic(void* a, B* mpo, B x, usz xs, usz l) {
|
||||
}
|
||||
DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, xs, l) {
|
||||
B* mpo = ms+(B*)a;
|
||||
switch(v(x)->type) {
|
||||
switch(TY(x)) {
|
||||
case t_bitarr: { u64* xp = bitarr_ptr(x); for (usz i = 0; i < l; i++) mpo[i] = m_i32(bitp_get(xp, xs+i)); return; }
|
||||
case t_i8arr: case t_i8slice: { i8* xp = i8any_ptr (x); for (usz i = 0; i < l; i++) mpo[i] = m_i32(xp[i+xs]); return; }
|
||||
case t_i16arr: case t_i16slice: { i16* xp = i16any_ptr(x); for (usz i = 0; i < l; i++) mpo[i] = m_i32(xp[i+xs]); return; }
|
||||
@ -269,7 +269,7 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x
|
||||
if (l==0) return; \
|
||||
u8* xp = tyany_ptr(x); \
|
||||
T* rp = ms + (T*)a; \
|
||||
u8 xt = v(x)->type; \
|
||||
u8 xt = TY(x); \
|
||||
if (xt==t_bitarr) { \
|
||||
for (usz i = 0; i < l; i++) rp[i] = bitp_get((u64*)xp, xs+i); \
|
||||
} else { \
|
||||
|
||||
@ -166,7 +166,7 @@ FORCE_INLINE B arr_join_inline(B w, B x, bool consume, bool* reusedW) {
|
||||
usz ria = wia+xia;
|
||||
if (reusable(w)) {
|
||||
u64 wsz = mm_size(v(w));
|
||||
u8 wt = v(w)->type;
|
||||
u8 wt = TY(w);
|
||||
// TODO f64∾i32, i32∾i8, c32∾c8 etc
|
||||
switch (wt) {
|
||||
case t_bitarr: if (BITARR_SZ( ria)<wsz && TI(x,elType)==el_bit) { bit_cpy(bitarr_ptr(w),wia,bitarr_ptr(x),0,xia); goto rw; } break;
|
||||
@ -220,7 +220,7 @@ static inline bool inplace_add(B w, B x) { // consumes x if returns true; fails
|
||||
usz ria = wia+1;
|
||||
if (reusable(w)) {
|
||||
u64 wsz = mm_size(v(w));
|
||||
u8 wt = v(w)->type;
|
||||
u8 wt = TY(w);
|
||||
switch (wt) {
|
||||
case t_bitarr: if (BITARR_SZ( ria)<wsz && q_bit(x)) { bitp_set(bitarr_ptr(w),wia,o2bu(x)); goto ok; } break;
|
||||
case t_i8arr: if (TYARR_SZ(I8, ria)<wsz && q_i8 (x)) { i8arr_ptr (w)[wia]=o2iu(x); goto ok; } break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user