return value from ptr_inc

This commit is contained in:
dzaima 2021-11-20 00:58:18 +02:00
parent 2baa9ac196
commit 5484c109ea
10 changed files with 25 additions and 33 deletions

View File

@ -1215,8 +1215,7 @@ B shape_uc1(B t, B o, B x) {
usz xia = a(x)->ia;
if (rnk(x)==1) return shape_uc1_t(c1(o, x), xia);
ur xr = rnk(x);
ShArr* sh = shObj(x);
ptr_inc(sh);
ShArr* sh = ptr_inc(shObj(x));
return truncReshape(shape_uc1_t(c1(o, shape_c1(t, x)), xia), xia, xia, xr, sh);
}

View File

@ -552,8 +552,8 @@ B repl_c2(B t, B w, B x) {
B res;
if (replMode>0) {
Block* block = bqn_compSc(x, fullpath, args, sc, replMode==2);
ptr_dec(sc->body); ptr_inc(block->bodies[0]);
sc->body = block->bodies[0];
ptr_dec(sc->body);
sc->body = ptr_inc(block->bodies[0]);
res = execBlockInline(block, sc);
ptr_dec(block);
} else {

View File

@ -38,7 +38,7 @@ static Arr* m_fillslice(Arr* p, B* ptr, usz ia) {
return (Arr*)r;
}
static Arr* fillarr_slice (B x, usz s, usz ia) { return m_fillslice(a(x), c(FillArr,x)->a+s, ia); }
static Arr* fillslice_slice(B x, usz s, usz ia) { Arr* p=c(Slice,x)->p; ptr_inc(p); Arr* r = m_fillslice(p, c(FillSlice,x)->a+s, ia); dec(x); return r; }
static Arr* fillslice_slice(B x, usz s, usz ia) { Arr* p = ptr_inc(c(Slice,x)->p); Arr* r = m_fillslice(p, c(FillSlice,x)->a+s, ia); dec(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]); }

View File

@ -105,7 +105,7 @@ static Arr* m_hslice(Arr* p, B* ptr, usz ia) {
return (Arr*)r;
}
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=c(Slice,x)->p; ptr_inc(p); Arr* r = m_hslice(p, c(HSlice,x)->a+s, ia); dec(x); return r; }
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); dec(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]); }

View File

@ -50,7 +50,7 @@ static usz* arr_shAlloc(Arr* x, ur r) { // sets rank, allocates & returns shape
}
static void arr_shSetI(Arr* x, ur r, ShArr* sh) { // set rank and assign and increment shape if needed
sprnk(x,r);
if (r>1) { x->sh = sh->a; ptr_inc(sh); }
if (r>1) { x->sh = ptr_inc(sh)->a; }
else { x->sh = &x->ia; }
}
static void arr_shSetU(Arr* x, ur r, ShArr* sh) { // set rank and assign shape

View File

@ -9,7 +9,7 @@ static Arr* TP(m_,slice) (Arr* p, TEl* ptr, usz ia) {
return (Arr*)r;
}
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=c(Slice,x)->p; ptr_inc(p); Arr* r = TP(m_,slice) (p, ((TEl*)c(TySlice,x)->a)+s, ia); dec(x); return r; }
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]); }

View File

@ -295,7 +295,6 @@ static void mm_visitP(void* x);
static void dec(B x);
static B inc(B x);
static void ptr_dec(void* x);
static void ptr_inc(void* x);
void printRaw(B x); // doesn't consume
void print(B x); // doesn't consume
void arr_print(B x); // doesn't consume
@ -518,7 +517,7 @@ static B incBy(B x, i64 am) { // am mustn't be negative!
if (isVal(VALIDATE(x))) v(x)->refc+= am;
return x;
}
static void ptr_inc(void* x) { VALIDATEP((Value*)x)->refc++; }
#define ptr_inc(X) ({ AUTO x_ = (X); VALIDATEP((Value*)x_)->refc++; x_; })

View File

@ -215,10 +215,7 @@ INS B i_FAIL(u32* bc, Scope* sc, B* cStack) {
POS_UPD; GS_UPD; thrM(q_N(sc->vars[2])? "This block cannot be called monadically" : "This block cannot be called dyadically");
}
INS B i_RETD(Scope* sc) {
Body* b = sc->body;
ptr_inc(sc);
ptr_inc(b->nsDesc);
return m_ns(sc, b->nsDesc);
return m_ns(ptr_inc(sc), ptr_inc(sc->body->nsDesc));
}
#undef INS

View File

@ -19,8 +19,8 @@ static void repl_init() {
static B gsc_exec_inline(B src, B path, B args) {
Block* block = bqn_compSc(src, path, args, gsc, true);
ptr_dec(gsc->body); ptr_inc(block->bodies[0]); // redirect new errors to the newly executed code; initial scope had 0 vars, so this is safe
gsc->body = block->bodies[0];
ptr_dec(gsc->body); // redirect new errors to the newly executed code; initial scope had 0 vars, so this is safe
gsc->body = ptr_inc(block->bodies[0]);
B r = execBlockInline(block, gsc);
ptr_dec(block);
return r;
@ -199,8 +199,8 @@ int main(int argc, char* argv[]) {
}
Block* block = bqn_compSc(code, inc(replPath), emptySVec(), gsc, true);
ptr_dec(gsc->body); ptr_inc(block->bodies[0]);
gsc->body = block->bodies[0];
ptr_dec(gsc->body);
gsc->body = ptr_inc(block->bodies[0]);
B res;
if (time) {

View File

@ -348,7 +348,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
i32 bodyCount = TSSIZE(bodies);
Block* bl = mm_alloc(fsizeof(Block,bodies,Body*,bodyCount), t_block);
bl->comp = comp; ptr_inc(comp);
bl->comp = ptr_inc(comp);
bl->ty = (u8)ty;
bl->bc = nbc;
bl->blocks = nBl==NULL? NULL : nBl->a;
@ -532,7 +532,6 @@ B evalBC(Block* bl, Body* b, Scope* sc) { // doesn't consume
printf("new eval\n");
B* origStack = gStack;
#endif
B* objs = bl->comp->objs->a;
u32* bc = b->bc;
pushEnv(sc, bc);
gsReserve(b->maxStack);
@ -577,7 +576,7 @@ B evalBC(Block* bl, Body* b, Scope* sc) { // doesn't consume
switch(*bc++) {
case POPS: dec(POP); break;
case PUSH: {
ADD(inc(objs[*bc++]));
ADD(inc(bl->comp->objs->a[*bc++]));
break;
}
case ADDI: {
@ -716,9 +715,7 @@ B evalBC(Block* bl, Body* b, Scope* sc) { // doesn't consume
break;
}
case RETD: {
ptr_inc(sc);
ptr_inc(b->nsDesc);
ADD(m_ns(sc, b->nsDesc));
ADD(m_ns(ptr_inc(sc), ptr_inc(b->nsDesc)));
goto end;
}
case ALIM: { P(o) u32 l = *bc++;
@ -773,8 +770,8 @@ B evalBC(Block* bl, Body* b, Scope* sc) { // doesn't consume
Scope* m_scope(Body* body, Scope* psc, u16 varAm, i32 initVarAm, B* initVars) { // consumes initVarAm items of initVars
Scope* sc = mm_alloc(fsizeof(Scope, vars, B, varAm), t_scope);
sc->body = body; ptr_inc(body);
sc->psc = psc; if(psc) ptr_inc(psc);
sc->body = ptr_inc(body);
sc->psc = psc; if (psc) ptr_inc(psc);
sc->varAm = varAm;
sc->ext = NULL;
i32 i = 0;
@ -783,7 +780,7 @@ Scope* m_scope(Body* body, Scope* psc, u16 varAm, i32 initVarAm, B* initVars) {
return sc;
}
B execBlockInline(Block* block, Scope* sc) { ptr_inc(sc); return execBodyInlineI(block, block->bodies[0], sc); }
B execBlockInline(Block* block, Scope* sc) { return execBodyInlineI(block, block->bodies[0], ptr_inc(sc)); }
FORCE_INLINE B execBlock(Block* block, Body* body, Scope* psc, i32 ga, B* svar) { // consumes svar contents
u16 varAm = body->varAm;
@ -807,24 +804,24 @@ B md2Bl_d(B m, B f, B g) { Md2Block* c = c(Md2Block,m); Block* bl=c(Md2Block, m)
B m_funBlock(Block* bl, Scope* psc) { // doesn't consume anything
if (bl->imm) return execBlock(bl, bl->bodies[0], psc, 0, NULL);
FunBlock* r = mm_alloc(sizeof(FunBlock), t_fun_block);
r->bl = bl; ptr_inc(bl);
r->sc = psc; ptr_inc(psc);
r->bl = ptr_inc(bl);
r->sc = ptr_inc(psc);
r->c1 = funBl_c1;
r->c2 = funBl_c2;
return tag(r,FUN_TAG);
}
B m_md1Block(Block* bl, Scope* psc) {
Md1Block* r = mm_alloc(sizeof(Md1Block), t_md1_block);
r->bl = bl; ptr_inc(bl);
r->sc = psc; ptr_inc(psc);
r->bl = ptr_inc(bl);
r->sc = ptr_inc(psc);
r->c1 = md1Bl_c1;
r->c2 = md1Bl_c2;
return tag(r,MD1_TAG);
}
B m_md2Block(Block* bl, Scope* psc) {
Md2Block* r = mm_alloc(sizeof(Md2Block), t_md2_block);
r->bl = bl; ptr_inc(bl);
r->sc = psc; ptr_inc(psc);
r->bl = ptr_inc(bl);
r->sc = ptr_inc(psc);
r->c1 = md2Bl_c1;
r->c2 = md2Bl_c2;
return tag(r,MD2_TAG);