put in a bit more effort printing messages while things are really bad

This commit is contained in:
dzaima 2022-04-06 22:38:51 +03:00
parent 537369e5e7
commit e3baa868f7
3 changed files with 31 additions and 17 deletions

View File

@ -29,7 +29,7 @@ heapverifyn-singeli:
rtverifyn-singeli: rtverifyn-singeli:
@${MAKE} singeli=1 t=rtverifyn_si f="-O3 -DRT_VERIFY -DEEQUAL_NEGZERO -march=native" c @${MAKE} singeli=1 t=rtverifyn_si f="-O3 -DRT_VERIFY -DEEQUAL_NEGZERO -march=native" c
wasi-o3: 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: 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 @${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

View File

@ -667,9 +667,11 @@ void base_init() { // very first init function
#undef FD #undef FD
} }
bool cbqn_initialized;
void cbqn_init() { void cbqn_init() {
#define F(X) X##_init(); #define F(X) X##_init();
FOR_INIT(F) FOR_INIT(F)
#undef F #undef F
cbqn_initialized = true;
} }
#undef FOR_INIT #undef FOR_INIT

View File

@ -1144,6 +1144,7 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes p
return s; return s;
} }
extern bool cbqn_initialized;
NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) { NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) {
B src = comp->src; B src = comp->src;
if (!q_N(src) && !q_N(comp->indices)) { 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; 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(" bcPos=%d\n", bcPos); // in case the pretty error generator is broken
// printf(" inds:%d…%d\n", cs, ce); // printf(" inds:%d…%d\n", cs, ce);
if (CATCH) { // want to try really hard to print errors
freeThrown();
int start = fprintf(stderr, "at "); // want to try really hard to print errors
usz srcL = a(src)->ia; if (!cbqn_initialized) goto native_print;
SGetU(src) if (CATCH) goto native_print;
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;
}
B s = emptyCVec(); B s = emptyCVec();
fprintRaw(stderr, vm_fmtPoint(src, s, comp->path, cs, ce)); fprintRaw(stderr, vm_fmtPoint(src, s, comp->path, cs, ce));
fputc('\n', stderr); fputc('\n', stderr);
popCatch(); 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); //print_BCStream((u32*)i32arr_ptr(comp->bc)+bcPos);
} else { } else {
#ifdef DEBUG #ifdef DEBUG
@ -1278,4 +1287,7 @@ NOINLINE void freeThrown() {
NOINLINE NORETURN void thrM(char* s) { NOINLINE NORETURN void thrM(char* s) {
thr(fromUTF8(s, strlen(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));
}