builtin initialization in load.c
This commit is contained in:
parent
cc36fd0d7c
commit
8cfa3e7f55
@ -44,7 +44,7 @@ static inline B arith_recd(BBB2B f, B w, B x) {
|
|||||||
dec(x);
|
dec(x);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
#define ffnx(NAME, EXPR, EXTRA) static B NAME##_c2(B t, B w, B x) { \
|
#define ffnx(NAME, EXPR, EXTRA) B NAME##_c2(B t, B w, B x) { \
|
||||||
if (isF64(w) & isF64(x)) return m_f64(EXPR); \
|
if (isF64(w) & isF64(x)) return m_f64(EXPR); \
|
||||||
EXTRA \
|
EXTRA \
|
||||||
if (isArr(w)|isArr(x)) { B ow=w; B ox=x; \
|
if (isArr(w)|isArr(x)) { B ow=w; B ox=x; \
|
||||||
@ -89,7 +89,7 @@ static inline B arith_recd(BBB2B f, B w, B x) {
|
|||||||
thrM(#NAME ": invalid arithmetic"); \
|
thrM(#NAME ": invalid arithmetic"); \
|
||||||
}
|
}
|
||||||
#else // if !TYPED_ARITH
|
#else // if !TYPED_ARITH
|
||||||
#define ffnx(name, expr, extra) static B name##_c2(B t, B w, B x) { \
|
#define ffnx(name, expr, extra) B name##_c2(B t, B w, B x) { \
|
||||||
if (isF64(w) & isF64(x)) return m_f64(expr); \
|
if (isF64(w) & isF64(x)) return m_f64(expr); \
|
||||||
extra \
|
extra \
|
||||||
P2(name) \
|
P2(name) \
|
||||||
@ -153,8 +153,8 @@ B decp_c1(B t, B x);
|
|||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CMP(NAME,OP,FC,CF) \
|
#define CMP(NAME,OP,FC,CF) \
|
||||||
static B NAME##_c2(B t, B w, B x) { \
|
B NAME##_c2(B t, B w, B x) { \
|
||||||
CMP_IMPL(OP, FC, CF); \
|
CMP_IMPL(OP, FC, CF); \
|
||||||
P2(NAME); \
|
P2(NAME); \
|
||||||
return m_i32(compare(w, x) OP 0); \
|
return m_i32(compare(w, x) OP 0); \
|
||||||
@ -165,14 +165,14 @@ CMP(lt, < , 1, 0)
|
|||||||
CMP(gt, > , 0, 1)
|
CMP(gt, > , 0, 1)
|
||||||
#undef CMP
|
#undef CMP
|
||||||
|
|
||||||
static B eq_c2(B t, B w, B x) {
|
B eq_c2(B t, B w, B x) {
|
||||||
CMP_IMPL(==, 0, 0);
|
CMP_IMPL(==, 0, 0);
|
||||||
P2(eq);
|
P2(eq);
|
||||||
B r = m_i32(atomEqual(w, x));
|
B r = m_i32(atomEqual(w, x));
|
||||||
dec(w); dec(x);
|
dec(w); dec(x);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
static B ne_c2(B t, B w, B x) {
|
B ne_c2(B t, B w, B x) {
|
||||||
CMP_IMPL(!=, 1, 1);
|
CMP_IMPL(!=, 1, 1);
|
||||||
P2(ne);
|
P2(ne);
|
||||||
B r = m_i32(!atomEqual(w, x));
|
B r = m_i32(!atomEqual(w, x));
|
||||||
@ -181,38 +181,38 @@ static B ne_c2(B t, B w, B x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern B rt_merge;
|
extern B rt_merge;
|
||||||
static B gt_c1(B t, B x) {
|
B gt_c1(B t, B x) {
|
||||||
if (isAtm(x)) return x;
|
if (isAtm(x)) return x;
|
||||||
return bqn_merge(x);
|
return bqn_merge(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static B add_c1(B t, B x) { return x; }
|
B add_c1(B t, B x) { return x; }
|
||||||
static B sub_c1(B t, B x) { if (isF64(x)) return m_f64( -x.f ); P1( sub); thrM("-: Negating non-number"); }
|
B sub_c1(B t, B x) { if (isF64(x)) return m_f64( -x.f ); P1( sub); thrM("-: Negating non-number"); }
|
||||||
static B not_c1(B t, B x) { if (isF64(x)) return m_f64( 1-x.f ); P1( not); thrM("¬: Argument was not a number"); }
|
B not_c1(B t, B x) { if (isF64(x)) return m_f64( 1-x.f ); P1( not); thrM("¬: Argument was not a number"); }
|
||||||
static B mul_c1(B t, B x) { if (isF64(x)) return m_f64(x.f==0?0:x.f>0?1:-1); P1(mul); thrM("×: Getting sign of non-number"); }
|
B mul_c1(B t, B x) { if (isF64(x)) return m_f64(x.f==0?0:x.f>0?1:-1); P1(mul); thrM("×: Getting sign of non-number"); }
|
||||||
static B div_c1(B t, B x) { if (isF64(x)) return m_f64( 1/x.f ); P1( div); thrM("÷: Getting reciprocal of non-number"); }
|
B div_c1(B t, B x) { if (isF64(x)) return m_f64( 1/x.f ); P1( div); thrM("÷: Getting reciprocal of non-number"); }
|
||||||
static B pow_c1(B t, B x) { if (isF64(x)) return m_f64( exp(x.f)); P1( pow); thrM("⋆: Getting exp of non-number"); }
|
B pow_c1(B t, B x) { if (isF64(x)) return m_f64( exp(x.f)); P1( pow); thrM("⋆: Getting exp of non-number"); }
|
||||||
static B floor_c1(B t, B x) { if (isF64(x)) return m_f64(floor(x.f)); P1(floor); thrM("⌊: Argument was not a number"); }
|
B floor_c1(B t, B x) { if (isF64(x)) return m_f64(floor(x.f)); P1(floor); thrM("⌊: Argument was not a number"); }
|
||||||
static B ceil_c1(B t, B x) { if (isF64(x)) return m_f64( ceil(x.f)); P1( ceil); thrM("⌈: Argument was not a number"); }
|
B ceil_c1(B t, B x) { if (isF64(x)) return m_f64( ceil(x.f)); P1( ceil); thrM("⌈: Argument was not a number"); }
|
||||||
static B stile_c1(B t, B x) { if (isF64(x)) return m_f64( fabs(x.f)); P1(stile); thrM("|: Argument was not a number"); }
|
B stile_c1(B t, B x) { if (isF64(x)) return m_f64( fabs(x.f)); P1(stile); thrM("|: Argument was not a number"); }
|
||||||
static B log_c1(B t, B x) { if (isF64(x)) return m_f64( log(x.f)); P1( log); thrM("⋆⁼: Getting log of non-number"); }
|
B log_c1(B t, B x) { if (isF64(x)) return m_f64( log(x.f)); P1( log); thrM("⋆⁼: Getting log of non-number"); }
|
||||||
|
|
||||||
static B lt_c1(B t, B x) { return m_unit(x); }
|
B lt_c1(B t, B x) { return m_unit(x); }
|
||||||
static B eq_c1(B t, B x) { B r = m_i32(isArr(x)? rnk(x) : 0); decR(x); return r; }
|
B eq_c1(B t, B x) { B r = m_i32(isArr(x)? rnk(x) : 0); decR(x); return r; }
|
||||||
static B ne_c1(B t, B x) { B r = m_f64(isArr(x)&&rnk(x)? *a(x)->sh : 1); decR(x); return r; }
|
B ne_c1(B t, B x) { B r = m_f64(isArr(x)&&rnk(x)? *a(x)->sh : 1); decR(x); return r; }
|
||||||
|
|
||||||
extern B rt_sortDsc;
|
extern B rt_sortDsc;
|
||||||
static B or_c1(B t, B x) { return c1(rt_sortDsc, x); }
|
B or_c1(B t, B x) { return c1(rt_sortDsc, x); }
|
||||||
B and_c1(B t, B x); // defined in sort.c
|
B and_c1(B t, B x); // defined in sort.c
|
||||||
|
|
||||||
#undef P1
|
#undef P1
|
||||||
#undef P2
|
#undef P2
|
||||||
|
|
||||||
#define F(A,M,D) A(add) A(sub) A(mul) A(div) A(pow) A(floor) A(ceil) A(stile) A(eq) A(ne) D(le) D(ge) A(lt) A(gt) A(and) A(or) A(not) A(log)
|
|
||||||
void arith_init() { BI_FNS(F)
|
|
||||||
|
void arith_init() {
|
||||||
c(BFn,bi_add)->ident = c(BFn,bi_sub)->ident = c(BFn,bi_or )->ident = c(BFn,bi_ne)->ident = c(BFn,bi_gt)->ident = m_i32(0);
|
c(BFn,bi_add)->ident = c(BFn,bi_sub)->ident = c(BFn,bi_or )->ident = c(BFn,bi_ne)->ident = c(BFn,bi_gt)->ident = m_i32(0);
|
||||||
c(BFn,bi_mul)->ident = c(BFn,bi_div)->ident = c(BFn,bi_and)->ident = c(BFn,bi_eq)->ident = c(BFn,bi_ge)->ident = c(BFn,bi_pow)->ident = c(BFn,bi_not)->ident = m_i32(1);
|
c(BFn,bi_mul)->ident = c(BFn,bi_div)->ident = c(BFn,bi_and)->ident = c(BFn,bi_eq)->ident = c(BFn,bi_ge)->ident = c(BFn,bi_pow)->ident = c(BFn,bi_not)->ident = m_i32(1);
|
||||||
c(BFn,bi_floor)->ident = m_f64(1.0/0.0);
|
c(BFn,bi_floor)->ident = m_f64(1.0/0.0);
|
||||||
c(BFn,bi_ceil )->ident = m_f64(-1.0/0.0);
|
c(BFn,bi_ceil )->ident = m_f64(-1.0/0.0);
|
||||||
}
|
}
|
||||||
#undef F
|
|
||||||
|
|||||||
@ -291,13 +291,9 @@ B count_c2(B t, B w, B x) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void fns_init() {
|
||||||
|
|
||||||
#define F(A,M,D) A(ud) A(pair) A(fne) A(feq) A(ltack) A(rtack) M(fmtF) A(indexOf) A(memberOf) A(find) A(count)
|
|
||||||
void fns_init() { BI_FNS(F)
|
|
||||||
ti[t_funBI].print = print_funBI;
|
ti[t_funBI].print = print_funBI;
|
||||||
ti[t_funBI].identity = funBI_identity;
|
ti[t_funBI].identity = funBI_identity;
|
||||||
ti[t_funBI].fn_uc1 = funBI_uc1;
|
ti[t_funBI].fn_uc1 = funBI_uc1;
|
||||||
ti[t_funBI].fn_ucw = funBI_ucw;
|
ti[t_funBI].fn_ucw = funBI_ucw;
|
||||||
}
|
}
|
||||||
#undef F
|
|
||||||
|
|||||||
@ -380,16 +380,9 @@ B cell_c2(B d, B w, B x) { B f = c(Md1D,d)->f;
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ba(NAME) bi_##NAME = mm_alloc(sizeof(Md1), t_md1BI, ftag(MD1_TAG)); c(Md1,bi_##NAME)->c2 = NAME##_c2; c(Md1,bi_##NAME)->c1 = NAME##_c1 ; c(Md1,bi_##NAME)->extra=pm1_##NAME; gc_add(bi_##NAME);
|
|
||||||
#define bd(NAME) bi_##NAME = mm_alloc(sizeof(Md1), t_md1BI, ftag(MD1_TAG)); c(Md1,bi_##NAME)->c2 = NAME##_c2; c(Md1,bi_##NAME)->c1 = c1_invalid; c(Md1,bi_##NAME)->extra=pm1_##NAME; gc_add(bi_##NAME);
|
|
||||||
#define bm(NAME) bi_##NAME = mm_alloc(sizeof(Md1), t_md1BI, ftag(MD1_TAG)); c(Md1,bi_##NAME)->c2 = c2_invalid;c(Md1,bi_##NAME)->c1 = NAME##_c1 ; c(Md1,bi_##NAME)->extra=pm1_##NAME; gc_add(bi_##NAME);
|
|
||||||
|
|
||||||
static void print_md1BI(B x) { printf("%s", format_pm1(c(Md1,x)->extra)); }
|
static void print_md1BI(B x) { printf("%s", format_pm1(c(Md1,x)->extra)); }
|
||||||
|
void md1_init() {
|
||||||
void md1_init() { ba(tbl) ba(each) ba(fold) ba(scan) ba(const) ba(swap) ba(cell) ba(timed) ba(fchars) bm(fbytes) bm(flines) ba(import)
|
|
||||||
ti[t_md1BI].print = print_md1BI;
|
ti[t_md1BI].print = print_md1BI;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef ba
|
|
||||||
#undef bd
|
|
||||||
#undef bm
|
|
||||||
|
|||||||
@ -1,12 +1,5 @@
|
|||||||
#include "../core.h"
|
#include "../core.h"
|
||||||
|
|
||||||
typedef struct BMd2 {
|
|
||||||
struct Md1;
|
|
||||||
BBBBB2B uc1;
|
|
||||||
BBBBBB2B ucw;
|
|
||||||
} BMd2;
|
|
||||||
|
|
||||||
void print_md2BI(B x) { printf("%s", format_pm2(c(Md1,x)->extra)); }
|
|
||||||
B md2BI_uc1(B t, B o, B f, B g, B x) { return c(BMd2,t)->uc1(t, o, f, g, x); }
|
B md2BI_uc1(B t, B o, B f, B g, B x) { return c(BMd2,t)->uc1(t, o, f, g, x); }
|
||||||
B md2BI_ucw(B t, B o, B f, B g, B w, B x) { return c(BMd2,t)->ucw(t, o, f, g, w, x); }
|
B md2BI_ucw(B t, B o, B f, B g, B w, B x) { return c(BMd2,t)->ucw(t, o, f, g, w, x); }
|
||||||
|
|
||||||
@ -156,17 +149,11 @@ B before_uc1(B t, B o, B f, B g, B x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define ba(N) { B t=bi_##N=mm_alloc(sizeof(BMd2), t_md2BI, ftag(MD2_TAG)); BMd2*m=c(BMd2,t); m->c2 = N##_c2 ; m->c1 = N##_c1; m->extra=pm2_##N; m->uc1=def_m2_uc1; m->ucw=def_m2_ucw; gc_add(t); }
|
|
||||||
#define bd(N) { B t=bi_##N=mm_alloc(sizeof(BMd2), t_md2BI, ftag(MD2_TAG)); BMd2*m=c(BMd2,t); m->c2 = N##_c2 ; m->c1 = c1_invalid; m->extra=pm2_##N; m->uc1=def_m2_uc1; m->ucw=def_m2_ucw; gc_add(t); }
|
|
||||||
#define bm(N) { B t=bi_##N=mm_alloc(sizeof(BMd2), t_md2BI, ftag(MD2_TAG)); BMd2*m=c(BMd2,t); m->c2 = c2_invalid; m->c1 = N##_c1; m->extra=pm2_##N; m->uc1=def_m2_uc1; m->ucw=def_m2_ucw; gc_add(t); }
|
|
||||||
|
|
||||||
void md2_init() { ba(val) ba(repeat) ba(atop) ba(over) ba(before) ba(after) ba(cond) ba(fillBy) ba(under) ba(catch)
|
static void print_md2BI(B x) { printf("%s", format_pm2(c(Md1,x)->extra)); }
|
||||||
|
void md2_init() {
|
||||||
ti[t_md2BI].print = print_md2BI;
|
ti[t_md2BI].print = print_md2BI;
|
||||||
ti[t_md2BI].m2_uc1 = md2BI_uc1;
|
ti[t_md2BI].m2_uc1 = md2BI_uc1;
|
||||||
ti[t_md2BI].m2_ucw = md2BI_ucw;
|
ti[t_md2BI].m2_ucw = md2BI_ucw;
|
||||||
c(BMd2,bi_before)->uc1 = before_uc1;
|
c(BMd2,bi_before)->uc1 = before_uc1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef ba
|
|
||||||
#undef bd
|
|
||||||
#undef bm
|
|
||||||
|
|||||||
@ -845,12 +845,10 @@ B select_ucw(B t, B o, B w, B x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define F(A,M,D) A(shape) A(pick) A(select) A(slash) A(join) A(couple) A(shiftb) A(shifta) A(take) A(drop) A(group) A(reverse)
|
void sfns_init() {
|
||||||
void sfns_init() { BI_FNS(F)
|
|
||||||
c(BFn,bi_pick)->uc1 = pick_uc1;
|
c(BFn,bi_pick)->uc1 = pick_uc1;
|
||||||
c(BFn,bi_reverse)->uc1 = reverse_uc1;
|
c(BFn,bi_reverse)->uc1 = reverse_uc1;
|
||||||
c(BFn,bi_pick)->ucw = pick_ucw;
|
c(BFn,bi_pick)->ucw = pick_ucw;
|
||||||
c(BFn,bi_slash)->ucw = slash_ucw;
|
c(BFn,bi_slash)->ucw = slash_ucw;
|
||||||
c(BFn,bi_select)->ucw = select_ucw;
|
c(BFn,bi_select)->ucw = select_ucw;
|
||||||
}
|
}
|
||||||
#undef F
|
|
||||||
|
|||||||
@ -48,7 +48,3 @@ B and_c1(B t, B x) {
|
|||||||
dec(x);
|
dec(x);
|
||||||
return withFill(r.b,xf);
|
return withFill(r.b,xf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define F(A,M,D) A(gradeUp) A(gradeDown)
|
|
||||||
void sort_init() { BI_FNS(F) }
|
|
||||||
#undef F
|
|
||||||
|
|||||||
@ -190,10 +190,6 @@ B hash_c1(B t, B x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define F(A,M,D) M(type) M(decp) M(primInd) M(glyph) M(repr) A(fill) A(grLen) D(grOrd) A(asrt) M(out) M(show) M(sys) M(bqn) D(cmp) D(internal) A(hash)
|
|
||||||
void sysfn_init() { BI_FNS(F) }
|
|
||||||
#undef F
|
|
||||||
|
|
||||||
static B makeRel(B md) { // doesn't consume
|
static B makeRel(B md) { // doesn't consume
|
||||||
return m1_d(inc(md), path_dir(inc(comp_currPath)));
|
return m1_d(inc(md), path_dir(inc(comp_currPath)));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,10 +31,11 @@ typedef struct BFn {
|
|||||||
BBB2B uc1;
|
BBB2B uc1;
|
||||||
BBBB2B ucw;
|
BBBB2B ucw;
|
||||||
} BFn;
|
} BFn;
|
||||||
#define BI_A(N) { B t=bi_##N = mm_alloc(sizeof(BFn), t_funBI, ftag(FUN_TAG)); BFn*f=c(BFn,t); f->c2=N##_c2 ; f->c1=N##_c1 ; f->extra=pf_##N; f->ident=bi_N; f->uc1=def_fn_uc1; f->ucw=def_fn_ucw; gc_add(t); }
|
typedef struct BMd2 {
|
||||||
#define BI_D(N) { B t=bi_##N = mm_alloc(sizeof(BFn), t_funBI, ftag(FUN_TAG)); BFn*f=c(BFn,t); f->c2=N##_c2 ; f->c1=c1_invalid; f->extra=pf_##N; f->ident=bi_N; f->uc1=def_fn_uc1; f->ucw=def_fn_ucw; gc_add(t); }
|
struct Md1;
|
||||||
#define BI_M(N) { B t=bi_##N = mm_alloc(sizeof(BFn), t_funBI, ftag(FUN_TAG)); BFn*f=c(BFn,t); f->c2=c2_invalid; f->c1=N##_c1 ; f->extra=pf_##N; f->ident=bi_N; f->uc1=def_fn_uc1; f->ucw=def_fn_ucw; gc_add(t); }
|
BBBBB2B uc1;
|
||||||
#define BI_FNS(F) F(BI_A,BI_M,BI_D)
|
BBBBBB2B ucw;
|
||||||
|
} BMd2;
|
||||||
|
|
||||||
static i64 isum(B x) { // doesn't consume; may error; TODO error on overflow
|
static i64 isum(B x) { // doesn't consume; may error; TODO error on overflow
|
||||||
assert(isArr(x));
|
assert(isArr(x));
|
||||||
|
|||||||
@ -35,11 +35,11 @@ B fork_c2(B t, B w, B x);
|
|||||||
B md2H_c1(B d, B x);
|
B md2H_c1(B d, B x);
|
||||||
B md2H_c2(B d, B w, B x);
|
B md2H_c2(B d, B w, B x);
|
||||||
// consume all args
|
// consume all args
|
||||||
static 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; }
|
static 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; return r; }
|
||||||
static B m_md2D(B m, B f, B g) { B r = mm_alloc(sizeof(Md2D), t_md2D, ftag(FUN_TAG)); c(Md2D,r)->f = f; c(Md2D,r)->m2 = m; c(Md2D,r)->g = g; c(Md2D,r)->c1=md2D_c1; c(Md2D,r)->c2=md2D_c2; c(Md2D,r)->extra=pf_md2d; return r; }
|
static B m_md2D(B m, B f, B g) { B r = mm_alloc(sizeof(Md2D), t_md2D, ftag(FUN_TAG)); c(Md2D,r)->f = f; c(Md2D,r)->m2 = m; c(Md2D,r)->g = g; c(Md2D,r)->c1=md2D_c1; c(Md2D,r)->c2=md2D_c2; return r; }
|
||||||
static B m_md2H(B m, B g) { B r = mm_alloc(sizeof(Md2H), t_md2H, ftag(MD1_TAG)); c(Md2H,r)->m2 = m; c(Md2H,r)->g = g; c(Md2H,r)->c1=md2H_c1; c(Md2H,r)->c2=md2H_c2; return r; }
|
static B m_md2H(B m, B g) { B r = mm_alloc(sizeof(Md2H), t_md2H, ftag(MD1_TAG)); c(Md2H,r)->m2 = m; c(Md2H,r)->g = g; c(Md2H,r)->c1=md2H_c1; c(Md2H,r)->c2=md2H_c2; return r; }
|
||||||
static B m_fork(B f, B g, B h) { B r = mm_alloc(sizeof(Fork), t_fork, ftag(FUN_TAG)); c(Fork,r)->f = f; c(Fork,r)->g = g; c(Fork,r)->h = h; c(Fork,r)->c1=fork_c1; c(Fork,r)->c2=fork_c2; c(Fork,r)->extra=pf_fork; return r; }
|
static B m_fork(B f, B g, B h) { B r = mm_alloc(sizeof(Fork), t_fork, ftag(FUN_TAG)); c(Fork,r)->f = f; c(Fork,r)->g = g; c(Fork,r)->h = h; c(Fork,r)->c1=fork_c1; c(Fork,r)->c2=fork_c2; return r; }
|
||||||
static B m_atop( B g, B h) { B r = mm_alloc(sizeof(Atop), t_atop, ftag(FUN_TAG)); c(Atop,r)->g = g; c(Atop,r)->h = h; c(Atop,r)->c1=tr2D_c1; c(Atop,r)->c2=tr2D_c2; c(Atop,r)->extra=pf_atop; return r; }
|
static B m_atop( B g, B h) { B r = mm_alloc(sizeof(Atop), t_atop, ftag(FUN_TAG)); c(Atop,r)->g = g; c(Atop,r)->h = h; c(Atop,r)->c1=tr2D_c1; c(Atop,r)->c2=tr2D_c2; return r; }
|
||||||
|
|
||||||
// consume all args
|
// consume all args
|
||||||
static B m1_d(B m, B f ) { if(isMd1(m)) return TI(m).m1_d(m, f ); thrM("Interpreting non-1-modifier as 1-modifier"); }
|
static B m1_d(B m, B f ) { if(isMd1(m)) return TI(m).m1_d(m, f ); thrM("Interpreting non-1-modifier as 1-modifier"); }
|
||||||
|
|||||||
53
src/h.h
53
src/h.h
@ -151,70 +151,69 @@ enum ElType { // a⌈b shall return the type that can store both, if possible; a
|
|||||||
|
|
||||||
char* format_type(u8 u);
|
char* format_type(u8 u);
|
||||||
|
|
||||||
#define FOR_PFN(F) F(none, "(unknown fn)") \
|
#define FOR_PFN(A,M,D) \
|
||||||
/*arith.c*/ F(add,"+") F(sub,"-") F(mul,"×") F(div,"÷") F(pow,"⋆") F(floor,"⌊") F(ceil,"⌈") F(stile,"|") F(eq,"=") \
|
/*arith.c*/ A(add,"+") A(sub,"-") A(mul,"×") A(div,"÷") A(pow,"⋆") A(floor,"⌊") A(ceil,"⌈") A(stile,"|") A(eq,"=") \
|
||||||
/*arith.c*/ F(ne,"≠") F(le,"≤") F(ge,"≥") F(lt,"<") F(gt,">") F(and,"∧") F(or,"∨") F(not,"¬") F(log,"⋆⁼") \
|
/*arith.c*/ A(ne,"≠") D(le,"≤") D(ge,"≥") A(lt,"<") A(gt,">") A(and,"∧") A(or,"∨") A(not,"¬") A(log,"⋆⁼") \
|
||||||
/*fns.c*/ F(ud,"↕") F(fne,"≢") F(feq,"≡") F(ltack,"⊣") F(rtack,"⊢") F(fmtF,"•FmtF") F(indexOf,"⊐") F(memberOf,"∊") F(find,"⍷") F(count,"⊒") \
|
/*fns.c*/ A(ud,"↕") A(fne,"≢") A(feq,"≡") A(ltack,"⊣") A(rtack,"⊢") M(fmtF,"•FmtF") A(indexOf,"⊐") A(memberOf,"∊") A(find,"⍷") A(count,"⊒") \
|
||||||
/*sfns.c*/ F(shape,"⥊") F(pick,"⊑") F(pair,"{𝕨‿𝕩}") F(select,"⊏") F(slash,"/") F(join,"∾") F(couple,"≍") F(shiftb,"»") F(shifta,"«") F(take,"↑") F(drop,"↓") F(group,"⊔") F(reverse,"⌽") \
|
/*sfns.c*/ A(shape,"⥊") A(pick,"⊑") A(pair,"{𝕨‿𝕩}") A(select,"⊏") A(slash,"/") A(join,"∾") A(couple,"≍") A(shiftb,"»") A(shifta,"«") A(take,"↑") A(drop,"↓") A(group,"⊔") A(reverse,"⌽") \
|
||||||
/*derv.c*/ F(fork,"(fork)") F(atop,"(atop)") F(md1d,"(derived 1-modifier)") F(md2d,"(derived 2-modifier)") \
|
/*sort.c*/ A(gradeUp,"⍋") A(gradeDown,"⍒") \
|
||||||
/*sort.c*/ F(gradeUp,"⍋") F(gradeDown,"⍒") \
|
/*sysfn.c*/ M(type,"•Type") M(decp,"•Decompose") M(primInd,"•PrimInd") M(glyph,"•Glyph") M(repr,"•Repr") A(fill,"•FillFn") \
|
||||||
/*sysfn.c*/ F(type,"•Type") F(decp,"•Decompose") F(primInd,"•PrimInd") F(glyph,"•Glyph") F(repr,"•Repr") F(fill,"•FillFn") \
|
/*sysfn.c*/ A(grLen,"•GroupLen") D(grOrd,"•groupOrd") A(asrt,"!") M(out,"•Out") M(show,"•Show") M(sys,"•getsys") M(bqn,"•BQN") D(cmp,"•Cmp") D(internal,"•Internal") A(hash,"•Hash") \
|
||||||
/*sysfn.c*/ F(grLen,"•GroupLen") F(grOrd,"•groupOrd") F(asrt,"!") F(sys,"•getsys") F(bqn,"•BQN") F(cmp,"•Cmp") F(internal,"•Internal") F(show,"•Show") F(out,"•Out") F(hash,"•Hash") \
|
|
||||||
|
|
||||||
#define FOR_PM1(F) F(none, "(unknown 1-modifier)") \
|
#define FOR_PM1(A,M,D) \
|
||||||
/*md1.c*/ F(tbl,"⌜") F(each,"¨") F(fold,"´") F(scan,"`") F(const,"˙") F(swap,"˜") F(cell,"˘") \
|
/*md1.c*/ A(tbl,"⌜") A(each,"¨") A(fold,"´") A(scan,"`") A(const,"˙") A(swap,"˜") A(cell,"˘") \
|
||||||
/*md1.c*/ F(timed,"•_timed") F(fchars,"•FChars") F(fbytes,"•FBytes") F(flines,"•FLines") F(import,"•Import")
|
/*md1.c*/ A(timed,"•_timed") A(fchars,"•FChars") M(fbytes,"•FBytes") M(flines,"•FLines") A(import,"•Import")
|
||||||
|
|
||||||
#define FOR_PM2(F) F(none, "(unknown 2-modifier)") \
|
#define FOR_PM2(A,M,D) \
|
||||||
/*md2.c*/ F(val,"⊘") F(repeat,"⍟") F(fillBy,"•_fillBy_") F(catch,"⎊") \
|
/*md2.c*/ A(val,"⊘") A(repeat,"⍟") A(fillBy,"•_fillBy_") A(catch,"⎊") \
|
||||||
/*md2.c*/ F(atop,"∘") F(over,"○") F(before,"⊸") F(after,"⟜") F(cond,"◶") F(under,"⌾")
|
/*md2.c*/ A(atop,"∘") A(over,"○") A(before,"⊸") A(after,"⟜") A(cond,"◶") A(under,"⌾")
|
||||||
|
|
||||||
enum PrimFns {
|
enum PrimFns { pf_none,
|
||||||
#define F(N,X) pf_##N,
|
#define F(N,X) pf_##N,
|
||||||
FOR_PFN(F)
|
FOR_PFN(F,F,F)
|
||||||
#undef F
|
#undef F
|
||||||
};
|
};
|
||||||
enum PrimMd1 {
|
enum PrimMd1 { pm1_none,
|
||||||
#define F(N,X) pm1_##N,
|
#define F(N,X) pm1_##N,
|
||||||
FOR_PM1(F)
|
FOR_PM1(F,F,F)
|
||||||
#undef F
|
#undef F
|
||||||
};
|
};
|
||||||
enum PrimMd2 {
|
enum PrimMd2 { pm2_none,
|
||||||
#define F(N,X) pm2_##N,
|
#define F(N,X) pm2_##N,
|
||||||
FOR_PM2(F)
|
FOR_PM2(F,F,F)
|
||||||
#undef F
|
#undef F
|
||||||
};
|
};
|
||||||
|
|
||||||
static char* format_pf(u8 u) {
|
static char* format_pf(u8 u) {
|
||||||
switch(u) { default: return "(unknown function)";
|
switch(u) { default: return "(unknown function)";
|
||||||
#define F(N,X) case pf_##N: return X;
|
#define F(N,X) case pf_##N: return X;
|
||||||
FOR_PFN(F)
|
FOR_PFN(F,F,F)
|
||||||
#undef F
|
#undef F
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static char* format_pm1(u8 u) {
|
static char* format_pm1(u8 u) {
|
||||||
switch(u) { default: return"(unknown 1-modifier)";
|
switch(u) { default: return"(unknown 1-modifier)";
|
||||||
#define F(N,X) case pm1_##N: return X;
|
#define F(N,X) case pm1_##N: return X;
|
||||||
FOR_PM1(F)
|
FOR_PM1(F,F,F)
|
||||||
#undef F
|
#undef F
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static char* format_pm2(u8 u) {
|
static char* format_pm2(u8 u) {
|
||||||
switch(u) { default: return"(unknown 2-modifier)";
|
switch(u) { default: return"(unknown 2-modifier)";
|
||||||
#define F(N,X) case pm2_##N: return X;
|
#define F(N,X) case pm2_##N: return X;
|
||||||
FOR_PM2(F)
|
FOR_PM2(F,F,F)
|
||||||
#undef F
|
#undef F
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define F(N,X) extern B bi_##N;
|
#define F(N,X) extern B bi_##N;
|
||||||
FOR_PFN(F)
|
FOR_PFN(F,F,F)
|
||||||
#undef F
|
#undef F
|
||||||
#define F(N,X) extern B bi_##N;
|
#define F(N,X) extern B bi_##N;
|
||||||
FOR_PM1(F)
|
FOR_PM1(F,F,F)
|
||||||
#undef F
|
#undef F
|
||||||
#define F(N,X) extern B bi_##N;
|
#define F(N,X) extern B bi_##N;
|
||||||
FOR_PM2(F)
|
FOR_PM2(F,F,F)
|
||||||
#undef F
|
#undef F
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
48
src/load.c
48
src/load.c
@ -2,16 +2,16 @@
|
|||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
#include "utils/file.h"
|
#include "utils/file.h"
|
||||||
|
|
||||||
|
#define FA(N,X) B bi_##N; B N##_c1(B t, B x); B N##_c2(B t, B w, B x);
|
||||||
|
#define FM(N,X) B bi_##N; B N##_c1(B t, B x);
|
||||||
|
#define FD(N,X) B bi_##N; B N##_c2(B t, B w, B x);
|
||||||
|
FOR_PFN(FA,FM,FD)
|
||||||
|
FOR_PM1(FA,FM,FD)
|
||||||
|
FOR_PM2(FA,FM,FD)
|
||||||
|
#undef FA
|
||||||
|
#undef FM
|
||||||
|
#undef FD
|
||||||
|
|
||||||
#define F(N,X) B bi_##N;
|
|
||||||
FOR_PFN(F)
|
|
||||||
#undef F
|
|
||||||
#define F(N,X) B bi_##N;
|
|
||||||
FOR_PM1(F)
|
|
||||||
#undef F
|
|
||||||
#define F(N,X) B bi_##N;
|
|
||||||
FOR_PM2(F)
|
|
||||||
#undef F
|
|
||||||
TypeInfo ti[t_COUNT];
|
TypeInfo ti[t_COUNT];
|
||||||
|
|
||||||
B r1Objs[rtLen];
|
B r1Objs[rtLen];
|
||||||
@ -81,7 +81,7 @@ void bqn_setComp(B comp) { // consumes; doesn't unload old comp, but whatever
|
|||||||
gc_add(load_comp);
|
gc_add(load_comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void load_init() {
|
static inline void load_init() { // very last init function
|
||||||
comp_currPath = bi_N;
|
comp_currPath = bi_N;
|
||||||
comp_currArgs = bi_N;
|
comp_currArgs = bi_N;
|
||||||
gc_addFn(load_gcFn);
|
gc_addFn(load_gcFn);
|
||||||
@ -240,7 +240,7 @@ static B def_m1_d(B m, B f ) { thrM("cannot derive this"); }
|
|||||||
static B def_m2_d(B m, B f, B g) { thrM("cannot derive this"); }
|
static B def_m2_d(B m, B f, B g) { thrM("cannot derive this"); }
|
||||||
static B def_slice(B x, usz s) { thrM("cannot slice non-array!"); }
|
static B def_slice(B x, usz s) { thrM("cannot slice non-array!"); }
|
||||||
|
|
||||||
static inline void base_init() {
|
static inline void base_init() { // very first init function
|
||||||
for (i32 i = 0; i < t_COUNT; i++) {
|
for (i32 i = 0; i < t_COUNT; i++) {
|
||||||
ti[i].free = def_free;
|
ti[i].free = def_free;
|
||||||
ti[i].visit = def_visit;
|
ti[i].visit = def_visit;
|
||||||
@ -275,9 +275,33 @@ static inline void base_init() {
|
|||||||
bi_optOut = tag(3, TAG_TAG);
|
bi_optOut = tag(3, TAG_TAG);
|
||||||
bi_noFill = tag(5, TAG_TAG);
|
bi_noFill = tag(5, TAG_TAG);
|
||||||
assert((MD1_TAG>>1) == (MD2_TAG>>1)); // just to be sure it isn't changed incorrectly, `isMd` depends on this
|
assert((MD1_TAG>>1) == (MD2_TAG>>1)); // just to be sure it isn't changed incorrectly, `isMd` depends on this
|
||||||
|
|
||||||
|
#define FA(N,X) { B t=bi_##N = mm_alloc(sizeof(BFn), t_funBI, ftag(FUN_TAG)); BFn*f=c(BFn,t); f->c2=N##_c2 ; f->c1=N##_c1 ; f->extra=pf_##N; f->ident=bi_N; f->uc1=def_fn_uc1; f->ucw=def_fn_ucw; gc_add(t); }
|
||||||
|
#define FM(N,X) { B t=bi_##N = mm_alloc(sizeof(BFn), t_funBI, ftag(FUN_TAG)); BFn*f=c(BFn,t); f->c2=c2_invalid; f->c1=N##_c1 ; f->extra=pf_##N; f->ident=bi_N; f->uc1=def_fn_uc1; f->ucw=def_fn_ucw; gc_add(t); }
|
||||||
|
#define FD(N,X) { B t=bi_##N = mm_alloc(sizeof(BFn), t_funBI, ftag(FUN_TAG)); BFn*f=c(BFn,t); f->c2=N##_c2 ; f->c1=c1_invalid; f->extra=pf_##N; f->ident=bi_N; f->uc1=def_fn_uc1; f->ucw=def_fn_ucw; gc_add(t); }
|
||||||
|
FOR_PFN(FA,FM,FD)
|
||||||
|
#undef FA
|
||||||
|
#undef FM
|
||||||
|
#undef FD
|
||||||
|
|
||||||
|
#define FA(N,X) { B t = bi_##N = mm_alloc(sizeof(Md1), t_md1BI, ftag(MD1_TAG)); c(Md1,t)->c2 = N##_c2 ; c(Md1,t)->c1 = N##_c1 ; c(Md1,t)->extra=pm1_##N; gc_add(t); }
|
||||||
|
#define FM(N,X) { B t = bi_##N = mm_alloc(sizeof(Md1), t_md1BI, ftag(MD1_TAG)); c(Md1,t)->c2 = c2_invalid; c(Md1,t)->c1 = N##_c1 ; c(Md1,t)->extra=pm1_##N; gc_add(t); }
|
||||||
|
#define FD(N,X) { B t = bi_##N = mm_alloc(sizeof(Md1), t_md1BI, ftag(MD1_TAG)); c(Md1,t)->c2 = N##_c2 ; c(Md1,t)->c1 = c1_invalid; c(Md1,t)->extra=pm1_##N; gc_add(t); }
|
||||||
|
FOR_PM1(FA,FM,FD)
|
||||||
|
#undef FA
|
||||||
|
#undef FM
|
||||||
|
#undef FD
|
||||||
|
|
||||||
|
#define FA(N,X) { B t=bi_##N=mm_alloc(sizeof(BMd2), t_md2BI, ftag(MD2_TAG)); BMd2*m=c(BMd2,t); m->c2 = N##_c2 ; m->c1 = N##_c1; m->extra=pm2_##N; m->uc1=def_m2_uc1; m->ucw=def_m2_ucw; gc_add(t); }
|
||||||
|
#define FM(N,X) { B t=bi_##N=mm_alloc(sizeof(BMd2), t_md2BI, ftag(MD2_TAG)); BMd2*m=c(BMd2,t); m->c2 = N##_c2 ; m->c1 = c1_invalid; m->extra=pm2_##N; m->uc1=def_m2_uc1; m->ucw=def_m2_ucw; gc_add(t); }
|
||||||
|
#define FD(N,X) { B t=bi_##N=mm_alloc(sizeof(BMd2), t_md2BI, ftag(MD2_TAG)); BMd2*m=c(BMd2,t); m->c2 = c2_invalid; m->c1 = N##_c1; m->extra=pm2_##N; m->uc1=def_m2_uc1; m->ucw=def_m2_ucw; gc_add(t); }
|
||||||
|
FOR_PM2(FA,FM,FD)
|
||||||
|
#undef FA
|
||||||
|
#undef FM
|
||||||
|
#undef FD
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FOR_INIT(F) F(base) F(harr) F(fillarr) F(i32arr) F(c32arr) F(f64arr) F(hash) F(fns) F(sfns) F(arith) F(sort) F(md1) F(md2) F(sysfn) F(derv) F(comp) F(rtWrap) F(ns) F(load)
|
#define FOR_INIT(F) F(base) F(harr) F(fillarr) F(i32arr) F(c32arr) F(f64arr) F(hash) F(sfns) F(fns) F(arith) F(md1) F(md2) F(derv) F(comp) F(rtWrap) F(ns) F(load)
|
||||||
#define F(X) void X##_init();
|
#define F(X) void X##_init();
|
||||||
FOR_INIT(F)
|
FOR_INIT(F)
|
||||||
#undef F
|
#undef F
|
||||||
|
|||||||
3
src/ns.c
3
src/ns.c
@ -103,6 +103,9 @@ void nsDesc_visit(Value* x) {
|
|||||||
void nsDesc_print(B x) {
|
void nsDesc_print(B x) {
|
||||||
printf("(namespace description)");
|
printf("(namespace description)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void ns_init() {
|
void ns_init() {
|
||||||
ti[t_ns].free = ns_free; ti[t_nsDesc].free = nsDesc_free;
|
ti[t_ns].free = ns_free; ti[t_nsDesc].free = nsDesc_free;
|
||||||
ti[t_ns].visit = ns_visit; ti[t_nsDesc].visit = nsDesc_visit;
|
ti[t_ns].visit = ns_visit; ti[t_nsDesc].visit = nsDesc_visit;
|
||||||
|
|||||||
16
src/vm.c
16
src/vm.c
@ -593,6 +593,15 @@ void allocStack(void** curr, void** start, void** end, i32 elSize, i32 count) {
|
|||||||
*end = ((char*)*start)+sz;
|
*end = ((char*)*start)+sz;
|
||||||
mprotect(*end, pageSize, PROT_NONE); // idk first way i found to force erroring on overflow
|
mprotect(*end, pageSize, PROT_NONE); // idk first way i found to force erroring on overflow
|
||||||
}
|
}
|
||||||
|
void print_vmStack() {
|
||||||
|
#ifdef DEBUG_VM
|
||||||
|
printf("vm stack:");
|
||||||
|
for (i32 i = 0; i < (bcDepth>>1) + 1; i++) { printf(" %d", vmStack[i]); fflush(stdout); }
|
||||||
|
printf("\n"); fflush(stdout);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void comp_init() {
|
void comp_init() {
|
||||||
ti[t_comp ].free = comp_free; ti[t_comp ].visit = comp_visit; ti[t_comp ].print = comp_print;
|
ti[t_comp ].free = comp_free; ti[t_comp ].visit = comp_visit; ti[t_comp ].print = comp_print;
|
||||||
@ -609,13 +618,6 @@ void comp_init() {
|
|||||||
allocStack((void**)&envCurr, (void**)&envStart, (void**)&envEnd, sizeof(Env), ENV_SIZE);
|
allocStack((void**)&envCurr, (void**)&envStart, (void**)&envEnd, sizeof(Env), ENV_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_vmStack() {
|
|
||||||
#ifdef DEBUG_VM
|
|
||||||
printf("vm stack:");
|
|
||||||
for (i32 i = 0; i < (bcDepth>>1) + 1; i++) { printf(" %d", vmStack[i]); fflush(stdout); }
|
|
||||||
printf("\n"); fflush(stdout);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user