optional source for precompiled programs

This commit is contained in:
dzaima 2021-05-16 13:42:58 +03:00
parent c2013e3b5d
commit d046d92390
5 changed files with 40 additions and 30 deletions

6
cc.bqn
View File

@ -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) # 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 args•args
@ -28,12 +28,12 @@ FChars ← {𝕨•FChars path∾𝕩}
FLines {𝕨•FLines path𝕩} FLines {𝕨•FLines path𝕩}
glyphs Import "glyphs.bqn" glyphs Import "glyphs.bqn"
_getComp { (3+useInd) (𝕗 Import "c.bqn"){𝔽} } _getComp { (3+2×useInd) <˜ 4 (𝕗 Import "c.bqn"){𝔽} }
useInd "-i"args args˜useInd useInd "-i"args args˜useInd
Comp ((<"inc(runtime["•Repr"])"˙)¨62) glyphs _getComp Comp ((<"inc(runtime["•Repr"])"˙)¨62) glyphs _getComp
J (@+10)¨ J (@+10)¨
Fconst @NumChar, Str, Fconst @NumChar, 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 1Fout Frun 1Fout
Long {¯2𝕩¨<","@+10} Long {¯2𝕩¨<","@+10}
LFC LongFoutComp LFC LongFoutComp

View File

@ -21,7 +21,7 @@ void heapVerify_checkFn(Value* v) {
printf("delta %d for %s: ", (i32)v->refc, format_type(v->type)); printf("delta %d for %s: ", (i32)v->refc, format_type(v->type));
#endif #endif
heap_observed = v; 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; Value* v = x;
if(heapVerify_mode==0) v->refc--; if(heapVerify_mode==0) v->refc--;
else if(heapVerify_mode==1) 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; return true;
} }

View File

@ -9,9 +9,15 @@ Block* load_compObj(B x, B src) { // consumes
dec(x); dec(x);
return r; 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 Block* load_compImport(B bc, B objs, B blocks) { // consumes all
return compile(bc, objs, blocks, bi_N, bi_N, bi_N); return compile(bc, objs, blocks, bi_N, bi_N, bi_N);
} }
#endif
B load_comp; B load_comp;
B load_compArg; B load_compArg;

View File

@ -215,7 +215,7 @@ u8 fillElType(B x) {
Value* VALIDATEP(Value* x) { Value* VALIDATEP(Value* x) {
if (x->refc<=0 || (x->refc>>28) == 'a' || x->type==t_empty) { 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); 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(""); err("");
} }
if (ti[x->type].isArr) { if (ti[x->type].isArr) {

View File

@ -373,7 +373,7 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
vmStack[stackNum] = bcPos; vmStack[stackNum] = bcPos;
for(i32 i = 0; i < bcDepth; i++) printf(" "); for(i32 i = 0; i < bcDepth; i++) printf(" ");
printBC(sbc); printf("@%d << ", bcPos); 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++; bcCtr++;
for (i32 i = 0; i < sc->varAm; i++) VALIDATE(sc->vars[i]); for (i32 i = 0; i < sc->varAm; i++) VALIDATE(sc->vars[i]);
#endif #endif
@ -497,7 +497,7 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
#ifdef DEBUG_VM #ifdef DEBUG_VM
for(i32 i = 0; i < bcDepth; i++) printf(" "); for(i32 i = 0; i < bcDepth; i++) printf(" ");
printBC(sbc); printf("@%ld: ", sbc-c(I32Arr,b->comp->bc)->a); 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 #endif
} }
end:; end:;
@ -685,6 +685,31 @@ void popCatch() {
#endif #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) { NOINLINE void vm_pst(Env* s, Env* e) {
assert(s<=e); assert(s<=e);
@ -698,28 +723,7 @@ NOINLINE void vm_pst(Env* s, Env* e) {
} }
i32 bcPos = c->bcV; i32 bcPos = c->bcV;
Comp* comp = c->sc->body->comp; Comp* comp = c->sc->body->comp;
B src = comp->src; vm_printPos(comp, bcPos, i);
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);
}
i--; i--;
} }
} }