move toConstant to builtins.h
This commit is contained in:
parent
b69f65081d
commit
c2adbd4a3b
@ -102,6 +102,16 @@ static bool isPervasiveDyExt(B x) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool toConstant(B x, B* out) { // doesn't consume x; if possible, writes an owned reference to out, else leaves out unmodified
|
||||||
|
if (!isCallable(x)) { *out = inc(x); return true; }
|
||||||
|
if (TY(x) == t_md1D) {
|
||||||
|
Md1D* d = c(Md1D,x);
|
||||||
|
Md1* m1 = d->m1;
|
||||||
|
if (PTY(m1)==t_md1BI && m1->flags==n_const) { *out = inc(d->f); return true; }
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
extern GLOBAL B
|
extern GLOBAL B
|
||||||
#define F(N,X) bi_##N,
|
#define F(N,X) bi_##N,
|
||||||
FOR_PFN(F,F,F)
|
FOR_PFN(F,F,F)
|
||||||
|
|||||||
@ -100,23 +100,14 @@ static B md2D_uc1(B t, B o, B x) {
|
|||||||
return TIv(m,m2_uc1)(m, o, f, g, x);
|
return TIv(m,m2_uc1)(m, o, f, g, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static B toConstant(B x) { // doesn't consume x
|
|
||||||
if (!isCallable(x)) return inc(x);
|
|
||||||
if (TY(x) == t_md1D) {
|
|
||||||
Md1D* d = c(Md1D,x);
|
|
||||||
Md1* m1 = d->m1;
|
|
||||||
if (PTY(m1)==t_md1BI && m1->flags==n_const) return inc(d->f);
|
|
||||||
}
|
|
||||||
return bi_N;
|
|
||||||
}
|
|
||||||
STATIC_GLOBAL NFnDesc* ucwWrapDesc;
|
STATIC_GLOBAL NFnDesc* ucwWrapDesc;
|
||||||
STATIC_GLOBAL NFnDesc* uc1WrapDesc;
|
STATIC_GLOBAL NFnDesc* uc1WrapDesc;
|
||||||
|
|
||||||
static B fork_uc1(B t, B o, B x) {
|
static B fork_uc1(B t, B o, B x) {
|
||||||
B f = toConstant(c(Fork, t)->f);
|
B f;
|
||||||
B g = c(Fork, t)->g;
|
B g = c(Fork, t)->g;
|
||||||
B h = c(Fork, t)->h;
|
B h = c(Fork, t)->h;
|
||||||
if (RARE(q_N(f) | !isFun(g) | !isFun(h))) { dec(f); return def_fn_uc1(t, o, x); }
|
if (LIKELY(isFun(g) && isFun(h) && toConstant(c(Fork, t)->f, &f))) {
|
||||||
B args[] = {g, o, f};
|
B args[] = {g, o, f};
|
||||||
B tmp = m_nfn(ucwWrapDesc, tag(args, RAW_TAG));
|
B tmp = m_nfn(ucwWrapDesc, tag(args, RAW_TAG));
|
||||||
B r = TI(h,fn_uc1)(h,tmp,x);
|
B r = TI(h,fn_uc1)(h,tmp,x);
|
||||||
@ -124,6 +115,8 @@ static B fork_uc1(B t, B o, B x) {
|
|||||||
decG(tmp);
|
decG(tmp);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
return def_fn_uc1(t, o, x);
|
||||||
|
}
|
||||||
static B ucwWrap_c1(B t, B x) {
|
static B ucwWrap_c1(B t, B x) {
|
||||||
B* args = c(B, nfn_objU(t));
|
B* args = c(B, nfn_objU(t));
|
||||||
B g = args[0];
|
B g = args[0];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user