put in a bit more effort printing messages while things are really bad
This commit is contained in:
parent
537369e5e7
commit
e3baa868f7
2
makefile
2
makefile
@ -29,7 +29,7 @@ heapverifyn-singeli:
|
||||
rtverifyn-singeli:
|
||||
@${MAKE} singeli=1 t=rtverifyn_si f="-O3 -DRT_VERIFY -DEEQUAL_NEGZERO -march=native" c
|
||||
wasi-o3:
|
||||
@${MAKE} singeli=0 t=wasi_o3 f="-DWASM -O3 -DCATCH_ERRORS=0 -D_WASI_EMULATED_MMAN --target=wasm32-wasi" LDFLAGS="-lwasi-emulated-mman --target=wasm32-wasi" LD_LIBS= PIE= c
|
||||
@${MAKE} singeli=0 t=wasi_o3 f="-DWASM -DWASI -O3 -DCATCH_ERRORS=0 -D_WASI_EMULATED_MMAN --target=wasm32-wasi" LDFLAGS="-lwasi-emulated-mman --target=wasm32-wasi" LD_LIBS= PIE= c
|
||||
emcc-o3:
|
||||
@${MAKE} singeli=0 t=emcc_o3 f='-DWASM -DEMCC -O3' LDFLAGS='-s EXPORTED_FUNCTIONS=_main,_cbqn_runLine -s EXPORTED_RUNTIME_METHODS=ccall,cwrap -s ALLOW_MEMORY_GROWTH=1' CC=emcc c
|
||||
|
||||
|
||||
@ -667,9 +667,11 @@ void base_init() { // very first init function
|
||||
#undef FD
|
||||
}
|
||||
|
||||
bool cbqn_initialized;
|
||||
void cbqn_init() {
|
||||
#define F(X) X##_init();
|
||||
FOR_INIT(F)
|
||||
#undef F
|
||||
cbqn_initialized = true;
|
||||
}
|
||||
#undef FOR_INIT
|
||||
|
||||
44
src/vm.c
44
src/vm.c
@ -1144,6 +1144,7 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes p
|
||||
return s;
|
||||
}
|
||||
|
||||
extern bool cbqn_initialized;
|
||||
NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) {
|
||||
B src = comp->src;
|
||||
if (!q_N(src) && !q_N(comp->indices)) {
|
||||
@ -1151,25 +1152,33 @@ NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) {
|
||||
B inde = IGetU(comp->indices, 1); usz ce = o2s(IGetU(inde,bcPos))+1;
|
||||
// printf(" bcPos=%d\n", bcPos); // in case the pretty error generator is broken
|
||||
// printf(" inds:%d…%d\n", cs, ce);
|
||||
if (CATCH) { // want to try really hard to print errors
|
||||
freeThrown();
|
||||
int start = fprintf(stderr, "at ");
|
||||
usz srcL = a(src)->ia;
|
||||
SGetU(src)
|
||||
usz srcS = cs; while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--;
|
||||
usz srcE = srcS; while (srcE<srcL) { u32 chr = o2cu(GetU(src, srcE)); if(chr=='\n')break; printUTF8(chr); srcE++; }
|
||||
if (ce>srcE) ce = srcE;
|
||||
cs-= srcS; ce-= srcS;
|
||||
fputc('\n', stderr);
|
||||
for (i32 i = 0; i < cs+start; i++) fputc(' ', stderr);
|
||||
for (i32 i = cs; i < ce; i++) fputc('^', stderr);
|
||||
fputc('\n', stderr);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// want to try really hard to print errors
|
||||
if (!cbqn_initialized) goto native_print;
|
||||
if (CATCH) goto native_print;
|
||||
|
||||
B s = emptyCVec();
|
||||
fprintRaw(stderr, vm_fmtPoint(src, s, comp->path, cs, ce));
|
||||
fputc('\n', stderr);
|
||||
popCatch();
|
||||
return;
|
||||
|
||||
native_print:
|
||||
freeThrown();
|
||||
int start = fprintf(stderr, "at ");
|
||||
usz srcL = a(src)->ia;
|
||||
SGetU(src)
|
||||
usz srcS = cs; while (srcS>0 && o2cu(GetU(src,srcS-1))!='\n') srcS--;
|
||||
usz srcE = srcS; while (srcE<srcL) { u32 chr = o2cu(GetU(src, srcE)); if(chr=='\n')break; printUTF8(chr); srcE++; }
|
||||
if (ce>srcE) ce = srcE;
|
||||
cs-= srcS; ce-= srcS;
|
||||
fputc('\n', stderr);
|
||||
for (i32 i = 0; i < cs+start; i++) fputc(' ', stderr);
|
||||
for (i32 i = cs; i < ce; i++) fputc('^', stderr);
|
||||
fputc('\n', stderr);
|
||||
return;
|
||||
|
||||
//print_BCStream((u32*)i32arr_ptr(comp->bc)+bcPos);
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
@ -1278,4 +1287,7 @@ NOINLINE void freeThrown() {
|
||||
NOINLINE NORETURN void thrM(char* s) {
|
||||
thr(fromUTF8(s, strlen(s)));
|
||||
}
|
||||
NOINLINE NORETURN void thrOOM() { thr(inc(oomMessage)); }
|
||||
NOINLINE NORETURN void thrOOM() {
|
||||
if (oomMessage.u==0) err("out-of-memory encountered before out-of-memory error message object was initialized");
|
||||
thr(inc(oomMessage));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user