header file cleanup
This commit is contained in:
parent
229a32237a
commit
ca13fb567a
@ -398,15 +398,15 @@ B cell_c1(Md1D* d, B x) { B f = d->f;
|
||||
}
|
||||
B rank_c1(Md2D* d, B x) { B f = d->f; B g = d->g;
|
||||
f64 kf;
|
||||
bool gf = isFun(g);
|
||||
if (RARE(gf)) g = c1(g, inc(x));
|
||||
B gi = m_f64(0);
|
||||
if (RARE(isFun(g))) gi = g = c1iX(g, x);
|
||||
if (LIKELY(isNum(g))) {
|
||||
kf = req_whole(o2fG(g));
|
||||
} else {
|
||||
usz gia = check_rank_vec(g);
|
||||
SGetU(g); kf = GetU(g, gia==2).f;
|
||||
kf = IGetU(g, gia==2).f;
|
||||
decA(gi);
|
||||
}
|
||||
if (gf) dec(g);
|
||||
if (isAtm(x)) return c1wrap(f, x);
|
||||
ur xr = RNK(x);
|
||||
ur cr = cell_rank(xr, kf);
|
||||
@ -513,7 +513,7 @@ NOINLINE B for_cells_AA(B f, B w, B x, ur wcr, ur xcr, u32 chr) {
|
||||
B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g;
|
||||
f64 wf, xf;
|
||||
B gi = m_f64(0);
|
||||
if (RARE(isFun(g))) { gi = g = c2(g, inc(w), inc(x)); }
|
||||
if (RARE(isFun(g))) gi = g = c2iWX(g, w, x);
|
||||
if (LIKELY(isNum(g))) {
|
||||
wf = xf = req_whole(o2fG(g));
|
||||
} else {
|
||||
|
||||
@ -132,8 +132,8 @@ NOINLINE B before_c1F(Md2D* d, B x, B f) { errMd(f); return c2(d->g, c(Fun,f)->c
|
||||
NOINLINE B after_c1F (Md2D* d, B x, B g) { errMd(g); return c2(d->f, x, c(Fun,g)->c1(g,inc(x))); }
|
||||
B before_c1(Md2D* d, B x) { B f=d->f; return isCallable(f)? before_c1F(d, x, f) : c2(d->g, inc(f), x); }
|
||||
B after_c1 (Md2D* d, B x) { B g=d->g; return isCallable(g)? after_c1F (d, x, g) : c2(d->f, x, inc(g)); }
|
||||
B before_c2(Md2D* d, B w, B x) { return c2(d->g, c1i(d->f, w), x); }
|
||||
B after_c2 (Md2D* d, B w, B x) { return c2(d->f, w, c1i(d->g, x)); }
|
||||
B before_c2(Md2D* d, B w, B x) { return c2(d->g, c1I(d->f, w), x); }
|
||||
B after_c2 (Md2D* d, B w, B x) { return c2(d->f, w, c1I(d->g, x)); }
|
||||
B atop_c1(Md2D* d, B x) { return c1(d->f, c1(d->g, x)); }
|
||||
B atop_c2(Md2D* d, B w, B x) { return c1(d->f, c2(d->g, w, x)); }
|
||||
B over_c1(Md2D* d, B x) { return c1(d->f, c1(d->g, x)); }
|
||||
|
||||
@ -50,10 +50,10 @@ B decp_c1(B t, B x) {
|
||||
}
|
||||
|
||||
B primInd_c1(B t, B x) {
|
||||
if (!isVal(x)) return m_i32(rtLen);
|
||||
if (!isVal(x)) return m_i32(RT_LEN);
|
||||
if (isPrim(x)) { B r = m_i32(v(x)->flags-1); dec(x); return r; }
|
||||
dec(x);
|
||||
return m_i32(rtLen);
|
||||
return m_i32(RT_LEN);
|
||||
}
|
||||
|
||||
B nsFmt(B x);
|
||||
@ -1500,8 +1500,7 @@ static Body* file_nsGen;
|
||||
|
||||
#define OPTSYS_0(X)
|
||||
#define OPTSYS_1(X) X
|
||||
#define OPTSYS_B(COND) OPTSYS_##COND
|
||||
#define OPTSYS(COND) OPTSYS_B(COND)
|
||||
#define OPTSYS(COND) JOIN0(OPTSYS_,COND)
|
||||
|
||||
#define FOR_DEFAULT_SYSVALS(F) \
|
||||
F("out", U"•Out", bi_out) \
|
||||
|
||||
@ -26,7 +26,7 @@
|
||||
#include "core/arrFns.h"
|
||||
|
||||
#ifdef RT_VERIFY
|
||||
extern B r1Objs[rtLen];
|
||||
extern B r1Objs[RT_LEN];
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
52
src/h.h
52
src/h.h
@ -63,7 +63,6 @@
|
||||
// #define RT_PERF // time runtime primitives
|
||||
// #define RT_VERIFY // compare native and runtime versions of primitives
|
||||
// #define NO_RT // whether to completely disable self-hosted runtime loading
|
||||
// #define PRECOMP // execute just precompiled code at src/gen/interp
|
||||
|
||||
|
||||
#ifdef __OpenBSD__
|
||||
@ -83,7 +82,7 @@
|
||||
#define CATCH_ERRORS 0
|
||||
#endif
|
||||
|
||||
#define rtLen 64
|
||||
#define RT_LEN 64
|
||||
|
||||
#if CATCH_ERRORS
|
||||
#define PROPER_FILLS (EACH_FILLS&SFNS_FILLS)
|
||||
@ -178,6 +177,7 @@ typedef size_t ux;
|
||||
#define printf(...) replxx_print(global_replxx, __VA_ARGS__)
|
||||
#define fprintf(f, ...) replxx_print(global_replxx, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if USZ_64
|
||||
typedef u64 usz;
|
||||
#define USZ_MAX ((u64)(1ULL<<48))
|
||||
@ -187,6 +187,7 @@ typedef size_t ux;
|
||||
#define USZ_MAX ((u32)((1LL<<32)-1))
|
||||
#define CHECK_IA(IA,W) if ((IA) > ((1LL<<31)/W - 1000)) thrOOM()
|
||||
#endif
|
||||
|
||||
#if UNSAFE_SIZES
|
||||
#undef CHECK_IA
|
||||
#define CHECK_IA(IA,W)
|
||||
@ -194,12 +195,6 @@ typedef size_t ux;
|
||||
typedef u8 ur;
|
||||
#define UR_MAX 255
|
||||
|
||||
#define CTR_FOR(F)
|
||||
#define CTR_PRINT(N) if(N) printf(#N ": "N64u"\n", N);
|
||||
#define F(N) extern u64 N;
|
||||
CTR_FOR(F)
|
||||
#undef F
|
||||
|
||||
// .FF0 .111111111110000000000000000000000000000000000000000000000000000 infinity
|
||||
// .FF8 .111111111111000000000000000000000000000000000000000000000000000 qNaN
|
||||
// .FF. .111111111110nnn................................................ sNaN aka tagged aka not f64, if nnn≠0
|
||||
@ -222,11 +217,6 @@ static const u16 VAL_TAG = 0b1111111111110 ; // FFF. 1111111111110............
|
||||
#define tag(V, T) b(ptr2u64(V) | ftag(T))
|
||||
#define taga(V) tag(V,ARR_TAG)
|
||||
|
||||
void cbqn_init(void);
|
||||
|
||||
// #if __STDC_IEC_559__ == 0 // this has some issues on M1, so disabling for now
|
||||
// #error "IEEE 754 floating point number support is required for CBQN"
|
||||
// #endif
|
||||
typedef union B {
|
||||
u64 u;
|
||||
f64 f;
|
||||
@ -413,6 +403,7 @@ B toCells(B x); // consumes
|
||||
B toKCells(B x, ur k); // consumes
|
||||
B withFill(B x, B f); // consumes both
|
||||
|
||||
void cbqn_init(void);
|
||||
B bqn_exec(B str, B path, B args); // consumes all
|
||||
B bqn_execFile(B path, B args); // consumes
|
||||
B bqn_explain(B str, B path); // consumes str
|
||||
@ -426,11 +417,12 @@ NOINLINE NORETURN void thrF(char* s, ...);
|
||||
NOINLINE NORETURN void thrOOM(void);
|
||||
#if CATCH_ERRORS
|
||||
jmp_buf* prepareCatch(void);
|
||||
#define CATCH setjmp(*prepareCatch()) // use as `if (CATCH) { /*handle error*/ freeThrown(); return; } /*potentially erroring thing*/ popCatch(); /*no errors yay*/`
|
||||
#else // note: popCatch() must always be called if no error was caught, so no returns before it!
|
||||
#define CATCH false
|
||||
#define CATCH setjmp(*prepareCatch()) // use as `if (CATCH) { /*handle error*/ freeThrown(); return; } /*potentially erroring thing*/ popCatch(); /*no errors yay*/`
|
||||
void popCatch(void); // note: popCatch() must always be called if no error is thrown, so no returns before it!
|
||||
#else
|
||||
#define CATCH false
|
||||
#define popCatch()
|
||||
#endif
|
||||
void popCatch(void);
|
||||
extern B thrownMsg;
|
||||
void freeThrown(void);
|
||||
|
||||
@ -637,7 +629,7 @@ static void decR(B x) {
|
||||
if(!--vx->refc) value_freeF(vx);
|
||||
}
|
||||
void decA_F(B x);
|
||||
static void decA(B x) { if (RARE(isVal(x))) decA_F(x); } // decrement what's likely an atom
|
||||
static void decA(B x) { if (RARE(isVal(x))) decA_F(x); } // decrement a value which is likely to not be heap-allocated
|
||||
static inline B inc(B x) {
|
||||
if (isVal(VALIDATE(x))) v(x)->refc++;
|
||||
return x;
|
||||
@ -699,12 +691,12 @@ static B c2(B f, B w, B x) { // BQN-call f dyadically; consumes 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
|
||||
static B c1i(B f, B x) {
|
||||
SHOULD_INLINE B c1I(B f, B x) {
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, x));
|
||||
dec(x); errMd(f);
|
||||
return inc(f);
|
||||
}
|
||||
static B c2i(B f, B w, B x) {
|
||||
SHOULD_INLINE B c2I(B f, B w, B x) {
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, w, x));
|
||||
dec(w); dec(x); errMd(f);
|
||||
return inc(f);
|
||||
@ -714,16 +706,6 @@ static B c1iX(B f, B x) { // c1 with inc(x)
|
||||
errMd(f);
|
||||
return inc(f);
|
||||
}
|
||||
static B c2iX(B f, B w, B x) { // c2 with inc(x)
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, w, inc(x)));
|
||||
dec(w); errMd(f);
|
||||
return inc(f);
|
||||
}
|
||||
static B c2iW(B f, B w, B x) { // c2 with inc(w)
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, inc(w), x));
|
||||
dec(x); errMd(f);
|
||||
return inc(f);
|
||||
}
|
||||
static B c2iWX(B f, B w, B x) { // c2 with inc(w), inc(x)
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, inc(w), inc(x)));
|
||||
errMd(f);
|
||||
@ -741,13 +723,3 @@ struct Md2 {
|
||||
D2C1 c1; // f(md2d{this,f,g}, x); consumes x
|
||||
D2C2 c2; // f(md2d{this,f,g},w,x); consumes w,x
|
||||
};
|
||||
static B m1_d(B m, B f );
|
||||
static B m2_d(B m, B f, B g);
|
||||
static B m2_h(B m, B g);
|
||||
static B m_md1D(Md1* m, B f );
|
||||
static B m_md2D(Md2* m, B f, B g);
|
||||
static B m_md2H(Md2* m, B g);
|
||||
static B m_fork(B f, B g, B h);
|
||||
static B m_atop( B g, B h);
|
||||
|
||||
|
||||
|
||||
19
src/load.c
19
src/load.c
@ -63,9 +63,6 @@ FOR_PM2(FA,FM,FD)
|
||||
#undef FM
|
||||
#undef FD
|
||||
|
||||
#define F(N) u64 N;
|
||||
CTR_FOR(F)
|
||||
#undef F
|
||||
char* pfn_repr(u8 u) {
|
||||
switch(u) { default: return "(unknown function)";
|
||||
#define F(N,X) case pf_##N: return X;
|
||||
@ -94,7 +91,7 @@ char* pm2_repr(u8 u) {
|
||||
FOR_TI(F)
|
||||
#undef F
|
||||
|
||||
B r1Objs[rtLen];
|
||||
B r1Objs[RT_LEN];
|
||||
B rtWrap_wrap(B x, bool nnbi); // consumes
|
||||
void rtWrap_print(void);
|
||||
|
||||
@ -397,9 +394,9 @@ void load_init() { // very last init function
|
||||
/* ´˝`∘○⊸⟜⌾⊘◶ */ 1,1,1,1,1,1,1,1,1,1,
|
||||
/* ⎉⚇⍟⎊ */ 1,1,1,1
|
||||
};
|
||||
assert(sizeof(fruntime)/sizeof(B) == rtLen);
|
||||
for (u64 i = 0; i < rtLen; i++) inc(fruntime[i]);
|
||||
B frtObj = m_caB(rtLen, fruntime);
|
||||
assert(sizeof(fruntime)/sizeof(B) == RT_LEN);
|
||||
for (u64 i = 0; i < RT_LEN; i++) inc(fruntime[i]);
|
||||
B frtObj = m_caB(RT_LEN, fruntime);
|
||||
|
||||
#ifndef NO_RT
|
||||
B provide[] = {bi_type,bi_fill,bi_log,bi_grLen,bi_grOrd,bi_asrt,bi_add,bi_sub,bi_mul,bi_div,bi_pow,bi_floor,bi_eq,bi_le,bi_fne,bi_shape,bi_pick,bi_ud,bi_tbl,bi_scan,bi_fillBy,bi_val,bi_catch};
|
||||
@ -432,7 +429,7 @@ void load_init() { // very last init function
|
||||
|
||||
|
||||
|
||||
if (IA(rtObjRaw) != rtLen) err("incorrectly defined rtLen!");
|
||||
if (IA(rtObjRaw) != RT_LEN) err("incorrectly defined RT_LEN!");
|
||||
HArr_p runtimeH = m_harrUc(rtObjRaw);
|
||||
SGet(rtObjRaw)
|
||||
|
||||
@ -445,7 +442,7 @@ void load_init() { // very last init function
|
||||
rt_depth = Get(rtObjRaw, n_depth );
|
||||
rt_insert = Get(rtObjRaw, n_insert );
|
||||
|
||||
for (usz i = 0; i < rtLen; i++) {
|
||||
for (usz i = 0; i < RT_LEN; i++) {
|
||||
#ifdef RT_WRAP
|
||||
r1Objs[i] = Get(rtObjRaw, i); gc_add(r1Objs[i]);
|
||||
#endif
|
||||
@ -478,7 +475,7 @@ void load_init() { // very last init function
|
||||
(void)frtObj;
|
||||
(void)rtComplete;
|
||||
(void)runtime;
|
||||
for (usz i = 0; i < rtLen; i++) {
|
||||
for (usz i = 0; i < RT_LEN; i++) {
|
||||
B r = fruntime[i];
|
||||
if (isVal(r)) v(r)->flags|= i+1;
|
||||
}
|
||||
@ -514,7 +511,6 @@ void load_init() { // very last init function
|
||||
cbqn_heapVerify();
|
||||
#endif
|
||||
rtWrap_print();
|
||||
CTR_FOR(CTR_PRINT)
|
||||
print_allocStats();
|
||||
exit(0);
|
||||
#else // use compiler
|
||||
@ -562,7 +558,6 @@ void bqn_exit(i32 code) {
|
||||
cbqn_heapDump(NULL);
|
||||
#endif
|
||||
rtWrap_print();
|
||||
CTR_FOR(CTR_PRINT)
|
||||
print_allocStats();
|
||||
before_exit();
|
||||
exit(code);
|
||||
|
||||
@ -485,19 +485,17 @@ NOINLINE void apd_sh_fail(ApdMut* m, B x, u8 mode) {
|
||||
void apd_widen(ApdMut* m, B x, ApdFn** fns);
|
||||
ApdFn* apd_tot_fns[]; ApdFn* apd_sh0_fns[]; ApdFn* apd_sh1_fns[]; ApdFn* apd_sh2_fns[];
|
||||
|
||||
#define APD_CAT(A,B) A##B
|
||||
|
||||
#define APD_OR_FILL_0(X)
|
||||
#define APD_OR_FILL_1(X) \
|
||||
B f0=m->fill; if (noFill(f0)) goto noFill; \
|
||||
if (!fillEqualsGetFill(f0, X)) { dec(m->fill); m->fill=bi_noFill; } \
|
||||
noFill:;
|
||||
|
||||
#define APD_OR_FILL(EB, X) APD_CAT(APD_OR_FILL_,EB)(X)
|
||||
#define APD_OR_FILL(EB, X) JOIN0(APD_OR_FILL_,EB)(X)
|
||||
|
||||
#define APD_POS_0() m->pos
|
||||
#define APD_POS_1() m->obj->ia
|
||||
#define APD_POS(EB) APD_CAT(APD_POS_,EB)()
|
||||
#define APD_POS(EB) JOIN0(APD_POS_,EB)()
|
||||
|
||||
#define APD_WIDEN(TY) do { apd_widen(m, x, apd_##TY##_fns); return; } while(0)
|
||||
#define APD_INC_POS(EB)
|
||||
|
||||
9
src/vm.c
9
src/vm.c
@ -1309,14 +1309,11 @@ jmp_buf* prepareCatch() { // in the case of returning false, must call popCatch(
|
||||
cf->envDepth = (envCurr+1)-envStart;
|
||||
return &(cf++)->jmp;
|
||||
}
|
||||
#endif
|
||||
|
||||
void popCatch() {
|
||||
#if CATCH_ERRORS
|
||||
assert(cf>cfStart);
|
||||
cf--;
|
||||
#endif
|
||||
assert(cf>cfStart);
|
||||
cf--;
|
||||
}
|
||||
#endif
|
||||
|
||||
NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes prepend
|
||||
SGetU(src)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user