From 72f25dad54e3ec42652d079d06e1a2266d5cb7b7 Mon Sep 17 00:00:00 2001 From: dzaima Date: Thu, 1 Sep 2022 13:29:03 +0300 Subject: [PATCH] =?UTF-8?q?bitarr=20=E2=86=951=20and=20=E2=86=952?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/README.md | 8 ++++---- src/builtins/fns.c | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/README.md b/src/README.md index 2295cc46..74786bf2 100644 --- a/src/README.md +++ b/src/README.md @@ -2,12 +2,12 @@ ## Conventions -Functions starting with `m_` allocate a new object. +Functions starting with `m_` create a new object (some NaN-boxed, some heap-allocated). Functions starting with `q_` are queries/predicates, and return a boolean. Functions ending with `R` are either supposed to be called rarely, or the caller expects that a part of it happens rarely. -Functions ending with `N` are non-inlined versions of another one. -Functions ending with `F` are rarely invoked fallback parts of a function. -Functions ending with `P` take a pointer argument. +Functions ending with `N` are non-inlined versions of another function. +Functions ending with `F` are infrequently needed fallback parts of a function. +Functions ending with `P` (or sometimes containing `p` or `P`) take a pointer argument (as opposed to a (NaN-boxed) `B`). Functions ending with `U` return (or take) a non-owned object (`U` = "unincremented"). Functions ending with `_c1` are monadic implementations, `_c2` are dyadic (see [builtin implementations](#builtin-implementations)) Variables starting with `bi_` are builtins (primitives or special values). diff --git a/src/builtins/fns.c b/src/builtins/fns.c index db917d34..b683178b 100644 --- a/src/builtins/fns.c +++ b/src/builtins/fns.c @@ -19,11 +19,12 @@ void ud_rec(B** p, usz d, usz r, i32* pos, usz* sh) { } } } +static Arr* bitUD[3]; B ud_c1(B t, B x) { if (isAtm(x)) { usz xu = o2s(x); if (LIKELY(xu<=I8_MAX)) { - if (RARE(xu==0)) return emptyIVec(); + if (RARE(xu<=2)) return taga(ptr_inc(bitUD[xu])); i8* rp; B r = m_i8arrv(&rp, xu); for (usz i = 0; i < xu; i++) rp[i] = i; return r; @@ -377,6 +378,7 @@ void fun_gcFn() { mm_visit(enclosed_0); mm_visit(enclosed_1); mm_visit(globalNameList); + for (i32 i = 0; i < 3; i++) mm_visitP(bitUD[i]); } @@ -395,4 +397,7 @@ void fns_init() { TIi(t_funBI,fn_im) = funBI_im; { u64* p; Arr* a=m_bitarrp(&p, 1); arr_shAlloc(a,0); *p= 0; enclosed_0=taga(a); } { u64* p; Arr* a=m_bitarrp(&p, 1); arr_shAlloc(a,0); *p=~0ULL; enclosed_1=taga(a); } + bitUD[0] = a(emptyIVec()); + { u64* p; B a=m_bitarrv(&p, 1); *p=0; bitUD[1] = a(a); } + { u64* p; B a=m_bitarrv(&p, 2); *p=0; bitp_set(p,1,1); bitUD[2] = a(a); } }