make non-varargs the default array creation method

This commit is contained in:
dzaima 2021-04-01 12:37:22 +03:00
parent a98365aac8
commit 9e48514f19
5 changed files with 17 additions and 33 deletions

2
cc.bqn
View File

@ -5,7 +5,7 @@ args↓˜↩ return
"call with argument specifying path of mlochbaum/BQN!"!2args
path(args)"/src/"
args˜1
L {"m_vaB("(𝕩)(","¨𝕩)")"}
L {"m_caB(" (𝕩)",(B[]){" (1","¨𝕩)"})"}
LI {"m_cai32("(𝕩)",(i32[]){"(1","¨𝕩)"})"}
# Escape the special characters that appear in BQN sources.
Esc{

View File

@ -48,21 +48,14 @@ HArr* toHArr(B x) {
B m_vaf64(usz sz, ...) {
va_list vargs;
va_start(vargs, sz);
B m_caf64(usz sz, f64* a) {
HArr_p r = m_harrv(sz);
for (usz i = 0; i < sz; i++) r.a[i] = m_f64(va_arg(vargs, f64));
va_end(vargs);
for (usz i = 0; i < sz; i++) r.a[i] = m_f64(a[i]);
return r.b;
}
B m_vaB(usz sz, ...) {
va_list vargs;
va_start(vargs, sz);
HArr_p r = m_harrv(sz);
for (usz i = 0; i < sz; i++) r.a[i] = va_arg(vargs, B);
va_end(vargs);
B m_caB(usz ia, B* a) {
HArr_p r = m_harrv(ia);
for (usz i = 0; i < ia; i++) r.a[i] = a[i];
return r.b;
}

View File

@ -24,13 +24,10 @@ B m_i32arrp(usz ia) { // doesn't write any shape/size info! be careful!
i32* i32arr_ptr(B x) { VT(x, t_i32arr); return c(I32Arr,x)->a; }
B m_vai32(usz sz, ...) {
va_list vargs;
va_start(vargs, sz);
B r = m_i32arrv(sz);
B m_cai32(usz ia, i32* a) {
B r = m_i32arrv(ia);
i32* rp = i32arr_ptr(r);
for (usz i = 0; i < sz; i++) rp[i] = va_arg(vargs, i32);
va_end(vargs);
for (usz i = 0; i < ia; i++) rp[i] = a[i];
return r;
}

View File

@ -45,12 +45,6 @@ B m_str32(u32* s) {
for (u64 i = 0; i < sz; i++) r.a[i] = m_c32(s[i]);
return r.b;
}
B m_cai32(usz ia, i32* a) {
B r = m_i32arrv(ia);
i32* rp = i32arr_ptr(r);
for (usz i = 0; i < ia; i++) rp[i] = a[i];
return r;
}
__ssize_t getline (char **__restrict __lineptr, size_t *restrict n, FILE *restrict stream);

View File

@ -13,6 +13,13 @@ void* aalloc(usz sz) { // actual allocate
void* p = malloc(sz);
return p;
}
void mm_free(Value* x) {
#ifdef ALLOC_STAT
ctr_f[x->type]++;
x->refc = 0x61616161;
#endif
free(x);
}
void* mm_allocN(usz sz, u8 type) {
Value* x = aalloc(sz);
@ -31,8 +38,8 @@ void* mm_allocN(usz sz, u8 type) {
#ifdef DEBUG
memset(x, 'a', sz);
#endif
x->flags = x->extra = x->mmInfo = x->type = 0;
x->refc = 1;
x->flags = 0;
x->type = type;
return x;
}
@ -40,13 +47,6 @@ B mm_alloc(usz sz, u8 type, u64 tag) {
assert(tag>1LL<<16); // make sure it's `ftag`ged :|
return b((u64)mm_allocN(sz,type) | tag);
}
void mm_free(Value* x) {
#ifdef ALLOC_STAT
ctr_f[x->type]++;
x->refc = 0x61616161;
#endif
free(x);
}
void mm_visit(B x) {
}