clean up some function names
This commit is contained in:
parent
2359e54661
commit
5636c1e2ca
@ -5,6 +5,8 @@
|
||||
Functions starting with `m_` allocate a new object.
|
||||
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 not inlined.
|
||||
Functions ending with `P` take a pointer argument.
|
||||
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).
|
||||
|
||||
@ -27,16 +27,16 @@ NORETURN NOINLINE void err(char* s) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
NOINLINE B c1_rare(B f, B x) { dec(x);
|
||||
NOINLINE B c1N(B f, B x) { dec(x);
|
||||
if (isMd(f)) thrM("Calling a modifier");
|
||||
return inc(VALIDATE(f));
|
||||
}
|
||||
NOINLINE B c2_rare(B f, B w, B x) { dec(w); dec(x);
|
||||
NOINLINE B c2N(B f, B w, B x) { dec(w); dec(x);
|
||||
if (isMd(f)) thrM("Calling a modifier");
|
||||
return inc(VALIDATE(f));
|
||||
}
|
||||
NOINLINE void value_freeR(Value* x) { value_free(x); }
|
||||
NOINLINE void decA_rare(B x) { dec(x); }
|
||||
NOINLINE void value_freeN(Value* x) { value_free(x); }
|
||||
NOINLINE void decA_N(B x) { dec(x); }
|
||||
void noop_visit(Value* x) { }
|
||||
NOINLINE B c1_bad(B f, B x) { thrM("This function can't be called monadically"); }
|
||||
NOINLINE B c2_bad(B f, B w, B x) { thrM("This function can't be called dyadically"); }
|
||||
|
||||
33
src/h.h
33
src/h.h
@ -541,42 +541,39 @@ enum Flags {
|
||||
static bool reusable(B x) { return v(x)->refc==1; }
|
||||
#define REUSE(X) ({ B x_ = (X); v(x_)->flags = 0; x_; })
|
||||
#define DEF_FREE(TY) static inline void TY##_freeO(Value* x); static void TY##_freeF(Value* x) { TY##_freeO(x); mm_free(x); } static inline void TY##_freeO(Value* x)
|
||||
static inline void value_free(Value* x) {
|
||||
// TIv(x,freeO)(x); mm_free(x);
|
||||
TIv(x,freeF)(x);
|
||||
}
|
||||
void value_freeR(Value* x);
|
||||
FORCE_INLINE void value_free(Value* x) { TIv(x,freeF)(x); }
|
||||
void value_freeN(Value* x);
|
||||
static void dec(B x) {
|
||||
if (!isVal(VALIDATE(x))) return;
|
||||
Value* vx = v(x);
|
||||
if(!--vx->refc) value_free(vx);
|
||||
}
|
||||
static void ptr_dec(void* x) { if(!--VALIDATEP((Value*)x)->refc) value_free(x); }
|
||||
static void ptr_decR(void* x) { if(!--VALIDATEP((Value*)x)->refc) value_freeR(x); }
|
||||
static inline void ptr_dec(void* x) { if(!--VALIDATEP((Value*)x)->refc) value_free(x); }
|
||||
static inline void ptr_decR(void* x) { if(!--VALIDATEP((Value*)x)->refc) value_freeN(x); }
|
||||
#define tptr_dec(X, F) ({ Value* x_ = (Value*)(X); if (!--VALIDATEP(x_)->refc) F(x_); })
|
||||
static void decR(B x) {
|
||||
if (!isVal(VALIDATE(x))) return;
|
||||
Value* vx = v(x);
|
||||
if(!--vx->refc) value_freeR(vx);
|
||||
if(!--vx->refc) value_freeN(vx);
|
||||
}
|
||||
void decA_rare(B x);
|
||||
static void decA(B x) { if (RARE(isVal(x))) decA_rare(x); } // decrement what's likely an atom
|
||||
static B inc(B x) {
|
||||
void decA_N(B x);
|
||||
static void decA(B x) { if (RARE(isVal(x))) decA_N(x); } // decrement what's likely an atom
|
||||
static inline B inc(B x) {
|
||||
if (isVal(VALIDATE(x))) v(x)->refc++;
|
||||
return x;
|
||||
}
|
||||
static void decG(B x) {
|
||||
static inline void decG(B x) {
|
||||
#if DEBUG
|
||||
assert(isVal(x));
|
||||
#endif
|
||||
Value* vx = v(x);
|
||||
if(!--vx->refc) value_free(vx);
|
||||
}
|
||||
static B incG(B x) { // inc for guaranteed heap objects
|
||||
static inline B incG(B x) { // inc for guaranteed heap-allocated objects
|
||||
v(VALIDATE(x))->refc++;
|
||||
return x;
|
||||
}
|
||||
static B incBy(B x, i64 am) { // am mustn't be negative!
|
||||
static inline B incBy(B x, i64 am) { // you most likely don't want am to be negative as this won't free on refc==0
|
||||
if (isVal(VALIDATE(x))) v(x)->refc+= am;
|
||||
return x;
|
||||
}
|
||||
@ -591,15 +588,15 @@ typedef struct Fun {
|
||||
} Fun;
|
||||
|
||||
|
||||
B c1_rare(B f, B x);
|
||||
B c2_rare(B f, B w, B x);
|
||||
B c1N(B f, B x);
|
||||
B c2N(B f, B w, B x);
|
||||
static B c1(B f, B x) { // BQN-call f monadically; consumes x
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, x));
|
||||
return c1_rare(f, x);
|
||||
return c1N(f, x);
|
||||
}
|
||||
static B c2(B f, B w, B x) { // BQN-call f dyadically; consumes w,x
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, w, x));
|
||||
return c2_rare(f, w, x);
|
||||
return c2N(f, w, x);
|
||||
}
|
||||
static void errMd(B x) { if(RARE(isMd(x))) thrM("Calling a modifier"); }
|
||||
// like c1/c2, but with less overhead on non-functions
|
||||
|
||||
@ -34,7 +34,7 @@ NOINLINE void mut_to(Mut* m, u8 n) {
|
||||
}
|
||||
}
|
||||
|
||||
NOINLINE B vec_addR(B w, B x) {
|
||||
NOINLINE B vec_add_new(B w, B x) {
|
||||
usz wia = a(w)->ia;
|
||||
MAKE_MUT(r, wia+1); mut_init(r, el_or(TI(w,elType), selfElType(x)));
|
||||
MUTG_INIT(r);
|
||||
|
||||
@ -231,9 +231,9 @@ static inline bool inplace_add(B w, B x) { // consumes x if returns true; fails
|
||||
}
|
||||
return false;
|
||||
}
|
||||
B vec_addR(B w, B x);
|
||||
B vec_add_new(B w, B x);
|
||||
static B vec_add(B w, B x) { // consumes both; fills may be wrong
|
||||
if (inplace_add(w, x)) return w;
|
||||
return vec_addR(w, x);
|
||||
return vec_add_new(w, x);
|
||||
}
|
||||
B vec_addN(B w, B x); // vec_add but not inlined
|
||||
|
||||
Loading…
Reference in New Issue
Block a user