all native builtins

This commit is contained in:
dzaima 2021-12-30 02:28:20 +02:00
parent b656c9aa44
commit 14d298231f
4 changed files with 40 additions and 16 deletions

View File

@ -18,13 +18,13 @@
/* arithm.c*/M(sin,"•math.Sin") M(cos,"•math.Cos") M(tan,"•math.Tan") M(asin,"•math.Asin") M(acos,"•math.Acos") M(atan,"•math.Atan") /* arithm.c*/M(sin,"•math.Sin") M(cos,"•math.Cos") M(tan,"•math.Tan") M(asin,"•math.Asin") M(acos,"•math.Acos") M(atan,"•math.Atan")
#define FOR_PM1(A,M,D) \ #define FOR_PM1(A,M,D) \
/*md1.c*/A(tbl,"") A(each,"¨") A(fold,"´") A(scan,"`") A(const,"˙") A(swap,"˜") A(cell,"˘") \ /*md1.c*/A(tbl,"") A(each,"¨") A(fold,"´") A(scan,"`") A(const,"˙") A(swap,"˜") A(cell,"˘") A(insert,"˝") \
/*inverse.c*/A(undo,"") \ /*inverse.c*/A(undo,"") \
/* everything before the definition of •_timed is defined to be pure, and everything after is not */ \ /* everything before the definition of •_timed is defined to be pure, and everything after is not */ \
/*md1.c*/A(timed,"•_timed") /*md1.c*/A(timed,"•_timed")
#define FOR_PM2(A,M,D) \ #define FOR_PM2(A,M,D) \
/*md2.c*/A(val,"") A(repeat,"") A(rank,"") A(fillBy,"•_fillBy_") A(catch,"") \ /*md2.c*/A(val,"") A(repeat,"") A(rank,"") A(depth,"") A(fillBy,"•_fillBy_") A(catch,"") \
/*md2.c*/A(atop,"") A(over,"") A(before,"") A(after,"") A(cond,"") A(under,"") \ /*md2.c*/A(atop,"") A(over,"") A(before,"") A(after,"") A(cond,"") A(under,"") \
/* everything before the definition of •_while_ is defined to be pure, and everything after is not */ \ /* everything before the definition of •_while_ is defined to be pure, and everything after is not */ \
/*md2.c*/A(while,"•_while_") /*md2.c*/A(while,"•_while_")
@ -35,8 +35,8 @@ enum PrimNumbers {
/* ⊣⊢⥊∾≍⋈↑↓↕« */ n_ltack , n_rtack , n_shape , n_join , n_couple , n_pair , n_take , n_drop , n_ud , n_shifta, /* ⊣⊢⥊∾≍⋈↑↓↕« */ n_ltack , n_rtack , n_shape , n_join , n_couple , n_pair , n_take , n_drop , n_ud , n_shifta,
/* »⌽⍉/⍋⍒⊏⊑⊐⊒ */ n_shiftb , n_reverse, n_transp, n_slash, n_gradeUp, n_gradeDown, n_select, n_pick , n_indexOf, n_count, /* »⌽⍉/⍋⍒⊏⊑⊐⊒ */ n_shiftb , n_reverse, n_transp, n_slash, n_gradeUp, n_gradeDown, n_select, n_pick , n_indexOf, n_count,
/* ∊⍷⊔!˙˜˘¨⌜⁼ */ n_memberOf, n_find , n_group , n_asrt , n_const , n_swap , n_cell , n_each , n_tbl , n_undo, /* ∊⍷⊔!˙˜˘¨⌜⁼ */ n_memberOf, n_find , n_group , n_asrt , n_const , n_swap , n_cell , n_each , n_tbl , n_undo,
/* ´˝`∘○⊸⟜⌾⊘◶ */ n_fold , n_reduce , n_scan , n_atop , n_over , n_before , n_after , n_under, n_val , n_cond, /* ´˝`∘○⊸⟜⌾⊘◶ */ n_fold , n_insert , n_scan , n_atop , n_over , n_before , n_after , n_under, n_val , n_cond,
/* ⎉⚇⍟⎊ */ n_rank , n_depth2 , n_repeat, n_catch /* ⎉⚇⍟⎊ */ n_rank , n_depth , n_repeat, n_catch
}; };
extern B rt_invFnReg, rt_invFnSwap; extern B rt_invFnReg, rt_invFnSwap;
extern BB2B rt_invFnRegFn; extern BB2B rt_invFnRegFn;

View File

@ -340,6 +340,20 @@ B timed_c1(Md1D* d, B x) { B f = d->f;
} }
static B m1c1(B t, B f, B x) { // consumes x
B fn = m1_d(inc(t), inc(f));
B r = c1(fn, x);
dec(fn);
return r;
}
static B m1c2(B t, B f, B w, B x) { // consumes w,x
B fn = m1_d(inc(t), inc(f));
B r = c2(fn, w, x);
dec(fn);
return r;
}
extern B rt_cell; extern B rt_cell;
B cell_c1(Md1D* d, B x) { B f = d->f; B cell_c1(Md1D* d, B x) { B f = d->f;
if (isAtm(x) || rnk(x)==0) { if (isAtm(x) || rnk(x)==0) {
@ -372,12 +386,12 @@ B cell_c2(Md1D* d, B w, B x) { B f = d->f;
B r = c2(f, w, x); B r = c2(f, w, x);
return isAtm(r)? m_atomUnit(r) : r; return isAtm(r)? m_atomUnit(r) : r;
} }
B fn = m1_d(inc(rt_cell), inc(f)); // TODO return m1c2(rt_cell, f, w, x);
B r = c2(fn, w, x);
dec(fn);
return r;
} }
extern B rt_insert;
B insert_c1(Md1D* d, B x) { return m1c1(rt_insert, d->f, x); }
B insert_c2(Md1D* d, B w, B x) { return m1c2(rt_insert, d->f, w, x); }
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)); }

View File

@ -177,13 +177,13 @@ B while_c2(Md2D* d, B w, B x) { B f=d->f; B g=d->g;
return x; return x;
} }
B m1c(B t, B f, B g, B x) { // consumes x static B m2c1(B t, B f, B g, B x) { // consumes x
B fn = m2_d(inc(t), inc(f), inc(g)); B fn = m2_d(inc(t), inc(f), inc(g));
B r = c1(fn, x); B r = c1(fn, x);
dec(fn); dec(fn);
return r; return r;
} }
B m2c(B t, B f, B g, B w, B x) { // consumes w,x static B m2c2(B t, B f, B g, B w, B x) { // consumes w,x
B fn = m2_d(inc(t), inc(f), inc(g)); B fn = m2_d(inc(t), inc(f), inc(g));
B r = c2(fn, w, x); B r = c2(fn, w, x);
dec(fn); dec(fn);
@ -249,9 +249,17 @@ B rank_c1(Md2D* d, B x) { B f = d->f; B g = d->g;
} }
extern B rt_rank; extern B rt_rank;
B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g; // TODO B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g; // TODO
return m2c(rt_rank, f, g, w, x); return m2c2(rt_rank, f, g, w, x);
} }
extern B rt_depth;
B depth_c1(Md2D* d, B x) { return m2c1(rt_depth, d->f, d->g, x); }
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)); }
void md2_init() { void md2_init() {
TIi(t_md2BI,print) = print_md2BI; TIi(t_md2BI,print) = print_md2BI;

View File

@ -102,7 +102,7 @@ B comp_currArgs;
B comp_currSrc; B comp_currSrc;
B comp_currRe; B comp_currRe;
B rt_merge, rt_undo, rt_select, rt_slash, rt_join, rt_ud, rt_pick,rt_take, rt_drop, B rt_merge, rt_undo, rt_select, rt_slash, rt_join, rt_ud, rt_pick, rt_take, rt_drop, rt_insert, rt_depth,
rt_group, rt_under, rt_reverse, rt_indexOf, rt_count, rt_memberOf, rt_find, rt_cell, rt_rank, rt_transp; rt_group, rt_under, rt_reverse, rt_indexOf, rt_count, rt_memberOf, rt_find, rt_cell, rt_rank, rt_transp;
Block* load_compObj(B x, B src, B path, Scope* sc) { // consumes x,src Block* load_compObj(B x, B src, B path, Scope* sc) { // consumes x,src
SGet(x) SGet(x)
@ -322,8 +322,8 @@ void load_init() { // very last init function
/* ⊣⊢⥊∾≍⋈↑↓↕« */ bi_ltack , bi_rtack , bi_shape , bi_join , bi_couple , bi_pair , bi_take , bi_drop , bi_ud , bi_shifta, /* ⊣⊢⥊∾≍⋈↑↓↕« */ bi_ltack , bi_rtack , bi_shape , bi_join , bi_couple , bi_pair , bi_take , bi_drop , bi_ud , bi_shifta,
/* »⌽⍉/⍋⍒⊏⊑⊐⊒ */ bi_shiftb , bi_reverse, bi_transp, bi_slash, bi_gradeUp, bi_gradeDown, bi_select, bi_pick , bi_indexOf, bi_count, /* »⌽⍉/⍋⍒⊏⊑⊐⊒ */ bi_shiftb , bi_reverse, bi_transp, bi_slash, bi_gradeUp, bi_gradeDown, bi_select, bi_pick , bi_indexOf, bi_count,
/* ∊⍷⊔!˙˜˘¨⌜⁼ */ bi_memberOf, bi_find , bi_group , bi_asrt , bi_const , bi_swap , bi_cell , bi_each , bi_tbl , bi_undo, /* ∊⍷⊔!˙˜˘¨⌜⁼ */ bi_memberOf, bi_find , bi_group , bi_asrt , bi_const , bi_swap , bi_cell , bi_each , bi_tbl , bi_undo,
/* ´˝`∘○⊸⟜⌾⊘◶ */ bi_fold , bi_N , bi_scan , bi_atop , bi_over , bi_before , bi_after , bi_under, bi_val , bi_cond, /* ´˝`∘○⊸⟜⌾⊘◶ */ bi_fold , bi_insert , bi_scan , bi_atop , bi_over , bi_before , bi_after , bi_under, bi_val , bi_cond,
/* ⎉⚇⍟⎊ */ bi_rank , bi_N , bi_repeat, bi_catch /* ⎉⚇⍟⎊ */ bi_rank , bi_depth , bi_repeat, bi_catch
}; };
bool rtComplete[] = { bool rtComplete[] = {
@ -332,8 +332,8 @@ void load_init() { // very last init function
/* ⊣⊢⥊∾≍⋈↑↓↕« */ 1,1,1,1,1,1,1,1,1,1, /* ⊣⊢⥊∾≍⋈↑↓↕« */ 1,1,1,1,1,1,1,1,1,1,
/* »⌽⍉/⍋⍒⊏⊑⊐⊒ */ 1,1,1,1,1,1,1,1,1,1, /* »⌽⍉/⍋⍒⊏⊑⊐⊒ */ 1,1,1,1,1,1,1,1,1,1,
/* ∊⍷⊔!˙˜˘¨⌜⁼ */ 1,1,1,1,1,1,1,1,1,1, /* ∊⍷⊔!˙˜˘¨⌜⁼ */ 1,1,1,1,1,1,1,1,1,1,
/* ´˝`∘○⊸⟜⌾⊘◶ */ 1,0,1,1,1,1,1,1,1,1, /* ´˝`∘○⊸⟜⌾⊘◶ */ 1,1,1,1,1,1,1,1,1,1,
/* ⎉⚇⍟⎊ */ 1,0,1,1 /* ⎉⚇⍟⎊ */ 1,1,1,1
}; };
assert(sizeof(fruntime)/sizeof(B) == rtLen); assert(sizeof(fruntime)/sizeof(B) == rtLen);
for (u64 i = 0; i < rtLen; i++) inc(fruntime[i]); for (u64 i = 0; i < rtLen; i++) inc(fruntime[i]);
@ -392,6 +392,8 @@ void load_init() { // very last init function
rt_cell = Get(rtObjRaw, n_cell ); gc_add(rt_cell); rt_cell = Get(rtObjRaw, n_cell ); gc_add(rt_cell);
rt_rank = Get(rtObjRaw, n_rank ); gc_add(rt_rank); rt_rank = Get(rtObjRaw, n_rank ); gc_add(rt_rank);
rt_transp = Get(rtObjRaw, n_transp ); gc_add(rt_transp); rt_transp = Get(rtObjRaw, n_transp ); gc_add(rt_transp);
rt_depth = Get(rtObjRaw, n_depth ); gc_add(rt_depth);
rt_insert = Get(rtObjRaw, n_insert ); gc_add(rt_insert);
for (usz i = 0; i < rtLen; i++) { for (usz i = 0; i < rtLen; i++) {
#ifdef RT_WRAP #ifdef RT_WRAP