)vars
This commit is contained in:
parent
1770251bad
commit
7e89e190f2
17
src/load.c
17
src/load.c
@ -182,19 +182,10 @@ Block* bqn_compScc(B str, B path, B args, Scope* sc, B comp, B rt, bool repl) {
|
||||
i32 depth = repl? -1 : 0;
|
||||
Scope* csc = sc;
|
||||
while (csc) {
|
||||
Body* body = csc->body;
|
||||
if (csc->varAm) {
|
||||
B nameList = body->bl->comp->nameList; SGetU(nameList);
|
||||
for (u64 i = 0; i < csc->varAm; i++) {
|
||||
i32 nameID = body->varData[i + body->varAm];
|
||||
vName = vec_add(vName, inc(GetU(nameList, nameID)));
|
||||
vDepth = vec_add(vDepth, m_i32(depth));
|
||||
}
|
||||
}
|
||||
if (csc->ext) for (u64 i = 0; i < csc->ext->varAm; i++) {
|
||||
vName = vec_add(vName, inc(csc->ext->vars[i+csc->ext->varAm]));
|
||||
vDepth = vec_add(vDepth, m_i32(depth));
|
||||
}
|
||||
B vars = listVars(csc);
|
||||
usz am = a(vars)->ia;
|
||||
vName = vec_join(vName, vars); // TODO this completely-non-performance-sensitive piece of code is 1.7% of the binary size
|
||||
for (usz i = 0; i < am; i++) vDepth = vec_add(vDepth, m_i32(depth));
|
||||
csc = csc->psc;
|
||||
depth++;
|
||||
}
|
||||
|
||||
14
src/main.c
14
src/main.c
@ -202,6 +202,20 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
heap_printInfo(sizes, types);
|
||||
goto cont;
|
||||
} else if (isCmd(cmdS, &cmdE, "vars")) {
|
||||
B r = listVars(gsc);
|
||||
if (q_N(r)) {
|
||||
printf("Couldn't list variables\n");
|
||||
} else {
|
||||
usz ia = a(r)->ia;
|
||||
B* rp = harr_ptr(r);
|
||||
for (usz i = 0; i < ia; i++) {
|
||||
if (i!=0) printf(", ");
|
||||
printRaw(rp[i]);
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
goto cont;
|
||||
} else if (isCmd(cmdS, &cmdE, "gc ")) {
|
||||
#if ENABLE_GC
|
||||
if (gc_depth!=0) printf("Cannot GC currently\n");
|
||||
|
||||
22
src/vm.c
22
src/vm.c
@ -85,6 +85,28 @@ void print_gStack() {
|
||||
}
|
||||
}
|
||||
|
||||
B listVars(Scope* sc) {
|
||||
Body* b = sc->body;
|
||||
if (b==NULL) return bi_N;
|
||||
|
||||
B r = emptyHVec();
|
||||
usz am0 = sc->varAm;
|
||||
if (am0) {
|
||||
B nameList = b->bl->comp->nameList; SGetU(nameList);
|
||||
i32* varData = b->varData; usz bam = b->varAm;
|
||||
for (u64 i = 0; i < am0; i++) {
|
||||
i32 nameID = varData[i + bam];
|
||||
r = vec_add(r, inc(GetU(nameList, nameID)));
|
||||
}
|
||||
}
|
||||
if (sc->ext) {
|
||||
ScopeExt* scExt = sc->ext; usz am = scExt->varAm; B* vars = scExt->vars;
|
||||
for (u64 i = 0; i < am; i++) r = vec_add(r, inc(vars[i+am]));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
Body* m_body(i32 vam, i32 pos, u32 maxStack, u16 maxPSC) { // leaves varIDs and nsDesc uninitialized
|
||||
Body* body = mm_alloc(fsizeof(Body, varData, i32, vam*2), t_body);
|
||||
|
||||
|
||||
1
src/vm.h
1
src/vm.h
@ -148,6 +148,7 @@ 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); // 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
|
||||
B listVars(Scope* sc); // doesn't consume; returns bi_N if not accessable
|
||||
|
||||
typedef struct Nvm_res { u8* p; B refs; } Nvm_res;
|
||||
Nvm_res m_nvm(Body* b);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user