native ⚇0

This commit is contained in:
dzaima 2023-01-27 22:59:22 +02:00
parent ac2a1c528d
commit 4a45a07a2b
2 changed files with 44 additions and 5 deletions

View File

@ -1,6 +1,8 @@
#include "../core.h"
#include "../utils/each.h"
#include "../utils/talloc.h"
#include "../utils/mut.h"
#include "../nfns.h"
#include "../builtins.h"
#include <math.h>
@ -482,11 +484,45 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g;
}
// TODO fills on EACH_FILLS
NFnDesc* depthfDesc;
B depthf_c1(B t, B x) {
if (isArr(x)) return eachm_fn(t, x, depthf_c1);
else return c1(nfn_objU(t), x);
}
B depthf_c2(B t, B w, B x) {
if (isArr(w) || isArr(x)) return eachd_fn(t, w, x, depthf_c2);
else return c2(nfn_objU(t), w, x);
}
extern B rt_depth;
B depth_c1(Md2D* d, B x) { SLOW3("!F⚇𝕨 𝕩", d->g, x, d->f); return m2c1(rt_depth, d->f, d->g, x); }
B depth_c2(Md2D* d, B w, B x) { SLOW3("!𝕨 𝔽⚇f 𝕩", w, x, d->g); return m2c2(rt_depth, d->f, d->g, w, x); }
B depth_c1(Md2D* d, B x) {
if (isF64(d->g) && o2fG(d->g)==0) {
if (isArr(x)) {
B f = m_nfn(depthfDesc, incG(d->f));
B r = eachm_fn(f, x, depthf_c1);
decG(f);
return r;
} else {
return c1(d->f, x);
}
}
SLOW3("!F⚇𝕨 𝕩", d->g, x, d->f);
return m2c1(rt_depth, d->f, d->g, x);
}
B depth_c2(Md2D* d, B w, B x) {
if (isF64(d->g) && o2fG(d->g)==0) {
if (isArr(w) || isArr(x)) {
B f = m_nfn(depthfDesc, incG(d->f));
B r = eachd_fn(f, w, x, depthf_c2);
decG(f);
return r;
} else {
return c2(d->f, w, x);
}
}
SLOW3("!𝕨 𝔽⚇f 𝕩", w, x, d->g);
return m2c2(rt_depth, d->f, d->g, w, x);
}
static void print_md2BI(FILE* f, B x) { fprintf(f, "%s", pm2_repr(c(Md1,x)->extra)); }
@ -502,3 +538,6 @@ void md2_init() {
TIi(t_md2BI,m2_ix) = md2BI_ix;
c(BMd2,bi_before)->uc1 = before_uc1;
}
void md2Post_init() {
depthfDesc = registerNFn(m_c8vec_0("(depth fn)"), depthf_c1, depthf_c2);
}

View File

@ -8,7 +8,7 @@
#define PRECOMPILED_FILE1(X) PRECOMPILED_FILE0(X)
#define PRECOMPILED_FILE(END) PRECOMPILED_FILE1(../build/BYTECODE_DIR/gen/END)
#define FOR_INIT(F) F(base) F(harr) F(mutF) F(cmpA) F(fillarr) F(tyarr) F(hash) F(sfns) F(fns) F(arith) F(md1) F(md2) F(derv) F(comp) F(rtWrap) F(ns) F(nfn) F(sysfn) F(inverse) F(slash) F(search) F(load) F(sysfnPost) F(dervPost) F(ryu) F(ffi) F(mmap) F(typesFinished)
#define FOR_INIT(F) F(base) F(harr) F(mutF) F(cmpA) F(fillarr) F(tyarr) F(hash) F(sfns) F(fns) F(arith) F(md1) F(md2) F(derv) F(comp) F(rtWrap) F(ns) F(nfn) F(sysfn) F(inverse) F(slash) F(search) F(load) F(sysfnPost) F(dervPost) F(md2Post) F(ryu) F(ffi) F(mmap) F(typesFinished)
#define F(X) NOINLINE void X##_init(void);
FOR_INIT(F)
#undef F