cache monadic •Import
This commit is contained in:
parent
0389eda29b
commit
d032c97b13
@ -309,9 +309,19 @@ B count_c2(B t, B w, B x) {
|
|||||||
return c2(rt_count, w, x);
|
return c2(rt_count, w, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
H_b2i* prevImports;
|
||||||
|
i32 prevImportIdx(B path, i32 pos) {
|
||||||
|
if (prevImports==NULL) prevImports = m_b2i(16);
|
||||||
|
return swap_b2i(&prevImports, path, pos, -1);
|
||||||
|
}
|
||||||
|
void fun_gcFn() {
|
||||||
|
if (prevImports!=NULL) mm_visitP(prevImports);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void fns_init() {
|
void fns_init() {
|
||||||
|
gc_addFn(fun_gcFn);
|
||||||
TIi(t_funBI,print) = print_funBI;
|
TIi(t_funBI,print) = print_funBI;
|
||||||
TIi(t_funBI,identity) = funBI_identity;
|
TIi(t_funBI,identity) = funBI_identity;
|
||||||
TIi(t_funBI,fn_uc1) = funBI_uc1;
|
TIi(t_funBI,fn_uc1) = funBI_uc1;
|
||||||
|
|||||||
@ -629,8 +629,35 @@ B flines_c2(B d, B w, B x) {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
static NFnDesc* importDesc;
|
static NFnDesc* importDesc;
|
||||||
B import_c1(B d, B x) { return bqn_execFile(path_rel(nfn_objU(d), x), emptySVec()); }
|
|
||||||
B import_c2(B d, B w, B x) { return bqn_execFile(path_rel(nfn_objU(d), x), w); }
|
|
||||||
|
|
||||||
|
B import_c2(B d, B w, B x) {
|
||||||
|
return bqn_execFile(path_rel(nfn_objU(d), x), w);
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 prevImportIdx(B path, i32 pos); // defined in fns.c
|
||||||
|
static B importKeyList;
|
||||||
|
static B importValList;
|
||||||
|
B import_c1(B d, B x) {
|
||||||
|
if (importKeyList.u==0) {
|
||||||
|
importKeyList = emptyHVec();
|
||||||
|
importValList = emptyHVec();
|
||||||
|
}
|
||||||
|
B path = path_abs(path_rel(nfn_objU(d), x));
|
||||||
|
i32 prevIdx = prevImportIdx(path, a(importKeyList)->ia);
|
||||||
|
if (prevIdx!=-1) { dec(path); return IGet(importValList, prevIdx); }
|
||||||
|
B r = bqn_execFile(inc(path), emptySVec());
|
||||||
|
importKeyList = vec_add(importKeyList, path);
|
||||||
|
importValList = vec_add(importValList, inc(r));
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
static void sys_gcFn() {
|
||||||
|
mm_visit(importKeyList);
|
||||||
|
mm_visit(importValList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static NFnDesc* listDesc;
|
static NFnDesc* listDesc;
|
||||||
B list_c1(B d, B x) {
|
B list_c1(B d, B x) {
|
||||||
return file_list(path_rel(nfn_objU(d), x));
|
return file_list(path_rel(nfn_objU(d), x));
|
||||||
@ -849,7 +876,7 @@ B sys_c1(B t, B x) {
|
|||||||
|
|
||||||
B cdPath;
|
B cdPath;
|
||||||
void sysfn_init() {
|
void sysfn_init() {
|
||||||
cdPath = m_str8(1, "."); gc_add(cdPath);
|
cdPath = m_str8(1, "."); gc_add(cdPath); gc_addFn(sys_gcFn);
|
||||||
fCharsDesc = registerNFn(m_str8l("(file).Chars"), fchars_c1, fchars_c2);
|
fCharsDesc = registerNFn(m_str8l("(file).Chars"), fchars_c1, fchars_c2);
|
||||||
fileAtDesc = registerNFn(m_str8l("(file).At"), fileAt_c1, fileAt_c2);
|
fileAtDesc = registerNFn(m_str8l("(file).At"), fileAt_c1, fileAt_c2);
|
||||||
fLinesDesc = registerNFn(m_str8l("(file).Lines"), flines_c1, flines_c2);
|
fLinesDesc = registerNFn(m_str8l("(file).Lines"), flines_c1, flines_c2);
|
||||||
|
|||||||
@ -525,6 +525,8 @@ void base_init() { // very first init function
|
|||||||
TIi(t_funBI,freeO) = TIi(t_md1BI,freeO) = TIi(t_md2BI,freeO) = builtin_free;
|
TIi(t_funBI,freeO) = TIi(t_md1BI,freeO) = TIi(t_md2BI,freeO) = builtin_free;
|
||||||
TIi(t_funBI,freeF) = TIi(t_md1BI,freeF) = TIi(t_md2BI,freeF) = builtin_free;
|
TIi(t_funBI,freeF) = TIi(t_md1BI,freeF) = TIi(t_md2BI,freeF) = builtin_free;
|
||||||
TIi(t_funBI,visit) = funBI_visit;
|
TIi(t_funBI,visit) = funBI_visit;
|
||||||
|
TIi(t_hashmap,visit) = noop_visit;
|
||||||
|
|
||||||
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) bi_##N = m_bfn(N##_c1, N##_c2, pf_##N);
|
#define FA(N,X) bi_##N = m_bfn(N##_c1, N##_c2, pf_##N);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user