Store compiler and runtime in •ReBQN result

This commit is contained in:
Marshall Lochbaum 2021-12-15 21:38:48 -05:00
parent 5c2a921e56
commit 4d394ea441
3 changed files with 26 additions and 8 deletions

View File

@ -520,13 +520,16 @@ B getRandNS() {
return incG(randNS);
}
static NFnDesc* reBQNDesc;
static B ns_getNUf(B ns, B field) {
B r = ns_getNU(ns, field, false); dec(field); return r;
}
B reBQN_c1(B t, B x) {
if (!isNsp(x)) thrM("•ReBQN: Argument must be a namespace");
B replStr = m_str8l("repl");
B repl = ns_getNU(x, replStr, false); dec(replStr);
B repl = ns_getNUf(x, m_str8l("repl"));
B prim = ns_getNUf(x, m_str8l("primitives"));
dec(x);
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");
dec(x);
Block* initBlock = bqn_comp(m_str8l("\"(REPL initializer)\""), inc(cdPath), m_f64(0));
B scVal;
if (replVal==0) {
@ -536,7 +539,9 @@ B reBQN_c1(B t, B x) {
scVal = tag(sc,OBJ_TAG);
}
ptr_dec(initBlock);
return m_nfn(reBQNDesc, m_hVec2(m_f64(replVal), scVal));
B dat = m_hVec4(m_f64(replVal), scVal, bi_N, bi_N);
init_comp(harr_ptr(dat)+2, prim);
return m_nfn(reBQNDesc, dat);
}
B repl_c2(B t, B w, B x) {
vfyStr(x, "REPL", "𝕩");
@ -550,7 +555,7 @@ B repl_c2(B t, B w, B x) {
B res;
if (replMode>0) {
Block* block = bqn_compSc(x, fullpath, args, sc, replMode==2);
Block* block = bqn_compScc(x, fullpath, args, sc, op[2], op[3], replMode==2);
ptr_dec(sc->body);
sc->body = ptr_inc(block->bodies[0]);
res = execBlockInline(block, sc);

View File

@ -164,7 +164,7 @@ NOINLINE Block* bqn_comp(B str, B path, B args) { // consumes all
comp_currEnvPos = prevEnvPos;
return r;
}
NOINLINE 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, Scope* sc, B comp, B rt, bool repl) { // consumes str,path,args
B prevPath = comp_currPath ; comp_currPath = path;
B prevArgs = comp_currArgs ; comp_currArgs = args;
B prevSrc = comp_currSrc ; comp_currSrc = str;
@ -191,7 +191,7 @@ NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // con
csc = csc->psc;
depth++;
}
Block* r = load_compObj(c2(load_comp, m_hVec4(incG(load_rtObj), incG(bi_sys), vName, vDepth), inc(str)), str, path, sc);
Block* r = load_compObj(c2(comp, m_hVec4(incG(rt), incG(bi_sys), vName, vDepth), inc(str)), str, path, sc);
dec(path); dec(args);
comp_currPath = prevPath;
comp_currArgs = prevArgs;
@ -199,6 +199,17 @@ NOINLINE Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl) { // con
comp_currEnvPos = prevEnvPos;
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, sc, load_comp, load_rtObj, repl);
}
void init_comp(B* set, B prim) { // doesn't consume
if (q_N(prim)) {
set[0] = inc(load_comp);
set[1] = inc(load_rtObj);
} else {
thrM("•ReBQN: primitives⇐ unimplemented");
}
}
B bqn_exec(B str, B path, B args) { // consumes all
Block* block = bqn_comp(str, path, args);

View File

@ -142,10 +142,12 @@ struct Scope {
};
Block* bqn_comp(B str, B path, B args);
Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl);
Block* bqn_compSc (B str, B path, B args, Scope* sc, bool repl);
Block* bqn_compScc(B str, B path, B args, Scope* sc, B comp, B rt, bool repl);
Block* compile(B bcq, B objs, B blocks, B bodies, B indices, B tokenInfo, B src, B path, Scope* sc);
Scope* m_scope(Body* body, Scope* psc, u16 varAm, i32 initVarAm, B* initVars);
Body* m_body(i32 vam, i32 pos, u32 maxStack, u16 maxPSC); // leaves varIDs and nsDesc uninitialized
void init_comp(B* set, B prim);
typedef struct Nvm_res { u8* p; B refs; } Nvm_res;
Nvm_res m_nvm(Body* b);