use printf & fprintf instead of putchar & co

This commit is contained in:
dzaima 2024-05-05 01:07:47 +03:00
parent b657778205
commit 4a40739398
9 changed files with 43 additions and 43 deletions

View File

@ -260,7 +260,7 @@ B casrt_c1(B t, B x) {
B sys_c1(B t, B x); B sys_c1(B t, B x);
B out_c1(B t, B x) { B out_c1(B t, B x) {
if (isAtm(x) || RNK(x)!=1) thrM("•Out: Argument must be a string"); if (isAtm(x) || RNK(x)!=1) thrM("•Out: Argument must be a string");
printsB(x); putchar('\n'); printsB(x); printf("\n");
return x; return x;
} }
B show_c1(B t, B x) { B show_c1(B t, B x) {
@ -271,7 +271,7 @@ B show_c1(B t, B x) {
#else #else
printI(x); printI(x);
#endif #endif
putchar('\n'); printf("\n");
#endif #endif
return x; return x;
} }

View File

@ -13,7 +13,7 @@ void heapVerify_checkFn(Value* v) {
printf("delta %d for %s @ %p: ", (i32)v->refc, type_repr(v->type), v); printf("delta %d for %s @ %p: ", (i32)v->refc, type_repr(v->type), v);
#endif #endif
heap_observed = v; heap_observed = v;
printI(tag(v,OBJ_TAG)); putchar('\n'); printI(tag(v,OBJ_TAG)); printf("\n");
} }
} }

View File

@ -518,10 +518,10 @@ B g_t (void* x) { return tag(x,OBJ_TAG); }
B g_ta(void* x) { return tag(x,ARR_TAG); } B g_ta(void* x) { return tag(x,ARR_TAG); }
B g_tf(void* x) { return tag(x,FUN_TAG); } B g_tf(void* x) { return tag(x,FUN_TAG); }
GLOBAL bool ignore_bad_tag; GLOBAL bool ignore_bad_tag;
void g_p(B x) { fprintI(stderr,x); fputc(10,stderr); fflush(stderr); } void g_p(B x) { fprintI(stderr,x); fprintf(stderr,"\n"); fflush(stderr); }
void g_i(B x) { B r = info_c2(x, m_f64(1), inc(x)); fprintI(stderr,r); dec(r); fputc(10,stderr); fflush(stderr); } void g_i(B x) { B r = info_c2(x, m_f64(1), inc(x)); fprintI(stderr,r); dec(r); fprintf(stderr,"\n"); fflush(stderr); }
void g_pv(void* x) { ignore_bad_tag=true; fprintI(stderr,tag(x,OBJ_TAG)); fputc(10,stderr); fflush(stderr); ignore_bad_tag=false; } void g_pv(void* x) { ignore_bad_tag=true; fprintI(stderr,tag(x,OBJ_TAG)); fprintf(stderr,"\n"); fflush(stderr); ignore_bad_tag=false; }
void g_iv(void* x) { ignore_bad_tag=true; B xo = tag(x, OBJ_TAG); B r = C2(info, m_f64(1), inc(xo)); fprintI(stderr,r); dec(r); fputc(10,stderr); fflush(stderr); ignore_bad_tag=false; } void g_iv(void* x) { ignore_bad_tag=true; B xo = tag(x, OBJ_TAG); B r = C2(info, m_f64(1), inc(xo)); fprintI(stderr,r); dec(r); fprintf(stderr,"\n"); fflush(stderr); ignore_bad_tag=false; }
void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); } void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); }
#if DEBUG #if DEBUG
@ -536,7 +536,7 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); }
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);
fprintf(stderr, "bad refcount for type %d @ %p: %d\nattempting to print: ", x->type, x, x->refc); fflush(stderr); fprintf(stderr, "bad refcount for type %d @ %p: %d\nattempting to print: ", x->type, x, x->refc); fflush(stderr);
fprintI(stderr, tag(x,OBJ_TAG)); fputc('\n', stderr); fflush(stderr); fprintI(stderr, tag(x,OBJ_TAG)); fprintf(stderr, "\n"); fflush(stderr);
fatal(""); fatal("");
} }
if (TIv(x,isArr)) { if (TIv(x,isArr)) {
@ -578,7 +578,7 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); }
fprintf(stderr, "atom: "); fprintf(stderr, "atom: ");
if (cbqn_initialized && FORMATTER) { fprintsB(stderr, x = bqn_fmt(inc(x))); dec(x); } if (cbqn_initialized && FORMATTER) { fprintsB(stderr, x = bqn_fmt(inc(x))); dec(x); }
else fprintI(stderr, x); else fprintI(stderr, x);
fputc('\n', stderr); fprintf(stderr, "\n");
} }
} }
void warn_slow1(char* s, B x) { void warn_slow1(char* s, B x) {

View File

@ -749,7 +749,7 @@ void cbqn_runLine0(char* ln, i64 read) {
if (i!=0) printf(", "); if (i!=0) printf(", ");
printsB(rp[i]); printsB(rp[i]);
} }
putchar('\n'); printf("\n");
} }
return; return;
} else if (isCmd(cmdS, &cmdE, "gc ")) { } else if (isCmd(cmdS, &cmdE, "gc ")) {
@ -803,7 +803,7 @@ void cbqn_runLine0(char* ln, i64 read) {
usz ia=PIA(expla); usz ia=PIA(expla);
for(usz i=0; i<ia; i++) { for(usz i=0; i<ia; i++) {
printsB(expla->a[i]); printsB(expla->a[i]);
putchar('\n'); printf("\n");
} }
ptr_dec(expla); ptr_dec(expla);
return; return;
@ -865,9 +865,9 @@ void cbqn_runLine0(char* ln, i64 read) {
if (output!=2 && FORMATTER) { if (output!=2 && FORMATTER) {
B resFmt = bqn_fmt(res); B resFmt = bqn_fmt(res);
printsB(resFmt); dec(resFmt); printsB(resFmt); dec(resFmt);
putchar('\n'); printf("\n");
} else { } else {
printI(res); putchar('\n'); fflush(stdout); printI(res); printf("\n"); fflush(stdout);
dec(res); dec(res);
} }
} else dec(res); } else dec(res);
@ -877,7 +877,7 @@ void cbqn_runLine0(char* ln, i64 read) {
void cbqn_runLine(char* ln, i64 len) { void cbqn_runLine(char* ln, i64 len) {
if(CATCH) { if(CATCH) {
cbqn_takeInterrupts(false); cbqn_takeInterrupts(false);
fprintf(stderr, "Error: "); printErrMsg(thrownMsg); fputc('\n', stderr); fprintf(stderr, "Error: "); printErrMsg(thrownMsg); fprintf(stderr, "\n");
vm_pst(envCurr+1, envStart+envPrevHeight); vm_pst(envCurr+1, envStart+envPrevHeight);
freeThrown(); freeThrown();
#if HEAP_VERIFY #if HEAP_VERIFY
@ -901,7 +901,7 @@ void cbqn_evalSrc(char* src, i64 len) {
B code = utf8Decode(src, len); B code = utf8Decode(src, len);
B resFmt = bqn_fmt(bqn_exec(code, bi_N)); B resFmt = bqn_fmt(bqn_exec(code, bi_N));
printsB(resFmt); dec(resFmt); printsB(resFmt); dec(resFmt);
putchar('\n'); printf("\n");
} }
#endif #endif
@ -1092,7 +1092,7 @@ int main(int argc, char* argv[]) {
char* ln = NULL; char* ln = NULL;
size_t gl = 0; size_t gl = 0;
i64 read = getline(&ln, &gl, stdin); i64 read = getline(&ln, &gl, stdin);
if (read<=0 || ln[0]==0) { if(!silentREPL) putchar('\n'); break; } if (read<=0 || ln[0]==0) { if(!silentREPL) printf("\n"); break; }
if (ln[read-1]==10) ln[--read] = 0; if (ln[read-1]==10) ln[--read] = 0;
if (ln[read-1]==13) ln[--read] = 0; if (ln[read-1]==13) ln[--read] = 0;
cbqn_runLine(ln, read); cbqn_runLine(ln, read);

View File

@ -189,7 +189,7 @@ static void ns_visit(Value* x) {
mm_visitP(c->sc); mm_visitP(c->sc);
} }
static void ns_print(FILE* f, B x) { static void ns_print(FILE* f, B x) {
fputc('{', f); fprintf(f, "{");
NSDesc* desc = c(NS,x)->desc; NSDesc* desc = c(NS,x)->desc;
Scope* sc = c(NS,x)->sc; Scope* sc = c(NS,x)->sc;
i32 am = desc->varAm; i32 am = desc->varAm;
@ -204,7 +204,7 @@ static void ns_print(FILE* f, B x) {
fprintI(f, sc->vars[i]); fprintI(f, sc->vars[i]);
} }
} }
fputc('}', f); fprintf(f, "}");
} }
B nsFmt(B x) { // consumes B nsFmt(B x) { // consumes
B s = emptyCVec(); B s = emptyCVec();

View File

@ -160,7 +160,7 @@ usz addObj(B* objs, B val) { // consumes val
i32 nc_ty(B x) { return o2iG(IGetU(x, 0)); } i32 nc_ty(B x) { return o2iG(IGetU(x, 0)); }
B nc_generate(B p1) { // consumes B nc_generate(B p1) { // consumes
// printf("p1: "); printI(p1); putchar('\n'); // printf("p1: "); printI(p1); printf("\n");
usz p1ia = IA(p1); usz p1ia = IA(p1);
B listFinal; B listFinal;
@ -201,7 +201,7 @@ B nc_generate(B p1) { // consumes
} }
} }
decG(p1); decG(p1);
// printf("p2: "); printI(p2); putchar('\n'); // printf("p2: "); printI(p2); printf("\n");
// parse as either tacit or explicit // parse as either tacit or explicit
SGetU(p2) SGetU(p2)
@ -215,7 +215,7 @@ B nc_generate(B p1) { // consumes
while(i>0) { while(i>0) {
B en1 = GetU(p2, i-1); B en1 = GetU(p2, i-1);
u8 en1t = nc_ty(en1); u8 en1t = nc_ty(en1);
// printf("e @ %d: ", i); printI(e); putchar('\n'); // printf("e @ %d: ", i); printI(e); printf("\n");
if (en1t==4 || en1t==5) { // assignment if (en1t==4 || en1t==5) { // assignment
if (!explicit && i!=1) thrM("Native compiler: Assignment in the middle of tacit code"); if (!explicit && i!=1) thrM("Native compiler: Assignment in the middle of tacit code");
@ -255,7 +255,7 @@ B nc_generate(B p1) { // consumes
e = m_hvec2(m_f64(explicit? 3 : 0), bc); e = m_hvec2(m_f64(explicit? 3 : 0), bc);
i-= 1; i-= 1;
} }
// printf("e: "); printI(e); putchar('\n'); // printf("e: "); printI(e); printf("\n");
decG(p2); decG(p2);
return e; return e;
} }
@ -293,7 +293,7 @@ B nc_parseStatements(B tokens, usz i0, usz* i1, u32 close, B* objs, Vars vars) {
B ct; B ct;
if (i==tia) ct = m_c32(0); if (i==tia) ct = m_c32(0);
else ct = GetU(tokens, i++); else ct = GetU(tokens, i++);
// printf("next token: "); printI(ct); putchar('\n'); // printf("next token: "); printI(ct); printf("\n");
if (isC32(ct)) { if (isC32(ct)) {
u32 ctc = o2cG(ct); u32 ctc = o2cG(ct);

View File

@ -60,10 +60,10 @@ B wfn_identity(B x) {
#define CHK(EXP,GOT,W,X) { if (!eequal(EXP,GOT)) { \ #define CHK(EXP,GOT,W,X) { if (!eequal(EXP,GOT)) { \
printI(f); printf(": failed RT_VERIFY\n"); fflush(stdout); \ printI(f); printf(": failed RT_VERIFY\n"); fflush(stdout); \
if (RT_VERIFY_ARGS) { \ if (RT_VERIFY_ARGS) { \
if(!q_N(W)){printf("𝕨:"); printI(W); printf(" / "); printsB(C2(info, m_i32(1), inc(W))); putchar('\n'); fflush(stdout); } \ if(!q_N(W)){printf("𝕨:"); printI(W); printf(" / "); printsB(C2(info, m_i32(1), inc(W))); printf("\n"); fflush(stdout); } \
{ printf("𝕩:"); printI(X); printf(" / "); printsB(C2(info, m_i32(1), inc(X))); putchar('\n'); fflush(stdout); } \ { printf("𝕩:"); printI(X); printf(" / "); printsB(C2(info, m_i32(1), inc(X))); printf("\n"); fflush(stdout); } \
{ printf("got:"); printI(GOT); printf(" / "); printsB(C2(info, m_i32(1), inc(GOT))); putchar('\n'); fflush(stdout); } \ { printf("got:"); printI(GOT); printf(" / "); printsB(C2(info, m_i32(1), inc(GOT))); printf("\n"); fflush(stdout); } \
{ printf("exp:"); printI(EXP); printf(" / "); printsB(C2(info, m_i32(1), inc(EXP))); putchar('\n'); fflush(stdout); } \ { printf("exp:"); printI(EXP); printf(" / "); printsB(C2(info, m_i32(1), inc(EXP))); printf("\n"); fflush(stdout); } \
} \ } \
vm_pstLive(); exit(1); \ vm_pstLive(); exit(1); \
}} }}

View File

@ -18,7 +18,7 @@ void vg_printDump_p(char* name, void* data, u64 len) {
printBitDef(cd>>j, cv>>j); printBitDef(cd>>j, cv>>j);
} }
} }
putchar('\n'); printf("\n");
} }
void vg_printDefined_u64(char* name, u64 x) { void vg_printDefined_u64(char* name, u64 x) {

View File

@ -45,16 +45,16 @@ void print_BC(FILE* f, u32* p, i32 w) {
buf[clen++] = (c&15)>9? 'A'+(c&15)-10 : '0'+(c&15); buf[clen++] = (c&15)>9? 'A'+(c&15)-10 : '0'+(c&15);
c>>= 4; c>>= 4;
} while(c); } while(c);
fputc(' ', f); fprintf(f, " ");
for (i32 i = 0; i < clen; i++) fputc(buf[clen-i-1], f); for (i32 i = 0; i < clen; i++) fprintf(f, "%c", buf[clen-i-1]);
len+= clen+1; len+= clen+1;
} }
len = w-len; len = w-len;
while(len-->0) fputc(' ', f); while(len-->0) fprintf(f, " ");
} }
void print_BCStream(FILE* f, u32* p) { void print_BCStream(FILE* f, u32* p) {
while(true) { while(true) {
print_BC(f, p, 10); fputc(10, f); print_BC(f, p, 10); fprintf(f, "\n");
if (*p == RETD || *p == RETN) return; if (*p == RETD || *p == RETN) return;
p = nextBC(p); p = nextBC(p);
} }
@ -170,7 +170,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
bool boArr = isArr(bodyObj); bool boArr = isArr(bodyObj);
i32 boCount = boArr? IA(bodyObj) : 1; i32 boCount = boArr? IA(bodyObj) : 1;
if (boCount<1 || boCount>5) thrM("VM compiler: Unexpected body list length"); if (boCount<1 || boCount>5) thrM("VM compiler: Unexpected body list length");
// if (boArr) { printI(bodyObj); putchar('\n'); } // if (boArr) { printI(bodyObj); printf("\n"); }
i32 firstMPos = failBodyI; i32 firstMPos = failBodyI;
for (i32 i = 0; i < 6; i+= 2) { for (i32 i = 0; i < 6; i+= 2) {
@ -207,7 +207,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
bodyPs[1] = bodyPs[3] = I32_MAX; bodyPs[1] = bodyPs[3] = I32_MAX;
mCount = dCount = 1; mCount = dCount = 1;
} }
// for (int i = 0; i < mapLen+2; i++) printf("%d ", bodyPs[i]); putchar('\n'); printf("things: %d %d\n", mCount, dCount); // for (int i = 0; i < mapLen+2; i++) printf("%d ", bodyPs[i]); printf("\n"); printf("things: %d %d\n", mCount, dCount);
TALLOC(Body*, bodyMap, mapLen+2); // map from index in bodyPs to the corresponding body TALLOC(Body*, bodyMap, mapLen+2); // map from index in bodyPs to the corresponding body
TSALLOC(NextRequest, bodyReqs, 10); // list of SETH/PRED-s to fill out when bodyMap is complete TSALLOC(NextRequest, bodyReqs, 10); // list of SETH/PRED-s to fill out when bodyMap is complete
@ -753,7 +753,7 @@ B evalBC(Body* b, Scope* sc, Block* bl) { // doesn't consume
vmStack[stackNum] = bcPos; vmStack[stackNum] = bcPos;
for(i32 i = 0; i < bcDepth; i++) fprintf(stderr," "); for(i32 i = 0; i < bcDepth; i++) fprintf(stderr," ");
print_BC(stderr,sbc,20); fprintf(stderr,"@%d in: ",bcPos); print_BC(stderr,sbc,20); fprintf(stderr,"@%d in: ",bcPos);
for (i32 i = 0; i < lgStack-origStack; i++) { if(i)fprintf(stderr,"; "); fprintI(stderr,origStack[i]); } fputc('\n',stderr); fflush(stderr); for (i32 i = 0; i < lgStack-origStack; i++) { if(i)fprintf(stderr,"; "); fprintI(stderr,origStack[i]); } fprintf(stderr,"\n"); fflush(stderr);
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
@ -955,7 +955,7 @@ B evalBC(Body* b, Scope* sc, Block* bl) { // doesn't consume
#if DEBUG_VM #if DEBUG_VM
for(i32 i = 0; i < bcDepth; i++) fprintf(stderr," "); for(i32 i = 0; i < bcDepth; i++) fprintf(stderr," ");
print_BC(stderr,sbc,20); fprintf(stderr,"@%d out: ",BCPOS(b, sbc)); print_BC(stderr,sbc,20); fprintf(stderr,"@%d out: ",BCPOS(b, sbc));
for (i32 i = 0; i < lgStack-origStack; i++) { if(i)fprintf(stderr,"; "); fprintI(stderr,origStack[i]); } fputc('\n',stderr); fflush(stderr); for (i32 i = 0; i < lgStack-origStack; i++) { if(i)fprintf(stderr,"; "); fprintI(stderr,origStack[i]); } fprintf(stderr,"\n"); fflush(stderr);
#endif #endif
} }
end:; end:;
@ -1380,7 +1380,7 @@ NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) {
B msg = vm_fmtPoint(src, emptyCVec(), comp->fullpath, cs, ce); B msg = vm_fmtPoint(src, emptyCVec(), comp->fullpath, cs, ce);
fprintsB(stderr, msg); fprintsB(stderr, msg);
dec(msg); dec(msg);
fputc('\n', stderr); fprintf(stderr, "\n");
popCatch(); popCatch();
return; return;
@ -1393,10 +1393,10 @@ native_print:
usz srcE = srcS; while (srcE<srcL) { u32 chr = o2cG(GetU(src, srcE)); if(chr=='\n')break; fprintCodepoint(stderr, chr); srcE++; } usz srcE = srcS; while (srcE<srcL) { u32 chr = o2cG(GetU(src, srcE)); if(chr=='\n')break; fprintCodepoint(stderr, chr); srcE++; }
if (ce>srcE) ce = srcE; if (ce>srcE) ce = srcE;
cs-= srcS; ce-= srcS; cs-= srcS; ce-= srcS;
fputc('\n', stderr); fprintf(stderr, "\n");
for (i32 i = 0; i < cs+start; i++) fputc(' ', stderr); for (i32 i = 0; i < cs+start; i++) fprintf(stderr, " ");
for (i32 i = cs; i < ce; i++) fputc('^', stderr); for (i32 i = cs; i < ce; i++) fprintf(stderr, "^");
fputc('\n', stderr); fprintf(stderr, "\n");
return; return;
//print_BCStream((u32*)i32arr_ptr(comp->bc)+bcPos); //print_BCStream((u32*)i32arr_ptr(comp->bc)+bcPos);
@ -1686,7 +1686,7 @@ NOINLINE void printErrMsg(B msg) {
void before_exit(void); void before_exit(void);
NOINLINE NORETURN void throwImpl(bool rethrow) { NOINLINE NORETURN void throwImpl(bool rethrow) {
// printf("gStack %p-%p:\n", gStackStart, gStack); B* c = gStack; // printf("gStack %p-%p:\n", gStackStart, gStack); B* c = gStack;
// while (c>gStackStart) { printI(*--c); putchar('\n'); } printf("gStack printed\n"); // while (c>gStackStart) { printI(*--c); printf("\n"); } printf("gStack printed\n");
NOGC_CHECK("throwing during noAlloc"); NOGC_CHECK("throwing during noAlloc");
if (!rethrow) envPrevHeight = envCurr-envStart + 1; if (!rethrow) envPrevHeight = envCurr-envStart + 1;
#if USE_SETJMP #if USE_SETJMP
@ -1705,7 +1705,7 @@ NOINLINE NORETURN void throwImpl(bool rethrow) {
} else { // uncaught error } else { // uncaught error
#endif #endif
assert(cf==cfStart); assert(cf==cfStart);
fprintf(stderr, "Error: "); printErrMsg(thrownMsg); fputc('\n',stderr); fflush(stderr); fprintf(stderr, "Error: "); printErrMsg(thrownMsg); fprintf(stderr,"\n"); fflush(stderr);
Env* envEnd = envStart+envPrevHeight; Env* envEnd = envStart+envPrevHeight;
unwindEnv(envStart-1); unwindEnv(envStart-1);
vm_pst(envCurr+1, envEnd); vm_pst(envCurr+1, envEnd);