inci→inc, ptr_dec_rare
This commit is contained in:
parent
c340de8e1c
commit
ae1ca2f1d9
4
cc.bqn
4
cc.bqn
@ -26,10 +26,10 @@ FChars ← •FChars path⊸∾
|
||||
|
||||
compile ← Import "c.bqn"
|
||||
useInd ← "-i"≡⊑args ⋄ args↓˜↩useInd
|
||||
Comp ← (3+useInd) ↑ ((<"inci(runtime["∾⍕∾"])"˙)¨↕62)⊸Compile
|
||||
Comp ← (3+useInd) ↑ ((<"inc(runtime["∾⍕∾"])"˙)¨↕62)⊸Compile
|
||||
J ← ∾∾⟜\n¨
|
||||
Fconst ← ≡◶⟨@⊸≤◶Num‿Char, Str, ⊑⟩
|
||||
prov ← {"inci("∾𝕩∾")"}¨"bi_type"‿"bi_fill"‿"bi_log"‿"bi_grLen"‿"bi_grOrd"‿"bi_asrt"‿"bi_add"‿"bi_sub"‿"bi_mul"‿"bi_div"‿"bi_pow"‿"bi_floor"‿"bi_eq"‿"bi_le"‿"bi_fne"‿"bi_shape"‿"bi_pick"‿"bi_ud"‿"bi_tbl"‿"bi_scan"‿"bi_fillBy"‿"bi_val"
|
||||
prov ← {"inc("∾𝕩∾")"}¨"bi_type"‿"bi_fill"‿"bi_log"‿"bi_grLen"‿"bi_grOrd"‿"bi_asrt"‿"bi_add"‿"bi_sub"‿"bi_mul"‿"bi_div"‿"bi_pow"‿"bi_floor"‿"bi_eq"‿"bi_le"‿"bi_fne"‿"bi_shape"‿"bi_pick"‿"bi_ud"‿"bi_tbl"‿"bi_scan"‿"bi_fillBy"‿"bi_val"
|
||||
Fout ← {((≠𝕩)↑⟨LI F¨,L ·prov⊸∾⍟(𝕨⊣0) Fconst¨,L (LI F¨)¨,L (L F¨)¨⟩) {𝕎𝕩}¨ 𝕩}
|
||||
Frun ← 1⊸Fout
|
||||
Long ← {¯2↓∾𝕩∾¨<","∾\n}
|
||||
|
||||
@ -43,7 +43,7 @@ B eq_c2(B t, B w, B x) {
|
||||
i32 wia = a(w)->ia;
|
||||
i32 xia = a(x)->ia;
|
||||
if (wia != xia) { dec(w);dec(x); return m_i32(0); }
|
||||
for (i32 i = 0; i<wia; i++) if(!o2i(eq_c2(t,inci(wp[i]),inci(xp[i]))))
|
||||
for (i32 i = 0; i<wia; i++) if(!o2i(eq_c2(t,inc(wp[i]),inc(xp[i]))))
|
||||
{ dec(w);dec(x); return m_i32(0); }
|
||||
dec(w);dec(x); return m_i32(1);
|
||||
}
|
||||
|
||||
@ -46,8 +46,8 @@ B m_c32slice(B p, u32* ptr) {
|
||||
return tag(r, ARR_TAG);
|
||||
}
|
||||
|
||||
B c32arr_slice (B x, usz s) {return m_c32slice(x , c(C32Arr ,x)->a+s); }
|
||||
B c32slice_slice(B x, usz s) { B r = m_c32slice(inci(c(C32Slice,x)->p), c(C32Slice,x)->a+s); dec(x); return r; }
|
||||
B c32arr_slice (B x, usz s) {return m_c32slice(x , c(C32Arr ,x)->a+s); }
|
||||
B c32slice_slice(B x, usz s) { B r = m_c32slice(inc(c(C32Slice,x)->p), c(C32Slice,x)->a+s); dec(x); return r; }
|
||||
|
||||
|
||||
B c32arr_get (B x, usz n) { VT(x,t_c32arr ); return m_c32(c(C32Arr ,x)->a[n]); }
|
||||
|
||||
14
src/derv.c
14
src/derv.c
@ -42,16 +42,16 @@ B md2D_c1(B t, B x) { return c(Md2,c(Md2D, t)->m2)->c1(t, x); }
|
||||
B md2D_c2(B t, B w, B x) { return c(Md2,c(Md2D, t)->m2)->c2(t, w, x); }
|
||||
B atop_c1(B t, B x) { return c1(c(Atop,t)->g, c1(c(Atop,t)->h, x)); }
|
||||
B atop_c2(B t, B w, B x) { return c1(c(Atop,t)->g, c2(c(Atop,t)->h, w, x)); }
|
||||
B fork_c1(B t, B x) { B g=c1(c(Fork,t)->h, inci(x)); return c2(c(Fork,t)->g, c1(c(Fork,t)->f, x), g); }
|
||||
B fork_c2(B t, B w, B x) { B g=c2(c(Fork,t)->h, inci(w), inci(x)); return c2(c(Fork,t)->g, c2(c(Fork,t)->f, w, x), g); }
|
||||
B fork_c1(B t, B x) { B g=c1(c(Fork,t)->h, inc(x)); return c2(c(Fork,t)->g, c1(c(Fork,t)->f, x), g); }
|
||||
B fork_c2(B t, B w, B x) { B g=c2(c(Fork,t)->h, inc(w), inc(x)); return c2(c(Fork,t)->g, c2(c(Fork,t)->f, w, x), g); }
|
||||
B md2H_c1(B d, B x) { Md1D* m=c(Md1D,d); Md2H* t=c(Md2H,m->m1); return md2D_c1(m_md2D(t->m2, m->f, t->g), x); }
|
||||
B md2H_c2(B d, B w, B x) { Md1D* m=c(Md1D,d); Md2H* t=c(Md2H,m->m1); return md2D_c2(m_md2D(t->m2, m->f, t->g), w, x); }
|
||||
|
||||
B md1D_decompose(B x) { B r=m_v3(m_i32(4),inci(c(Md1D,x)->f),inci(c(Md1D,x)->m1) ); dec(x); return r; }
|
||||
B md2D_decompose(B x) { B r=m_v4(m_i32(5),inci(c(Md2D,x)->f),inci(c(Md2D,x)->m2), inci(c(Md2D,x)->g)); dec(x); return r; }
|
||||
B md2H_decompose(B x) { B r=m_v3(m_i32(6), inci(c(Md2H,x)->m2), inci(c(Md2H,x)->g)); dec(x); return r; }
|
||||
B fork_decompose(B x) { B r=m_v4(m_i32(3),inci(c(Fork,x)->f),inci(c(Fork,x)->g ), inci(c(Fork,x)->h)); dec(x); return r; }
|
||||
B atop_decompose(B x) { B r=m_v3(m_i32(2), inci(c(Atop,x)->g ), inci(c(Atop,x)->h)); dec(x); return r; }
|
||||
B md1D_decompose(B x) { B r=m_v3(m_i32(4),inc(c(Md1D,x)->f),inc(c(Md1D,x)->m1) ); dec(x); return r; }
|
||||
B md2D_decompose(B x) { B r=m_v4(m_i32(5),inc(c(Md2D,x)->f),inc(c(Md2D,x)->m2), inc(c(Md2D,x)->g)); dec(x); return r; }
|
||||
B md2H_decompose(B x) { B r=m_v3(m_i32(6), inc(c(Md2H,x)->m2), inc(c(Md2H,x)->g)); dec(x); return r; }
|
||||
B fork_decompose(B x) { B r=m_v4(m_i32(3),inc(c(Fork,x)->f),inc(c(Fork,x)->g ), inc(c(Fork,x)->h)); dec(x); return r; }
|
||||
B atop_decompose(B x) { B r=m_v3(m_i32(2), inc(c(Atop,x)->g ), inc(c(Atop,x)->h)); dec(x); return r; }
|
||||
|
||||
// consume all args
|
||||
B m_md1D(B m, B f ) { B r = mm_alloc(sizeof(Md1D), t_md1D, ftag(FUN_TAG)); c(Md1D,r)->f = f; c(Md1D,r)->m1 = m; c(Md1D,r)->c1=md1D_c1; c(Md1D,r)->c2=md1D_c2; c(Md1D,r)->extra=pf_md1d; return r; }
|
||||
|
||||
@ -35,8 +35,8 @@ B withFill(B x, B fill) {
|
||||
B getFill(B x) {
|
||||
if (isArr(x)) {
|
||||
u8 t = v(x)->type;
|
||||
if (t==t_fillarr ) { B r = inci(c(FillArr,x )->fill); dec(x); return r; }
|
||||
if (t==t_fillslice) { B r = inci(c(FillArr,c(Slice,x)->p)->fill); dec(x); return r; }
|
||||
if (t==t_fillarr ) { B r = inc(c(FillArr,x )->fill); dec(x); return r; }
|
||||
if (t==t_fillslice) { B r = inc(c(FillArr,c(Slice,x)->p)->fill); dec(x); return r; }
|
||||
if (t==t_c32arr || t==t_c32slice) return m_c32(' ');
|
||||
}
|
||||
if (isC32(x)) return m_c32(' ');
|
||||
@ -54,12 +54,12 @@ B m_fillslice(B p, B* ptr) {
|
||||
return tag(r, ARR_TAG);
|
||||
}
|
||||
|
||||
B fillarr_slice (B x, usz s) {return m_fillslice(x , c(FillArr ,x)->a+s); }
|
||||
B fillslice_slice(B x, usz s) { B r = m_fillslice(inci(c(FillSlice,x)->p), c(FillSlice,x)->a+s); dec(x); return r; }
|
||||
B fillarr_slice (B x, usz s) {return m_fillslice(x , c(FillArr ,x)->a+s); }
|
||||
B fillslice_slice(B x, usz s) { B r = m_fillslice(inc(c(FillSlice,x)->p), c(FillSlice,x)->a+s); dec(x); return r; }
|
||||
|
||||
|
||||
B fillarr_get (B x, usz n) { VT(x,t_fillarr ); return inci(c(FillArr ,x)->a[n]); }
|
||||
B fillslice_get(B x, usz n) { VT(x,t_fillslice); return inci(c(FillSlice,x)->a[n]); }
|
||||
B fillarr_get (B x, usz n) { VT(x,t_fillarr ); return inc(c(FillArr ,x)->a[n]); }
|
||||
B fillslice_get(B x, usz n) { VT(x,t_fillslice); return inc(c(FillSlice,x)->a[n]); }
|
||||
void fillarr_free(B x) {
|
||||
decSh(x);
|
||||
B* p = c(FillArr, x)->a;
|
||||
|
||||
18
src/h.h
18
src/h.h
@ -132,7 +132,7 @@ B mm_alloc(usz sz, u8 type, u64 tag) {
|
||||
|
||||
// some primitive actions
|
||||
void dec(B x);
|
||||
void inc(B x);
|
||||
B inc(B x);
|
||||
void ptr_dec(void* x);
|
||||
void ptr_inc(void* x);
|
||||
void print(B x);
|
||||
@ -328,12 +328,16 @@ void dec(B x) {
|
||||
Value* vx = v(x);
|
||||
if(!--vx->refc) value_free(x, vx);
|
||||
}
|
||||
void ptr_dec(void* x) { dec(tag(x, OBJ_TAG)); }
|
||||
B inc(B x) {
|
||||
if (isVal(VALIDATE(x))) v(x)->refc++;
|
||||
return x;
|
||||
}
|
||||
void ptr_dec(void* x) { if(!--((Value*)x)->refc) value_free(tag(x, OBJ_TAG), x); }
|
||||
void ptr_inc(void* x) { ((Value*)x)->refc++; }
|
||||
static NOINLINE void value_free_rare(B x, Value* vx) { value_free(x, vx); }
|
||||
void ptr_dec_rare(void* x) { if(!--((Value*)x)->refc) value_free_rare(tag(x, OBJ_TAG), x); }
|
||||
bool reusable(B x) { return v(x)->refc==1; }
|
||||
|
||||
void inc (B x) { if (isVal(VALIDATE(x))) v(x)->refc++; }
|
||||
B inci(B x) { inc(x); return x; }
|
||||
void ptr_inc(void* x) { ((Value*)x)->refc++; }
|
||||
|
||||
|
||||
void printUTF8(u32 c);
|
||||
@ -389,11 +393,11 @@ B c2_invalid(B f, B w, B x) { return err("This function can't be called dyadical
|
||||
|
||||
NOINLINE B c1_rare(B f, B x) { dec(x);
|
||||
if (isMd(f)) return err("Calling a modifier");
|
||||
return inci(VALIDATE(f));
|
||||
return inc(VALIDATE(f));
|
||||
}
|
||||
NOINLINE B c2_rare(B f, B w, B x) { dec(w); dec(x);
|
||||
if (isMd(f)) return err("Calling a modifier");
|
||||
return inci(VALIDATE(f));
|
||||
return inc(VALIDATE(f));
|
||||
}
|
||||
B c1(B f, B x) { // BQN-call f monadically; consumes x
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, x));
|
||||
|
||||
@ -76,12 +76,12 @@ B m_hslice(B p, B* ptr) {
|
||||
return tag(r, ARR_TAG);
|
||||
}
|
||||
|
||||
B harr_slice (B x, usz s) {return m_hslice(x , c(HArr ,x)->a+s); }
|
||||
B hslice_slice(B x, usz s) { B r = m_hslice(inci(c(HSlice,x)->p), c(HSlice,x)->a+s); dec(x); return r; }
|
||||
B harr_slice (B x, usz s) {return m_hslice(x , c(HArr ,x)->a+s); }
|
||||
B hslice_slice(B x, usz s) { B r = m_hslice(inc(c(HSlice,x)->p), c(HSlice,x)->a+s); dec(x); return r; }
|
||||
|
||||
|
||||
B harr_get (B x, usz n) { VT(x,t_harr ); return inci(c(HArr ,x)->a[n]); }
|
||||
B hslice_get(B x, usz n) { VT(x,t_hslice); return inci(c(HSlice,x)->a[n]); }
|
||||
B harr_get (B x, usz n) { VT(x,t_harr ); return inc(c(HArr ,x)->a[n]); }
|
||||
B hslice_get(B x, usz n) { VT(x,t_hslice); return inc(c(HSlice,x)->a[n]); }
|
||||
void harr_free(B x) {
|
||||
decSh(x);
|
||||
B* p = harr_ptr(x);
|
||||
|
||||
@ -54,8 +54,8 @@ B m_i32slice(B p, i32* ptr) {
|
||||
return tag(r, ARR_TAG);
|
||||
}
|
||||
|
||||
B i32arr_slice (B x, usz s) {return m_i32slice(x , c(I32Arr ,x)->a+s); }
|
||||
B i32slice_slice(B x, usz s) { B r = m_i32slice(inci(c(I32Slice,x)->p), c(I32Slice,x)->a+s); dec(x); return r; }
|
||||
B i32arr_slice (B x, usz s) {return m_i32slice(x , c(I32Arr ,x)->a+s); }
|
||||
B i32slice_slice(B x, usz s) { B r = m_i32slice(inc(c(I32Slice,x)->p), c(I32Slice,x)->a+s); dec(x); return r; }
|
||||
|
||||
|
||||
B i32arr_get (B x, usz n) { VT(x,t_i32arr ); return m_i32(c(I32Arr ,x)->a[n]); }
|
||||
|
||||
10
src/main.c
10
src/main.c
@ -32,7 +32,7 @@ void pr(char* a, B b) {
|
||||
|
||||
Block* ca3(B b) {
|
||||
B* ps = harr_ptr(b);
|
||||
Block* r = compile(inci(ps[0]),inci(ps[1]),inci(ps[2]));
|
||||
Block* r = compile(inc(ps[0]),inc(ps[1]),inc(ps[2]));
|
||||
dec(b);
|
||||
return r;
|
||||
}
|
||||
@ -92,7 +92,7 @@ int main() {
|
||||
for (usz i = 0; i < runtimeLen; i++) {
|
||||
if (isVal(runtime[i])) v(runtime[i])->flags|= i+1;
|
||||
}
|
||||
c1(rtFinish, m_v2(inci(bi_decp), inci(bi_primInd)));
|
||||
c1(rtFinish, m_v2(inc(bi_decp), inc(bi_primInd)));
|
||||
|
||||
// uncomment to use src/interp; needed for test.bqn
|
||||
// Block* c = ca3(
|
||||
@ -112,7 +112,7 @@ int main() {
|
||||
#include "formatter"
|
||||
);
|
||||
B fmtM = m_funBlock(fmt_b, 0); ptr_dec(fmt_b);
|
||||
B fmt = TI(fmtM).m1_d(fmtM, m_caB(4, (B[]){inci(bi_type), inci(bi_decp), inci(bi_fmtF), inci(bi_fmtN)}));
|
||||
B fmt = TI(fmtM).m1_d(fmtM, m_caB(4, (B[]){inc(bi_type), inc(bi_decp), inc(bi_fmtF), inc(bi_fmtN)}));
|
||||
#endif
|
||||
|
||||
|
||||
@ -132,7 +132,7 @@ int main() {
|
||||
// exit(1);
|
||||
// }
|
||||
// if (c_src) {
|
||||
// B cbc = c2(comp, inci(rtObj), fromUTF8(c_src, c_len));
|
||||
// B cbc = c2(comp, inc(rtObj), fromUTF8(c_src, c_len));
|
||||
// Block* cbc_b = ca3(cbc);
|
||||
// comp = m_funBlock(cbc_b, 0);
|
||||
// free(c_src);
|
||||
@ -146,7 +146,7 @@ int main() {
|
||||
getline(&ln, &gl, stdin);
|
||||
if (ln[0]==10) break;
|
||||
B obj = fromUTF8(ln, strlen(ln));
|
||||
B cbc = c2(comp, inci(currentRuntime), obj);
|
||||
B cbc = c2(comp, inc(currentRuntime), obj);
|
||||
free(ln);
|
||||
Block* cbc_b = ca3(cbc);
|
||||
|
||||
|
||||
14
src/md1.c
14
src/md1.c
@ -33,7 +33,7 @@ B tbl_c2(B d, B w, B x) { B f = c(Md1D,d)->f;
|
||||
for (usz wi = 0; wi < wia; wi++) {
|
||||
B cw = wget(w,wi);
|
||||
for (usz xi = 0; xi < xia; xi++) {
|
||||
r.a[ri++] = c2(f, inci(cw), xget(x,xi));
|
||||
r.a[ri++] = c2(f, inc(cw), xget(x,xi));
|
||||
}
|
||||
dec(cw);
|
||||
}
|
||||
@ -47,17 +47,17 @@ B scan_c1(B d, B x) { B f = c(Md1D,d)->f;
|
||||
if (!isArr(x)) return err("`: argument cannot be a scalar");
|
||||
ur xr = rnk(x);
|
||||
if (xr==0) return err("`: argument cannot be a scalar");
|
||||
HArr_p r = (v(x)->type==t_harr && reusable(x))? harr_parts(inci(x)) : m_harrc(x);
|
||||
HArr_p r = (v(x)->type==t_harr && reusable(x))? harr_parts(inc(x)) : m_harrc(x);
|
||||
usz ia = r.c->ia;
|
||||
if (ia==0) { dec(x); return r.b; }
|
||||
BS2B xget = TI(x).get;
|
||||
if (xr==1) {
|
||||
r.a[0] = xget(x,0);
|
||||
for (usz i = 1; i < ia; i++) r.a[i] = c2(f, inci(r.a[i-1]), xget(x,i));
|
||||
for (usz i = 1; i < ia; i++) r.a[i] = c2(f, inc(r.a[i-1]), xget(x,i));
|
||||
} else {
|
||||
usz csz = arr_csz(x);
|
||||
for (usz i = 0; i < csz; i++) r.a[i] = xget(x,i);
|
||||
for (usz i = csz; i < ia; i++) r.a[i] = c2(f, inci(r.a[i-csz]), xget(x,i));
|
||||
for (usz i = csz; i < ia; i++) r.a[i] = c2(f, inc(r.a[i-csz]), xget(x,i));
|
||||
}
|
||||
dec(x);
|
||||
return r.b;
|
||||
@ -65,7 +65,7 @@ B scan_c1(B d, B x) { B f = c(Md1D,d)->f;
|
||||
B scan_c2(B d, B w, B x) { B f = c(Md1D,d)->f;
|
||||
if (!isArr(x)) return err("`: 𝕩 cannot be a scalar");
|
||||
ur xr = rnk(x); usz* xsh = a(x)->sh; BS2B xget = TI(x).get;
|
||||
HArr_p r = (v(x)->type==t_harr && reusable(x))? harr_parts(inci(x)) : m_harrc(x);
|
||||
HArr_p r = (v(x)->type==t_harr && reusable(x))? harr_parts(inc(x)) : m_harrc(x);
|
||||
usz ia = r.c->ia;
|
||||
if (isArr(w)) {
|
||||
ur wr = rnk(w); usz* wsh = a(w)->sh; BS2B wget = TI(w).get;
|
||||
@ -75,13 +75,13 @@ B scan_c2(B d, B w, B x) { B f = c(Md1D,d)->f;
|
||||
if (ia==0) { dec(x); return r.b; }
|
||||
usz csz = arr_csz(x);
|
||||
for (usz i = 0; i < csz; i++) r.a[i] = c2(f, wget(w,i), xget(x,i));
|
||||
for (usz i = csz; i < ia; i++) r.a[i] = c2(f, inci(r.a[i-csz]), xget(x,i));
|
||||
for (usz i = csz; i < ia; i++) r.a[i] = c2(f, inc(r.a[i-csz]), xget(x,i));
|
||||
dec(w);
|
||||
} else {
|
||||
if (xr!=1) return err("`: if 𝕨 is scalar, 𝕩 must be a vector");
|
||||
if (ia==0) { dec(x); return r.b; }
|
||||
B pr = r.a[0] = c2(f, w, xget(x,0));
|
||||
for (usz i = 1; i < ia; i++) r.a[i] = pr = c2(f, inci(pr), xget(x,i));
|
||||
for (usz i = 1; i < ia; i++) r.a[i] = pr = c2(f, inc(pr), xget(x,i));
|
||||
}
|
||||
dec(x);
|
||||
return r.b;
|
||||
|
||||
42
src/vm.c
42
src/vm.c
@ -126,7 +126,9 @@ typedef struct Body {
|
||||
|
||||
typedef struct Scope {
|
||||
struct Value;
|
||||
u64 bcInd; // DEBUG: place of this in bytecode array
|
||||
#ifdef DEBUG
|
||||
u64 bcInd; // DEBUG: place of this in bytecode array
|
||||
#endif
|
||||
u16 varAm;
|
||||
Scope* psc;
|
||||
B vars[];
|
||||
@ -141,7 +143,7 @@ Block* compile(B bcq, B objs, B blocks) {
|
||||
usz bam = a(blocks)->ia;
|
||||
|
||||
// B* objPtr = harr_ptr(objs); usz objIA = a(objs)->ia;
|
||||
// for (usz i = 0; i < objIA; i++) objPtr[i] = c2(bi_fill, c1(bi_pick, inci(objPtr[i])), objPtr[i]);
|
||||
// for (usz i = 0; i < objIA; i++) objPtr[i] = c2(bi_fill, c1(bi_pick, inc(objPtr[i])), objPtr[i]);
|
||||
|
||||
I32Arr* bca = toI32Arr(bcq);
|
||||
i32* bc = bca->a;
|
||||
@ -189,7 +191,7 @@ Block* compile(B bcq, B objs, B blocks) {
|
||||
comp->blocks[i] = bl;
|
||||
}
|
||||
|
||||
Block* ret = c(Block,inci(tag(comp->blocks[0], OBJ_TAG)));
|
||||
Block* ret = c(Block,inc(tag(comp->blocks[0], OBJ_TAG)));
|
||||
// TODO store blocks in each body, then decrement each of comp->blocks; also then move temp block list out of Comp as it's useless then
|
||||
// for (usz i = 0; i < bam; i++) ptr_dec(comp->blocks[i]);
|
||||
|
||||
@ -295,7 +297,7 @@ B evalBC(Body* b, Scope* sc) {
|
||||
switch(*bc++) {
|
||||
case POPS: dec(POP); break;
|
||||
case PUSH: {
|
||||
ADD(inci(objs[*bc++]));
|
||||
ADD(inc(objs[*bc++]));
|
||||
break;
|
||||
}
|
||||
case FN1C: { P(f)P(x)
|
||||
@ -347,15 +349,15 @@ B evalBC(Body* b, Scope* sc) {
|
||||
break;
|
||||
}
|
||||
case LOCO: { i32 d = *bc++; i32 p = *bc++;
|
||||
ADD(inci(scd(sc,d)->vars[p]));
|
||||
ADD(inc(scd(sc,d)->vars[p]));
|
||||
break;
|
||||
}
|
||||
case SETN: { P(s) P(x) v_set(sc, s, inci(x), false); ADD(x); break; }
|
||||
case SETU: { P(s) P(x) v_set(sc, s, inci(x), true ); ADD(x); break; }
|
||||
case SETN: { P(s) P(x) v_set(sc, s, inc(x), false); ADD(x); break; }
|
||||
case SETU: { P(s) P(x) v_set(sc, s, inc(x), true ); ADD(x); break; }
|
||||
case SETM: { P(s)P(f)P(x)
|
||||
B w = v_get(sc, s);
|
||||
B r = c2(f,w,x); dec(f);
|
||||
v_set(sc, s, inci(r), true);
|
||||
v_set(sc, s, inc(r), true);
|
||||
ADD(r);
|
||||
break;
|
||||
}
|
||||
@ -390,7 +392,9 @@ B actualExec(Block* bl, Scope* psc, u32 ga, B* svar) {
|
||||
sc->psc = psc; if(psc)ptr_inc(psc);
|
||||
u16 varAm = sc->varAm = bdy->varAm;
|
||||
assert(varAm>=ga);
|
||||
sc->bcInd = bdy->bc-c(I32Arr,bdy->comp->bc)->a;
|
||||
#ifdef DEBUG
|
||||
sc->bcInd = bdy->bc-c(I32Arr,bdy->comp->bc)->a;
|
||||
#endif
|
||||
i32 i = 0;
|
||||
while (i<ga) { sc->vars[i] = svar[i]; i++; }
|
||||
while (i<varAm) sc->vars[i++] = bi_noVar;
|
||||
@ -403,12 +407,12 @@ B actualExec(Block* bl, Scope* psc, u32 ga, B* svar) {
|
||||
return r;
|
||||
}
|
||||
|
||||
B funBl_c1(B t, B x) { FunBlock* b=c(FunBlock, t ); return actualExec(b->bl, b->sc, 3, (B[]){inci(t), x, bi_nothing }); }
|
||||
B funBl_c2(B t, B w, B x) { FunBlock* b=c(FunBlock, t ); return actualExec(b->bl, b->sc, 3, (B[]){inci(t), x, w }); }
|
||||
B md1Bl_c1(B D, B x) { Md1D* d=c(Md1D,D); Md1Block* b=c(Md1Block, d->m1); return actualExec(b->bl, b->sc, 5, (B[]){inci(D), x, bi_nothing, inci(d->m1), inci(d->f) }); }
|
||||
B md1Bl_c2(B D, B w, B x) { Md1D* d=c(Md1D,D); Md1Block* b=c(Md1Block, d->m1); return actualExec(b->bl, b->sc, 5, (B[]){inci(D), x, w , inci(d->m1), inci(d->f) }); }
|
||||
B md2Bl_c1(B D, B x) { Md2D* d=c(Md2D,D); Md2Block* b=c(Md2Block, d->m2); return actualExec(b->bl, b->sc, 6, (B[]){inci(D), x, bi_nothing, inci(d->m2), inci(d->f), inci(d->g)}); }
|
||||
B md2Bl_c2(B D, B w, B x) { Md2D* d=c(Md2D,D); Md2Block* b=c(Md2Block, d->m2); return actualExec(b->bl, b->sc, 6, (B[]){inci(D), x, w , inci(d->m2), inci(d->f), inci(d->g)}); }
|
||||
B funBl_c1(B t, B x) { FunBlock* b=c(FunBlock, t ); return actualExec(b->bl, b->sc, 3, (B[]){inc(t), x, bi_nothing }); }
|
||||
B funBl_c2(B t, B w, B x) { FunBlock* b=c(FunBlock, t ); return actualExec(b->bl, b->sc, 3, (B[]){inc(t), x, w }); }
|
||||
B md1Bl_c1(B D, B x) { Md1D* d=c(Md1D,D); Md1Block* b=c(Md1Block, d->m1); return actualExec(b->bl, b->sc, 5, (B[]){inc(D), x, bi_nothing, inc(d->m1), inc(d->f) }); }
|
||||
B md1Bl_c2(B D, B w, B x) { Md1D* d=c(Md1D,D); Md1Block* b=c(Md1Block, d->m1); return actualExec(b->bl, b->sc, 5, (B[]){inc(D), x, w , inc(d->m1), inc(d->f) }); }
|
||||
B md2Bl_c1(B D, B x) { Md2D* d=c(Md2D,D); Md2Block* b=c(Md2Block, d->m2); return actualExec(b->bl, b->sc, 6, (B[]){inc(D), x, bi_nothing, inc(d->m2), inc(d->f), inc(d->g)}); }
|
||||
B md2Bl_c2(B D, B w, B x) { Md2D* d=c(Md2D,D); Md2Block* b=c(Md2Block, d->m2); return actualExec(b->bl, b->sc, 6, (B[]){inc(D), x, w , inc(d->m2), inc(d->f), inc(d->g)}); }
|
||||
B m_funBlock(Block* bl, Scope* psc) {
|
||||
if (bl->imm) return actualExec(bl, psc, 0, NULL);
|
||||
B r = mm_alloc(sizeof(FunBlock), t_fun_block, ftag(FUN_TAG));
|
||||
@ -440,13 +444,13 @@ void body_free(B x) { Body* c = c(Body ,x); ptr_dec(c->comp); }
|
||||
void block_free(B x) { Block* c = c(Block,x); ptr_dec(c->body); }
|
||||
void scope_free(B x) {
|
||||
Scope* c = c(Scope,x);
|
||||
if (c->psc) ptr_dec(c->psc);
|
||||
if (c->psc) ptr_dec_rare(c->psc);
|
||||
u16 am = c->varAm;
|
||||
for (u32 i = 0; i < am; i++) dec(c->vars[i]);
|
||||
}
|
||||
void funBl_free(B x) { FunBlock* c = c(FunBlock,x); ptr_dec(c->sc); ptr_dec(c->bl); }
|
||||
void md1Bl_free(B x) { Md1Block* c = c(Md1Block,x); ptr_dec(c->sc); ptr_dec(c->bl); }
|
||||
void md2Bl_free(B x) { Md2Block* c = c(Md2Block,x); ptr_dec(c->sc); ptr_dec(c->bl); }
|
||||
void funBl_free(B x) { FunBlock* c = c(FunBlock,x); ptr_dec_rare(c->sc); ptr_dec_rare(c->bl); }
|
||||
void md1Bl_free(B x) { Md1Block* c = c(Md1Block,x); ptr_dec_rare(c->sc); ptr_dec_rare(c->bl); }
|
||||
void md2Bl_free(B x) { Md2Block* c = c(Md2Block,x); ptr_dec_rare(c->sc); ptr_dec_rare(c->bl); }
|
||||
|
||||
void comp_print (B x) { printf("(%p: comp)",v(x)); }
|
||||
void body_print (B x) { printf("(%p: body varam=%d)",v(x),c(Body,x)->varAm); }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user