optional source for precompiled programs
This commit is contained in:
parent
c2013e3b5d
commit
d046d92390
6
cc.bqn
6
cc.bqn
@ -1,4 +1,4 @@
|
||||
#! /usr/bin/env dbqn
|
||||
#!/usr/bin/env bqn
|
||||
# Modified version of https://github.com/mlochbaum/BQN/blob/master/src/cjs.bqn, which is under the ISC license (https://github.com/mlochbaum/BQN/blob/master/LICENSE)
|
||||
|
||||
args←•args
|
||||
@ -28,12 +28,12 @@ FChars ← {𝕨•FChars path∾𝕩}
|
||||
FLines ← {𝕨•FLines path∾𝕩}
|
||||
|
||||
glyphs ← Import "glyphs.bqn"
|
||||
_getComp ← { (3+useInd) ↑ (𝕗 Import "c.bqn"){𝔽} }
|
||||
_getComp ← { (3+2×useInd)↑ <∘⊢∾˜ 4↑ (𝕗 Import "c.bqn"){𝔽} }
|
||||
useInd ← "-i"≡⊑args ⋄ args↓˜↩useInd
|
||||
Comp ← ((<"inc(runtime["∾•Repr∾"])"˙)¨↕62) glyphs _getComp ⊢
|
||||
J ← ∾∾⟜(@+10)¨
|
||||
Fconst ← ≡◶⟨@⊸≤◶Num‿Char, Str, ⊑⟩
|
||||
Fout ← {((≠𝕩)↑⟨LI F¨,L Fconst¨,L (LI ·F¨ 4↑⊢)¨,L (L F¨)¨⟩) {𝕎𝕩}¨ 𝕩}
|
||||
Fout ← {((≠𝕩)↑⟨LI F¨ ⋄ L Fconst¨ ⋄ L (LI ·F¨ 4↑⊢)¨ ⋄ L (LI F¨)¨ ⋄ Str⟩) {𝕎𝕩}¨ 𝕩}
|
||||
Frun ← 1⊸Fout
|
||||
Long ← {¯2↓∾𝕩∾¨<","∾@+10}
|
||||
LFC ← Long∘Fout∘Comp
|
||||
|
||||
@ -21,7 +21,7 @@ void heapVerify_checkFn(Value* v) {
|
||||
printf("delta %d for %s: ", (i32)v->refc, format_type(v->type));
|
||||
#endif
|
||||
heap_observed = v;
|
||||
print(tag(v,OBJ_TAG)); puts("");
|
||||
print(tag(v,OBJ_TAG)); putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ bool heapVerify_visitP(void* x) {
|
||||
Value* v = x;
|
||||
if(heapVerify_mode==0) v->refc--;
|
||||
else if(heapVerify_mode==1) v->refc++;
|
||||
else if(heapVerify_mode==2) if (x==heap_observed) { printf("referee: %p ", heap_curr); print(tag(heap_curr,OBJ_TAG)); puts(""); }
|
||||
else if(heapVerify_mode==2) if (x==heap_observed) { printf("referee: %p ", heap_curr); print(tag(heap_curr,OBJ_TAG)); putchar('\n'); }
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -9,9 +9,15 @@ Block* load_compObj(B x, B src) { // consumes
|
||||
dec(x);
|
||||
return r;
|
||||
}
|
||||
#ifdef RT_SRC
|
||||
Block* load_compImport(B bc, B objs, B blocks, B inds, B src) { // consumes all
|
||||
return compile(bc, objs, blocks, inds, bi_N, src);
|
||||
}
|
||||
#else
|
||||
Block* load_compImport(B bc, B objs, B blocks) { // consumes all
|
||||
return compile(bc, objs, blocks, bi_N, bi_N, bi_N);
|
||||
}
|
||||
#endif
|
||||
|
||||
B load_comp;
|
||||
B load_compArg;
|
||||
|
||||
@ -215,7 +215,7 @@ u8 fillElType(B x) {
|
||||
Value* VALIDATEP(Value* x) {
|
||||
if (x->refc<=0 || (x->refc>>28) == 'a' || x->type==t_empty) {
|
||||
printf("bad refcount for type %d: %d\nattempting to print: ", x->type, x->refc); fflush(stdout);
|
||||
print(tag(x,OBJ_TAG)); puts(""); fflush(stdout);
|
||||
print(tag(x,OBJ_TAG)); putchar('\n'); fflush(stdout);
|
||||
err("");
|
||||
}
|
||||
if (ti[x->type].isArr) {
|
||||
|
||||
52
src/vm.c
52
src/vm.c
@ -373,7 +373,7 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
|
||||
vmStack[stackNum] = bcPos;
|
||||
for(i32 i = 0; i < bcDepth; i++) printf(" ");
|
||||
printBC(sbc); printf("@%d << ", bcPos);
|
||||
for (i32 i = 0; i < b->maxStack; i++) { if(i)printf(" ⋄ "); print(gStack[i]); } puts(""); fflush(stdout);
|
||||
for (i32 i = 0; i < b->maxStack; i++) { if(i)printf(" ⋄ "); print(gStack[i]); } putchar('\n'); fflush(stdout);
|
||||
bcCtr++;
|
||||
for (i32 i = 0; i < sc->varAm; i++) VALIDATE(sc->vars[i]);
|
||||
#endif
|
||||
@ -497,7 +497,7 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
|
||||
#ifdef DEBUG_VM
|
||||
for(i32 i = 0; i < bcDepth; i++) printf(" ");
|
||||
printBC(sbc); printf("@%ld: ", sbc-c(I32Arr,b->comp->bc)->a);
|
||||
for (i32 i = 0; i < b->maxStack; i++) { if(i)printf(" ⋄ "); print(gStack[i]); } puts(""); fflush(stdout);
|
||||
for (i32 i = 0; i < b->maxStack; i++) { if(i)printf(" ⋄ "); print(gStack[i]); } putchar('\n'); fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
end:;
|
||||
@ -685,6 +685,31 @@ void popCatch() {
|
||||
#endif
|
||||
}
|
||||
|
||||
NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) {
|
||||
B src = comp->src;
|
||||
if (!isNothing(src) && !isNothing(comp->indices)) {
|
||||
B inds = TI(comp->indices).getU(comp->indices, 0); usz cs = o2s(TI(inds).getU(inds,bcPos));
|
||||
B inde = TI(comp->indices).getU(comp->indices, 1); usz ce = o2s(TI(inde).getU(inde,bcPos))+1;
|
||||
int start = pos==-1? 0 : printf("%ld: ", pos);
|
||||
usz srcL = a(src)->ia;
|
||||
BS2B srcGetU = TI(src).getU;
|
||||
usz srcS = cs;
|
||||
while (srcS>0 && o2cu(srcGetU(src,srcS-1))!='\n') srcS--;
|
||||
usz srcE = srcS;
|
||||
while (srcE<srcL) { u32 chr = o2cu(srcGetU(src, srcE)); if(chr=='\n')break; printUTF8(chr); srcE++; }
|
||||
if (ce>srcE) ce = srcE;
|
||||
cs-= srcS;
|
||||
ce-= srcS;
|
||||
putchar('\n');
|
||||
for (i32 i = 0; i < cs+start; i++) putchar(' ');
|
||||
for (i32 i = cs; i < ce; i++) putchar('^');
|
||||
putchar('\n');
|
||||
// printf(" inds:%d…%d\n", cinds, cinde);
|
||||
} else {
|
||||
if (pos!=-1) printf("%ld: ", pos);
|
||||
printf("source unknown\n");
|
||||
}
|
||||
}
|
||||
|
||||
NOINLINE void vm_pst(Env* s, Env* e) {
|
||||
assert(s<=e);
|
||||
@ -698,28 +723,7 @@ NOINLINE void vm_pst(Env* s, Env* e) {
|
||||
}
|
||||
i32 bcPos = c->bcV;
|
||||
Comp* comp = c->sc->body->comp;
|
||||
B src = comp->src;
|
||||
if (!isNothing(src) && !isNothing(comp->indices)) {
|
||||
B inds = TI(comp->indices).getU(comp->indices, 0); usz cs = o2s(TI(inds).getU(inds,bcPos));
|
||||
B inde = TI(comp->indices).getU(comp->indices, 1); usz ce = o2s(TI(inde).getU(inde,bcPos))+1;
|
||||
int start = printf("%ld: ", i);
|
||||
usz srcL = a(src)->ia;
|
||||
BS2B srcGetU = TI(src).getU;
|
||||
usz srcS = cs;
|
||||
while (srcS>0 && o2cu(srcGetU(src,srcS-1))!='\n') srcS--;
|
||||
usz srcE = srcS;
|
||||
while (srcE<srcL) { u32 chr = o2cu(srcGetU(src, srcE)); if(chr=='\n')break; printUTF8(chr); srcE++; }
|
||||
if (ce>srcE) ce = srcE;
|
||||
cs-= srcS;
|
||||
ce-= srcS;
|
||||
putchar('\n');
|
||||
for (i32 i = 0; i < cs+start; i++) putchar(' ');
|
||||
for (i32 i = cs; i < ce; i++) putchar('^');
|
||||
putchar('\n');
|
||||
// printf(" inds:%d…%d\n", cinds, cinde);
|
||||
} else {
|
||||
printf("%ld: source unknown\n", i);
|
||||
}
|
||||
vm_printPos(comp, bcPos, i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user