separate path & name, store path+name+args in state
This commit is contained in:
parent
fe280613af
commit
01a60dceff
@ -276,28 +276,25 @@ NOINLINE B vfyStr(B x, char* name, char* arg) {
|
||||
}
|
||||
|
||||
B cdPath;
|
||||
static NOINLINE B args_path(B* fullpath, B w, char* name) { // consumes w, returns args, writes to fullpath
|
||||
static NOINLINE B prep_state(B w, char* name) { // consumes w, returns ⟨path,name,args⟩
|
||||
if (!isArr(w) || RNK(w)!=1 || IA(w)>3) thrF("%U: 𝕨 must be a vector with at most 3 items, but had shape %H", name, w);
|
||||
usz ia = IA(w);
|
||||
SGet(w)
|
||||
B path = ia>0? vfyStr(Get(w,0),name,"Path" ) : inc(cdPath);
|
||||
B file = ia>1? vfyStr(Get(w,1),name,"Filename") : emptyCVec();
|
||||
B args = ia>2? Get(w,2) : emptySVec();
|
||||
*fullpath = vec_join(vec_addN(path, m_c32('/')), file);
|
||||
usz ia = IA(w); SGet(w)
|
||||
HArr_p r = m_harr0v(3);
|
||||
r.a[0] = ia>0? vfyStr(Get(w,0),name,"Path" ) : inc(cdPath);
|
||||
r.a[1] = ia>1? vfyStr(Get(w,1),name,"Filename") : emptyCVec();
|
||||
r.a[2] = ia>2? Get(w,2) : emptySVec();
|
||||
decG(w);
|
||||
return args;
|
||||
return r.b;
|
||||
}
|
||||
|
||||
B bqn_c1(B t, B x) {
|
||||
vfyStr(x, "•BQN", "𝕩");
|
||||
return rebqn_exec(x, bi_N, bi_N, nfn_objU(t));
|
||||
return rebqn_exec(x, bi_N, nfn_objU(t));
|
||||
}
|
||||
|
||||
B bqn_c2(B t, B w, B x) {
|
||||
vfyStr(x, "•BQN", "𝕩");
|
||||
B fullpath;
|
||||
B args = args_path(&fullpath, w, "•BQN");
|
||||
return rebqn_exec(x, fullpath, args, nfn_objU(t));
|
||||
return rebqn_exec(x, prep_state(w, "•BQN"), nfn_objU(t));
|
||||
}
|
||||
|
||||
B cmp_c2(B t, B w, B x) {
|
||||
@ -674,15 +671,15 @@ B rebqn_c1(B t, B x) {
|
||||
B sys = ns_getC(x, "system");
|
||||
i32 replVal = q_N(repl) || eqStr(repl,U"none")? 0 : eqStr(repl,U"strict")? 1 : eqStr(repl,U"loose")? 2 : 3;
|
||||
if (replVal==3) thrM("•ReBQN: Invalid repl value");
|
||||
Block* initBlock = bqn_comp(m_c8vec_0("\"(REPL initializer)\""), inc(cdPath), m_f64(0));
|
||||
B scVal;
|
||||
if (replVal==0) {
|
||||
scVal = bi_N;
|
||||
} else {
|
||||
Block* initBlock = bqn_comp(m_c8vec_0("\"(REPL initializer)\""), bi_N);
|
||||
Scope* sc = m_scope(initBlock->bodies[0], NULL, 0, 0, NULL);
|
||||
scVal = tag(sc,OBJ_TAG);
|
||||
ptr_dec(initBlock);
|
||||
}
|
||||
ptr_dec(initBlock);
|
||||
HArr_p d = m_harr0v(re_max);
|
||||
d.a[re_mode] = m_i32(replVal);
|
||||
d.a[re_scope] = scVal;
|
||||
@ -692,9 +689,7 @@ B rebqn_c1(B t, B x) {
|
||||
}
|
||||
B repl_c2(B t, B w, B x) {
|
||||
vfyStr(x, "REPL", "𝕩");
|
||||
B fullpath;
|
||||
B args = args_path(&fullpath, w, "REPL");
|
||||
return repl_exec(x, fullpath, args, nfn_objU(t));
|
||||
return repl_exec(x, prep_state(w, "REPL"), nfn_objU(t));
|
||||
}
|
||||
B repl_c1(B t, B x) {
|
||||
return repl_c2(t, emptyHVec(), x);
|
||||
@ -1763,16 +1758,16 @@ B sys_c1(B t, B x) {
|
||||
B idxs = C2(indexOf, incG(curr_ns), incG(x)); SGetU(idxs)
|
||||
|
||||
B path0 = COMPS_CREF(path);
|
||||
B name = COMPS_CREF(name);
|
||||
B args = COMPS_CREF(args);
|
||||
|
||||
#define CACHED(F) F(fileNS)F(path)F(name)F(wdpath)F(bqn)F(rebqn)
|
||||
#define CACHED(F) F(fileNS)F(path)F(wdpath)F(bqn)F(rebqn)
|
||||
#define F(X) B X = m_f64(0);
|
||||
CACHED(F)
|
||||
#undef F
|
||||
|
||||
#define CACHE_OBJ(NAME, COMP) ({ if (!NAME.u) NAME = (COMP); NAME; })
|
||||
#define REQ_PATH CACHE_OBJ(path, q_N(path0)? bi_N : path_abs(path_parent(inc(path0))))
|
||||
#define REQ_NAME CACHE_OBJ(name, path_name(inc(path0)))
|
||||
#define REQ_PATH CACHE_OBJ(path, q_N(path0)? bi_N : path_abs(incG(path0)))
|
||||
|
||||
M_HARR(r, IA(x))
|
||||
for (usz i = 0; i < IA(x); i++) {
|
||||
@ -1794,7 +1789,7 @@ B sys_c1(B t, B x) {
|
||||
case 8: initFileNS(); cr = m_nfn(fLinesDesc, inc(REQ_PATH)); break; // •FLines
|
||||
case 9: initFileNS(); cr = m_nfn(importDesc, inc(REQ_PATH)); break; // •Import
|
||||
case 10: initFileNS(); cr = m_nfn(ffiloadDesc, inc(REQ_PATH)); break; // •FFI
|
||||
case 11: if (q_N(path0)) thrM("No path present for •name"); cr = inc(REQ_NAME); break; // •name
|
||||
case 11: if (q_N(name)) thrM("No name present for •name"); cr = inc(name); break; // •name
|
||||
case 12: if (q_N(path0)) thrM("No path present for •path"); cr = inc(REQ_PATH); break; // •path
|
||||
case 13: { cr = inc(CACHE_OBJ(wdpath, path_abs(inc(cdPath)))); break; } // •wdpath
|
||||
case 14: { // •file
|
||||
@ -1809,8 +1804,9 @@ B sys_c1(B t, B x) {
|
||||
}
|
||||
case 15: { // •state
|
||||
if (q_N(args)) thrM("No arguments present for •state");
|
||||
if (q_N(name)) thrM("No name present for •state");
|
||||
if (q_N(path0)) thrM("No path present for •state");
|
||||
cr = m_hvec3(inc(REQ_PATH), inc(REQ_NAME), inc(args));
|
||||
cr = m_hvec3(inc(REQ_PATH), inc(name), inc(args));
|
||||
break;
|
||||
}
|
||||
case 16: { // •args
|
||||
|
||||
@ -66,10 +66,10 @@ BQN_EXP BQNV bqn_call2(BQNV f, BQNV w, BQNV x) {
|
||||
}
|
||||
|
||||
BQN_EXP BQNV bqn_eval(BQNV src) {
|
||||
return makeX(bqn_exec(inc(getB(src)), bi_N, bi_N));
|
||||
return makeX(bqn_exec(inc(getB(src)), bi_N));
|
||||
}
|
||||
BQN_EXP BQNV bqn_evalCStr(const char* str) {
|
||||
return makeX(bqn_exec(utf8Decode0(str), bi_N, bi_N));
|
||||
return makeX(bqn_exec(utf8Decode0(str), bi_N));
|
||||
}
|
||||
|
||||
|
||||
|
||||
3
src/h.h
3
src/h.h
@ -376,9 +376,8 @@ B withFill(B x, B f); // consumes both
|
||||
|
||||
void cbqn_init(void);
|
||||
NORETURN void bqn_exit(i32 code);
|
||||
B bqn_exec(B str, B path, B args); // consumes all
|
||||
B bqn_exec(B str, B state); // consumes all
|
||||
B bqn_execFile(B path, B args); // consumes
|
||||
B bqn_explain(B str, B path); // consumes str
|
||||
B bqn_fmt(B x); // consumes
|
||||
B bqn_repr(B x); // consumes
|
||||
|
||||
|
||||
101
src/load.c
101
src/load.c
@ -102,6 +102,17 @@ B r1Objs[RT_LEN];
|
||||
B rtWrap_wrap(B x, bool nnbi); // consumes
|
||||
void rtWrap_print(void);
|
||||
|
||||
static NOINLINE B m_lvB_0( ) { return emptyHVec(); }
|
||||
static NOINLINE B m_lvB_1(B a ) { return m_hvec1(a); }
|
||||
static NOINLINE B m_lvB_2(B a, B b ) { return m_hvec2(a,b); }
|
||||
static NOINLINE B m_lvB_3(B a, B b, B c ) { return m_hvec3(a,b,c); }
|
||||
static NOINLINE B m_lvB_4(B a, B b, B c, B d) { return m_hvec4(a,b,c,d); }
|
||||
static NOINLINE B m_lvi32_0( ) { return emptyIVec(); }
|
||||
static NOINLINE B m_lvi32_1(i32 a ) { i32* rp; B r = m_i32arrv(&rp,1); rp[0]=a; return r; }
|
||||
static NOINLINE B m_lvi32_2(i32 a, i32 b ) { i32* rp; B r = m_i32arrv(&rp,2); rp[0]=a; rp[1]=b; return r; }
|
||||
static NOINLINE B m_lvi32_3(i32 a, i32 b, i32 c ) { i32* rp; B r = m_i32arrv(&rp,3); rp[0]=a; rp[1]=b; rp[2]=c; return r; }
|
||||
static NOINLINE B m_lvi32_4(i32 a, i32 b, i32 c, i32 d) { i32* rp; B r = m_i32arrv(&rp,4); rp[0]=a; rp[1]=b; rp[2]=c; rp[3]=d; return r; }
|
||||
|
||||
static NOINLINE B evalFunBlockConsume(Block* block) {
|
||||
B r = evalFunBlock(block, NULL);
|
||||
ptr_dec(block);
|
||||
@ -175,39 +186,44 @@ B bqn_fmt(B x) { return x; }
|
||||
B bqn_repr(B x) { return x; }
|
||||
#endif
|
||||
|
||||
NOINLINE HArr* m_comps(B path, B args, B src, B re, i64 envPos) {
|
||||
assert(!q_N(re));
|
||||
static NOINLINE void comps_push(B src, B state, B re) {
|
||||
assert(comps_curr == NULL);
|
||||
HArr* r = m_harr0v(comps_max).c;
|
||||
COMPS_REF(r, path) = inc(path);
|
||||
COMPS_REF(r, args) = inc(args);
|
||||
if (q_N(state)) {
|
||||
COMPS_REF(r,path) = COMPS_REF(r,name) = COMPS_REF(r,args) = bi_N;
|
||||
} else {
|
||||
SGet(state)
|
||||
COMPS_REF(r, path) = Get(state,0);
|
||||
COMPS_REF(r, name) = Get(state,1);
|
||||
COMPS_REF(r, args) = Get(state,2);
|
||||
decG(state);
|
||||
}
|
||||
COMPS_REF(r, src) = inc(src);
|
||||
COMPS_REF(r, re) = inc(re);
|
||||
COMPS_REF(r, envPos) = m_f64(envPos);
|
||||
return r;
|
||||
COMPS_REF(r, envPos) = m_f64(envCurr-envStart);
|
||||
comps_curr = r;
|
||||
}
|
||||
|
||||
#define COMPS_PUSH(PATH, ARGS, STR, RE) \
|
||||
assert(comps_curr == NULL); \
|
||||
HArr* compsN = comps_curr = m_comps(PATH, ARGS, STR, RE, envCurr-envStart); \
|
||||
#define COMPS_PUSH(STR, STATE, RE) \
|
||||
comps_push(STR, STATE, RE); \
|
||||
if (CATCH) { COMPS_POP; rethrow(); }
|
||||
|
||||
#define COMPS_POP ({ assert(comps_curr==compsN); ptr_dec(comps_curr); comps_curr = NULL; })
|
||||
#define COMPS_POP ({ ptr_dec(comps_curr); comps_curr = NULL; })
|
||||
|
||||
static NOINLINE Block* bqn_compc(B str, B path, B args, B re) { // consumes str,path,args
|
||||
static NOINLINE Block* bqn_compc(B str, B state, B re) { // consumes str,state
|
||||
str = chr_squeeze(str);
|
||||
COMPS_PUSH(path, args, str, re);
|
||||
COMPS_PUSH(str, state, re);
|
||||
B* o = harr_ptr(re);
|
||||
Block* r = load_buildBlock(c2G(o[re_comp], incG(o[re_compOpts]), inc(str)), str, path, NULL, 0);
|
||||
dec(path); dec(args);
|
||||
Block* r = load_buildBlock(c2G(o[re_comp], incG(o[re_compOpts]), inc(str)), str, COMPS_CREF(path), NULL, 0);
|
||||
COMPS_POP; popCatch();
|
||||
return r;
|
||||
}
|
||||
Block* bqn_comp(B str, B path, B args) {
|
||||
return bqn_compc(str, path, args, def_re);
|
||||
Block* bqn_comp(B str, B state) {
|
||||
return bqn_compc(str, state, def_re);
|
||||
}
|
||||
Block* bqn_compScc(B str, B path, B args, B re, Scope* sc, bool loose, bool noNS) {
|
||||
Block* bqn_compScc(B str, B state, B re, Scope* sc, bool loose, bool noNS) {
|
||||
str = chr_squeeze(str);
|
||||
COMPS_PUSH(path, args, str, re);
|
||||
COMPS_PUSH(str, state, re);
|
||||
B* o = harr_ptr(re);
|
||||
B vName = emptyHVec();
|
||||
B vDepth = emptyIVec();
|
||||
@ -222,17 +238,16 @@ Block* bqn_compScc(B str, B path, B args, B re, Scope* sc, bool loose, bool noNS
|
||||
csc = csc->psc;
|
||||
depth++;
|
||||
}
|
||||
Block* r = load_buildBlock(c2G(o[re_comp], m_hvec4(incG(o[re_rt]), incG(bi_sys), vName, vDepth), inc(str)), str, path, sc, sc!=NULL? (noNS? -1 : 1) : 0);
|
||||
dec(path); dec(args);
|
||||
Block* r = load_buildBlock(c2G(o[re_comp], m_lvB_4(incG(o[re_rt]), incG(bi_sys), vName, vDepth), inc(str)), str, COMPS_CREF(path), sc, sc!=NULL? (noNS? -1 : 1) : 0);
|
||||
COMPS_POP; popCatch();
|
||||
return r;
|
||||
}
|
||||
NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // consumes str,path,args
|
||||
return bqn_compScc(str, path, args, def_re, sc, repl, false);
|
||||
NOINLINE Block* bqn_compSc(B str, B state, Scope* sc, bool repl) {
|
||||
return bqn_compScc(str, state, def_re, sc, repl, false);
|
||||
}
|
||||
|
||||
B bqn_exec(B str, B path, B args) { // consumes all
|
||||
return evalFunBlockConsume(bqn_comp(str, path, args));
|
||||
B bqn_exec(B str, B state) { // consumes all
|
||||
return evalFunBlockConsume(bqn_comp(str, state));
|
||||
}
|
||||
|
||||
B str_all, str_none;
|
||||
@ -280,7 +295,7 @@ void init_comp(B* new_re, B* prev_re, B prim, B sys) {
|
||||
new_re[re_rt] = prh.b;
|
||||
new_re[re_glyphs] = inc(rb);
|
||||
new_re[re_comp] = c1(load_compgen, rb);
|
||||
new_re[re_compOpts] = m_hvec2(inc(prh.b), incG(bi_sys));
|
||||
new_re[re_compOpts] = m_lvB_2(inc(prh.b), incG(bi_sys));
|
||||
}
|
||||
|
||||
if (q_N(sys)) {
|
||||
@ -354,7 +369,7 @@ B comps_getPrimitives(void) {
|
||||
usz l = IA(gg[gi]);
|
||||
u32* gp = c32arr_ptr(gg[gi]);
|
||||
for (usz i = 0; i < l; i++) {
|
||||
HARR_ADDA(ph, m_hvec2(m_c32(gp[i]), inc(pr[i])));
|
||||
HARR_ADDA(ph, m_lvB_2(m_c32(gp[i]), inc(pr[i])));
|
||||
}
|
||||
pr+= l;
|
||||
}
|
||||
@ -367,35 +382,25 @@ void comps_getSysvals(B* res) {
|
||||
res[1] = o[re_sysVals];
|
||||
}
|
||||
|
||||
B rebqn_exec(B str, B path, B args, B re) {
|
||||
return evalFunBlockConsume(bqn_compc(str, path, args, re));
|
||||
B rebqn_exec(B str, B state, B re) {
|
||||
return evalFunBlockConsume(bqn_compc(str, state, re));
|
||||
}
|
||||
B repl_exec(B str, B path, B args, B re) {
|
||||
B repl_exec(B str, B state, B re) {
|
||||
B* op = harr_ptr(re);
|
||||
i32 replMode = o2iG(op[re_mode]);
|
||||
if (replMode>0) {
|
||||
Scope* sc = c(Scope, op[re_scope]);
|
||||
Block* block = bqn_compScc(str, path, args, re, sc, replMode==2, true);
|
||||
Block* block = bqn_compScc(str, state, re, sc, replMode==2, true);
|
||||
ptr_dec(sc->body);
|
||||
sc->body = ptr_inc(block->bodies[0]);
|
||||
B res = execBlockInplace(block, sc);
|
||||
ptr_dec(block);
|
||||
return res;
|
||||
} else {
|
||||
return rebqn_exec(str, path, args, re);
|
||||
return rebqn_exec(str, state, re);
|
||||
}
|
||||
}
|
||||
|
||||
static NOINLINE B m_lvB_0( ) { return emptyHVec(); }
|
||||
static NOINLINE B m_lvB_1(B a ) { return m_hvec1(a); }
|
||||
static NOINLINE B m_lvB_2(B a, B b ) { return m_hvec2(a,b); }
|
||||
static NOINLINE B m_lvB_3(B a, B b, B c ) { return m_hvec3(a,b,c); }
|
||||
static NOINLINE B m_lvB_4(B a, B b, B c, B d) { return m_hvec4(a,b,c,d); }
|
||||
static NOINLINE B m_lvi32_0( ) { return emptyIVec(); }
|
||||
static NOINLINE B m_lvi32_1(i32 a ) { i32* rp; B r = m_i32arrv(&rp,1); rp[0]=a; return r; }
|
||||
static NOINLINE B m_lvi32_2(i32 a, i32 b ) { i32* rp; B r = m_i32arrv(&rp,2); rp[0]=a; rp[1]=b; return r; }
|
||||
static NOINLINE B m_lvi32_3(i32 a, i32 b, i32 c ) { i32* rp; B r = m_i32arrv(&rp,3); rp[0]=a; rp[1]=b; rp[2]=c; return r; }
|
||||
static NOINLINE B m_lvi32_4(i32 a, i32 b, i32 c, i32 d) { i32* rp; B r = m_i32arrv(&rp,4); rp[0]=a; rp[1]=b; rp[2]=c; rp[3]=d; return r; }
|
||||
B invalidFn_c1(B t, B x);
|
||||
|
||||
void comps_gcFn() {
|
||||
@ -466,7 +471,7 @@ void load_init() { // very last init function
|
||||
B setPrims = Get(rtRes,1);
|
||||
B setInv = Get(rtRes,2);
|
||||
dec(rtRes);
|
||||
dec(c1G(setPrims, m_hvec2(incG(bi_decp), incG(bi_primInd)))); decG(setPrims);
|
||||
dec(c1G(setPrims, m_lvB_2(incG(bi_decp), incG(bi_primInd)))); decG(setPrims);
|
||||
dec(c2G(setInv, incG(bi_setInvSwap), incG(bi_setInvReg))); decG(setInv);
|
||||
|
||||
|
||||
@ -530,7 +535,7 @@ void load_init() { // very last init function
|
||||
rt_invFnRegFn = rt_invFnSwapFn = invalidFn_c1;
|
||||
rt_invFnReg = rt_invFnSwap = incByG(bi_invalidFn, 2);
|
||||
#endif
|
||||
load_compOpts = m_hvec2(load_rt, incG(bi_sys));
|
||||
load_compOpts = m_lvB_2(load_rt, incG(bi_sys));
|
||||
|
||||
|
||||
#ifdef PRECOMP
|
||||
@ -548,7 +553,7 @@ void load_init() { // very last init function
|
||||
#endif
|
||||
bqn_exit(0);
|
||||
#else // use compiler
|
||||
B load_glyphs = m_hvec3(m_c32vec_0(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!"), m_c32vec_0(U"˙˜˘¨⌜⁼´˝`"), m_c32vec_0(U"∘○⊸⟜⌾⊘◶⎉⚇⍟⎊"));
|
||||
B load_glyphs = m_lvB_3(m_c32vec_0(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!"), m_c32vec_0(U"˙˜˘¨⌜⁼´˝`"), m_c32vec_0(U"∘○⊸⟜⌾⊘◶⎉⚇⍟⎊"));
|
||||
|
||||
B load_comp;
|
||||
#if ONLY_NATIVE_COMP
|
||||
@ -591,8 +596,10 @@ void load_init() { // very last init function
|
||||
#endif // PRECOMP
|
||||
}
|
||||
|
||||
NOINLINE B m_state(B path, B name, B args) { return m_lvB_3(path, name, args); }
|
||||
B bqn_execFile(B path, B args) { // consumes both
|
||||
return bqn_exec(path_chars(inc(path)), path, args);
|
||||
B state = m_state(path_parent(inc(path)), path_name(inc(path)), args);
|
||||
return bqn_exec(path_chars(path), state);
|
||||
}
|
||||
|
||||
void before_exit(void);
|
||||
@ -607,7 +614,7 @@ void bqn_exit(i32 code) {
|
||||
}
|
||||
|
||||
static B load_explain;
|
||||
B bqn_explain(B str, B path) {
|
||||
B bqn_explain(B str) {
|
||||
#if NO_EXPLAIN
|
||||
thrM("Explainer not included in this CBQN build");
|
||||
#else
|
||||
@ -620,7 +627,7 @@ B bqn_explain(B str, B path) {
|
||||
gc_add(load_explain = evalFunBlockConsume(expl_b));
|
||||
}
|
||||
|
||||
COMPS_PUSH(path, bi_N, str, def_re);
|
||||
COMPS_PUSH(str, bi_N, def_re);
|
||||
B c = c2(o[re_comp], incG(o[re_compOpts]), inc(str));
|
||||
COMPS_POP;
|
||||
B ret = c2(load_explain, c, str);
|
||||
|
||||
11
src/load.h
11
src/load.h
@ -2,6 +2,7 @@
|
||||
extern HArr* comps_curr; // global-ish state, valid during compilation; comps_max elements
|
||||
enum {
|
||||
comps_path,
|
||||
comps_name,
|
||||
comps_args,
|
||||
comps_src,
|
||||
comps_re, // HArr of re_* values (re_mode & re_scope have unspecified values)
|
||||
@ -22,9 +23,9 @@ void comps_getSysvals(B* res);
|
||||
|
||||
typedef struct Block Block;
|
||||
typedef struct Scope Scope;
|
||||
Block* bqn_comp(B str, B path, B args); // consumes all
|
||||
Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl); // consumes str,path,args
|
||||
Block* bqn_compScc(B str, B path, B args, B re, Scope* sc, bool loose, bool noNS); // consumes str,path,args
|
||||
B rebqn_exec(B str, B path, B args, B re); // consumes str,path,args; runs in a new environment
|
||||
B repl_exec(B str, B path, B args, B re); // consumes str,path,args; uses re_mode and re_scope
|
||||
Block* bqn_comp (B str, B state); // consumes all
|
||||
Block* bqn_compSc (B str, B state, Scope* sc, bool repl); // consumes str,state
|
||||
Block* bqn_compScc(B str, B state, B re, Scope* sc, bool loose, bool noNS); // consumes str,state
|
||||
B rebqn_exec (B str, B state, B re); // consumes str,state; runs in a new environment
|
||||
B repl_exec (B str, B state, B re); // consumes str,state; uses re_mode and re_scope
|
||||
void init_comp(B* new_re, B* prev_re, B prim, B sys); // doesn't consume; writes re_* compiling info into new_re
|
||||
|
||||
25
src/main.c
25
src/main.c
@ -20,7 +20,7 @@
|
||||
#error "Cannot use USE_REPLXX_IO without USE_REPLXX"
|
||||
#endif
|
||||
|
||||
static B replPath;
|
||||
static B replPath, replName;
|
||||
static Scope* gsc;
|
||||
static bool init = false;
|
||||
|
||||
@ -28,6 +28,7 @@ static NOINLINE void repl_init() {
|
||||
if (init) return;
|
||||
cbqn_init();
|
||||
replPath = m_c8vec_0("."); gc_add(replPath);
|
||||
replName = m_c8vec_0("(REPL)"); gc_add(replName);
|
||||
Body* body = m_nnsDesc();
|
||||
B ns = m_nns(body);
|
||||
gsc = ptr_inc(c(NS, ns)->sc); gc_add(tag(gsc,OBJ_TAG));
|
||||
@ -557,8 +558,9 @@ static NOINLINE i64 readInt(char** p) {
|
||||
#endif
|
||||
|
||||
|
||||
NOINLINE B gsc_exec_inplace(B src, B path, B args) {
|
||||
Block* block = bqn_compSc(src, path, args, gsc, true);
|
||||
B m_state(B path, B name, B args);
|
||||
NOINLINE B gsc_exec_inplace(B src, char* name, B args) {
|
||||
Block* block = bqn_compSc(src, m_state(incG(replPath), m_c8vec_0(name), args), gsc, true);
|
||||
ptr_dec(gsc->body); // redirect new errors to the newly executed code; initial scope had 0 vars, so this is safe
|
||||
gsc->body = ptr_inc(block->bodies[0]);
|
||||
B r = execBlockInplace(block, gsc);
|
||||
@ -580,7 +582,7 @@ void switchComp(void);
|
||||
static B escape_parser;
|
||||
static B simple_unescape(B x) {
|
||||
if (RARE(escape_parser.u==0)) {
|
||||
escape_parser = bqn_exec(utf8Decode0("{m←\"Expected surrounding quotes\" ⋄ m!2≤≠𝕩 ⋄ m!\"\"\"\"\"\"≡0‿¯1⊏𝕩 ⋄ s←¬e←<`'\\'=𝕩 ⋄ i‿o←\"\\\"\"nr\"⋈\"\\\"\"\"∾@+10‿13 ⋄ 1↓¯1↓{n←i⊐𝕩 ⋄ \"Unknown escape\"!∧´n≠≠i ⋄ n⊏o}⌾((s/»e)⊸/) s/𝕩}"), bi_N, bi_N);
|
||||
escape_parser = bqn_exec(utf8Decode0("{m←\"Expected surrounding quotes\" ⋄ m!2≤≠𝕩 ⋄ m!\"\"\"\"\"\"≡0‿¯1⊏𝕩 ⋄ s←¬e←<`'\\'=𝕩 ⋄ i‿o←\"\\\"\"nr\"⋈\"\\\"\"\"∾@+10‿13 ⋄ 1↓¯1↓{n←i⊐𝕩 ⋄ \"Unknown escape\"!∧´n≠≠i ⋄ n⊏o}⌾((s/»e)⊸/) s/𝕩}"), bi_N);
|
||||
gc_add(escape_parser);
|
||||
}
|
||||
return c1(escape_parser, x);
|
||||
@ -603,6 +605,7 @@ bool ryu_s2d_n(u8* buffer, int len, f64* result);
|
||||
#endif
|
||||
|
||||
void heap_printInfoStr(char* str);
|
||||
B bqn_explain(B str);
|
||||
extern bool gc_log_enabled, mem_log_enabled;
|
||||
void cbqn_runLine0(char* ln, i64 read) {
|
||||
if (ln[0]==0 || read==0) return;
|
||||
@ -797,7 +800,7 @@ void cbqn_runLine0(char* ln, i64 read) {
|
||||
return;
|
||||
#endif
|
||||
} else if (isCmd(cmdS, &cmdE, "e ") || isCmd(cmdS, &cmdE, "explain ")) {
|
||||
HArr* expla = toHArr(bqn_explain(utf8Decode0(cmdE), replPath));
|
||||
HArr* expla = toHArr(bqn_explain(utf8Decode0(cmdE)));
|
||||
usz ia=PIA(expla);
|
||||
for(usz i=0; i<ia; i++) {
|
||||
printsB(expla->a[i]);
|
||||
@ -813,7 +816,7 @@ void cbqn_runLine0(char* ln, i64 read) {
|
||||
code = utf8Decode0(ln);
|
||||
output = 1;
|
||||
}
|
||||
Block* block = bqn_compSc(code, incG(replPath), emptySVec(), gsc, true);
|
||||
Block* block = bqn_compSc(code, m_state(incG(replPath), incG(replName), emptySVec()), gsc, true);
|
||||
|
||||
ptr_dec(gsc->body);
|
||||
gsc->body = ptr_inc(block->bodies[0]);
|
||||
@ -967,12 +970,12 @@ int main(int argc, char* argv[]) {
|
||||
#define REQARG(X) if(*carg) { fprintf(stderr, "%s: -%s must end the option\n", argv[0], #X); exit(1); } if (i==argc) { fprintf(stderr, "%s: -%s requires an argument\n", argv[0], #X); exit(1); }
|
||||
case 'f': repl_init(); REQARG(f); goto execFile;
|
||||
case 'e': { repl_init(); REQARG(e);
|
||||
dec(gsc_exec_inplace(utf8Decode0(argv[i++]), m_c8vec_0("(-e)"), emptySVec()));
|
||||
dec(gsc_exec_inplace(utf8Decode0(argv[i++]), "(-e)", emptySVec()));
|
||||
break;
|
||||
}
|
||||
case 'L': { repl_init(); break; } // just initialize. mostly for perf testing
|
||||
case 'p': { repl_init(); REQARG(p);
|
||||
B r = gsc_exec_inplace(utf8Decode0(argv[i++]), m_c8vec_0("(-p)"), emptySVec());
|
||||
B r = gsc_exec_inplace(utf8Decode0(argv[i++]), "(-p)", emptySVec());
|
||||
if (FORMATTER) { r = bqn_fmt(r); printsB(r); }
|
||||
else { printI(r); }
|
||||
dec(r);
|
||||
@ -980,7 +983,7 @@ int main(int argc, char* argv[]) {
|
||||
break;
|
||||
}
|
||||
case 'o': { repl_init(); REQARG(o);
|
||||
B r = gsc_exec_inplace(utf8Decode0(argv[i++]), m_c8vec_0("(-o)"), emptySVec());
|
||||
B r = gsc_exec_inplace(utf8Decode0(argv[i++]), "(-o)", emptySVec());
|
||||
printsB(r); dec(r);
|
||||
printf("\n");
|
||||
break;
|
||||
@ -1004,7 +1007,7 @@ int main(int argc, char* argv[]) {
|
||||
usz ia = IA(lines);
|
||||
SGet(lines)
|
||||
for (u64 i = 0; i < ia; i++) {
|
||||
dec(gsc_exec_inplace(Get(lines, i), incG(replPath), emptySVec()));
|
||||
dec(gsc_exec_inplace(Get(lines, i), "(-R)", emptySVec()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1032,7 +1035,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
B execRes;
|
||||
if (execStdin) {
|
||||
execRes = gsc_exec_inplace(utf8DecodeA(stream_bytes(stdin)), m_c8vec_0("(-)"), args);
|
||||
execRes = gsc_exec_inplace(utf8DecodeA(stream_bytes(stdin)), "(stdin)", args);
|
||||
} else {
|
||||
execRes = bqn_execFile(src, args);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user