make arr_shVec return its argument

This commit is contained in:
dzaima 2022-06-10 00:06:14 +03:00
parent 638891bde1
commit 025043b84e
9 changed files with 22 additions and 35 deletions

View File

@ -62,8 +62,7 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f;
if (!EACH_FILLS && isFun(f) && isPervasiveDy(f) && TI(w,arrD1)) {
BBB2B fc2 = c(Fun,f)->c2;
if (TI(x,arrD1) && xia<80 && wia>130) {
Arr* wd = TI(w,slice)(inc(w), 0, wia);
arr_shVec(wd);
Arr* wd = arr_shVec(TI(w,slice)(inc(w), 0, wia));
r = fc2(f, slash_c2(f, m_i32(xia), taga(wd)), shape_c2(f, m_f64(ria), inc(x)));
} else {
SGet(w)

View File

@ -35,7 +35,7 @@ B m_vec1(B a) {
else if (LIKELY(c<U16_MAX)) { u16* rp; B r = m_c16arrv(&rp, 1); rp[0] = c; return r; }
else { u32* rp; B r = m_c32arrv(&rp, 1); rp[0] = c; return r; }
}
Arr* ra = m_fillarrp(1); arr_shVec(ra);
Arr* ra = arr_shVec(m_fillarrp(1));
fillarr_ptr(ra)[0] = a;
fillarr_setFill(ra, m_f64(0));
fillarr_setFill(ra, asFill(inc(a)));
@ -67,7 +67,7 @@ FORCE_INLINE B m_vec2Base(B a, B b, bool fills) {
if (noFill(bf)) { dec(af); goto noFills; }
if (!fillEqual(af,bf)) { dec(bf); dec(af); goto noFills; }
dec(bf);
Arr* ra = m_fillarrp(2); arr_shVec(ra);
Arr* ra = arr_shVec(m_fillarrp(2));
fillarr_setFill(ra, af);
fillarr_ptr(ra)[0] = a;
fillarr_ptr(ra)[1] = b;
@ -95,8 +95,7 @@ B shape_c1(B t, B x) {
decSh(v(x)); arr_shVec(a(x));
return x;
}
Arr* r = TI(x,slice)(x, 0, ia); arr_shVec(r);
return taga(r);
return taga(arr_shVec(TI(x,slice)(x, 0, ia)));
}
static B truncReshape(B x, usz xia, usz nia, ur nr, ShArr* sh) { // consumes all
B r; Arr* ra;
@ -173,9 +172,7 @@ B shape_c2(B t, B w, B x) {
nia = uszMul(nia, item);
if (fill) {
if (!isArr(x)) x = m_atomUnit(x);
Arr* a = take_impl(nia, x);
arr_shVec(a);
x = taga(a);
x = taga(arr_shVec(take_impl(nia, x)));
xia = nia;
}
}
@ -558,8 +555,7 @@ B slash_c2(B t, B w, B x) {
i32 wv = o2i(w);
if (wv<=0) {
if (wv<0) thrM("/: 𝕨 cannot be negative");
Arr* r = TI(x,slice)(x, 0, 0); arr_shVec(r);
return taga(r);
return taga(arr_shVec(TI(x,slice)(x, 0, 0)));
}
if (TI(x,elType)==el_i32) {
i32* xp = i32any_ptr(x);
@ -675,9 +671,9 @@ B slash_im(B t, B x) {
static B slicev(B x, usz s, usz ia) {
usz xia = a(x)->ia; assert(s+ia <= xia);
Arr* r = TI(x,slice)(x, s, ia); arr_shVec(r);
return taga(r);
return taga(arr_shVec(TI(x,slice)(x, s, ia)));
}
extern B rt_take, rt_drop;
B take_c1(B t, B x) { return c1(rt_take, x); }
B drop_c1(B t, B x) { return c1(rt_drop, x); }
@ -970,12 +966,12 @@ B group_c2(B t, B w, B x) {
len[n]++; // overallocation makes this safe after n<-1 check
}
Arr* r = m_fillarrp(ria); fillarr_setFill(r, m_f64(0)); arr_shVec(r);
Arr* r = arr_shVec(m_fillarrp(ria)); fillarr_setFill(r, m_f64(0));
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);
Arr* rf = m_fillarrp(0); fillarr_setFill(rf, m_f64(0)); arr_shVec(rf);
Arr* rf = arr_shVec(m_fillarrp(0)); fillarr_setFill(rf, m_f64(0));
fillarr_setFill(r, taga(rf));
u8 xe = TI(x,elType);
switch (xe) { default: UD;
@ -1035,7 +1031,7 @@ B group_c2(B t, B w, B x) {
for (usz i = 0; i < ria; i++) len[i] = pos[i] = 0;
for (usz i = 0; i < xia; i++) len[o2i64u(GetU(w, i))]++;
Arr* r = m_fillarrp(ria); fillarr_setFill(r, m_f64(0)); arr_shVec(r);
Arr* r = arr_shVec(m_fillarrp(ria)); fillarr_setFill(r, m_f64(0));
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);

View File

@ -67,9 +67,8 @@ static void fillarr_setFill(Arr* x, B fill) { assert(x->type==t_fillarr); ((Fill
static B* fillarr_ptr(Arr* x) { assert(x->type==t_fillarr); return ((FillArr*)x)->a; }
static B m_emptyFVec(B f) { // consumes f
Arr* r = m_fillarrp(0);
Arr* r = arr_shVec(m_fillarrp(0));
fillarr_setFill(r, f);
arr_shVec(r);
return taga(r);
}

View File

@ -12,8 +12,7 @@ B toCells(B x) {
usz p = 0;
if (rnk(x)==2) {
for (usz i = 0; i < cam; i++) {
Arr* s = slice(inc(x), p, csz); arr_shVec(s);
HARR_ADD(r, i, taga(s));
HARR_ADD(r, i, taga(arr_shVec(slice(inc(x), p, csz))));
p+= csz;
}
} else {

View File

@ -46,9 +46,10 @@ static ShArr* m_shArr(ur r) {
return ((ShArr*)mm_alloc(fsizeof(ShArr, a, usz, r), t_shape));
}
static void arr_shVec(Arr* x) {
static Arr* arr_shVec(Arr* x) {
sprnk(x, 1);
x->sh = &x->ia;
return x;
}
static usz* arr_shAlloc(Arr* x, ur r) { // sets rank, allocates & returns shape (or null if r<2)
if (r>1) {

View File

@ -80,7 +80,7 @@ void tyarr_init() {
{ u64* tmp; bi_emptyIVec = m_bitarrv(&tmp, 0); gc_add(bi_emptyIVec); }
{ u8* tmp; bi_emptyCVec = m_c8arrv (&tmp, 0); gc_add(bi_emptyCVec); }
Arr* emptySVec = m_fillarrp(0); arr_shVec(emptySVec);
Arr* emptySVec = arr_shVec(m_fillarrp(0));
fillarr_setFill(emptySVec, emptyCVec());
bi_emptySVec = taga(emptySVec); gc_add(bi_emptySVec);
}

View File

@ -577,6 +577,7 @@ static inline B incBy(B x, i64 am) { // you most likely don't want am to be nega
if (isVal(VALIDATE(x))) v(x)->refc+= am;
return x;
}
static inline B incByG(B x, i64 am) { v(x)->refc+= am; return x; }
#define ptr_inc(X) ({ AUTO x_ = (X); VALIDATEP((Value*)x_)->refc++; x_; })

View File

@ -123,10 +123,7 @@ B path_dir(B path) {
if (pia==0) thrM("Empty file path");
guaranteeStr(path);
for (i64 i = (i64)pia-1; i >= 0; i--) {
if (o2cu(GetU(path, i))=='/') {
Arr* r = TI(path,slice)(path, 0, i+1); arr_shVec(r);
return taga(r);
}
if (o2cu(GetU(path, i))=='/') return taga(arr_shVec(TI(path,slice)(path, 0, i+1)));
}
dec(path);
u32* rp; B r = m_c32arrv(&rp, 2); rp[0] = '.'; rp[1] = '/';
@ -141,8 +138,7 @@ B path_name(B path) {
for (i64 i = (i64)pia-1; i >= 0; i--) {
if (o2cu(GetU(path, i))=='/') {
if (i == pia-1) thrF("File path ended with a slash: '%R'", path);
Arr* r = TI(path,slice)(path, i+1, pia - (i+1)); arr_shVec(r);
return taga(r);
return taga(arr_shVec(TI(path,slice)(path, i+1, pia - (i+1))));
}
}
return path;
@ -275,10 +271,7 @@ B mmap_file(B path) {
holder->a = data;
holder->size = len;
arr_shVec((Arr*)holder);
Arr* r = mmapH_slice(taga(holder), 0, len);
arr_shVec(r);
return taga(r);
return taga(arr_shVec(mmapH_slice(taga(holder), 0, len)));
}
B mmapH_get(Arr* a, usz pos) { thrM("Reading mmapH directly"); }

View File

@ -1211,8 +1211,7 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes p
SGetU(s)
while (padStart>0 && o2cu(GetU(s,padStart-1))!='\n') padStart--;
Arr* slice = TI(src,slice)(inc(src),srcS, srcE-srcS); arr_shVec(slice);
AJOIN(taga(slice));
AJOIN(taga(arr_shVec(TI(src,slice)(inc(src),srcS, srcE-srcS))));
cs-= srcS;
ce-= srcS;
ACHR('\n');
@ -1442,7 +1441,7 @@ void profiler_displayResults() {
u32 c = o2cu(GetU(src, i));
curr+= m[i];
if (c=='\n' || i==sia-1) {
Arr* sl = TI(src,slice)(inc(src), pi, i-pi+(c=='\n'?0:1)); arr_shVec(sl);
Arr* sl = arr_shVec(TI(src,slice)(inc(src), pi, i-pi+(c=='\n'?0:1)));
if (curr==0) printf("");
else printf("%6d│", curr);
printRaw(taga(sl));