diff --git a/src/builtins/fns.c b/src/builtins/fns.c index 1db05c95..4b19239f 100644 --- a/src/builtins/fns.c +++ b/src/builtins/fns.c @@ -5,14 +5,6 @@ #include "../nfns.h" -void print_funBI(B x) { printf("%s", pfn_repr(c(Fun,x)->extra)); } -B funBI_uc1(B t, B o, B x) { return c(BFn,t)->uc1(t, o, x); } -B funBI_ucw(B t, B o, B w, B x) { return c(BFn,t)->ucw(t, o, w, x); } -B funBI_im(B t, B x) { return c(BFn,t)->im(t, x); } -B funBI_identity(B x) { return inc(c(BFn,x)->ident); } - - - void ud_rec(B** p, usz d, usz r, i32* pos, usz* sh) { if (d==r) { @@ -354,6 +346,14 @@ void fun_gcFn() { if (globalNames!=NULL) mm_visitP(globalNames); mm_visit(globalNameList); } + + + +static void print_funBI(B x) { printf("%s", pfn_repr(c(Fun,x)->extra)); } +static B funBI_uc1(B t, B o, B x) { return c(BFn,t)->uc1(t, o, x); } +static B funBI_ucw(B t, B o, B w, B x) { return c(BFn,t)->ucw(t, o, w, x); } +static B funBI_im(B t, B x) { return c(BFn,t)->im(t, x); } +static B funBI_identity(B x) { return inc(c(BFn,x)->ident); } void fns_init() { gc_addFn(fun_gcFn); TIi(t_funBI,print) = print_funBI; diff --git a/src/builtins/md1.c b/src/builtins/md1.c index 1d43dc73..142c09a9 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -518,6 +518,12 @@ B insert_c2(Md1D* d, B w, B x) { B f = d->f; #pragma GCC diagnostic pop static void print_md1BI(B x) { printf("%s", pm1_repr(c(Md1,x)->extra)); } +static B md1BI_im(Md1D* d, B x) { return ((BMd1*)d->m1)->im(d, x); } +static B md1BI_iw(Md1D* d, B w, B x) { return ((BMd1*)d->m1)->iw(d, w, x); } +static B md1BI_ix(Md1D* d, B w, B x) { return ((BMd1*)d->m1)->ix(d, w, x); } void md1_init() { TIi(t_md1BI,print) = print_md1BI; + TIi(t_md1BI,m1_im) = md1BI_im; + TIi(t_md1BI,m1_iw) = md1BI_iw; + TIi(t_md1BI,m1_ix) = md1BI_ix; } diff --git a/src/builtins/md2.c b/src/builtins/md2.c index 0eaaa305..4a8bd472 100644 --- a/src/builtins/md2.c +++ b/src/builtins/md2.c @@ -294,10 +294,16 @@ B depth_c2(Md2D* d, B w, B x) { return m2c2(rt_depth, d->f, d->g, w, x); } static void print_md2BI(B x) { printf("%s", pm2_repr(c(Md1,x)->extra)); } +static B md2BI_im(Md2D* d, B x) { return ((BMd2*)d->m2)->im(d, x); } +static B md2BI_iw(Md2D* d, B w, B x) { return ((BMd2*)d->m2)->iw(d, w, x); } +static B md2BI_ix(Md2D* d, B w, B x) { return ((BMd2*)d->m2)->ix(d, w, x); } void md2_init() { TIi(t_md2BI,print) = print_md2BI; TIi(t_md2BI,m2_uc1) = md2BI_uc1; TIi(t_md2BI,m2_ucw) = md2BI_ucw; + TIi(t_md2BI,m2_im) = md2BI_im; + TIi(t_md2BI,m2_iw) = md2BI_iw; + TIi(t_md2BI,m2_ix) = md2BI_ix; TIi(t_customObj,freeO) = customObj_freeO; TIi(t_customObj,freeF) = customObj_freeF; TIi(t_customObj,visit) = customObj_visit; diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 198e48f4..23ddcc64 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -868,7 +868,7 @@ static CastType getCastType(B e, B v) { c = q_N(v) ? 0 : isCharType(v(v)->type); } else { if (!isArr(e) || rnk(e)!=1 || a(e)->ia!=2) thrM("•bit._cast: 𝕗 elements must be numbers or two-element lists"); - SGetU(e); + SGetU(e) s = o2s(GetU(e,0)); u32 t = o2c(GetU(e,1)); c = t=='c'; @@ -911,11 +911,9 @@ static u8 typeOfCast(CastType t) { default: thrM("•bit._cast: unsupported result width"); } } -B bitcast_c1(Md1D* d, B x) { B f = d->f; - if (!isArr(f) || rnk(f)!=1 || a(f)->ia!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)"); - SGetU(f); - CastType xt = getCastType(GetU(f,0), x); - CastType zt = getCastType(GetU(f,1), bi_N); +B bitcast_impl(B el0, B el1, B x) { + CastType xt = getCastType(el0, x); + CastType zt = getCastType(el1, bi_N); ur xr; if (!isArr(x) || (xr=rnk(x))<1) thrM("•bit._cast: 𝕩 must have rank at least 1"); usz* sh = a(x)->sh; @@ -948,6 +946,18 @@ B bitcast_c1(Md1D* d, B x) { B f = d->f; } return r; } + +B bitcast_c1(Md1D* d, B x) { B f = d->f; + if (!isArr(f) || rnk(f)!=1 || a(f)->ia!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)"); + SGetU(f) + return bitcast_impl(GetU(f,0), GetU(f,1), x); +} + +B bitcast_im(Md1D* d, B x) { B f = d->f; + if (!isArr(f) || rnk(f)!=1 || a(f)->ia!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)"); + SGetU(f) + return bitcast_impl(GetU(f,1), GetU(f,0), x); +} static B bitNS; B getBitNS() { if (bitNS.u == 0) { @@ -1058,4 +1068,5 @@ void sysfn_init() { } void sysfnPost_init() { file_nsGen = m_nnsDesc("path","at","list","bytes","chars","lines"); + c(BMd1,bi_bitcast)->im = bitcast_im; } diff --git a/src/core.h b/src/core.h index 3279e33f..241f5f6a 100644 --- a/src/core.h +++ b/src/core.h @@ -52,6 +52,9 @@ typedef struct BMd1 { typedef struct BMd2 { struct Md2; + D2C1 im; + D2C2 iw; + D2C2 ix; M2C4 uc1; M2C5 ucw; } BMd2; diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index f3756ad1..9319a0bc 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -486,7 +486,7 @@ void freeOpt(OptRes o) { file_wChars(m_str8l("asm_off"), o); dec(o); B s = emptyCVec(); #define F(X) AFMT("s/%p$/%p # i_" #X "/;", i_##X, i_##X); - F(POPS)F(INC)F(FN1C)F(FN1O)F(FN2C)F(FN2O)F(FN1Oi)F(FN2Oi)F(ARR_0)F(ARR_2)F(ARR_p)F(DFND_0)F(DFND_1)F(DFND_2)F(MD1C)F(MD2C)F(MD2R)F(TR2D)F(TR3D)F(TR3O)F(NOVAR)F(EXTO)F(EXTU)F(SETN)F(SETU)F(SETM)F(SETC)F(SETH)F(PRED1)F(PRED2)F(SETNi)F(SETUi)F(SETMi)F(SETCi)F(SETNv)F(SETUv)F(SETMv)F(SETCv)F(FLDO)F(VFYM)F(ALIM)F(CHKV)F(FAIL)F(RETD) + F(POPS)F(INC)F(FN1C)F(FN1O)F(FN2C)F(FN2O)F(FN1Oi)F(FN2Oi)F(ARR_0)F(ARR_2)F(ARR_p)F(DFND_0)F(DFND_1)F(DFND_2)F(MD1C)F(MD2C)F(MD2R)F(TR2D)F(TR3D)F(TR3O)F(NOVAR)F(EXTO)F(EXTU)F(SETN)F(SETU)F(SETM)F(SETC)F(SETH1)F(SETH2)F(PRED1)F(PRED2)F(SETNi)F(SETUi)F(SETMi)F(SETCi)F(SETNv)F(SETUv)F(SETMv)F(SETCv)F(FLDO)F(VFYM)F(ALIM)F(CHKV)F(FAIL)F(RETD) #undef F file_wChars(m_str8l("asm_sed"), s); dec(s); } diff --git a/src/load.c b/src/load.c index 843fb55c..237f815b 100644 --- a/src/load.c +++ b/src/load.c @@ -581,6 +581,9 @@ static NOINLINE B m_bm2(D2C1 c1, D2C2 c2, u8 id) { m->c1 = c1; m->c2 = c2; m->extra = id; + m->im = def_m2_im; + m->iw = def_m2_iw; + m->ix = def_m2_ix; m->uc1 = def_m2_uc1; m->ucw = def_m2_ucw; B r = tag(m,MD2_TAG); gc_add(r);