proper i64 formatting, move openbsd hack up
This commit is contained in:
parent
ebd6e1a222
commit
96f3089410
@ -18,7 +18,7 @@ Value* heap_curr;
|
||||
void heapVerify_checkFn(Value* v) {
|
||||
if (v->refc!=0) {
|
||||
#ifdef OBJ_COUNTER
|
||||
printf("delta %d for %s, uid %ld: ", v->refc, format_type(v->type), v->uid);
|
||||
printf("delta %d for %s, uid "N64d": ", v->refc, format_type(v->type), v->uid);
|
||||
#else
|
||||
printf("delta %d for %s: ", (i32)v->refc, format_type(v->type));
|
||||
#endif
|
||||
|
||||
@ -69,7 +69,7 @@ NOINLINE void print(B x) {
|
||||
else if (x.u==bi_noVar.u) printf("(unset variable placeholder)");
|
||||
else if (x.u==bi_badHdr.u) printf("(bad header note)");
|
||||
else if (x.u==bi_noFill.u) printf("(no fill placeholder)");
|
||||
else printf("(todo tag %lx)", x.u>>48);
|
||||
else printf("(todo tag "N64x")", x.u>>48);
|
||||
}
|
||||
|
||||
NOINLINE void printRaw(B x) {
|
||||
@ -137,18 +137,18 @@ NOINLINE B append_fmt(B s, char* p, ...) {
|
||||
assert(c);
|
||||
if (mode) {
|
||||
assert(c=='l'||c=='i');
|
||||
if (c=='i') snprintf(buf, 30, mode==1? "%u" : "%x", va_arg(a, u32));
|
||||
else snprintf(buf, 30, mode==1? "%lu" : "%lx", va_arg(a, u64));
|
||||
if (c=='i') snprintf(buf, 30, mode==1? "%u" : "%x", va_arg(a, u32));
|
||||
else snprintf(buf, 30, mode==1? N64u : N64x, va_arg(a, u64));
|
||||
} else {
|
||||
if (c=='i') {
|
||||
i32 v = va_arg(a, i32);
|
||||
if (v<0) AU("¯");
|
||||
snprintf(buf, 30, "%lu", (u64)(v<0?-v:v));
|
||||
snprintf(buf, 30, N64u, (u64)(v<0?-v:v));
|
||||
} else { assert(c=='l');
|
||||
i64 v = va_arg(a, i64);
|
||||
if (v<0) AU("¯");
|
||||
if (v==I64_MIN) snprintf(buf, 30, "9223372036854775808");
|
||||
else snprintf(buf, 30, "%lu", (u64)(v<0?-v:v));
|
||||
else snprintf(buf, 30, N64u, (u64)(v<0?-v:v));
|
||||
}
|
||||
}
|
||||
A8(buf);
|
||||
@ -156,7 +156,7 @@ NOINLINE B append_fmt(B s, char* p, ...) {
|
||||
}
|
||||
case 's': {
|
||||
usz v = va_arg(a, usz);
|
||||
snprintf(buf, 30, sizeof(usz)==4? "%u" : "%lu", v);
|
||||
snprintf(buf, 30, sizeof(usz)==4? "%u" : N64u, v);
|
||||
A8(buf);
|
||||
break;
|
||||
}
|
||||
@ -450,24 +450,24 @@ B bqn_merge(B x) { // consumes
|
||||
|
||||
NOINLINE void printAllocStats() {
|
||||
#ifdef ALLOC_STAT
|
||||
printf("total ever allocated: %lu\n", talloc);
|
||||
printf("allocated heap size: %ld\n", mm_heapAlloc);
|
||||
printf("used heap size: %ld\n", mm_heapUsed());
|
||||
printf("total ever allocated: "N64u"\n", talloc);
|
||||
printf("allocated heap size: "N64u"\n", mm_heapAlloc);
|
||||
printf("used heap size: "N64u"\n", mm_heapUsed());
|
||||
ctr_a[t_harr]+= ctr_a[t_harrPartial];
|
||||
ctr_a[t_harrPartial] = 0;
|
||||
printf("ctrA←"); for (i64 i = 0; i < t_COUNT; i++) { if(i)printf("‿"); printf("%lu", ctr_a[i]); } printf("\n");
|
||||
printf("ctrF←"); for (i64 i = 0; i < t_COUNT; i++) { if(i)printf("‿"); printf("%lu", ctr_f[i]); } printf("\n");
|
||||
printf("ctrA←"); for (i64 i = 0; i < t_COUNT; i++) { if(i)printf("‿"); printf(N64u, ctr_a[i]); } printf("\n");
|
||||
printf("ctrF←"); for (i64 i = 0; i < t_COUNT; i++) { if(i)printf("‿"); printf(N64u, ctr_f[i]); } printf("\n");
|
||||
printf("names←⟨"); for (i64 i = 0; i < t_COUNT; i++) { if(i)printf(","); printf("\"%s\"", format_type(i)); } printf("⟩\n");
|
||||
u64 leakedCount = 0;
|
||||
for (i64 i = 0; i < t_COUNT; i++) leakedCount+= ctr_a[i]-ctr_f[i];
|
||||
printf("leaked object count: %ld\n", leakedCount);
|
||||
printf("leaked object count: "N64u"\n", leakedCount);
|
||||
#ifdef ALLOC_SIZES
|
||||
for(i64 i = 0; i < actrc; i++) {
|
||||
u32* c = actrs[i];
|
||||
bool any = false;
|
||||
for (i64 j = 0; j < t_COUNT; j++) if (c[j]) any=true;
|
||||
if (any) {
|
||||
printf("%ld", i*4);
|
||||
printf(N64u, i*4);
|
||||
for (i64 k = 0; k < t_COUNT; k++) printf("‿%u", c[k]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
11
src/h.h
11
src/h.h
@ -55,12 +55,12 @@
|
||||
// #define PRECOMP // execute just precompiled code at src/gen/interp
|
||||
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
#define __wchar_t __wchar_t2 // horrible hack for BSD
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#ifdef __OpenBSD__
|
||||
#define __wchar_t __wchar_t2 // horrible hack for BSD
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
@ -107,6 +107,9 @@
|
||||
#define LIKELY(X) __builtin_expect(X,1)
|
||||
#define RARE(X) __builtin_expect(X,0)
|
||||
#define RFLD(X,T,F) ((T*)((char*)(X) - offsetof(T,F))) // reverse-read field: `T* x = …; E v = x->f; x == RFLD(v, T, f)`
|
||||
#define N64x "%"SCNx64
|
||||
#define N64d "%"SCNd64
|
||||
#define N64u "%"SCNu64
|
||||
|
||||
typedef u32 usz;
|
||||
typedef u8 ur;
|
||||
@ -114,7 +117,7 @@ typedef u8 ur;
|
||||
#define UR_MAX 255
|
||||
|
||||
#define CTR_FOR(F)
|
||||
#define CTR_PRINT(N) if(N) printf(#N ": %lu\n", N);
|
||||
#define CTR_PRINT(N) if(N) printf(#N ": "N64u"\n", N);
|
||||
#define F(N) extern u64 N;
|
||||
CTR_FOR(F)
|
||||
#undef F
|
||||
|
||||
@ -68,7 +68,7 @@ void gc_forceGC() {
|
||||
gc_tagNew = gc_tagCurr;
|
||||
gc_tagCurr^= 0x80;
|
||||
#ifdef LOG_GC
|
||||
fprintf(stderr, "GC kept %ldB from %ld objects, freed %ldB, including directly %ldB from %ld objects; took %.3fms\n", gc_visitBytes, gc_visitCount, startAllocB-allocB, gc_freedBytes, gc_freedCount, (nsTime()-start)/1e6);
|
||||
fprintf(stderr, "GC kept "N64d"B from "N64d" objects, freed "N64d"B, including directly "N64d"B from "N64d" objects; took %.3fms\n", gc_visitBytes, gc_visitCount, startAllocB-allocB, gc_freedBytes, gc_freedCount, (nsTime()-start)/1e6);
|
||||
#endif
|
||||
gc_lastAlloc = allocB;
|
||||
#endif
|
||||
|
||||
8
src/vm.c
8
src/vm.c
@ -579,7 +579,7 @@ B evalBC(Body* b, Scope* sc) { // doesn't consume
|
||||
}
|
||||
#ifdef DEBUG_VM
|
||||
for(i32 i = 0; i < bcDepth; i++) printf(" ");
|
||||
printBC(sbc); printf("@%ld: ", BCPOS(b, sbc));
|
||||
printBC(sbc); printf("@"N64d": ", BCPOS(b, sbc));
|
||||
for (i32 i = 0; i < b->maxStack; i++) { if(i)printf(" ⋄ "); print(gStack[i]); } putchar('\n'); fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
@ -802,7 +802,7 @@ NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) {
|
||||
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);
|
||||
int start = pos==-1? 0 : printf(N64d": ", pos);
|
||||
usz srcL = a(src)->ia;
|
||||
BS2B srcGetU = TI(src).getU;
|
||||
usz srcS = cs;
|
||||
@ -818,7 +818,7 @@ NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) {
|
||||
putchar('\n');
|
||||
// printf(" inds:%d…%d\n", cinds, cinde);
|
||||
} else {
|
||||
if (pos!=-1) printf("%ld: ", pos);
|
||||
if (pos!=-1) printf(N64d": ", pos);
|
||||
printf("source unknown\n");
|
||||
}
|
||||
}
|
||||
@ -830,7 +830,7 @@ NOINLINE void vm_pst(Env* s, Env* e) {
|
||||
while (i>=0) {
|
||||
Env* c = s+i;
|
||||
if (l>30 && i==l-10) {
|
||||
printf("(%ld entries omitted)\n", l-20);
|
||||
printf("("N64d" entries omitted)\n", l-20);
|
||||
i = 10;
|
||||
}
|
||||
Comp* comp = c->sc->body->comp;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user