changes to •ReBQN

This commit is contained in:
dzaima 2021-12-17 14:39:42 +02:00
parent 7b2c79fb87
commit 12250ef202
4 changed files with 34 additions and 29 deletions

View File

@ -126,7 +126,7 @@ src/gen/customRuntime:
@echo "Copying precompiled bytecode from the bytecode branch"
git checkout remotes/origin/bytecode src/gen/{compiles,formatter,runtime0,runtime1,src}
git reset src/gen/{compiles,formatter,runtime0,runtime1,src}
${bd}/load.o: src/gen/compiles
${bd}/load.o: src/gen/customRuntime

View File

@ -63,6 +63,7 @@ static void harr_abandon(HArr_p p) { VTY(p.b, t_harrPartial);
value_free((Value*)p.c);
}
// unsafe-ish things - don't allocate/GC anything before having written to all items
static HArr_p m_harrUv(usz ia) {
HArr* r = m_arr(fsizeof(HArr,a,B,ia), t_harr, ia);
arr_shVec((Arr*)r);

View File

@ -155,7 +155,7 @@ void load_gcFn() {
mm_visit(rt_invFnReg);
mm_visit(rt_invFnSwap);
}
static Block* bqn_compc(B str, B path, B args, B comp, B compArg) { // consumes str,path,args
static NOINLINE Block* bqn_compc(B str, B path, B args, B comp, B compArg) { // 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;
@ -168,7 +168,7 @@ static Block* bqn_compc(B str, B path, B args, B comp, B compArg) { // consumes
comp_currEnvPos = prevEnvPos;
return r;
}
NOINLINE Block* bqn_comp(B str, B path, B args) { // consumes all
Block* bqn_comp(B str, B path, B args) { // consumes all
return bqn_compc(str, path, args, load_comp, load_compArg);
}
Block* bqn_compScc(B str, B path, B args, Scope* sc, B comp, B rt, bool repl) { // consumes str,path,args
@ -216,54 +216,56 @@ B bqn_exec(B str, B path, B args) { // consumes all
ptr_dec(block);
return res;
}
void bqn_setComp(B comp) { // consumes; doesn't unload old comp, but whatever
load_comp = comp;
gc_add(load_comp);
}
void init_comp(B* set, B prim) { // doesn't consume
void init_comp(B* set, B prim) {
if (q_N(prim)) {
set[0] = inc(load_comp);
set[1] = inc(load_rtObj);
set[2] = inc(load_glyphs);
} else {
if (!isArr(prim)||rnk(prim)!=1) thrM("•ReBQN: 𝕩.primitives must be a list");
if (!isArr(prim) || rnk(prim)!=1) thrM("•ReBQN: 𝕩.primitives must be a list");
usz pia = a(prim)->ia;
usz np[3] = {0}; // number of functions, 1-modifiers, and 2-modifiers
SGetU(prim);
for (usz i = 0; i < pia; i++) { // check and count
B p = GetU(prim, i);
if (!isArr(p)||rnk(p)!=1||a(p)->ia!=2) thrM("•ReBQN: 𝕩.primitives must consist of glyph-primitive pairs");
if (!isArr(p) || rnk(p)!=1 || a(p)->ia!=2) thrM("•ReBQN: 𝕩.primitives must consist of glyph-primitive pairs");
if (!isC32(IGet(p, 0))) thrM("•ReBQN 𝕩.primitives: Glyphs must be characters");
B v = IGetU(p, 1);
i32 t = isFun(v) ? 0 : isMd1(v) ? 1 : isMd2(v) ? 2 : 3;
i32 t = isFun(v)? 0 : isMd1(v) ? 1 : isMd2(v) ? 2 : 3;
if (t==3) thrM("•ReBQN 𝕩.primitives: Primitives must be operations");
np[t] += 1;
np[t]+= 1;
}
HArr_p r = m_harrUv(3);
usz i = 0;
HArr_p r = m_harrs(3, &i);
u32* gl[3];
usz sum = 0;
for (usz i = 0; i < 3; i++) {
for (; i < 3; i++) {
usz l = np[i];
r.a[i] = m_c32arrv(gl+i, l);
np[i] = sum;
sum += l;
sum+= l;
}
HArr_p prh = m_harrUv(pia);
B *rt = prh.a;
for (usz i = 0; i < pia; i++) {
harr_fv(r);
i = 0;
HArr_p prh = m_harrs(pia, &i);
B* rt = prh.a;
for (; i < pia; i++) {
B gv = GetU(prim, i);
B v = IGet(gv, 1);
i32 t = isFun(v) ? 0 : isMd1(v) ? 1 : isMd2(v) ? 2 : 3;
*(gl[t]++) = o2cu(IGet(gv, 0));
rt[np[t]++] = v;
}
set[1] = prh.b;
set[1] = harr_fv(prh);
set[2] = inc(r.b);
set[0] = c1(load_compgen, r.b);
}
}
B getPrimitives(void) {
B getPrimitives() {
B g, r;
if (q_N(comp_currRe)) {
g = load_glyphs; r = load_rtObj;
@ -272,16 +274,18 @@ B getPrimitives(void) {
}
B* pr = harr_ptr(r);
B* gg = harr_ptr(g);
HArr_p ph = m_harrUv(a(r)->ia); B* p = ph.a;
usz pi = 0;
HArr_p ph = m_harrs(a(r)->ia, &pi);
for (usz gi = 0; gi < 3; gi++) {
usz l = a(gg[gi])->ia;
u32 *gp = c32arr_ptr(gg[gi]);
u32* gp = c32arr_ptr(gg[gi]);
for (usz i = 0; i < l; i++) {
p[i] = m_hVec2(m_c32(gp[i]), inc(pr[i]));
ph.a[pi] = m_hVec2(m_c32(gp[i]), inc(pr[i]));
pi++;
}
p += l; pr += l;
pr+= l;
}
return ph.b;
return harr_fv(ph);
}
B rebqn_exec(B str, B path, B args, B o) {

View File

@ -141,13 +141,13 @@ struct Scope {
B vars[];
};
Block* bqn_comp(B str, B path, B args);
Block* bqn_compSc(B str, B path, B args, Scope* sc, bool repl);
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* 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);
B rebqn_exec(B str, B path, B args, B o);
void init_comp(B* set, B prim); // doesn't consume; writes into first 3 elements of set
B rebqn_exec(B str, B path, B args, B o); // consumes str,path,args
typedef struct Nvm_res { u8* p; B refs; } Nvm_res;
Nvm_res m_nvm(Body* b);