don't use arr_sh*

This commit is contained in:
dzaima 2021-07-03 01:37:54 +03:00
parent c0a75327ef
commit d49d5a3e31
10 changed files with 30 additions and 63 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 = arr_shAllocI(r, ria, xia);
usz* rsh = arrP_shAllocI(a(r), ria, xia);
if (rsh) memcpy(rsh, sh, sizeof(usz)*xia);
usz pos[xia]; B* crp = rp;

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));
arr_shCopy(res, x);
arrP_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]); }
@ -243,7 +243,7 @@ static B unshare(B x) {
return r.b;
}
case t_fillarr: {
B r = m_fillarrp(xia); arr_shCopy(r, x);
B r = m_fillarrp(xia); arrP_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

@ -10,7 +10,7 @@ B shape_c1(B t, B x) {
usz ia = a(x)->ia;
if (reusable(x)) {
decSh(v(x));
arr_shVec(x, ia);
arrP_shVec(a(x), ia);
return x;
}
Arr* r = TI(x).slice(x, 0);
@ -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 = arr_shAllocR(r.b, ir);
usz* sh = arrP_shAllocR((Arr*)r.c, ir);
if (sh) {
sh[0] = 0;
memcpy(sh+1, a(xf)->sh+1, sizeof(usz)*(ir-1));
@ -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));
arr_shVec(r, ria);
arrP_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));
arr_shVec(rf, 0);
arrP_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++) { arr_shVec(rp[i], len[i]); }
for (usz i = 0; i < ria; i++) { arrP_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));
arr_shVec(r, ria);
arrP_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);
arr_shVec(rf, 0);
arrP_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++) { arr_shVec(rp[i], len[i]); }
for (usz i = 0; i < ria; i++) { arrP_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);
arr_shVec(bi_emptySVec, 0);
arrP_shVec(a(bi_emptySVec), 0);
fillarr_setFill(bi_emptySVec, inc(bi_emptyCVec));
}

View File

@ -73,7 +73,7 @@ static B m_unit(B x) {
B xf = asFill(inc(x));
if (noFill(xf)) {
HArr_p r = m_harrUp(1);
arr_shAllocR(r.b, 0);
arrP_shAllocR((Arr*)r.c, 0);
r.a[0] = x;
return r.b;
}

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;
arr_shCopy(p.b, x);
arrP_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;
arr_shCopy(p.b, x);
arrP_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 arr_shAllocR(p.b, r);
return arrP_shAllocR((Arr*)p.c, r);
}
static void harr_abandon(HArr_p p) { VTY(p.b, t_harrPartial);
gsPop();
@ -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);
arr_shAllocR(r.b, 0);
arrP_shAllocR((Arr*)r.c, 0);
r.a[0] = x;
return r.b;
}

View File

@ -11,7 +11,7 @@ NORETURN NOINLINE void err(char* s) {
exit(1);
}
B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec;
B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; // TODO add some way to get inc(these) without going through the tagging mess
NOINLINE TStack* ts_e(TStack* o, u32 elsz, u64 am) { u64 size = o->size;
u64 alsz = mm_round(fsizeof(TStack, data, u8, (size+am)*elsz));
@ -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 = arr_shAllocI(r, 0, xr+xfr);
usz* rsh = arrP_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));

View File

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

10
src/h.h
View File

@ -348,17 +348,17 @@ void slice_visit(Value* x);
void slice_print(B x);
typedef void (*B2v)(B);
typedef Arr* (*BS2A)(B, usz);
typedef B (* BS2B)(B, usz);
typedef B (*BSS2B)(B, usz, usz);
typedef bool (* B2b)(B);
typedef void (* B2v)(B);
typedef Arr* (* BS2A)(B, usz);
typedef B (* BS2B)(B, usz);
typedef B (* BSS2B)(B, usz, usz);
typedef B (* B2B)(B);
typedef B (* BB2B)(B, B);
typedef B (* BBB2B)(B, B, B);
typedef B (* BBBB2B)(B, B, B, B);
typedef B (* BBBBB2B)(B, B, B, B, B);
typedef B (*BBBBBB2B)(B, B, B, B, B, B);
typedef bool (*B2b)(B);
typedef struct TypeInfo {
V2v free; // expects refc==0, type may be cleared to t_empty for garbage collection

View File

@ -53,15 +53,15 @@ static B mut_fv(Mut* m) { assert(m->type!=el_MAX);
return r;
}
static B mut_fc(Mut* m, B x) { assert(m->type!=el_MAX);
B r = taga(m->val);
arr_shCopy(r, x);
return r;
Arr* a = m->val;
arrP_shCopy(a, x);
return taga(a);
}
static B mut_fcd(Mut* m, B x) { assert(m->type!=el_MAX);
B r = taga(m->val);
arr_shCopy(r, x);
Arr* a = m->val;
arrP_shCopy(a, x);
dec(x);
return r;
return taga(a);
}
static Arr* mut_fp(Mut* m) { assert(m->type!=el_MAX); // has ia set
return m->val;