•bit._cast⁼, support inverses of 1- and 2-modifier builtins
This commit is contained in:
parent
87d2f3a469
commit
71c9c67e46
@ -5,14 +5,6 @@
|
|||||||
#include "../nfns.h"
|
#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) {
|
void ud_rec(B** p, usz d, usz r, i32* pos, usz* sh) {
|
||||||
if (d==r) {
|
if (d==r) {
|
||||||
@ -354,6 +346,14 @@ void fun_gcFn() {
|
|||||||
if (globalNames!=NULL) mm_visitP(globalNames);
|
if (globalNames!=NULL) mm_visitP(globalNames);
|
||||||
mm_visit(globalNameList);
|
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() {
|
void fns_init() {
|
||||||
gc_addFn(fun_gcFn);
|
gc_addFn(fun_gcFn);
|
||||||
TIi(t_funBI,print) = print_funBI;
|
TIi(t_funBI,print) = print_funBI;
|
||||||
|
|||||||
@ -518,6 +518,12 @@ B insert_c2(Md1D* d, B w, B x) { B f = d->f;
|
|||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
static void print_md1BI(B x) { printf("%s", pm1_repr(c(Md1,x)->extra)); }
|
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() {
|
void md1_init() {
|
||||||
TIi(t_md1BI,print) = print_md1BI;
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 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() {
|
void md2_init() {
|
||||||
TIi(t_md2BI,print) = print_md2BI;
|
TIi(t_md2BI,print) = print_md2BI;
|
||||||
TIi(t_md2BI,m2_uc1) = md2BI_uc1;
|
TIi(t_md2BI,m2_uc1) = md2BI_uc1;
|
||||||
TIi(t_md2BI,m2_ucw) = md2BI_ucw;
|
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,freeO) = customObj_freeO;
|
||||||
TIi(t_customObj,freeF) = customObj_freeF;
|
TIi(t_customObj,freeF) = customObj_freeF;
|
||||||
TIi(t_customObj,visit) = customObj_visit;
|
TIi(t_customObj,visit) = customObj_visit;
|
||||||
|
|||||||
@ -868,7 +868,7 @@ static CastType getCastType(B e, B v) {
|
|||||||
c = q_N(v) ? 0 : isCharType(v(v)->type);
|
c = q_N(v) ? 0 : isCharType(v(v)->type);
|
||||||
} else {
|
} else {
|
||||||
if (!isArr(e) || rnk(e)!=1 || a(e)->ia!=2) thrM("•bit._cast: 𝕗 elements must be numbers or two-element lists");
|
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));
|
s = o2s(GetU(e,0));
|
||||||
u32 t = o2c(GetU(e,1));
|
u32 t = o2c(GetU(e,1));
|
||||||
c = t=='c';
|
c = t=='c';
|
||||||
@ -911,11 +911,9 @@ static u8 typeOfCast(CastType t) {
|
|||||||
default: thrM("•bit._cast: unsupported result width");
|
default: thrM("•bit._cast: unsupported result width");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
B bitcast_c1(Md1D* d, B x) { B f = d->f;
|
B bitcast_impl(B el0, B el1, B x) {
|
||||||
if (!isArr(f) || rnk(f)!=1 || a(f)->ia!=2) thrM("•bit._cast: 𝕗 must be a 2-element list (from‿to)");
|
CastType xt = getCastType(el0, x);
|
||||||
SGetU(f);
|
CastType zt = getCastType(el1, bi_N);
|
||||||
CastType xt = getCastType(GetU(f,0), x);
|
|
||||||
CastType zt = getCastType(GetU(f,1), bi_N);
|
|
||||||
ur xr;
|
ur xr;
|
||||||
if (!isArr(x) || (xr=rnk(x))<1) thrM("•bit._cast: 𝕩 must have rank at least 1");
|
if (!isArr(x) || (xr=rnk(x))<1) thrM("•bit._cast: 𝕩 must have rank at least 1");
|
||||||
usz* sh = a(x)->sh;
|
usz* sh = a(x)->sh;
|
||||||
@ -948,6 +946,18 @@ B bitcast_c1(Md1D* d, B x) { B f = d->f;
|
|||||||
}
|
}
|
||||||
return r;
|
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;
|
static B bitNS;
|
||||||
B getBitNS() {
|
B getBitNS() {
|
||||||
if (bitNS.u == 0) {
|
if (bitNS.u == 0) {
|
||||||
@ -1058,4 +1068,5 @@ void sysfn_init() {
|
|||||||
}
|
}
|
||||||
void sysfnPost_init() {
|
void sysfnPost_init() {
|
||||||
file_nsGen = m_nnsDesc("path","at","list","bytes","chars","lines");
|
file_nsGen = m_nnsDesc("path","at","list","bytes","chars","lines");
|
||||||
|
c(BMd1,bi_bitcast)->im = bitcast_im;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,9 @@ typedef struct BMd1 {
|
|||||||
|
|
||||||
typedef struct BMd2 {
|
typedef struct BMd2 {
|
||||||
struct Md2;
|
struct Md2;
|
||||||
|
D2C1 im;
|
||||||
|
D2C2 iw;
|
||||||
|
D2C2 ix;
|
||||||
M2C4 uc1;
|
M2C4 uc1;
|
||||||
M2C5 ucw;
|
M2C5 ucw;
|
||||||
} BMd2;
|
} BMd2;
|
||||||
|
|||||||
@ -486,7 +486,7 @@ void freeOpt(OptRes o) {
|
|||||||
file_wChars(m_str8l("asm_off"), o); dec(o);
|
file_wChars(m_str8l("asm_off"), o); dec(o);
|
||||||
B s = emptyCVec();
|
B s = emptyCVec();
|
||||||
#define F(X) AFMT("s/%p$/%p # i_" #X "/;", i_##X, i_##X);
|
#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
|
#undef F
|
||||||
file_wChars(m_str8l("asm_sed"), s); dec(s);
|
file_wChars(m_str8l("asm_sed"), s); dec(s);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -581,6 +581,9 @@ static NOINLINE B m_bm2(D2C1 c1, D2C2 c2, u8 id) {
|
|||||||
m->c1 = c1;
|
m->c1 = c1;
|
||||||
m->c2 = c2;
|
m->c2 = c2;
|
||||||
m->extra = id;
|
m->extra = id;
|
||||||
|
m->im = def_m2_im;
|
||||||
|
m->iw = def_m2_iw;
|
||||||
|
m->ix = def_m2_ix;
|
||||||
m->uc1 = def_m2_uc1;
|
m->uc1 = def_m2_uc1;
|
||||||
m->ucw = def_m2_ucw;
|
m->ucw = def_m2_ucw;
|
||||||
B r = tag(m,MD2_TAG); gc_add(r);
|
B r = tag(m,MD2_TAG); gc_add(r);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user