arrP_sh* → arr_sh*

This commit is contained in:
dzaima 2021-07-03 01:38:56 +03:00
parent d49d5a3e31
commit 08df9bfe7b
18 changed files with 60 additions and 60 deletions

View File

@ -58,7 +58,7 @@ B ud_c1(B t, B x) {
B* rp = fillarr_ptr(r);
for (usz i = 0; i < ria; i++) rp[i] = m_f64(0); // don't break if allocation errors
usz* rsh = arrP_shAllocI(a(r), ria, xia);
usz* rsh = arr_shAllocI(a(r), ria, xia);
if (rsh) memcpy(rsh, sh, sizeof(usz)*xia);
usz pos[xia]; B* crp = rp;
@ -234,7 +234,7 @@ B indexOf_c2(B t, B w, B x) {
}
dec(w); dec(x);
i32* rp; Arr* r = m_i32arrp(&rp, 1);
arrP_shAllocR(r, 0);
arr_shAllocR(r, 0);
rp[0] = res;
return taga(r);
} else if (rnk(x)==1) {

View File

@ -184,7 +184,7 @@ B variation_c2(B t, B w, B x) {
} else if (u32_get(&wp, wpE, U"f")) {
res = m_fillarrp(xia);
fillarr_setFill(res, getFillQ(x));
arrP_shCopy(a(res), x);
arr_shCopy(a(res), x);
B* rp = fillarr_ptr(res);
if (xe==el_i32) { i32* xp=i32any_ptr(x); for (usz i = 0; i < xia; i++) rp[i] = m_f64(xp[i]); }
else if (xe==el_f64) { f64* xp=f64any_ptr(x); for (usz i = 0; i < xia; i++) rp[i] = m_f64(xp[i]); }
@ -192,7 +192,7 @@ B variation_c2(B t, B w, B x) {
} else thrF("•internal.Variation: Bad type \"%R\"", taga(wc));
if (slice) {
Arr* slice = TI(res).slice(res, 0);
arrP_shCopy(slice, res);
arr_shCopy(slice, res);
res = taga(slice);
}
if (u32_get(&wp, wpE, U"Inc")) {
@ -243,7 +243,7 @@ static B unshare(B x) {
return r.b;
}
case t_fillarr: {
B r = m_fillarrp(xia); arrP_shCopy(a(r), x);
B r = m_fillarrp(xia); arr_shCopy(a(r), x);
fillarr_setFill(r, unshare(c(FillArr,x)->fill));
B* rp = fillarr_ptr(r); B* xp = fillarr_ptr(x);
for (usz i = 0; i < xia; i++) rp[i] = unshare(xp[i]);

View File

@ -348,7 +348,7 @@ B cell_c1(B d, B x) { B f = c(Md1D,d)->f;
usz p = 0;
for (; i < cam; i++) {
Arr* s = slice(inc(x), p);
arrP_shSetI(s, csz, cr, csh);
arr_shSetI(s, csz, cr, csh);
r.a[i] = c1(f, taga(s));
p+= csz;
}

View File

@ -10,11 +10,11 @@ B shape_c1(B t, B x) {
usz ia = a(x)->ia;
if (reusable(x)) {
decSh(v(x));
arrP_shVec(a(x), ia);
arr_shVec(a(x), ia);
return x;
}
Arr* r = TI(x).slice(x, 0);
arrP_shVec(r, ia);
arr_shVec(r, ia);
return taga(r);
}
B shape_c2(B t, B w, B x) {
@ -28,7 +28,7 @@ B shape_c2(B t, B w, B x) {
B r; Arr* ra;
if (reusable(x)) { r = x; decSh(v(x)); ra = (Arr*)v(r); }
else { ra = TI(x).slice(x, 0); r = taga(ra); }
usz* sh = arrP_shAllocI(ra, nia, nr);
usz* sh = arr_shAllocI(ra, nia, nr);
if (sh) for (u32 i = 0; i < nr; i++) sh[i] = o2s(wget(w,i));
dec(w);
return r;
@ -63,7 +63,7 @@ B select_c1(B t, B x) {
if (xr==0) thrM("⊏: Argument cannot be rank 0");
if (a(x)->sh[0]==0) thrF("⊏: Argument shape cannot start with 0 (%H ≡ ≢𝕩)", x);
Arr* r = TI(x).slice(inc(x),0);
usz* sh = arrP_shAllocR(r, xr-1);
usz* sh = arr_shAllocR(r, xr-1);
usz ia = 1;
for (i32 i = 1; i < xr; i++) {
if (sh) sh[i-1] = a(x)->sh[i];
@ -82,7 +82,7 @@ B select_c2(B t, B w, B x) {
usz cam = a(x)->sh[0];
usz wi = WRAP(o2i64(w), cam, thrF("⊏: Indexing out-of-bounds (𝕨≡%R, %s≡≠𝕩)", w, cam));
Arr* r = TI(x).slice(inc(x), wi*csz);
usz* sh = arrP_shAllocI(r, csz, xr-1);
usz* sh = arr_shAllocI(r, csz, xr-1);
if (sh) memcpy(sh, a(x)->sh+1, (xr-1)*sizeof(usz));
dec(x);
return taga(r);
@ -174,7 +174,7 @@ B select_c2(B t, B w, B x) {
mut_copy(r, i*csz, x, csz*(usz)c, csz);
}
Arr* ra = mut_fp(r);
usz* rsh = arrP_shAllocR(ra, rr);
usz* rsh = arr_shAllocR(ra, rr);
if (rsh) {
memcpy(rsh , a(w)->sh , wr *sizeof(usz));
memcpy(rsh+wr, a(x)->sh+1, (xr-1)*sizeof(usz));
@ -307,7 +307,7 @@ B slash_c2(B t, B w, B x) {
if (wv<=0) {
if (wv<0) thrM("/: 𝕨 cannot be negative");
Arr* r = TI(x).slice(x, 0);
arrP_shVec(r,0);
arr_shVec(r,0);
return taga(r);
}
usz ri = 0;
@ -337,7 +337,7 @@ B slash_c2(B t, B w, B x) {
B slicev(B x, usz s, usz ia) {
usz xia = a(x)->ia; assert(s+ia <= xia);
Arr* r = TI(x).slice(x, s);
arrP_shVec(r, ia);
arr_shVec(r, ia);
return taga(r);
}
extern B rt_take, rt_drop;
@ -395,7 +395,7 @@ B join_c1(B t, B x) {
if (ir==0) thrM("∾: Empty vector 𝕩 cannot have a unit fill element");
B xff = getFillQ(xf);
HArr_p r = m_harrUp(0);
usz* sh = arrP_shAllocR((Arr*)r.c, ir);
usz* sh = arr_shAllocR((Arr*)r.c, ir);
if (sh) {
sh[0] = 0;
memcpy(sh+1, a(xf)->sh+1, sizeof(usz)*(ir-1));
@ -433,7 +433,7 @@ B join_c1(B t, B x) {
}
assert(ri==cam*csz);
Arr* ra = mut_fp(r);
usz* sh = arrP_shAllocR(ra, ir);
usz* sh = arr_shAllocR(ra, ir);
if (sh) {
sh[0] = cam;
memcpy(sh+1, x0sh+1, sizeof(usz)*(ir-1));
@ -471,7 +471,7 @@ B join_c2(B t, B w, B x) {
mut_copy(r, 0, w, 0, wia);
mut_copy(r, wia, x, 0, xia);
Arr* ra = mut_fp(r);
usz* sh = arrP_shAllocR(ra, c);
usz* sh = arr_shAllocR(ra, c);
if (sh) {
for (i32 i = 1; i < c; i++) {
usz s = xsh[i+xr-c];
@ -490,7 +490,7 @@ B couple_c1(B t, B x) {
usz rr = rnk(x);
usz ia = a(x)->ia;
Arr* r = TI(x).slice(inc(x),0);
usz* sh = arrP_shAllocI(r, ia, rr+1);
usz* sh = arr_shAllocI(r, ia, rr+1);
if (sh) { sh[0] = 1; memcpy(sh+1, a(x)->sh, rr*sizeof(usz)); }
dec(x);
return taga(r);
@ -517,7 +517,7 @@ B couple_c2(B t, B w, B x) {
mut_copy(r, 0, w, 0, ia);
mut_copy(r, ia, x, 0, ia);
Arr* ra = mut_fp(r);
usz* sh = arrP_shAllocR(ra, wr+1);
usz* sh = arr_shAllocR(ra, wr+1);
if (sh) { sh[0]=2; memcpy(sh+1, a(w)->sh, wr*sizeof(usz)); }
if (!SFNS_FILLS) { dec(w); dec(x); return taga(ra); }
B rf = fill_both(w, x);
@ -612,13 +612,13 @@ B group_c2(B t, B w, B x) {
for (usz i = 0; i < xia; i++) { i32 n = wp[i]; if (n>=0) len[n]++; }
B r = m_fillarrp(ria); fillarr_setFill(r, m_f64(0));
arrP_shVec(a(r), ria);
arr_shVec(a(r), ria);
B* rp = fillarr_ptr(r);
for (usz i = 0; i < ria; i++) rp[i] = m_f64(0); // don't break if allocation errors
B xf = getFillQ(x);
B rf = m_fillarrp(0); fillarr_setFill(rf, m_f64(0));
arrP_shVec(a(rf), 0);
arr_shVec(a(rf), 0);
fillarr_setFill(r, rf);
if (TI(x).elType==el_i32) {
for (usz i = 0; i < ria; i++) { i32* t; rp[i] = m_i32arrv(&t, len[i]); }
@ -646,7 +646,7 @@ B group_c2(B t, B w, B x) {
i32 n = wp[i];
if (n>=0) fillarr_ptr(rp[n])[pos[n]++] = xget(x, i);
}
for (usz i = 0; i < ria; i++) { arrP_shVec(a(rp[i]), len[i]); }
for (usz i = 0; i < ria; i++) { arr_shVec(a(rp[i]), len[i]); }
}
fillarr_setFill(rf, xf);
dec(w); dec(x); TFREE(len); TFREE(pos);
@ -670,7 +670,7 @@ B group_c2(B t, B w, B x) {
}
B r = m_fillarrp(ria); fillarr_setFill(r, m_f64(0));
arrP_shVec(a(r), ria);
arr_shVec(a(r), ria);
B* rp = fillarr_ptr(r);
for (usz i = 0; i < ria; i++) rp[i] = m_f64(0); // don't break if allocation errors
B xf = getFillQ(x);
@ -682,7 +682,7 @@ B group_c2(B t, B w, B x) {
rp[i] = c;
}
B rf = m_fillarrp(0);
arrP_shVec(a(rf), 0);
arr_shVec(a(rf), 0);
fillarr_setFill(rf, xf);
fillarr_setFill(r, rf);
BS2B xget = TI(x).get;
@ -690,7 +690,7 @@ B group_c2(B t, B w, B x) {
i64 n = o2i64u(wgetU(w, i));
if (n>=0) fillarr_ptr(rp[n])[pos[n]++] = xget(x, i);
}
for (usz i = 0; i < ria; i++) { arrP_shVec(a(rp[i]), len[i]); }
for (usz i = 0; i < ria; i++) { arr_shVec(a(rp[i]), len[i]); }
dec(w); dec(x); TFREE(len); TFREE(pos);
return r;
}

View File

@ -46,6 +46,6 @@ void c32arr_init() {
ti[t_c32arr].canStore = c32arr_canStore;
u32* tmp; bi_emptyCVec = m_c32arrv(&tmp, 0); gc_add(bi_emptyCVec);
bi_emptySVec = m_fillarrp(0); gc_add(bi_emptySVec);
arrP_shVec(a(bi_emptySVec), 0);
arr_shVec(a(bi_emptySVec), 0);
fillarr_setFill(bi_emptySVec, inc(bi_emptyCVec));
}

View File

@ -11,13 +11,13 @@ typedef struct C32Slice {
static B m_c32arrv(u32** p, usz ia) {
C32Arr* r = mm_alloc(fsizeof(C32Arr,a,u32,ia), t_c32arr);
*p = r->a;
arrP_shVec((Arr*)r, ia);
arr_shVec((Arr*)r, ia);
return taga(r);
}
static B m_c32arrc(u32** p, B x) { assert(isArr(x));
C32Arr* r = mm_alloc(fsizeof(C32Arr,a,u32,a(x)->ia), t_c32arr);
*p = r->a;
arrP_shCopy((Arr*)r, x);
arr_shCopy((Arr*)r, x);
return taga(r);
}
static Arr* m_c32arrp(u32** p, usz ia) { // doesn't write shape/rank

View File

@ -11,13 +11,13 @@ typedef struct F64Slice {
static B m_f64arrv(f64** p, usz ia) {
F64Arr* r = mm_alloc(fsizeof(F64Arr,a,f64,ia), t_f64arr);
*p = r->a;
arrP_shVec((Arr*)r, ia);
arr_shVec((Arr*)r, ia);
return taga(r);
}
static B m_f64arrc(f64** p, B x) { assert(isArr(x));
F64Arr* r = mm_alloc(fsizeof(F64Arr,a,f64,a(x)->ia), t_f64arr);
*p = r->a;
arrP_shCopy((Arr*)r, x);
arr_shCopy((Arr*)r, x);
return taga(r);
}
static Arr* m_f64arrp(f64** p, usz ia) { // doesn't write shape/rank

View File

@ -202,7 +202,7 @@ B withFill(B x, B fill) { // consumes both
}
base:;
FillArr* r = mm_alloc(fsizeof(FillArr,a,B,ia), t_fillarr);
arrP_shCopy((Arr*)r, x);
arr_shCopy((Arr*)r, x);
r->fill = fill;
B* a = r->a;
BS2B xget = TI(x).get;

View File

@ -73,12 +73,12 @@ static B m_unit(B x) {
B xf = asFill(inc(x));
if (noFill(xf)) {
HArr_p r = m_harrUp(1);
arrP_shAllocR((Arr*)r.c, 0);
arr_shAllocR((Arr*)r.c, 0);
r.a[0] = x;
return r.b;
}
FillArr* r = mm_alloc(fsizeof(FillArr,a,B,1), t_fillarr);
arrP_shAllocI((Arr*)r, 1, 0);
arr_shAllocI((Arr*)r, 1, 0);
r->fill = xf;
r->a[0] = x;
return taga(r);
@ -89,13 +89,13 @@ static B m_atomUnit(B x) {
Arr* r;
if (q_i32(x)) { i32* rp; r = m_i32arrp(&rp, 1); rp[0] = o2iu(x); }
else { f64* rp; r = m_f64arrp(&rp, 1); rp[0] = o2fu(x); }
arrP_shAllocR(r, 0);
arr_shAllocR(r, 0);
return taga(r);
}
if (isC32(x)) {
u32* rp; Arr* r = m_c32arrp(&rp, 1);
rp[0] = o2cu(x);
arrP_shAllocR(r,0);
arr_shAllocR(r,0);
return taga(r);
}
return m_unit(x);

View File

@ -14,7 +14,7 @@ B toCells(B x) {
if (rnk(x)==2) {
for (; i < cam; i++) {
Arr* s = slice(inc(x), p);
arrP_shVec(s, csz);
arr_shVec(s, csz);
r.a[i] = taga(s);
p+= csz;
}
@ -25,7 +25,7 @@ B toCells(B x) {
for (i32 i = 0; i < cr; i++) csh->a[i] = xsh[i+1];
for (; i < cam; i++) {
Arr* s = slice(inc(x), p);
arrP_shSetI(s, csz, cr, csh);
arr_shSetI(s, csz, cr, csh);
r.a[i] = taga(s);
p+= csz;
}
@ -53,7 +53,7 @@ B toKCells(B x, ur k) {
BS2A slice = TI(x).slice;
for (; i < cam; i++) {
Arr* s = slice(inc(x), p);
arrP_shSetI(s, csz, cr, csh);
arr_shSetI(s, csz, cr, csh);
r.a[i] = taga(s);
p+= csz;
}

View File

@ -42,14 +42,14 @@ static B harr_fv(HArr_p p) { VTY(p.b, t_harrPartial);
static B harr_fc(HArr_p p, B x) { VTY(p.b, t_harrPartial);
assert(p.c->ia == *p.c->sh);
p.c->type = t_harr;
arrP_shCopy((Arr*)p.c, x);
arr_shCopy((Arr*)p.c, x);
gsPop();
return p.b;
}
static B harr_fcd(HArr_p p, B x) { VTY(p.b, t_harrPartial);
assert(p.c->ia == *p.c->sh);
p.c->type = t_harr;
arrP_shCopy((Arr*)p.c, x);
arr_shCopy((Arr*)p.c, x);
dec(x);
gsPop();
return p.b;
@ -57,7 +57,7 @@ static B harr_fcd(HArr_p p, B x) { VTY(p.b, t_harrPartial);
static usz* harr_fa(HArr_p p, ur r) { VTY(p.b, t_harrPartial);
p.c->type = t_harr;
gsPop();
return arrP_shAllocR((Arr*)p.c, r);
return arr_shAllocR((Arr*)p.c, r);
}
static void harr_abandon(HArr_p p) { VTY(p.b, t_harrPartial);
gsPop();
@ -66,12 +66,12 @@ static void harr_abandon(HArr_p p) { VTY(p.b, t_harrPartial);
static HArr_p m_harrUv(usz ia) {
HArr* r = mm_alloc(fsizeof(HArr,a,B,ia), t_harr);
arrP_shVec((Arr*)r, ia);
arr_shVec((Arr*)r, ia);
return harrP_parts(r);
}
static HArr_p m_harrUc(B x) { assert(isArr(x));
HArr* r = mm_alloc(fsizeof(HArr,a,B,a(x)->ia), t_harr);
arrP_shCopy((Arr*)r, x);
arr_shCopy((Arr*)r, x);
return harrP_parts(r);
}
static HArr_p m_harrUp(usz ia) { // doesn't write shape/rank
@ -82,7 +82,7 @@ static HArr_p m_harrUp(usz ia) { // doesn't write shape/rank
static B m_hunit(B x) {
HArr_p r = m_harrUp(1);
arrP_shAllocR((Arr*)r.c, 0);
arr_shAllocR((Arr*)r.c, 0);
r.a[0] = x;
return r.b;
}

View File

@ -11,13 +11,13 @@ typedef struct I32Slice {
static B m_i32arrv(i32** p, usz ia) {
I32Arr* r = mm_alloc(fsizeof(I32Arr,a,i32,ia), t_i32arr);
*p = r->a;
arrP_shVec((Arr*)r, ia);
arr_shVec((Arr*)r, ia);
return taga(r);
}
static B m_i32arrc(i32** p, B x) { assert(isArr(x));
I32Arr* r = mm_alloc(fsizeof(I32Arr,a,i32,a(x)->ia), t_i32arr);
*p = r->a;
arrP_shCopy((Arr*)r, x);
arr_shCopy((Arr*)r, x);
return taga(r);
}
static Arr* m_i32arrp(i32** p, usz ia) { // doesn't write shape/rank

View File

@ -425,7 +425,7 @@ B bqn_merge(B x) { // consumes
B r = m_fillarrp(0);
fillarr_setFill(r, xff);
if (xr+xfr > UR_MAX) thrM(">: Result rank too large");
usz* rsh = arrP_shAllocI(a(r), 0, xr+xfr);
usz* rsh = arr_shAllocI(a(r), 0, xr+xfr);
if (rsh) {
memcpy (rsh , a(x)->sh, xr *sizeof(usz));
if(xfr)memcpy(rsh+xr, a(xf)->sh, xfr*sizeof(usz));
@ -452,7 +452,7 @@ B bqn_merge(B x) { // consumes
rp+= elIA;
}
Arr* ra = mut_fp(r);
usz* rsh = arrP_shAllocR(ra, xr+elR);
usz* rsh = arr_shAllocR(ra, xr+elR);
if (rsh) {
memcpy (rsh , a(x)->sh, xr *sizeof(usz));
if (elSh)memcpy(rsh+xr, elSh, elR*sizeof(usz));

View File

@ -36,28 +36,28 @@ static ShArr* m_shArr(ur r) {
return ((ShArr*)mm_alloc(fsizeof(ShArr, a, usz, r), t_shape));
}
static void arrP_shVec(Arr* x, usz ia) {
static void arr_shVec(Arr* x, usz ia) {
x->ia = ia;
sprnk(x, 1);
x->sh = &x->ia;
}
static usz* arrP_shAllocR(Arr* x, ur r) { // allocates shape, sets rank
static usz* arr_shAllocR(Arr* x, ur r) { // allocates shape, sets rank
sprnk(x,r);
if (r>1) return x->sh = m_shArr(r)->a;
x->sh = &x->ia;
return 0;
}
static usz* arrP_shAllocI(Arr* x, usz ia, ur r) { // allocates shape, sets ia,rank
static usz* arr_shAllocI(Arr* x, usz ia, ur r) { // allocates shape, sets ia,rank
x->ia = ia;
return arrP_shAllocR(x, r);
return arr_shAllocR(x, r);
}
static void arrP_shSetI(Arr* x, usz ia, ur r, ShArr* sh) {
static void arr_shSetI(Arr* x, usz ia, ur r, ShArr* sh) {
sprnk(x,r);
x->ia = ia;
if (r>1) { x->sh = sh->a; ptr_inc(sh); }
else { x->sh = &x->ia; }
}
static void arrP_shCopy(Arr* n, B o) { // copy shape,rank,ia from o to n
static void arr_shCopy(Arr* n, B o) { // copy shape,rank,ia from o to n
assert(isArr(o));
n->ia = a(o)->ia;
ur r = sprnk(n,rnk(o));

View File

@ -180,7 +180,7 @@ static void* nvm_alloc(u64 sz) {
// if (r==MAP_FAILED) thrM("JIT: Failed to allocate executable memory");
// return r;
TmpFile* src = mmX_allocN(fsizeof(TmpFile,a,u8,sz), t_i8arr);
arrP_shVec((Arr*)src, sz);
arr_shVec((Arr*)src, sz);
return src->a;
}
void nvm_free(u8* ptr) {

View File

@ -31,7 +31,7 @@ TmpFile* file_bytes(B path) { // consumes
u64 len = ftell(f);
fseek(f, 0, SEEK_SET);
TmpFile* src = mm_alloc(fsizeof(TmpFile,a,u8,len), t_i8arr);
arrP_shVec((Arr*)src, len);
arr_shVec((Arr*)src, len);
if (fread((char*)src->a, 1, len, f)!=len) thrF("Error reading file \"%R\"", path);
dec(path);
fclose(f);
@ -75,7 +75,7 @@ B path_dir(B path) { // consumes; returns directory part of file path with trail
for (i64 i = (i64)pia-1; i >= 0; i--) {
if (o2cu(pgetU(path, i))=='/') {
Arr* r = TI(path).slice(path, 0);
arrP_shVec(r, i+1);
arr_shVec(r, i+1);
return taga(r);
}
}

View File

@ -54,12 +54,12 @@ static B mut_fv(Mut* m) { assert(m->type!=el_MAX);
}
static B mut_fc(Mut* m, B x) { assert(m->type!=el_MAX);
Arr* a = m->val;
arrP_shCopy(a, x);
arr_shCopy(a, x);
return taga(a);
}
static B mut_fcd(Mut* m, B x) { assert(m->type!=el_MAX);
Arr* a = m->val;
arrP_shCopy(a, x);
arr_shCopy(a, x);
dec(x);
return taga(a);
}

View File

@ -842,7 +842,7 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes p
i64 padStart = padEnd;
while (padStart>0 && o2cu(srcGetU(s,padStart-1))!='\n') padStart--;
Arr* slice = TI(src).slice(inc(src),srcS); arrP_shVec(slice, srcE-srcS);
Arr* slice = TI(src).slice(inc(src),srcS); arr_shVec(slice, srcE-srcS);
AJOIN(taga(slice));
cs-= srcS;
ce-= srcS;