use fill info to try to type an array

and bug fixes :)
This commit is contained in:
dzaima 2021-05-02 17:07:41 +03:00
parent 14e12ea544
commit bfd1e0d49e
6 changed files with 95 additions and 56 deletions

View File

@ -156,26 +156,58 @@ B withFill(B x, B fill) { // consumes both
break;
}
usz ia = a(x)->ia;
// if (isNum(fill)) {
if (isNum(fill)) {
BS2B xgetU = TI(x).getU;
{
B r = m_i32arrc(x); i32* rp = i32arr_ptr(r);
for (usz i = 0; i < ia; i++) {
B c = xgetU(x, i);
if (!q_i32(c)) { dec(r); goto l_f64; }
rp[i] = o2iu(c);
}
dec(x);
return r;
}
l_f64: {
B r = m_f64arrc(x); f64* rp = f64arr_ptr(r);
for (usz i = 0; i < ia; i++) {
B c = xgetU(x, i);
if (!q_f64(c)) { dec(r); goto base; }
rp[i] = o2fu(c);
}
dec(x);
return r;
}
// bool ints = true;
// for (usz i = 0; i < ia; i++) {
// B c = xgetU(x, i);
// if (!isNum(c)) goto base;
// if (!q_i32(c)) ints = false;
// }
// if (ints) {
// B r = m_i32arrc(x); i32* rp = i32arr_ptr(r);
// for (usz i = 0; i < ia; i++) rp[i] = o2iu(xgetU(x, i));
// dec(x);
// return r;
// } else {
// B r = m_f64arrc(x); f64* rp = f64arr_ptr(r);
// BS2B xgetU = TI(x).getU;
// for (usz i = 0; i < ia; i++) {
// B c = xgetU(x, i);
// if (!q_f64(c)) { dec(r); goto base; }
// rp[i] = o2f(c);
// }
// return r;
// } else if (isC32(fill)) {
// B r = m_c32arrc(x); u32* rp = c32arr_ptr(r);
// BS2B xgetU = TI(x).getU;
// for (usz i = 0; i < ia; i++) {
// B c = xgetU(x, i);
// if (!isC32(c)) { dec(r); goto base; }
// rp[i] = o2c(c);
// }
// for (usz i = 0; i < ia; i++) rp[i] = o2fu(xgetU(x, i));
// dec(x);
// return r;
// }
// base:
} else if (isC32(fill)) {
B r = m_c32arrc(x); u32* rp = c32arr_ptr(r);
BS2B xgetU = TI(x).getU;
for (usz i = 0; i < ia; i++) {
B c = xgetU(x, i);
if (!isC32(c)) { dec(r); goto base; }
rp[i] = o2c(c);
}
dec(x);
return r;
}
base:
B r = m_arr(fsizeof(FillArr,a,B,ia), t_fillarr);
arr_shCopy(r, x);
c(FillArr,r)->fill = fill;

View File

@ -89,6 +89,7 @@ void gc_forceGC() {
gc_visitBytes = 0; gc_freedBytes = 0;
gc_visitCount = 0; gc_freedCount = 0;
#endif
#ifdef ENABLE_GC
gc_visitRoots();
mm_forHeap(gc_tryFree);
gc_tagNew = gc_tagCurr;
@ -97,6 +98,7 @@ void gc_forceGC() {
fprintf(stderr, "GC kept %ldB from %ld objects, freed %ldB from %ld objects; took %.3fms\n", gc_visitBytes, gc_visitCount, gc_freedBytes, gc_freedCount, (nsTime()-start)/1e6);
#endif
gc_lastAlloc = allocB;
#endif
}

View File

@ -341,9 +341,9 @@ u32 o2c (B x) { if (!isC32(x)) thrM("Expected character"); return (u32)x.u; }
i32 o2iu (B x) { return isI32(x)? (i32)(u32)x.u : (i32)x.f; }
i32 o2cu (B x) { return (u32)x.u; }
usz o2su (B x) { return (usz)x.f; }
i64 o2fu (B x) { return x.f; }
f64 o2fu (B x) { return x.f; }
i64 o2i64u(B x) { return (i64)x.f; }
bool q_i32(B x) { return isI32(x) || isF64(x)&(x.f==(i32)x.f); }
bool q_i32(B x) { return isI32(x) | (isF64(x) && x.f==(f64)(i32)x.f); }
bool q_f64(B x) { return isF64(x) || isI32(x); }

View File

@ -4,6 +4,7 @@
#endif
#define CATCH_ERRORS // whether to allow catching errors; currently means refcounts won't be accurate and can't be tested for
#define ENABLE_GC // whether to ever garbage-collect
// #define HEAP_VERIFY // enable usage of heapVerify()
// #define ALLOC_STAT // store basic allocation statistics
// #define ALLOC_SIZES // store per-type allocation size statistics
@ -68,30 +69,6 @@ Block* ca3(B x) {
ssize_t getline(char** line, size_t* n, FILE* stream);
void printAllocStats() {
#ifdef ALLOC_STAT
printf("total ever allocated: %lu\n", talloc);
printf("allocated heap size: %ld\n", mm_heapAllocated());
printf("used heap size: %ld\n", mm_heapUsed());
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");
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);
#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);
for (i64 k = 0; k < t_COUNT; k++) printf("‿%u", c[k]);
printf("\n");
}
}
#endif
#endif
}
int main() {
hdr_init();

View File

@ -91,7 +91,7 @@ B eachm_fn(BB2B f, B fo, B x) { // consumes x; x must be array
f64* xp = f64arr_ptr(x);
B r = reuse? x : m_f64arrc(x);
f64* rp = f64arr_ptr(r);
rp[i++] = o2iu(cr);
rp[i++] = o2fu(cr);
for (; i < ia; i++) {
cr = f(fo, m_f64(xp[i]));
if (!q_f64(cr)) {
@ -100,7 +100,7 @@ B eachm_fn(BB2B f, B fo, B x) { // consumes x; x must be array
if (!reuse) dec(r);
goto fallback;
}
rp[i] = o2iu(cr);
rp[i] = o2fu(cr);
}
if (!reuse) dec(x);
return r;

View File

@ -265,3 +265,31 @@ static inline void onFree(Value* x) {
#endif
// x->refc = 0x61616161;
}
void printAllocStats() {
#ifdef ALLOC_STAT
printf("total ever allocated: %lu\n", talloc);
printf("allocated heap size: %ld\n", mm_heapAllocated());
printf("used heap size: %ld\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");
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);
#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);
for (i64 k = 0; k < t_COUNT; k++) printf("‿%u", c[k]);
printf("\n");
}
}
#endif
#endif
}