print more things to stderr
This commit is contained in:
parent
e24f3c9df5
commit
c7e0b59e88
@ -10,17 +10,17 @@ bool please_tail_call_err = true;
|
|||||||
bool inErr;
|
bool inErr;
|
||||||
NORETURN NOINLINE void err(char* s) {
|
NORETURN NOINLINE void err(char* s) {
|
||||||
if (inErr) {
|
if (inErr) {
|
||||||
printf("\nCBQN encountered fatal error during information printing of another fatal error. Exiting without printing more info.\n");
|
fputs("\nCBQN encountered fatal error during information printing of another fatal error. Exiting without printing more info.", stderr);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
#endif
|
#endif
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
inErr = true;
|
inErr = true;
|
||||||
puts(s); fflush(stdout);
|
fputs(s, stderr); fflush(stderr);
|
||||||
vm_pstLive(); fflush(stdout);
|
vm_pstLive(); fflush(stderr); fflush(stdout);
|
||||||
print_vmStack(); fflush(stdout);
|
print_vmStack(); fflush(stderr);
|
||||||
puts("CBQN interpreter entered unexpected state, exiting.");
|
fputs("CBQN interpreter entered unexpected state, exiting.", stderr);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
#endif
|
#endif
|
||||||
@ -132,7 +132,7 @@ void fprint(FILE* f, B x) {
|
|||||||
NUM_FMT_BUF(buf, x.f);
|
NUM_FMT_BUF(buf, x.f);
|
||||||
fprintf(f, "%s", buf);
|
fprintf(f, "%s", buf);
|
||||||
} else if (isC32(x)) {
|
} else if (isC32(x)) {
|
||||||
if ((u32)x.u>=32) { fprintf(f, "'"); printUTF8((u32)x.u); fprintf(f, "'"); }
|
if ((u32)x.u>=32) { fprintf(f, "'"); fprintUTF8(f, (u32)x.u); fprintf(f, "'"); }
|
||||||
else if((u32)x.u>15) fprintf(f, "\\x%x", (u32)x.u);
|
else if((u32)x.u>15) fprintf(f, "\\x%x", (u32)x.u);
|
||||||
else fprintf(f, "\\x0%x", (u32)x.u);
|
else fprintf(f, "\\x0%x", (u32)x.u);
|
||||||
} else if (isVal(x)) {
|
} else if (isVal(x)) {
|
||||||
@ -236,7 +236,7 @@ NOINLINE B do_fmt(B s, char* p, va_list a) {
|
|||||||
while (*p != 0) { c = *p++;
|
while (*p != 0) { c = *p++;
|
||||||
if (c!='%') continue;
|
if (c!='%') continue;
|
||||||
if (lp!=p-1) AJOIN(fromUTF8(lp, p-1-lp));
|
if (lp!=p-1) AJOIN(fromUTF8(lp, p-1-lp));
|
||||||
switch(c = *p++) { default: printf("Unknown format character '%c'", c); UD;
|
switch(c = *p++) { default: printf("Unknown format character '%c'", c); err(""); UD;
|
||||||
case 'R': {
|
case 'R': {
|
||||||
B b = va_arg(a, B);
|
B b = va_arg(a, B);
|
||||||
if (isNum(b)) AFMT("%f", o2f(b));
|
if (isNum(b)) AFMT("%f", o2f(b));
|
||||||
@ -831,15 +831,15 @@ void g_pst(void) { vm_pstLive(); }
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#ifdef OBJ_COUNTER
|
#ifdef OBJ_COUNTER
|
||||||
#define PRINT_ID(X) printf("Object ID: "N64u"\n", (X)->uid)
|
#define PRINT_ID(X) fprintf(stderr, "Object ID: "N64u"\n", (X)->uid)
|
||||||
#else
|
#else
|
||||||
#define PRINT_ID(X)
|
#define PRINT_ID(X)
|
||||||
#endif
|
#endif
|
||||||
NOINLINE Value* VALIDATEP(Value* x) {
|
NOINLINE 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) {
|
||||||
PRINT_ID(x);
|
PRINT_ID(x);
|
||||||
printf("bad refcount for type %d: %d\nattempting to print: ", x->type, x->refc); fflush(stdout);
|
fprintf(stderr, "bad refcount for type %d: %d\nattempting to print: ", x->type, x->refc); fflush(stderr);
|
||||||
print(tag(x,OBJ_TAG)); putchar('\n'); fflush(stdout);
|
fprint(stderr, tag(x,OBJ_TAG)); fputc('\n', stderr); fflush(stderr);
|
||||||
err("");
|
err("");
|
||||||
}
|
}
|
||||||
if (TIv(x,isArr)) {
|
if (TIv(x,isArr)) {
|
||||||
@ -858,15 +858,15 @@ void g_pst(void) { vm_pstLive(); }
|
|||||||
if (!isVal(x)) return x;
|
if (!isVal(x)) return x;
|
||||||
VALIDATEP(v(x));
|
VALIDATEP(v(x));
|
||||||
if(isArr(x)!=TI(x,isArr) && v(x)->type!=t_freed && v(x)->type!=t_harrPartial) {
|
if(isArr(x)!=TI(x,isArr) && v(x)->type!=t_freed && v(x)->type!=t_harrPartial) {
|
||||||
printf("bad array tag/type: type=%d, obj=%p\n", v(x)->type, (void*)x.u);
|
fprintf(stderr, "bad array tag/type: type=%d, obj=%p\n", v(x)->type, (void*)x.u);
|
||||||
PRINT_ID(v(x));
|
PRINT_ID(v(x));
|
||||||
print(x);
|
fprint(stderr, x);
|
||||||
err("\n");
|
err("\n");
|
||||||
}
|
}
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
NOINLINE NORETURN void assert_fail(char* expr, char* file, int line, const char fn[]) {
|
NOINLINE NORETURN void assert_fail(char* expr, char* file, int line, const char fn[]) {
|
||||||
printf("%s:%d: %s: Assertion `%s` failed.\n", file, line, fn, expr);
|
fprintf(stderr, "%s:%d: %s: Assertion `%s` failed.\n", file, line, fn, expr);
|
||||||
err("");
|
err("");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -874,27 +874,27 @@ void g_pst(void) { vm_pstLive(); }
|
|||||||
static void warn_ln(B x) {
|
static void warn_ln(B x) {
|
||||||
if (isArr(x)) print_fmt("%s items, %S, shape=%H\n", a(x)->ia, eltype_repr(TI(x,elType)), x);
|
if (isArr(x)) print_fmt("%s items, %S, shape=%H\n", a(x)->ia, eltype_repr(TI(x,elType)), x);
|
||||||
else {
|
else {
|
||||||
printf("atom: ");
|
fprintf(stderr, "atom: ");
|
||||||
printRaw(x = bqn_fmt(inc(x))); dec(x);
|
fprintRaw(stderr, x = bqn_fmt(inc(x))); dec(x);
|
||||||
putchar('\n');
|
fputc('\n', stderr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void warn_slow1(char* s, B x) {
|
void warn_slow1(char* s, B x) {
|
||||||
if (isArr(x) && a(x)->ia<100) return;
|
if (isArr(x) && a(x)->ia<100) return;
|
||||||
printf("slow %s: ", s); warn_ln(x);
|
fprintf(stderr, "slow %s: ", s); warn_ln(x);
|
||||||
fflush(stdout);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
void warn_slow2(char* s, B w, B x) {
|
void warn_slow2(char* s, B w, B x) {
|
||||||
if ((isArr(w)||isArr(x)) && (!isArr(w) || a(w)->ia<50) && (!isArr(x) || a(x)->ia<50)) return;
|
if ((isArr(w)||isArr(x)) && (!isArr(w) || a(w)->ia<50) && (!isArr(x) || a(x)->ia<50)) return;
|
||||||
printf("slow %s:\n 𝕨: ", s); warn_ln(w);
|
fprintf(stderr, "slow %s:\n 𝕨: ", s); warn_ln(w);
|
||||||
printf(" 𝕩: "); warn_ln(x);
|
fprintf(stderr, " 𝕩: "); warn_ln(x);
|
||||||
fflush(stdout);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
void warn_slow3(char* s, B w, B x, B y) {
|
void warn_slow3(char* s, B w, B x, B y) {
|
||||||
if ((isArr(w)||isArr(x)) && (!isArr(w) || a(w)->ia<50) && (!isArr(x) || a(x)->ia<50)) return;
|
if ((isArr(w)||isArr(x)) && (!isArr(w) || a(w)->ia<50) && (!isArr(x) || a(x)->ia<50)) return;
|
||||||
printf("slow %s:\n 𝕨: ", s); warn_ln(w);
|
fprintf(stderr, "slow %s:\n 𝕨: ", s); warn_ln(w);
|
||||||
printf(" 𝕩: "); warn_ln(x);
|
fprintf(stderr, " 𝕩: "); warn_ln(x);
|
||||||
printf(" f: "); warn_ln(y);
|
fprintf(stderr, " f: "); warn_ln(y);
|
||||||
fflush(stdout);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -24,3 +24,4 @@ make f='-DNO_RT -DPRECOMP' c && ./BQN || exit
|
|||||||
make f='-DLOG_GC' c && ./BQN -p 2+2 || exit
|
make f='-DLOG_GC' c && ./BQN -p 2+2 || exit
|
||||||
make f='-DWRITE_ASM' c && ./BQN -p 2+2 || exit
|
make f='-DWRITE_ASM' c && ./BQN -p 2+2 || exit
|
||||||
make f='-DUSE_PERF' c && ./BQN -p 2+2 || exit
|
make f='-DUSE_PERF' c && ./BQN -p 2+2 || exit
|
||||||
|
make f='-DUSZ_64' c && ./BQN -p 2+2 || exit
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user