From c078f62b1f1aa5760985ba8c496eb729fd60f7be Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 28 Jan 2024 16:25:14 +0200 Subject: [PATCH] add GLOBAL, INIT_GLOBAL, or const to globals --- build/src/build.bqn | 4 +- src/builtins.h | 5 +- src/builtins/arithd.c | 6 +- src/builtins/arithm.c | 2 +- src/builtins/cmp.c | 2 +- src/builtins/compare.c | 4 +- src/builtins/fns.c | 10 ++-- src/builtins/fold.c | 2 +- src/builtins/grade.h | 4 +- src/builtins/group.c | 2 +- src/builtins/internal.c | 8 +-- src/builtins/inverse.c | 6 +- src/builtins/md2.c | 6 +- src/builtins/search.c | 4 +- src/builtins/select.c | 6 +- src/builtins/slash.c | 2 +- src/builtins/sysfn.c | 96 +++++++++++++++--------------- src/builtins/transpose.c | 2 +- src/core.h | 2 +- src/core/arrFns.h | 12 ++-- src/core/derv.c | 4 +- src/core/gstack.h | 6 +- src/core/heap.c | 12 ++-- src/core/mm.c | 2 +- src/core/stuff.c | 23 ++++--- src/core/stuff.h | 20 +++---- src/core/tyarr.c | 12 ++-- src/ffi.c | 12 ++-- src/h.h | 13 ++-- src/jit/nvm_x86_64.c | 8 +-- src/jit/x86_64.h | 6 +- src/load.c | 50 ++++++++-------- src/load.h | 4 +- src/main.c | 63 ++++++++++---------- src/nfns.c | 4 +- src/ns.c | 4 +- src/opt/gc.c | 26 ++++---- src/opt/gc.h | 2 +- src/opt/mm_2buddy.c | 6 +- src/opt/mm_2buddy.h | 10 ++-- src/opt/mm_buddy.c | 4 +- src/opt/mm_buddy.h | 10 ++-- src/opt/mm_buddyTemplate.c | 8 +-- src/opt/mm_malloc.h | 4 +- src/singeli/c/arithdDispatch.c | 2 +- src/singeli/src/genArithTables.bqn | 4 +- src/utils/calls.h | 8 +-- src/utils/file.c | 4 +- src/utils/hash.c | 2 +- src/utils/hash.h | 2 +- src/utils/mut.c | 46 +++++++------- src/utils/mut.h | 4 +- src/utils/ryu.c | 4 +- src/vm.c | 50 ++++++++-------- src/vm.h | 16 ++--- 55 files changed, 320 insertions(+), 320 deletions(-) diff --git a/build/src/build.bqn b/build/src/build.bqn index 5011d9ad..2ee88d56 100755 --- a/build/src/build.bqn +++ b/build/src/build.bqn @@ -730,7 +730,7 @@ cachedBin‿linkerCache ← { vnameX‿vname ← {po.versionName≡""? "on "⊸∾⊸⋈ "commit "∾("??"GitCmd ⟨"rev-parse", "HEAD"⟩)∾{""≡"determining version"GitCmd ⟨"status", "--porcelain", "src"⟩? ""; "-dirty"}; ⋈˜ po.versionName} src ← ∾⟨ - "char* cbqn_versionInfo = """ + "char* const cbqn_versionInfo = """ ∾∾⟜"\n"¨ ×∘≠¨⊸/ ⟨ "CBQN "∾vnameX @@ -745,7 +745,7 @@ cachedBin‿linkerCache ← { # "build invocation: "⊸∾⍟(×≠) ¯1↓∾∾⟜' '¨ •args """;", @+10 - "char* cbqn_versionString = """∾vname∾""";", @+10 + "char* const cbqn_versionString = """∾vname∾""";", @+10 ⟩ { •file.Exists AtRoot srcFile? src≡•FChars AtRoot srcFile? @; # don't update diff --git a/src/builtins.h b/src/builtins.h index 2688661e..20490822 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -52,8 +52,7 @@ enum PrimNumbers { /* ´˝`∘○⊸⟜⌾⊘◶ */ n_fold , n_insert , n_scan , n_atop , n_over , n_before , n_after , n_under, n_val , n_cond, /* ⎉⚇⍟⎊ */ n_rank , n_depth , n_repeat, n_catch }; -extern FC1 rt_invFnRegFn; -extern FC1 rt_invFnSwapFn; +extern GLOBAL FC1 rt_invFnRegFn, rt_invFnSwapFn; #ifdef RT_WRAP @@ -102,7 +101,7 @@ static bool isPervasiveDyExt(B x) { return false; } -extern B +extern GLOBAL B #define F(N,X) bi_##N, FOR_PFN(F,F,F) FOR_PM1(F,F,F) diff --git a/src/builtins/arithd.c b/src/builtins/arithd.c index 1be2c76b..d2a756ae 100644 --- a/src/builtins/arithd.c +++ b/src/builtins/arithd.c @@ -25,7 +25,7 @@ B leading_axis_arith(FC2 fc2, B w, B x, usz* wsh, usz* xsh, ur mr); #if SINGELI_SIMD #include "../singeli/c/arithdDispatch.c" - static AndBytesFn andBytes_fn = simd_andBytes; + static const AndBytesFn andBytes_fn = simd_andBytes; #else static void base_andBytes(u8* r, u8* x, u64 repeatedMask, u64 numBytes) { u64* x64 = (u64*)x; usz i; @@ -35,7 +35,7 @@ B leading_axis_arith(FC2 fc2, B w, B x, usz* wsh, usz* xsh, ur mr); for (usz j = 0; j < (numBytes&7); j++) r[i*8 + j] = v>>(j*8); } } - static AndBytesFn andBytes_fn = base_andBytes; + static const AndBytesFn andBytes_fn = base_andBytes; #endif B floor_c1(B t, B x); @@ -180,7 +180,7 @@ static B modint_AS(B w, B xv) { return modint_AA(w, C2(shape, C1(fne, incG(w)) GC2f("√", root , pow(x.f+0, 1.0/(w.f+0)), NOUNROLL,,,,,) GC2f("⋆", pow , pow(w.f+0, x.f), NOUNROLL,,,,,) GC2f("⋆⁼",log , log(x.f)/log(w.f), NOUNROLL,,,,,) - static u64 repeatNum[] = { + static u64 const repeatNum[] = { [el_i8 ] = 0x0101010101010101ULL, [el_i16] = 0x0001000100010001ULL, [el_i32] = 0x0000000100000001ULL, diff --git a/src/builtins/arithm.c b/src/builtins/arithm.c index 57075709..39d551f6 100644 --- a/src/builtins/arithm.c +++ b/src/builtins/arithm.c @@ -163,7 +163,7 @@ B eq_c1(B t, B x) { if (isAtm(x)) { decA(x); return m_i32(0); } B r = m_i32(RNK( B ne_c1(B t, B x) { if (isAtm(x)) { decA(x); return m_i32(1); } B r = m_f64(*SH(x)); decG(x); return r; } -static B mathNS; +static GLOBAL B mathNS; B getMathNS(void) { if (mathNS.u == 0) { #define F(X) incG(bi_##X), diff --git a/src/builtins/cmp.c b/src/builtins/cmp.c index 2080c124..3fa9c370 100644 --- a/src/builtins/cmp.c +++ b/src/builtins/cmp.c @@ -48,7 +48,7 @@ CMP_REC(ne, ne, swapped=0;) #undef CMP_REC #define CMPFN(A,F,S,T) A##_##F##S##_##T -#define FN_LUT_T(B,F,S,...) Cmp##S##Fn B##_##F##S +#define FN_LUT_T(B,F,S,...) INIT_GLOBAL Cmp##S##Fn B##_##F##S #define FN_LUT_C(B,A,F,S) FN_LUT_T(B,F,S)[] = {CMPFN(A,F,S,u1), CMPFN(A,F,S,i8), CMPFN(A,F,S,i16), CMPFN(A,F,S,i32), CMPFN(A,F,S,f64), CMPFN(A,F,S,u8), CMPFN(A,F,S,u16), CMPFN(A,F,S,u32)} #define FN_LUT_A(B,F,S) FN_LUT_T(B,F,S)[8] diff --git a/src/builtins/compare.c b/src/builtins/compare.c index 1ae6046f..a8b5268f 100644 --- a/src/builtins/compare.c +++ b/src/builtins/compare.c @@ -89,7 +89,7 @@ bool atomEEqual(B w, B x) { // doesn't consume // Functions in eqFns compare segments for matching // data argument comes from eqFnData static const u8 n = 99; -u8 eqFnData[] = { // for the main diagonal, amount to shift length by; otherwise, whether to swap arguments +u8 const eqFnData[] = { // for the main diagonal, amount to shift length by; otherwise, whether to swap arguments 0,0,0,0,0,n,n,n, 1,0,0,0,0,n,n,n, 1,1,1,0,0,n,n,n, @@ -144,7 +144,7 @@ u8 eqFnData[] = { // for the main diagonal, amount to shift length by; otherwise #undef DEF_EQ #endif bool notEq(void* a, void* b, u64 l, u64 data) { return false; } -EqFn eqFns[] = { +INIT_GLOBAL EqFn eqFns[] = { F(1_1), F(1_8), F(1_16), F(1_32), F(1_f64), notEq, notEq, notEq, F(1_8), F(8_8), F(s8_16), F(s8_32), F(s8_f64), notEq, notEq, notEq, F(1_16), F(s8_16), F(8_8), F(s16_32), F(s16_f64), notEq, notEq, notEq, diff --git a/src/builtins/fns.c b/src/builtins/fns.c index cf9f0934..56b1e9d3 100644 --- a/src/builtins/fns.c +++ b/src/builtins/fns.c @@ -91,8 +91,8 @@ NOINLINE B list_range(B x) { return taga(r); } -Arr* bitUD[3]; -B bit2x[2]; // ⟨0‿1 ⋄ 1‿0⟩ +GLOBAL Arr* bitUD[3]; +GLOBAL B bit2x[2]; // ⟨0‿1 ⋄ 1‿0⟩ B ud_c1(B t, B x) { if (!isAtm(x)) return list_range(x); usz xu = o2s(x); @@ -229,7 +229,7 @@ NOINLINE B for_cells_SA(B f, B w, B x, ur xcr, ur xr, u32 chr); // from cells.c B eq_c2(B, B, B); B feq_c2(B, B, B); B slash_c1(B, B); -extern B rt_find; +extern GLOBAL B rt_find; B find_c2(B t, B w, B x) { ur wr = isAtm(w) ? 0 : RNK(w); ur xr = isAtm(x) ? 0 : RNK(x); @@ -303,8 +303,8 @@ B find_c2(B t, B w, B x) { decG(x); decG(w); return r; } -static H_b2i* globalNames; -B globalNameList; +static GLOBAL H_b2i* globalNames; +GLOBAL B globalNameList; i32 str2gid(B s) { if (globalNames==NULL) { globalNames = m_b2i(32); diff --git a/src/builtins/fold.c b/src/builtins/fold.c index 1937df9a..6c1cfd82 100644 --- a/src/builtins/fold.c +++ b/src/builtins/fold.c @@ -345,7 +345,7 @@ static B m1c1(B t, B f, B x) { // consumes x decG(fn); return r; } -extern B rt_insert; +extern GLOBAL B rt_insert; extern B insert_base(B f, B x, bool has_w, B w); // from cells.c B insert_c1(Md1D* d, B x) { B f = d->f; diff --git a/src/builtins/grade.h b/src/builtins/grade.h index 59d6c360..80d3555d 100644 --- a/src/builtins/grade.h +++ b/src/builtins/grade.h @@ -254,8 +254,8 @@ B SORT_C1(B t, B x) { #endif -extern Arr* bitUD[3]; // from fns.c -extern B bit2x[2]; +extern GLOBAL Arr* bitUD[3]; // from fns.c +extern GLOBAL B bit2x[2]; extern B grade_bool(B x, usz ia, bool up); // slash.c #define GRADE_CHR GRADE_UD("⍋","⍒") diff --git a/src/builtins/group.c b/src/builtins/group.c index aa568f43..f32c2e02 100644 --- a/src/builtins/group.c +++ b/src/builtins/group.c @@ -259,7 +259,7 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) { return taga(r); } -extern B rt_group; +extern GLOBAL B rt_group; B group_c2(B t, B w, B x) { if (isAtm(x)) thrM("⊔: 𝕩 must be an array"); ur xr = RNK(x); diff --git a/src/builtins/internal.c b/src/builtins/internal.c index c80cb2c1..5d3987ce 100644 --- a/src/builtins/internal.c +++ b/src/builtins/internal.c @@ -79,10 +79,10 @@ B info_c1(B t, B x) { F(Af) F(Sf) F(AfInc) F(SfInc) \ F(Ab) F(AbInc) -#define F(X) static B v_##X; +#define F(X) static GLOBAL B v_##X; FOR_VARIATION(F) #undef F -static B listVariations_def; +static GLOBAL B listVariations_def; B listVariations_c2(B t, B w, B x) { if (!isArr(x)) thrM("•internal.ListVariations: 𝕩 must be an array"); @@ -162,7 +162,7 @@ static bool u8_get(u8** cv, u8* cE, const char* x) { } -static B variation_refs; +static GLOBAL B variation_refs; B variation_c2(B t, B w, B x) { if (!isArr(w)) thrM("•internal.Variation: Non-array 𝕨"); if (!isArr(x)) thrM("•internal.Variation: Non-array 𝕩"); @@ -380,7 +380,7 @@ B unshare_c1(B t, B x) { dec(x); return r; } -static B internalNS; +static GLOBAL B internalNS; B getInternalNS(void) { if (internalNS.u == 0) { #define F(X) v_##X = m_c8vec_0(#X); diff --git a/src/builtins/inverse.c b/src/builtins/inverse.c index 7eec0ade..cb560ff2 100644 --- a/src/builtins/inverse.c +++ b/src/builtins/inverse.c @@ -3,14 +3,14 @@ #include "../nfns.h" -static NFnDesc* fn_invRegDesc; -static NFnDesc* fn_invSwapDesc; +static GLOBAL NFnDesc* fn_invRegDesc; +static GLOBAL NFnDesc* fn_invSwapDesc; B fn_invReg_c1 (B t, B x) { B f = nfn_objU(t); return TI(f, fn_im)(f, x); } B fn_invReg_c2 (B t, B w, B x) { B f = nfn_objU(t); return TI(f, fn_ix)(f, w, x); } B fn_invSwap_c1(B t, B x) { B f = nfn_objU(t); return TI(f, fn_is)(f, x); } B fn_invSwap_c2(B t, B w, B x) { B f = nfn_objU(t); return TI(f, fn_iw)(f, w, x); } -extern B rt_undo; +extern GLOBAL B rt_undo; B undo_c1(Md1D* d, B x) { B f = d->f; if (isFun(f)) return TI(f, fn_im)(f, x); SLOW1("!runtime undo", x); diff --git a/src/builtins/md2.c b/src/builtins/md2.c index 0b94ec98..876a241e 100644 --- a/src/builtins/md2.c +++ b/src/builtins/md2.c @@ -8,7 +8,7 @@ B val_c1(Md2D* d, B x) { return c1(d->f, x); } B val_c2(Md2D* d, B w, B x) { return c2(d->g, w,x); } #if CATCH_ERRORS && !BI_CATCH_DISABLED -extern B lastErrMsg; // sysfn.c +extern GLOBAL B lastErrMsg; // sysfn.c B fillBy_c1(Md2D* d, B x) { B xf=getFillQ(x); @@ -53,7 +53,7 @@ B catch_c1(Md2D* d, B x) { return c1(d->f, x); } B catch_c2(Md2D* d, B w, B x) { return c2(d->f, w,x); } #endif -extern B rt_undo; +extern GLOBAL B rt_undo; void repeat_bounds(i64* bound, B g) { // doesn't consume #define UPD_BOUNDS(I) ({ i64 i_ = (I); if (i_bound[1]) bound[1] = i_; }) if (isArr(g)) { @@ -218,7 +218,7 @@ B depthf_c2(B t, B w, B x) { if (isArr(w) || isArr(x)) return eachd_fn(t, w, x, depthf_c2); else return c2(t, w, x); } -extern B rt_depth; +extern GLOBAL B rt_depth; B depth_c1(Md2D* d, B x) { if (isF64(d->g) && o2fG(d->g)==0) { if (isArr(x)) return eachm_fn(d->f, x, depthf_c1); diff --git a/src/builtins/search.c b/src/builtins/search.c index d80cc7e7..8ce7d8d1 100644 --- a/src/builtins/search.c +++ b/src/builtins/search.c @@ -44,7 +44,7 @@ extern NOINLINE void memset64(u64* p, u64 v, usz l) { for (usz i=0; i3) thrF("%U: 𝕨 must be a vector with at most 3 items, but had shape %H", name, w); usz ia = IA(w); SGet(w) @@ -323,10 +323,10 @@ B hash_c1(B t, B x) { -static Body* rand_ns; -static B rand_rangeName; static NFnDesc* rand_rangeDesc; -static B rand_dealName; static NFnDesc* rand_dealDesc; -static B rand_subsetName; static NFnDesc* rand_subsetDesc; +static GLOBAL Body* rand_ns; +static GLOBAL B rand_rangeName; static GLOBAL NFnDesc* rand_rangeDesc; +static GLOBAL B rand_dealName; static GLOBAL NFnDesc* rand_dealDesc; +static GLOBAL B rand_subsetName; static GLOBAL NFnDesc* rand_subsetDesc; #define RAND_START Scope* sc = c(NS,nfn_objU(t))->sc; \ u64 seed = sc->vars[0].u | sc->vars[1].u<<32; #define RAND_END sc->vars[0].u = seed>>32; \ @@ -418,8 +418,8 @@ B rand_range_c2(B t, B w, B x) { return taga(r); } -extern Arr* bitUD[3]; // from fns.c -extern B bit2x[2]; +extern GLOBAL Arr* bitUD[3]; // from fns.c +extern GLOBAL B bit2x[2]; B intRange16(ux s, ux n); B intRange32(ux s, ux n); void intRange32Fill(i32* xp, ux s, ux n); @@ -649,7 +649,7 @@ B makeRand_c1(B t, B x) { for (i32 i = 2; i < 5; i++) nfn_swapObj(sc->vars[i], incG(r)); return r; } -static B randNS; +static GLOBAL B randNS; B getRandNS(void) { if (randNS.u == 0) { #if RANDSEED==0 @@ -661,9 +661,9 @@ B getRandNS(void) { } return incG(randNS); } -static NFnDesc* bqnDesc; -static NFnDesc* rebqnDesc; -static NFnDesc* rebqnResDesc; +static GLOBAL NFnDesc* bqnDesc; +static GLOBAL NFnDesc* rebqnDesc; +static GLOBAL NFnDesc* rebqnResDesc; B rebqn_c1(B t, B x) { if (!isNsp(x)) thrM("•ReBQN: Argument must be a namespace"); B repl = ns_getC(x, "repl"); @@ -696,7 +696,7 @@ B repl_c1(B t, B x) { } #if CATCH_ERRORS -B lastErrMsg; +GLOBAL B lastErrMsg; B currentError_c1(B t, B x) { if (isNsp(x)) thrM("•CurrentError: Namespace 𝕩 is reserved"); dec(x); @@ -707,14 +707,14 @@ B currentError_c1(B t, B x) { B currentError_c1(B t, B x) { thrM("•CurrentError: No errors as error catching has been disabled"); } #endif -static Body* hashmap_ns; -static NFnDesc* hashmap_getDesc; -static NFnDesc* hashmap_hasDesc; -static NFnDesc* hashmap_setDesc; -static NFnDesc* hashmap_deleteDesc; -static NFnDesc* hashmap_countDesc; -static NFnDesc* hashmap_keysDesc; -static NFnDesc* hashmap_valuesDesc; +static GLOBAL Body* hashmap_ns; +static GLOBAL NFnDesc* hashmap_getDesc; +static GLOBAL NFnDesc* hashmap_hasDesc; +static GLOBAL NFnDesc* hashmap_setDesc; +static GLOBAL NFnDesc* hashmap_deleteDesc; +static GLOBAL NFnDesc* hashmap_countDesc; +static GLOBAL NFnDesc* hashmap_keysDesc; +static GLOBAL NFnDesc* hashmap_valuesDesc; // Hash object handling defined in search.c extern B hashmap_build(B keys, usz n); extern B hashmap_lookup(B* vars, B w, B x); @@ -761,7 +761,7 @@ B hashMap_c2(B t, B w, B x) { return ns; } -static NFnDesc* fileAtDesc; +static GLOBAL NFnDesc* fileAtDesc; B fileAt_c1(B d, B x) { return path_rel(nfn_objU(d), x, "•file.At"); } @@ -771,7 +771,7 @@ B fileAt_c2(B d, B w, B x) { dec(w); return r; } -static NFnDesc* fCharsDesc; +static GLOBAL NFnDesc* fCharsDesc; B fchars_c1(B d, B x) { return path_chars(path_rel(nfn_objU(d), x, "•file.Chars")); } @@ -782,7 +782,7 @@ B fchars_c2(B d, B w, B x) { dec(x); return p; } -static NFnDesc* fBytesDesc; +static GLOBAL NFnDesc* fBytesDesc; B fbytes_c1(B d, B x) { I8Arr* tf = path_bytes(path_rel(nfn_objU(d), x, "•file.Bytes")); usz ia = PIA(tf); @@ -798,7 +798,7 @@ B fbytes_c2(B d, B w, B x) { dec(x); return p; } -static NFnDesc* fLinesDesc; +static GLOBAL NFnDesc* fLinesDesc; B flines_c1(B d, B x) { return path_lines(path_rel(nfn_objU(d), x, "•file.Lines")); } @@ -820,7 +820,7 @@ B flines_c2(B d, B w, B x) { decG(s); return p; } -static NFnDesc* importDesc; +static GLOBAL NFnDesc* importDesc; @@ -863,18 +863,18 @@ B import_c1(B d, B x) { } -static NFnDesc* fTypeDesc; -static NFnDesc* fCreatedDesc; -static NFnDesc* fAccessedDesc; -static NFnDesc* fModifiedDesc; -static NFnDesc* fSizeDesc; -static NFnDesc* fExistsDesc; -static NFnDesc* fListDesc; -static NFnDesc* fMapBytesDesc; -static NFnDesc* createdirDesc; -static NFnDesc* realpathDesc; -static NFnDesc* renameDesc; -static NFnDesc* removeDesc; +static GLOBAL NFnDesc* fTypeDesc; +static GLOBAL NFnDesc* fCreatedDesc; +static GLOBAL NFnDesc* fAccessedDesc; +static GLOBAL NFnDesc* fModifiedDesc; +static GLOBAL NFnDesc* fSizeDesc; +static GLOBAL NFnDesc* fExistsDesc; +static GLOBAL NFnDesc* fListDesc; +static GLOBAL NFnDesc* fMapBytesDesc; +static GLOBAL NFnDesc* createdirDesc; +static GLOBAL NFnDesc* realpathDesc; +static GLOBAL NFnDesc* renameDesc; +static GLOBAL NFnDesc* removeDesc; B list_c1(B d, B x) { return path_list(path_rel(nfn_objU(d), x, "•file.List")); @@ -1248,7 +1248,7 @@ B tErrRaw_c1(B t, B x) { return x; } -static B termNS; +static GLOBAL B termNS; B getTermNS(void) { if (termNS.u == 0) { #define F(X) incG(bi_##X), @@ -1312,7 +1312,7 @@ B nHas_c2(B t, B w, B x) { decG(w); decG(x); return m_i32(!q_N(r)); } -static B nsNS; +static GLOBAL B nsNS; B getNsNS(void) { if (nsNS.u == 0) { #define F(X) incG(bi_##X), @@ -1612,7 +1612,7 @@ DEF_OP2(and) DEF_OP2(or) DEF_OP2(xor) DEF_OP2(add) DEF_OP2(sub) DEF_OP2(mul) #undef DEF_OP2 -static B bitNS; +static GLOBAL B bitNS; B getBitNS(void) { if (bitNS.u == 0) { #define F(X) incG(bi_bit##X), @@ -1627,7 +1627,7 @@ B getBitNS(void) { B getInternalNS(void); B getMathNS(void); -static Body* file_nsGen; +static GLOBAL Body* file_nsGen; #if FFI || FOR_BUILD #define FFIOPT 1 @@ -1691,10 +1691,10 @@ static Body* file_nsGen; F("rebqn", U"•ReBQN", tag(22,VAR_TAG)) \ /* end of FOR_DEFAULT_SYSVALS */ -NFnDesc* ffiloadDesc; +GLOBAL NFnDesc* ffiloadDesc; B ffiload_c2(B t, B w, B x); B indexOf_c2(B t, B w, B x); -bool fileInit; +GLOBAL bool fileInit; B invalidFn_c1 (B t, B x) { thrM("Using an invalid function"); } @@ -1729,10 +1729,10 @@ static NOINLINE void initSysDesc() { } #if HAS_VERSION -extern char* cbqn_versionString; +extern char* const cbqn_versionString; #endif -static B platformNS; +static GLOBAL B platformNS; static B getPlatformNS(void) { if (platformNS.u == 0) { @@ -1877,14 +1877,14 @@ B sys_c1(B t, B x) { } -static char* dsv_strs[] = { +static char* const dsv_strs[] = { #define F(L,N,B) L, FOR_DEFAULT_SYSVALS(F) #undef F }; -u32* dsv_text[] = { +u32* const dsv_text[] = { #define F(L,N,B) N, FOR_DEFAULT_SYSVALS(F) #undef F @@ -1904,7 +1904,7 @@ u32* dsv_text[] = { NULL }; -B def_sysNames, def_sysVals; +GLOBAL B def_sysNames, def_sysVals; void sysfn_init(void) { usz dsv_num = sizeof(dsv_strs)/sizeof(char*); usz i = 0; diff --git a/src/builtins/transpose.c b/src/builtins/transpose.c index fbba72d3..fa2be66a 100644 --- a/src/builtins/transpose.c +++ b/src/builtins/transpose.c @@ -63,7 +63,7 @@ typedef void (*TranspFn)(void*,void*,u64,u64,u64,u64); #define SINGELI_FILE transpose #include "../utils/includeSingeli.h" #else - static TranspFn transposeFns[] = { + static TranspFn const transposeFns[] = { transpose_i8, transpose_i16, transpose_i32, transpose_i64 }; #endif diff --git a/src/core.h b/src/core.h index fda86fd8..e17e310f 100644 --- a/src/core.h +++ b/src/core.h @@ -26,7 +26,7 @@ #include "core/arrFns.h" #ifdef RT_VERIFY - extern B r1Objs[RT_LEN]; + extern GLOBAL B r1Objs[RT_LEN]; #endif diff --git a/src/core/arrFns.h b/src/core/arrFns.h index 6944210d..f7d7c26a 100644 --- a/src/core/arrFns.h +++ b/src/core/arrFns.h @@ -49,17 +49,17 @@ SHOULD_INLINE void* m_tyarrlbp(Arr** rp, usz w, usz ia, u8 type) M_TYARR(2, , , SHOULD_INLINE void* m_tyarrlbv(B* rp, usz w, usz ia, u8 type) M_TYARR(2, , arr_shVec((Arr*)r);, taga(r), ) SHOULD_INLINE void* m_tyarrlbc(B* rp, usz w, B x, u8 type) M_TYARR(2, , arr_shCopy((Arr*)r,x);, taga(r), usz ia = IA(x);) -extern u8 elType2type[]; +extern u8 const elType2type[]; #define el2t(X) elType2type[X] // TODO maybe reorganize array types such that this can just be addition? -extern u8 elTypeWidth[]; +extern u8 const elTypeWidth[]; #define elWidth(X) elTypeWidth[X] -extern u8 elwBitLogT[]; +extern u8 const elwBitLogT[]; #define elwBitLog(X) elwBitLogT[X] -extern u8 elwByteLogT[]; +extern u8 const elwByteLogT[]; #define elwByteLog(X) elwByteLogT[X] -extern u8 arrTypeWidthLog[]; +extern u8 const arrTypeWidthLog[]; #define arrTypeWidthLog(X) arrTypeWidthLog[X] -extern u8 arrTypeBitsLog[]; +extern u8 const arrTypeBitsLog[]; #define arrTypeBitsLog(X) arrTypeBitsLog[X] #define arrNewType(X) el2t(TIi(X,elType)) diff --git a/src/core/derv.c b/src/core/derv.c index 18bb496c..c27b6ce6 100644 --- a/src/core/derv.c +++ b/src/core/derv.c @@ -109,8 +109,8 @@ static B toConstant(B x) { // doesn't consume x } return bi_N; } -static NFnDesc* ucwWrapDesc; -static NFnDesc* uc1WrapDesc; +static GLOBAL NFnDesc* ucwWrapDesc; +static GLOBAL NFnDesc* uc1WrapDesc; static B fork_uc1(B t, B o, B x) { B f = toConstant(c(Fork, t)->f); diff --git a/src/core/gstack.h b/src/core/gstack.h index eb66cc40..f3d30539 100644 --- a/src/core/gstack.h +++ b/src/core/gstack.h @@ -7,9 +7,9 @@ #define ENV_SIZE 4096 // max recursion depth; GS_SIZE and C stack size may limit this #endif -extern B* gStack; // points to after end -extern B* gStackStart; -extern B* gStackEnd; +extern GLOBAL B* gStack; // points to after end +extern GLOBAL B* gStackStart; +extern GLOBAL B* gStackEnd; void print_gStack(void); static void gsReserve(u64 am) { diff --git a/src/core/heap.c b/src/core/heap.c index c6d93226..c39d89fc 100644 --- a/src/core/heap.c +++ b/src/core/heap.c @@ -1,10 +1,10 @@ #include "../core.h" #if HEAP_VERIFY -u32 heapVerify_mode = -1; +GLOBAL u32 heapVerify_mode = -1; -Value* heap_observed; -Value* heap_curr; +GLOBAL Value* heap_observed; +GLOBAL Value* heap_curr; void heapVerify_checkFn(Value* v) { if (v->refc!=0) { #if OBJ_COUNTER @@ -32,15 +32,15 @@ void cbqn_heapVerify() { #endif -static u64 heap_PICounts[t_COUNT]; -static u64 heap_PISizes[t_COUNT]; +static GLOBAL u64 heap_PICounts[t_COUNT]; +static GLOBAL u64 heap_PISizes[t_COUNT]; NOINLINE void heap_PIFn(Value* v) { heap_PICounts[PTY(v)]++; heap_PISizes[PTY(v)]+= mm_size(v); } -static u64 heap_PIFreed[128]; +static GLOBAL u64 heap_PIFreed[128]; void heap_PIFreedFn(Value* v) { heap_PIFreed[v->mmInfo&127]++; } diff --git a/src/core/mm.c b/src/core/mm.c index 00506045..28ae3051 100644 --- a/src/core/mm.c +++ b/src/core/mm.c @@ -12,7 +12,7 @@ static u64 prepAllocSize(u64 sz) { } #define MMAP(SZ) mmap(NULL, prepAllocSize(SZ), PROT_READ|PROT_WRITE, MAP_NORESERVE|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) -bool mem_log_enabled; +GLOBAL bool mem_log_enabled; #if MM==0 #include "../opt/mm_malloc.c" diff --git a/src/core/stuff.c b/src/core/stuff.c index 75a355f2..d018b6ac 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -9,7 +9,7 @@ bool please_tail_call_err = true; void before_exit(void); -bool inErr; +GLOBAL bool inErr; NORETURN NOINLINE void fatal(char* s) { NOGC_E; #if MM!=0 @@ -61,8 +61,7 @@ NOINLINE B md_c2(B t, B w, B x) { thrM("Cannot call a modifier"); } NOINLINE B arr_c1(B t, B x) { dec(x); return inc(t); } NOINLINE B arr_c2(B t, B w, B x) { dec(w); dec(x); return inc(t); } - -extern B rt_under, bi_before; +extern GLOBAL B rt_under, bi_before; static B rtUnder_c1(B f, B g, B x) { // consumes x SLOW3("!runtime 𝕎⌾F 𝕩", f, x, g); B fn = m2_d(incG(rt_under), inc(f), inc(g)); @@ -87,7 +86,7 @@ B def_decompose(B x) { return m_hvec2(m_i32(isCallable(x)? (isImpureBuiltin(x)? 1 : 0) : -1),x); } -B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; +GLOBAL B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; NOINLINE TStack* ts_e(TStack* o, u32 elsz, u64 am) { u64 size = o->size; u64 alsz = mm_round(fsizeof(TStack, data, u8, (size+am)*elsz)); @@ -469,12 +468,12 @@ B bqn_merge(B x, u32 type) { } #if ALLOC_STAT - u64* ctr_a = 0; - u64* ctr_f = 0; - u64 actrc = 21000; - u64 talloc = 0; + GLOBAL u64* ctr_a = 0; + GLOBAL u64* ctr_f = 0; + GLOBAL u64 actrc = 21000; + GLOBAL u64 talloc = 0; #if ALLOC_SIZES - u32** actrs; + GLOBAL u32** actrs; #endif #endif @@ -518,7 +517,7 @@ Arr* g_a(B x) { return a(x); } B g_t (void* x) { return tag(x,OBJ_TAG); } B g_ta(void* x) { return tag(x,ARR_TAG); } B g_tf(void* x) { return tag(x,FUN_TAG); } -bool ignore_bad_tag; +GLOBAL bool ignore_bad_tag; void g_p(B x) { fprintI(stderr,x); fputc(10,stderr); fflush(stderr); } void g_i(B x) { B r = info_c2(x, m_f64(1), inc(x)); fprintI(stderr,r); dec(r); fputc(10,stderr); fflush(stderr); } void g_pv(void* x) { ignore_bad_tag=true; fprintI(stderr,tag(x,OBJ_TAG)); fputc(10,stderr); fflush(stderr); ignore_bad_tag=false; } @@ -526,7 +525,7 @@ void g_iv(void* x) { ignore_bad_tag=true; B xo = tag(x, OBJ_TAG); B r = C2(inf void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); } #if DEBUG - bool cbqn_noAlloc; + GLOBAL bool cbqn_noAlloc; NOINLINE void cbqn_NOGC_start() { cbqn_noAlloc=true; } #if OBJ_COUNTER #define PRINT_ID(X) fprintf(stderr, "Object ID: "N64u"\n", (X)->uid) @@ -572,7 +571,7 @@ void g_pst(void) { vm_pstLive(); fflush(stdout); fflush(stderr); } #else #define ONLY_ALWAYS #endif - extern bool cbqn_initialized; + extern GLOBAL bool cbqn_initialized; static void warn_ln(B x) { if (isArr(x)) fprint_fmt(stderr, "%s items, %S, shape=%H\n", IA(x), eltype_repr(TI(x,elType)), x); else { diff --git a/src/core/stuff.h b/src/core/stuff.h index b61063b6..d9cb0687 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -35,8 +35,8 @@ static void decSh(Value* x) { if (RARE(PRNK(x)>1)) decShObj(shObjP(x)); } typedef void (*M_CopyF)(void*, usz, B, usz, usz); typedef void (*M_FillF)(void*, usz, B, usz); -extern M_CopyF copyFns[el_MAX]; -extern M_FillF fillFns[el_MAX]; +extern INIT_GLOBAL M_CopyF copyFns[el_MAX]; +extern INIT_GLOBAL M_FillF fillFns[el_MAX]; #define COPY_TO(WHERE, ELT, MS, X, XS, LEN) copyFns[ELT](WHERE, MS, X, XS, LEN) #define FILL_TO(WHERE, ELT, MS, X, LEN) fillFns[ELT](WHERE, MS, X, LEN) @@ -327,23 +327,23 @@ static FC2 c2fn(B f) { // alloc stuff #if ALLOC_STAT - extern u64* ctr_a; - extern u64* ctr_f; - extern u64 actrc; - extern u64 talloc; + extern GLOBAL u64* ctr_a; + extern GLOBAL u64* ctr_f; + extern GLOBAL u64 actrc; + extern GLOBAL u64 talloc; #if ALLOC_SIZES - extern u32** actrs; + extern GLOBAL u32** actrs; #endif #endif #ifdef OOM_TEST - extern i64 oomTestLeft; + extern GLOBAL i64 oomTestLeft; NOINLINE NORETURN void thrOOMTest(void); #endif #ifdef GC_EVERY_NTH_ALLOC - extern u64 gc_depth; - extern u64 nth_alloc; + extern GLOBAL u64 gc_depth; + extern GLOBAL u64 nth_alloc; #endif FORCE_INLINE void preAlloc(usz sz, u8 type) { #ifdef OOM_TEST diff --git a/src/core/tyarr.c b/src/core/tyarr.c index 9121e4c9..74d73aaf 100644 --- a/src/core/tyarr.c +++ b/src/core/tyarr.c @@ -1,39 +1,39 @@ #include "../core.h" #include "../utils/mut.h" -u8 elType2type[] = { +u8 const elType2type[] = { [el_i8 ] = t_i8arr, [el_c8 ] = t_c8arr, [el_i16] = t_i16arr,[el_c16] = t_c16arr, [el_i32] = t_i32arr,[el_c32] = t_c32arr, [el_bit] = t_bitarr,[el_f64] = t_f64arr, [el_B] = t_invalid, [el_MAX] = t_invalid }; -u8 elTypeWidth[] = { +u8 const elTypeWidth[] = { [el_i8 ] = 1, [el_c8 ] = 1, [el_i16] = 2, [el_c16] = 2, [el_i32] = 4, [el_c32] = 4, [el_f64] = 8, [el_B ] = 8, [el_bit] = 0 }; -u8 elwBitLogT[] = { +u8 const elwBitLogT[] = { [el_i8 ] = 3, [el_c8 ] = 3, [el_i16] = 4, [el_c16] = 4, [el_i32] = 5, [el_c32] = 5, [el_f64] = 6, [el_B ] = 6, [el_bit] = 0 }; -u8 elwByteLogT[] = { +u8 const elwByteLogT[] = { [el_i8 ] = 0, [el_c8 ] = 0, [el_i16] = 1, [el_c16] = 1, [el_i32] = 2, [el_c32] = 2, [el_f64] = 3, [el_B ] = 3, [el_bit] = 99 }; -u8 arrTypeWidthLog[] = { +u8 const arrTypeWidthLog[] = { [t_bitarr]=0, // 0 for mut.c hack to allow restoring a bitarr offset from array pointer & arrTypeWidthLog-"corrected" element pointer [t_i8arr ]=0, [t_i8slice ]=0, [t_c8arr ]=0, [t_c8slice ]=0, [t_i16arr]=1, [t_i16slice]=1, [t_c16arr]=1, [t_c16slice]=1, [t_i32arr]=2, [t_i32slice]=2, [t_c32arr]=2, [t_c32slice]=2, [t_f64arr]=3, [t_f64slice]=3 }; -u8 arrTypeBitsLog[] = { +u8 const arrTypeBitsLog[] = { [t_bitarr]=0, [t_i8arr ]=3, [t_i8slice ]=3, [t_c8arr ]=3, [t_c8slice ]=3, [t_i16arr]=4, [t_i16slice]=4, [t_c16arr]=4, [t_c16slice]=4, diff --git a/src/ffi.c b/src/ffi.c index 75a49205..0333095f 100644 --- a/src/ffi.c +++ b/src/ffi.c @@ -167,8 +167,8 @@ typedef struct BoundFn { i32 xLen; // 0: length 0 array; else, ↑ #endif } BoundFn; -NFnDesc* boundFnDesc; -NFnDesc* foreignFnDesc; +GLOBAL NFnDesc* boundFnDesc; +GLOBAL NFnDesc* foreignFnDesc; B boundFn_c1(B t, B x) { BoundFn* c = c(BoundFn,t); return getB(((bqn_boundFn1)c->w_c1)(makeX(inc(c->obj)), makeX(x))); } B boundFn_c2(B t, B w, B x) { BoundFn* c = c(BoundFn,t); return getB(((bqn_boundFn2)c->w_c2)(makeX(inc(c->obj)), makeX(w), makeX(x))); } @@ -321,7 +321,7 @@ static const u8 sty_w[] = { [sty_i8]=1, [sty_i16]=2, [sty_i32]=4, [sty_i64]=8, [sty_f32]=4, [sty_f64]=8 }; -static const char* sty_names[] = { +static char* const sty_names[] = { [sty_void]="void", [sty_a]="a", [sty_ptr]="*", [sty_u8]="u8", [sty_u16]="u16", [sty_u32]="u32", [sty_u64]="u64", [sty_i8]="i8", [sty_i16]="i16", [sty_i32]="i32", [sty_i64]="i64", @@ -567,8 +567,8 @@ static NOINLINE B toW(u8 reT, u8 reW, B x) { case 6: ffi_checkRange(x, 2, "f64", 0, 0); return toF64Any(x); break; } } -static u8 reTyMapC[] = { [3]=t_c8arr, [4]=t_c16arr, [5]=t_c32arr }; -static u8 reTyMapI[] = { [3]=t_i8arr, [4]=t_i16arr, [5]=t_i32arr, [6]=t_f64arr }; +static u8 const reTyMapC[] = { [3]=t_c8arr, [4]=t_c16arr, [5]=t_c32arr }; +static u8 const reTyMapI[] = { [3]=t_i8arr, [4]=t_i16arr, [5]=t_i32arr, [6]=t_f64arr }; static B makeRe(u8 reT, u8 reW/*log*/, u8* src, u32 elW/*bytes*/) { u8* dst; B r; usz ia = (elW*8)>>reW; @@ -613,7 +613,7 @@ NOINLINE B readU16Bits(B x) { usz ia=IA(x); u16* xp=tyarr_ptr(x); i32* rp; B r=m NOINLINE B readU32Bits(B x) { usz ia=IA(x); u32* xp=tyarr_ptr(x); f64* rp; B r=m_f64arrv(&rp, ia); for (usz i=0; i - extern Replxx* global_replxx; + extern GLOBAL Replxx* global_replxx; #define printf(...) replxx_print(global_replxx, __VA_ARGS__) #define fprintf(f, ...) replxx_print(global_replxx, __VA_ARGS__) #endif @@ -298,7 +301,7 @@ typedef struct Arr { B VALIDATE(B x); Value* VALIDATEP(Value* x); #define UD assert(false) - extern bool cbqn_noAlloc; + extern GLOBAL bool cbqn_noAlloc; NOINLINE void cbqn_NOGC_start(); // function to allow breakpointing #define NOGC_CHECK(M) do { if (cbqn_noAlloc && !gc_depth) fatal(M); } while (0) #define NOGC_S cbqn_NOGC_start() @@ -347,7 +350,7 @@ static const B bi_noVar = b((u64)0x7FF2000000000001ull); // tag(1,TAG_TAG); static const B bi_okHdr = b((u64)0x7FF2000000000002ull); // tag(2,TAG_TAG); static const B bi_optOut = b((u64)0x7FF2000000000003ull); // tag(3,TAG_TAG); static const B bi_noFill = b((u64)0x7FF2000000000005ull); // tag(5,TAG_TAG); -extern B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; +extern GLOBAL B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; #define emptyHVec() incG(bi_emptyHVec) #define emptyIVec() incG(bi_emptyIVec) #define emptyCVec() incG(bi_emptyCVec) @@ -394,7 +397,7 @@ jmp_buf* prepareCatch(void); #define CATCH false #define popCatch() #endif -extern B thrownMsg; +extern GLOBAL B thrownMsg; void freeThrown(void); @@ -568,7 +571,7 @@ typedef B (*D2C2)(Md2D*, B, B); F(bool, isArr) /* whether this type would have an ARR_TAG tag, in cases where the tag is unknown */ \ F(bool, arrD1) /* is always an array with depth 1 */ \ -#define F(TY,N) extern TY ti_##N[t_COUNT]; +#define F(TY,N) extern GLOBAL TY ti_##N[t_COUNT]; FOR_TI(F) #undef F #define TIi(X,V) (ti_##V[X]) diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index b82cec1a..27e5c326 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -17,8 +17,8 @@ #define ALLOC_IMPL_MMX 1 // separate memory management system for executable code; isn't garbage-collected -EmptyValue* mmX_buckets[64]; -u64 mmX_ctrs[64]; +GLOBAL EmptyValue* mmX_buckets[64]; +GLOBAL u64 mmX_ctrs[64]; #define BSZ(X) (1ull<<(X)) #define BSZI(X) ((u8)(64-CLZ((X)-1ull))) #define MMI(X) X @@ -27,7 +27,7 @@ u64 mmX_ctrs[64]; #define MMI(X) X #define ALSZ 20 -static u64 nvm_mmap_seed = 0; +static GLOBAL u64 nvm_mmap_seed = 0; #ifdef __clang__ #if __clang_major__ <= 12 // old clang versions get stuck in an infinite loop while optimizing this __attribute__((optnone)) @@ -61,7 +61,7 @@ static void* mmap_nvm(u64 sz) { } } -extern bool mem_log_enabled; +extern GLOBAL bool mem_log_enabled; #define MMAP(SZ) mmap_nvm(sz); #define MUL 1 #define ALLOC_MODE 1 diff --git a/src/jit/x86_64.h b/src/jit/x86_64.h index 644648b6..ea067f61 100644 --- a/src/jit/x86_64.h +++ b/src/jit/x86_64.h @@ -49,9 +49,9 @@ typedef struct AsmStk { u8* c; // position for next write u8* e; // position past last writable position } AsmStk; -static AsmStk asm_ins; // TODO add as root -static AsmStk asm_rel; -static i32 asm_depth = 0; +static GLOBAL AsmStk asm_ins; // TODO add as root +static GLOBAL AsmStk asm_rel; +static GLOBAL i32 asm_depth = 0; static NOINLINE void asm_allocBuf(AsmStk* stk, u64 sz) { TAlloc* a = mm_alloc(sizeof(TAlloc) + sz, t_temp); diff --git a/src/load.c b/src/load.c index c5ed89cd..8b3b00fb 100644 --- a/src/load.c +++ b/src/load.c @@ -20,8 +20,8 @@ FOR_INIT(F) #undef F -u64 mm_heapMax = HEAP_MAX; -u64 mm_heapAlloc; +GLOBAL u64 mm_heapMax = HEAP_MAX; +GLOBAL u64 mm_heapAlloc; // compiler result: // [ @@ -48,23 +48,23 @@ u64 mm_heapAlloc; // [%, %, [[...nameList], %], %]? // optional; % marks things i haven't bothered to understand // ] -#define FA(N,X) B bi_##N; B N##_c1(B t, B x); B N##_c2(B t, B w, B x); -#define FM(N,X) B bi_##N; B N##_c1(B t, B x); -#define FD(N,X) B bi_##N; B N##_c2(B t, B w, B x); +#define FA(N,X) GLOBAL B bi_##N; B N##_c1(B t, B x); B N##_c2(B t, B w, B x); +#define FM(N,X) GLOBAL B bi_##N; B N##_c1(B t, B x); +#define FD(N,X) GLOBAL B bi_##N; B N##_c2(B t, B w, B x); FOR_PFN(FA,FM,FD) #undef FA #undef FM #undef FD -#define FA(N,X) B bi_##N; B N##_c1(Md1D* d, B x); B N##_c2(Md1D* d, B w, B x); -#define FM(N,X) B bi_##N; B N##_c1(Md1D* d, B x); -#define FD(N,X) B bi_##N; B N##_c2(Md1D* d, B w, B x); +#define FA(N,X) GLOBAL B bi_##N; B N##_c1(Md1D* d, B x); B N##_c2(Md1D* d, B w, B x); +#define FM(N,X) GLOBAL B bi_##N; B N##_c1(Md1D* d, B x); +#define FD(N,X) GLOBAL B bi_##N; B N##_c2(Md1D* d, B w, B x); FOR_PM1(FA,FM,FD) #undef FA #undef FM #undef FD -#define FA(N,X) B bi_##N; B N##_c1(Md2D*, B x); B N##_c2(Md2D*, B w, B x); -#define FM(N,X) B bi_##N; B N##_c1(Md2D*, B x); -#define FD(N,X) B bi_##N; B N##_c2(Md2D*, B w, B x); +#define FA(N,X) GLOBAL B bi_##N; B N##_c1(Md2D*, B x); B N##_c2(Md2D*, B w, B x); +#define FM(N,X) GLOBAL B bi_##N; B N##_c1(Md2D*, B x); +#define FD(N,X) GLOBAL B bi_##N; B N##_c2(Md2D*, B w, B x); FOR_PM2(FA,FM,FD) #undef FA #undef FM @@ -94,11 +94,11 @@ char* pm2_repr(u8 u) { -#define F(TY,N) TY ti_##N[t_COUNT]; +#define F(TY,N) GLOBAL TY ti_##N[t_COUNT]; FOR_TI(F) #undef F -B r1Objs[RT_LEN]; +GLOBAL B r1Objs[RT_LEN]; B rtWrap_wrap(B x, bool nnbi); // consumes void rtWrap_print(void); @@ -123,10 +123,10 @@ static NOINLINE B evalFunBlockConsume(Block* block) { return r; } -HArr* comps_curr; +GLOBAL HArr* comps_curr; -B rt_undo, rt_select, rt_slash, rt_insert, rt_depth, - rt_group, rt_under, rt_find; +GLOBAL B rt_undo, rt_select, rt_slash, rt_insert, rt_depth, + rt_group, rt_under, rt_find; Block* load_buildBlock(B x, B src, B path, B name, Scope* sc, i32 nsResult) { // consumes x,src B fullpath = q_N(name)? inc(path) : q_N(path)? inc(name) : IA(path)==1 && IGetU(path,0).u==m_c32('.').u? inc(name) : path_rel(path, inc(name), "(load_buildBlock)"); SGet(x) @@ -152,8 +152,8 @@ Block* load_importBlock(char* name, B bc, B objs, B blocks, B bodies) { // consu } #endif -B load_compgen; -B def_re; +GLOBAL B load_compgen; +GLOBAL B def_re; static void change_def_comp(B comp) { // consumes B* re = harr_ptr(def_re); // not pretty changing in-place, but still should be fine and it's for an unsafe feature anyway @@ -179,7 +179,7 @@ B compObj_c2(B t, B w, B x) { } #if FORMATTER -B load_fmt, load_repr; +GLOBAL B load_fmt, load_repr; B bqn_fmt(B x) { return c1G(load_fmt, x); } B bqn_repr(B x) { return c1G(load_repr, x); } #else @@ -251,7 +251,7 @@ B bqn_exec(B str, B state) { // consumes all return evalFunBlockConsume(bqn_comp(str, state)); } -B str_all, str_none; +GLOBAL B str_all, str_none; void init_comp(B* new_re, B* prev_re, B prim, B sys) { new_re[re_map] = m_importMap(); if (q_N(prim)) { @@ -630,7 +630,7 @@ void bqn_exit(i32 code) { exit(code); } -static B load_explain; +static GLOBAL B load_explain; B bqn_explain(B str) { #if NO_EXPLAIN thrM("Explainer not included in this CBQN build"); @@ -672,9 +672,9 @@ static B def_m1_d(B m, B f ) { thrM("cannot derive this"); } static B def_m2_d(B m, B f, B g) { thrM("cannot derive this"); } static Arr* def_slice(B x, usz s, usz ia) { fatal("cannot slice non-array!"); } -B rt_invFnReg, rt_invFnSwap; -FC1 rt_invFnRegFn; -FC1 rt_invFnSwapFn; +GLOBAL B rt_invFnReg, rt_invFnSwap; +GLOBAL FC1 rt_invFnRegFn; +GLOBAL FC1 rt_invFnSwapFn; B def_fn_im(B t, B x) { B fn = rt_invFnRegFn(rt_invFnReg, inc(t)); SLOW2("!runtime 𝕎⁼𝕩", t, x); B r = c1(fn, x); dec(fn); return r; } B def_fn_is(B t, B x) { B fn = rt_invFnSwapFn(rt_invFnSwap, inc(t)); SLOW2("!runtime 𝕎⁼𝕩", t, x); B r = c1(fn, x); dec(fn); return r; } B def_fn_iw(B t, B w, B x) { B fn = rt_invFnSwapFn(rt_invFnSwap, inc(t)); SLOW3("!runtime 𝕨F⁼𝕩", w, x, t); B r = c2(fn, w, x); dec(fn); return r; } @@ -862,7 +862,7 @@ void typesFinished_init() { #endif } -bool cbqn_initialized; +GLOBAL bool cbqn_initialized; void cbqn_init() { if (cbqn_initialized) return; #define F(X) X##_init(); diff --git a/src/load.h b/src/load.h index 1de3adf1..5ad227a4 100644 --- a/src/load.h +++ b/src/load.h @@ -1,5 +1,5 @@ #pragma once -extern HArr* comps_curr; // global-ish state, valid during compilation; comps_max elements +extern GLOBAL HArr* comps_curr; // global-ish state, valid during compilation; comps_max elements enum { comps_path, comps_name, @@ -19,7 +19,7 @@ enum { #define COMPS_CREF(N) COMPS_REF(comps_curr, N) #define COMPS_ACTIVE() (comps_curr!=NULL) -extern B def_sysNames, def_sysVals; +extern GLOBAL B def_sysNames, def_sysVals; B comps_getPrimitives(void); void comps_getSysvals(B* res); diff --git a/src/main.c b/src/main.c index fa687e97..8bc53dda 100644 --- a/src/main.c +++ b/src/main.c @@ -20,12 +20,12 @@ #error "Cannot use USE_REPLXX_IO without USE_REPLXX" #endif -static B replPath, replName; -static Scope* gsc; -static bool init = false; +static GLOBAL B replPath, replName; +static GLOBAL Scope* gsc; +static GLOBAL bool repl_initialized = false; static NOINLINE void repl_init() { - if (init) return; + if (repl_initialized) return; cbqn_init(); replPath = m_c8vec_0("."); gc_add(replPath); replName = m_c8vec_0("(REPL)"); gc_add(replName); @@ -33,7 +33,7 @@ static NOINLINE void repl_init() { B ns = m_nns(body); gsc = ptr_inc(c(NS, ns)->sc); gc_add(tag(gsc,OBJ_TAG)); ptr_dec(v(ns)); - init = true; + repl_initialized = true; } typedef struct { bool r; char* e; } IsCmdTmp; @@ -67,11 +67,11 @@ static NOINLINE i64 readInt(char** p) { #include #include #include "utils/cstr.h" - Replxx* global_replxx; - static char* global_histfile; - static u32 cfg_prefixChar = U'\\'; + GLOBAL Replxx* global_replxx; + static GLOBAL char* global_histfile; + static GLOBAL u32 cfg_prefixChar = U'\\'; - static i8 themes[3][12][3] = { + static i8 const themes[3][12][3] = { // {-1,-1,-1} for default/unchanged color, {-1,-1,n} for grayscale 0…23, else RGB 0…5 { // 0: "none" {-1,-1,-1}, {-1,-1,-1}, {-1,-1,-1}, {-1,-1,-1}, @@ -109,13 +109,13 @@ static NOINLINE i64 readInt(char** p) { }; typedef i8 Theme[12][3]; - static ReplxxColor theme_replxx[12]; + static GLOBAL ReplxxColor theme_replxx[12]; - static i32 cfg_theme = 1; - static bool cfg_enableKeyboard = true; - static B cfg_path; + static GLOBAL i32 cfg_theme = 1; + static GLOBAL bool cfg_enableKeyboard = true; + static GLOBAL B cfg_path; - static char* command_completion[] = { + static char* const command_completion[] = { ")ex ", ")r ", ")escaped ", @@ -148,7 +148,7 @@ static NOINLINE i64 readInt(char** p) { NOINLINE void cfg_set_theme(i32 num, bool writeCfg) { if (num>=3) return; cfg_theme = num; - i8 (*data)[3] = themes[num]; + i8 const (*data)[3] = themes[num]; for (int i = 0; i < 12; i++) { i8 v0 = data[i][0]; i8 v1 = data[i][1]; @@ -162,8 +162,8 @@ static NOINLINE i64 readInt(char** p) { if (writeCfg) cfg_changed(); } - extern u32* dsv_text[]; - static B sysvalNames, sysvalNamesNorm; + extern u32* const dsv_text[]; + static GLOBAL B sysvalNames, sysvalNamesNorm; NOINLINE void fill_color(ReplxxColor* cols, int s, int e, ReplxxColor col) { PLAINLOOP for (int i = s; i < e; i++) cols[i] = col; @@ -177,12 +177,12 @@ static NOINLINE i64 readInt(char** p) { static bool chr_num0(u32 c) { return chr_dig(c) || c==U'¯' || c==U'π' || c==U'∞'; } static bool chr_name0(u32 c) { return chr_low(c) || chr_upp(c) || c=='_'; } static bool chr_nameM(u32 c) { return chr_name0(c) || chr_num0(c); } - static u32* chrs_fn = U"!+-×÷⋆*√⌊⌈∧∨¬|=≠≤<>≥≡≢⊣⊢⥊∾≍⋈↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔«»𝔽𝔾𝕎𝕏𝕊"; - static u32* chrs_m1 = U"`˜˘¨⁼⌜´˝˙"; - static u32* chrs_m2 = U"∘⊸⟜○⌾⎉⚇⍟⊘◶⎊"; - static u32* chrs_lit = U"⟨⟩[]·@‿"; - static u32* chrs_dmd = U"←↩,⋄→⇐"; - static u32* chrs_blk = U"{}𝕨𝕩𝕗𝕘𝕣𝕤:?;"; + static u32* const chrs_fn = U"!+-×÷⋆*√⌊⌈∧∨¬|=≠≤<>≥≡≢⊣⊢⥊∾≍⋈↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔«»𝔽𝔾𝕎𝕏𝕊"; + static u32* const chrs_m1 = U"`˜˘¨⁼⌜´˝˙"; + static u32* const chrs_m2 = U"∘⊸⟜○⌾⎉⚇⍟⊘◶⎊"; + static u32* const chrs_lit = U"⟨⟩[]·@‿"; + static u32* const chrs_dmd = U"←↩,⋄→⇐"; + static u32* const chrs_blk = U"{}𝕨𝕩𝕗𝕘𝕣𝕤:?;"; NOINLINE bool chr_in(u32 val, u32* chrs) { while(*chrs) if (val == *(chrs++)) return true; return false; @@ -406,9 +406,9 @@ static NOINLINE i64 readInt(char** p) { return (TmpState){.s = s, .pos = replace? pos : pos+1}; } - static B b_pv; - static int b_pp; - static bool inBackslash; + static GLOBAL B b_pv; + static GLOBAL int b_pp; + static GLOBAL bool inBackslash; static void stopBackslash() { inBackslash = false; } NOINLINE void setPrev(B s, u64 pos) { // consumes decG(b_pv); @@ -440,7 +440,7 @@ static NOINLINE i64 readInt(char** p) { B indexOf_c2(B, B, B); B pick_c1(B, B); - static B b_key, b_val; + static GLOBAL B b_key, b_val; void modified_replxx(char** s_res, int* p_res, void* userData) { if (!cfg_enableKeyboard) return; CATCH_OOM(return) @@ -535,7 +535,7 @@ static NOINLINE i64 readInt(char** p) { gc_add(b_val = m_c32vec_0( U"˙˜˘¨⁼⌜´˝7∞¯•÷׬⎉⚇⍟◶⊘⎊⍎⍕⟨⟩√⋆⌽𝕨∊↑∧y⊔⊏⊐π←→↙𝕎⍷𝕣⍋YU⊑⊒⍳⊣⊢⍉𝕤↕𝕗𝕘⊸∘○⟜⋄↩↖𝕊D𝔽𝔾«J⌾»·|⥊𝕩↓∨⌊n≡∾≍≠⋈𝕏C⍒⌈N≢≤≥⇐‿")); sysvalNames = emptyHVec(); sysvalNamesNorm = emptyHVec(); - u32** c = dsv_text; + u32* const* c = dsv_text; while (*c) { bool unused; B str = m_c32vec_0(*(c++)); sysvalNames = vec_addN(sysvalNames, str); @@ -579,7 +579,7 @@ void clearImportCache(void); void switchComp(void); #endif -static B escape_parser; +static GLOBAL B escape_parser; static B simple_unescape(B x) { if (RARE(escape_parser.u==0)) { escape_parser = bqn_exec(utf8Decode0("{m←\"Expected surrounding quotes\" ⋄ m!2≤≠𝕩 ⋄ m!\"\"\"\"\"\"≡0‿¯1⊏𝕩 ⋄ s←¬e←<`'\\'=𝕩 ⋄ i‿o←\"\\\"\"nr\"⋈\"\\\"\"\"∾@+10‿13 ⋄ 1↓¯1↓{n←i⊐𝕩 ⋄ \"Unknown escape\"!∧´n≠≠i ⋄ n⊏o}⌾((s/»e)⊸/) s/𝕩}"), bi_N); @@ -605,7 +605,7 @@ bool ryu_s2d_n(u8* buffer, int len, f64* result); #endif void heap_printInfoStr(char* str); -extern bool gc_log_enabled, mem_log_enabled; +extern GLOBAL bool gc_log_enabled, mem_log_enabled; void cbqn_runLine0(char* ln, i64 read) { if (ln[0]==0 || read==0) return; @@ -911,7 +911,7 @@ int main() { } #elif !CBQN_LIB #if HAS_VERSION -extern char* cbqn_versionInfo; +extern char* const cbqn_versionInfo; #endif int main(int argc, char* argv[]) { #if USE_REPLXX_IO @@ -1104,6 +1104,5 @@ int main(int argc, char* argv[]) { cbqn_heapVerify(); #endif bqn_exit(0); - #undef INIT } #endif diff --git a/src/nfns.c b/src/nfns.c index 4a2cc468..0ac01d34 100644 --- a/src/nfns.c +++ b/src/nfns.c @@ -2,8 +2,8 @@ #include "h.h" #include "nfns.h" -static u32 nfn_curr; -static B nfn_list; +static GLOBAL u32 nfn_curr; +static GLOBAL B nfn_list; NFnDesc* registerNFn(B name, FC1 c1, FC2 c2) { u32 id = nfn_curr++; diff --git a/src/ns.c b/src/ns.c index 61b94987..4f0c2f8c 100644 --- a/src/ns.c +++ b/src/ns.c @@ -100,8 +100,8 @@ void ns_set(B ns, B name, B val) { VTY(ns, t_ns); -static i32* emptyi32ptr; -static B emptyi32obj; +static GLOBAL i32* emptyi32ptr; +static GLOBAL B emptyi32obj; Body* m_nnsDescF(i32 n, char** names) { if (emptyi32ptr==NULL) gc_add(emptyi32obj = m_i32arrv(&emptyi32ptr, 0)); incByG(emptyi32obj, 2); diff --git a/src/opt/gc.c b/src/opt/gc.c index cf2c81e6..37d3e98c 100644 --- a/src/opt/gc.c +++ b/src/opt/gc.c @@ -4,35 +4,35 @@ static void mm_freeFreedAndMerge(void); #include "../utils/time.h" #if GC_LOG_DETAILED - bool gc_log_enabled = true; + GLOBAL bool gc_log_enabled = true; #else - bool gc_log_enabled; + GLOBAL bool gc_log_enabled; #endif #endif -u64 gc_depth = 1; +GLOBAL u64 gc_depth = 1; #ifdef GC_EVERY_NTH_ALLOC - u64 nth_alloc = 1; + GLOBAL u64 nth_alloc = 1; #endif -vfn gc_roots[8]; -u32 gc_rootSz; +GLOBAL vfn gc_roots[8]; +GLOBAL u32 gc_rootSz; void gc_addFn(vfn f) { if (gc_rootSz>=8) fatal("Too many GC root functions"); gc_roots[gc_rootSz++] = f; } -Value* gc_rootObjs[512]; -u32 gc_rootObjSz; +GLOBAL Value* gc_rootObjs[512]; +GLOBAL u32 gc_rootObjSz; void gc_add(B x) { assert(isVal(x)); if (gc_rootObjSz>=512) fatal("Too many GC root objects"); gc_rootObjs[gc_rootObjSz++] = v(x); } -B* gc_rootBRefs[64]; u32 gc_rootBRefsSz; +GLOBAL B* gc_rootBRefs[64]; GLOBAL u32 gc_rootBRefsSz; void gc_add_ref(B* x) { if (gc_rootBRefsSz>=64) fatal("Too many GC root B refs"); gc_rootBRefs[gc_rootBRefsSz++] = x; @@ -79,10 +79,10 @@ static void gc_tryFree(Value* v) { } #if GC_LOG_DETAILED - u64 gcs_visitBytes, gcs_visitCount, gcs_freedBytes, gcs_freedCount, gcs_unkRefsBytes, gcs_unkRefsCount; // GC stat counters + GLOBAL u64 gcs_visitBytes, gcs_visitCount, gcs_freedBytes, gcs_freedCount, gcs_unkRefsBytes, gcs_unkRefsCount; // GC stat counters #endif -i32 visit_mode; +GLOBAL i32 visit_mode; enum { GC_DEC_REFC, // decrement refcount GC_INC_REFC, // increment refcount @@ -167,7 +167,7 @@ static void gcv2_unmark_visit(Value* x) { } #endif -u64 gc_lastAlloc; +GLOBAL u64 gc_lastAlloc; void gc_forceGC(bool toplevel) { #if ENABLE_GC u64 startTime=0, startSize=0; @@ -196,7 +196,7 @@ void gc_forceGC(bool toplevel) { #endif } -static bool gc_wantTopLevelGC; +static GLOBAL bool gc_wantTopLevelGC; bool gc_maybeGC(bool toplevel) { if (gc_depth) return false; u64 used = mm_heapUsed(); diff --git a/src/opt/gc.h b/src/opt/gc.h index 53bc0ee9..a0e5aeaa 100644 --- a/src/opt/gc.h +++ b/src/opt/gc.h @@ -1,6 +1,6 @@ #pragma once -extern u64 gc_depth; +extern GLOBAL u64 gc_depth; static void gc_disable() { gc_depth++; } static void gc_enable() { gc_depth--; } diff --git a/src/opt/mm_2buddy.c b/src/opt/mm_2buddy.c index 96369015..b9e36b82 100644 --- a/src/opt/mm_2buddy.c +++ b/src/opt/mm_2buddy.c @@ -5,15 +5,15 @@ #include "gc.c" #if OBJ_COUNTER - u64 currObjCounter; + GLOBAL u64 currObjCounter; #endif #if VERIFY_TAIL #error MM=2 doesn't support VERIFY_TAIL #endif #define ALLOC_MODE 0 -u64 mm_ctrs[128]; -EmptyValue* mm_buckets[128]; +GLOBAL u64 mm_ctrs[128]; +GLOBAL EmptyValue* mm_buckets[128]; #define b1_buckets mm_buckets #define b1_allocL mm_allocL #define ALSZ 20 diff --git a/src/opt/mm_2buddy.h b/src/opt/mm_2buddy.h index f9cd7125..510fc494 100644 --- a/src/opt/mm_2buddy.h +++ b/src/opt/mm_2buddy.h @@ -6,13 +6,13 @@ struct EmptyValue { // needs set: mmInfo; type=t_empty; next; everything else ca EmptyValue* next; }; #if OBJ_COUNTER - extern u64 currObjCounter; + extern GLOBAL u64 currObjCounter; #endif -extern u64 mm_heapAlloc; -extern u64 mm_heapMax; +extern GLOBAL u64 mm_heapAlloc; +extern GLOBAL u64 mm_heapMax; -extern u64 mm_ctrs[128]; -extern EmptyValue* mm_buckets[128]; +extern GLOBAL u64 mm_ctrs[128]; +extern GLOBAL EmptyValue* mm_buckets[128]; #define BSZ(X) (((X)&64? 3ull : 1ull)<<(X)) #define BN(X) mm_##X #include "mm_buddyTemplate.h" diff --git a/src/opt/mm_buddy.c b/src/opt/mm_buddy.c index 9f2aa6c0..439e415c 100644 --- a/src/opt/mm_buddy.c +++ b/src/opt/mm_buddy.c @@ -8,8 +8,8 @@ u64 currObjCounter; #endif -u64 mm_ctrs[64]; -EmptyValue* mm_buckets[64]; +GLOBAL u64 mm_ctrs[64]; +GLOBAL EmptyValue* mm_buckets[64]; #define ALSZ 20 #define BSZ(X) (1ull<<(X)) #define MUL 1 diff --git a/src/opt/mm_buddy.h b/src/opt/mm_buddy.h index 5ac089e4..0586515a 100644 --- a/src/opt/mm_buddy.h +++ b/src/opt/mm_buddy.h @@ -6,13 +6,13 @@ struct EmptyValue { // needs set: mmInfo; type=t_empty; next; everything else ca EmptyValue* next; }; #if OBJ_COUNTER - extern u64 currObjCounter; + extern GLOBAL u64 currObjCounter; #endif -extern u64 mm_heapAlloc; -extern u64 mm_heapMax; +extern GLOBAL u64 mm_heapAlloc; +extern GLOBAL u64 mm_heapMax; -extern u64 mm_ctrs[64]; -extern EmptyValue* mm_buckets[64]; +extern GLOBAL u64 mm_ctrs[64]; +extern GLOBAL EmptyValue* mm_buckets[64]; #define BSZ(X) (1ull<<(X)) #define BN(X) mm_##X #include "mm_buddyTemplate.h" diff --git a/src/opt/mm_buddyTemplate.c b/src/opt/mm_buddyTemplate.c index c2dbc5d2..7e8bf057 100644 --- a/src/opt/mm_buddyTemplate.c +++ b/src/opt/mm_buddyTemplate.c @@ -10,9 +10,9 @@ typedef struct AllocInfo { Value* p; u64 sz; } AllocInfo; -AllocInfo* al; -u64 alCap; -u64 alSize; +GLOBAL AllocInfo* al; +GLOBAL u64 alCap; +GLOBAL u64 alSize; FORCE_INLINE void BN(splitTo)(EmptyValue* c, i64 from, i64 to, bool notEqual) { c->mmInfo = MMI(to); @@ -31,7 +31,7 @@ FORCE_INLINE void BN(splitTo)(EmptyValue* c, i64 from, i64 to, bool notEqual) { } #if ALLOC_MODE==0 && ENABLE_GC - static bool BN(allocMore_rec); + static GLOBAL bool BN(allocMore_rec); #endif static NOINLINE void* BN(allocateMore)(i64 bucket, u8 type, i64 from, i64 to) { diff --git a/src/opt/mm_malloc.h b/src/opt/mm_malloc.h index 33d4195b..93fcb3e5 100644 --- a/src/opt/mm_malloc.h +++ b/src/opt/mm_malloc.h @@ -1,7 +1,7 @@ #include #include -extern u64 mm_heapAlloc; -extern u64 mm_heapMax; +extern GLOBAL u64 mm_heapAlloc; +extern GLOBAL u64 mm_heapMax; static void mm_free(Value* x) { preFree(x, false); diff --git a/src/singeli/c/arithdDispatch.c b/src/singeli/c/arithdDispatch.c index 69693fb1..ea4a9f6b 100644 --- a/src/singeli/c/arithdDispatch.c +++ b/src/singeli/c/arithdDispatch.c @@ -123,7 +123,7 @@ B bad_chrAtomSA(DyTableSA* table, B w, B x, usz ia, u8 xe) { return arith_recd(t u64 failAtomArr1(void* r, u64 w, void* x, u64 len) { return 0; } u64 failAtomArr2(void* r, u64 w, void* x, u64 len) { return 1; } -u8 nextType[] = { +u8 const nextType[] = { [t_i8arr ] = t_i16arr, [t_c8arr ] = t_c16arr, [t_i16arr] = t_i32arr, [t_c16arr] = t_c32arr, [t_i32arr] = t_f64arr, [t_c32arr] = t_empty, diff --git a/src/singeli/src/genArithTables.bqn b/src/singeli/src/genArithTables.bqn index 624916e2..2edfa673 100644 --- a/src/singeli/src/genArithTables.bqn +++ b/src/singeli/src/genArithTables.bqn @@ -103,7 +103,7 @@ Make ← {𝕊ns: cSrc∾↩ ∾⟨ "B ", cbqn, "_c2(B,B,B);", nl - "DyTableAA ", cbqn,"DyTableAA = {", nl + "INIT_GLOBAL DyTableAA ", cbqn,"DyTableAA = {", nl " .entsAA = {", nl ∾{ ⟨instrs, we‿xe⟩: { @@ -150,7 +150,7 @@ Make ← {𝕊ns: P ← {∾⟨"{",𝕨,",",𝕩,"}"⟩}´ cSrc∾↩ ∾⟨ - "DyTableSA ", cbqn,"DyTable", ⌽⍟swap (charAtm⊑"NC")∾"A", " = {", nl + "INIT_GLOBAL DyTableSA ", cbqn,"DyTable", ⌽⍟swap (charAtm⊑"NC")∾"A", " = {", nl " .ents = {", nl " {.bitsel=", hasNumArr◶⟨"bad", {𝕊:id∾swap/"R"}⟩ @, "_forBitsel", charAtm⊑"NC", "N_SA},", nl ∾{ 𝕊 num: diff --git a/src/utils/calls.h b/src/utils/calls.h index 1fcd77ab..d38cf376 100644 --- a/src/utils/calls.h +++ b/src/utils/calls.h @@ -8,7 +8,7 @@ static inline B m1c2_unsafe(D1C2 m, B f, B w, B x) { Md1D d; d.f=f; return m(&d, typedef void (*CmpAAFn)(u64*, void*, void*, u64); typedef void (*CmpASFn)(u64*, void*, u64, u64); -#define CMP_DEF(F, S) extern Cmp##S##Fn cmp_fns_##F##S[]; +#define CMP_DEF(F, S) extern INIT_GLOBAL Cmp##S##Fn cmp_fns_##F##S[]; CMP_DEF(eq, AS); CMP_DEF(eq, AA); CMP_DEF(ne, AS); CMP_DEF(ne, AA); CMP_DEF(gt, AS); CMP_DEF(gt, AA); @@ -28,12 +28,12 @@ CMP_DEF(le, AS); // Check if the l elements starting at a and b match typedef bool (*EqFn)(void* a, void* b, u64 l, u64 data); -extern EqFn eqFns[]; -extern u8 eqFnData[]; +extern INIT_GLOBAL EqFn eqFns[]; +extern u8 const eqFnData[]; #define EQFN_INDEX(W_ELT, X_ELT) ((W_ELT)*8 + (X_ELT)) typedef struct { EqFn fn; u8 data; } EqFnObj; #define EQFN_GET(W_ELT, X_ELT) ({ u8 eqfn_i_ = EQFN_INDEX(W_ELT, X_ELT); (EqFnObj){.fn=eqFns[eqfn_i_], .data=eqFnData[eqfn_i_]}; }) #define EQFN_CALL(FN, W, X, L) (FN).fn(W, X, L, (FN).data) typedef bool (*RangeFn)(void* xp, i64* res, u64 len); // writes min,max in res, assumes len≥1; returns 0 and leaves res undefined if either any (floor(x)≠x or abs>2⋆53), or (x≠(i64)x) -extern RangeFn getRange_fns[el_f64+1]; // limited to ≤el_f64 +extern INIT_GLOBAL RangeFn getRange_fns[el_f64+1]; // limited to ≤el_f64 diff --git a/src/utils/file.c b/src/utils/file.c index eccc25d2..c668b4f5 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -463,13 +463,13 @@ NOINLINE void writeNum(FILE* f, u64 v, i32 len) { PLAINLOOP for (i32 i = 0; i < len; i++) buf[i] = (v>>(8*i)) & 0xff; fwrite(buf, 1, len, f); } -static char* types_str[] = { +static char* const types_str[] = { #define F(X) #X, FOR_TYPE(F) #undef F NULL }; -static u8 types_val[] = { +static u8 const types_val[] = { #define F(X) t_##X, FOR_TYPE(F) #undef F diff --git a/src/utils/hash.c b/src/utils/hash.c index a2dd9eb2..0485762a 100644 --- a/src/utils/hash.c +++ b/src/utils/hash.c @@ -87,7 +87,7 @@ NOINLINE u64 bqn_hashObj(B x, const u64 secret[4]) { // TODO manual separation o } -u64 wy_secret[4]; +INIT_GLOBAL u64 wy_secret[4]; void hash_init(void) { u64 bad1=0xa0761d6478bd642full; // values wyhash64 is afraid of diff --git a/src/utils/hash.h b/src/utils/hash.h index 076185c7..71008116 100644 --- a/src/utils/hash.h +++ b/src/utils/hash.h @@ -2,7 +2,7 @@ #include "wyhash.h" #include "talloc.h" -extern u64 wy_secret[4]; +extern INIT_GLOBAL u64 wy_secret[4]; static void bcl(B x, usz ia) { // clean up bitarr tail bits to zero if (ia&63) { diff --git a/src/utils/mut.c b/src/utils/mut.c index 95255c82..4a538a08 100644 --- a/src/utils/mut.c +++ b/src/utils/mut.c @@ -43,7 +43,7 @@ static void* arr_ptr(Arr* t, u8 el) { return el==el_B? (void*)((HArr*)t)->a : (void*)((TyArr*)t)->a; } -u8 reuseElType[t_COUNT]; +INIT_GLOBAL u8 reuseElType[t_COUNT]; void mut_init_copy(Mut* m, B x, u8 el) { assert(m->fns == &mutFns[el_MAX]); if (reusable(x) && reuseElType[TY(x)]==el) { @@ -58,7 +58,7 @@ void mut_init_copy(Mut* m, B x, u8 el) { } } -static Arr* (*cpyFns[])(B) = { +static Arr* (* const cpyFns[])(B) = { [el_bit] = cpyBitArr, [el_i8] = cpyI8Arr, [el_c8] = cpyC8Arr, [el_i16] = cpyI16Arr, [el_c16] = cpyC16Arr, @@ -322,17 +322,17 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x #define COPY_FN(X,R) simd_copy_##X##_##R #define MAKE_CPY(TY, MAKE, GET, WR, XRP, H2T, E, N, ...) \ - static copy_fn copy0_##E##_fns[10]; \ + static copy_fn const copy0_##E##_fns[10]; \ NOINLINE void cpy##N##Arr_BF(void* xp, void* rp, u64 ia, Arr* xa) { \ - AS2B fn = TIv(xa,GET); \ - for (usz i=0; iobj; } NOINLINE Arr* apd_fill_end(ApdMut* m, u32 ty) { @@ -666,7 +666,7 @@ NOINLINE void apd_sh_init(ApdMut* m, B x) { if (xe==el_B) NOGC_E; } -NOINLINE void apd_widen(ApdMut* m, B x, ApdFn** fns) { +NOINLINE void apd_widen(ApdMut* m, B x, ApdFn* const* fns) { u8 xe = isArr(x)? TI(x,elType) : selfElType(x); u8 pe = TIv(m->obj,elType); u8 re = el_or(xe, pe); @@ -701,10 +701,10 @@ NOINLINE void apd_widen(ApdMut* m, B x, ApdFn** fns) { -M_CopyF copyFns[el_MAX]; -M_FillF fillFns[el_MAX]; -MutFns mutFns[el_MAX+1]; -u8 el_orArr[el_MAX*16 + el_MAX+1]; +INIT_GLOBAL M_CopyF copyFns[el_MAX]; +INIT_GLOBAL M_FillF fillFns[el_MAX]; +INIT_GLOBAL MutFns mutFns[el_MAX+1]; +INIT_GLOBAL u8 el_orArr[el_MAX*16 + el_MAX+1]; void mutF_init(void) { for (u8 i = 0; i <= el_MAX; i++) { for (u8 j = 0; j <= el_MAX; j++) { diff --git a/src/utils/mut.h b/src/utils/mut.h index af170e2c..ebeef513 100644 --- a/src/utils/mut.h +++ b/src/utils/mut.h @@ -25,7 +25,7 @@ struct MutFns { M_SetF m_set, m_setG; M_GetF m_getU; }; -extern MutFns mutFns[el_MAX+1]; +extern INIT_GLOBAL MutFns mutFns[el_MAX+1]; struct Mut { MutFns* fns; @@ -70,7 +70,7 @@ static Arr* mut_fp(Mut* m) { assert(m->fns->elType!=el_MAX); return m->val; } -extern u8 el_orArr[]; +extern INIT_GLOBAL u8 el_orArr[]; static u8 el_or(u8 a, u8 b) { return el_orArr[a*16 + b]; } diff --git a/src/utils/ryu.c b/src/utils/ryu.c index 485901d8..7e8702f4 100644 --- a/src/utils/ryu.c +++ b/src/utils/ryu.c @@ -381,8 +381,8 @@ static inline B to_chars(const floating_decimal_64 v, const bool sign, const boo return r; } -static B fmt_nan, fmt_zero; -static B fmt_inf[2]; +static GLOBAL B fmt_nan, fmt_zero; +static GLOBAL B fmt_inf[2]; B ryu_d2s(double f) { const uint64_t bits = double_to_bits(f); // decode the floating-point number, and unify normalized and subnormal cases. diff --git a/src/vm.c b/src/vm.c index e32e1dd1..01583d2c 100644 --- a/src/vm.c +++ b/src/vm.c @@ -61,16 +61,16 @@ void print_BCStream(FILE* f, u32* p) { } -B thrownMsg; -u64 envPrevHeight; +GLOBAL B thrownMsg; +GLOBAL u64 envPrevHeight; -Env* envCurr; // pointer to current environment; included to make for simpler current position updating -Env* envStart; -Env* envEnd; +GLOBAL Env* envCurr; // pointer to current environment; included to make for simpler current position updating +GLOBAL Env* envStart; +GLOBAL Env* envEnd; -B* gStack; // points to after end -B* gStackStart; -B* gStackEnd; +GLOBAL B* gStack; // points to after end +GLOBAL B* gStackStart; +GLOBAL B* gStackEnd; NOINLINE void gsReserveR(u64 am) { gsReserve(am); } void print_gStack() { B* c = gStackStart; @@ -140,7 +140,7 @@ typedef struct NextRequest { u32 pos2; // ↑ for dyadic; U32_MAX if not wanted } NextRequest; -static B emptyARMM; +static GLOBAL B emptyARMM; Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBlocks, B allBodies, B nameList, Scope* sc, i32 depth, i32 myPos, i32 nsResult) { assert(sc!=NULL || nsResult==0); @@ -1154,7 +1154,7 @@ void md2Bl_print(FILE* f, B x) { fprintf(f,"{2-modifier block}"); } B block_decompose(B x) { return m_hvec2(m_i32(1), x); } #if !defined(_WIN32) && !defined(_WIN64) -static usz pageSizeV; +static GLOBAL usz pageSizeV; #endif usz getPageSize() { @@ -1193,10 +1193,10 @@ void print_vmStack() { #endif } -B oomMessage; +GLOBAL B oomMessage; -u32 bL_m[BC_SIZE] = { // bytecode length map +u32 const bL_m[BC_SIZE] = { // bytecode length map [FN1C]=1, [FN2C]=1, [FN1O]=1, [FN2O]=1, [MD1C]=1, [MD2C]=1, [MD2R]=1, [TR2D]=1, [TR3D]=1, [TR3O]=1, @@ -1217,7 +1217,7 @@ u32 bL_m[BC_SIZE] = { // bytecode length map [FN2Oi]=5, [SETH2]=5, [PRED2]=5, }; -i32 sD_m[BC_SIZE] = { // stack diff map +i32 const sD_m[BC_SIZE] = { // stack diff map [PUSH ]= 1, [DYNO ]= 1, [DYNM]= 1, [DFND]= 1, [VARO]= 1, [VARM]= 1, [DFND0]= 1, [DFND1]=1, [DFND2]=1, [VARU ]= 1, [EXTO ]= 1, [EXTM]= 1, [EXTU]= 1, [SYSV]= 1, [ADDI]= 1, [ADDU ]= 1, [NOTM ]= 1, [FN1Ci]= 0, [FN1Oi]= 0, [CHKV]= 0, [VFYM]= 0, [FLDO]= 0, [FLDG]= 0, [FLDM]= 0, [RETD ]= 0, [ALIM ]=0, @@ -1231,7 +1231,7 @@ i32 sD_m[BC_SIZE] = { // stack diff map [FAIL]=0 }; -i32 sC_m[BC_SIZE] = { // stack consumed map +i32 const sC_m[BC_SIZE] = { // stack consumed map [PUSH]=0, [DYNO]=0, [DYNM]=0, [DFND]=0, [VARO ]=0,[VARM ]=0,[NOTM ]=0, [VARU]=0, [EXTO]=0, [EXTM]=0, [EXTU]=0, [SYSV]=0, [ADDI]=0, [ADDU]=0, [DFND0]=0,[DFND1]=0,[DFND2]=0, @@ -1247,7 +1247,7 @@ i32 sC_m[BC_SIZE] = { // stack consumed map [FAIL]=0 }; -i32 sA_m[BC_SIZE]; // stack added map +INIT_GLOBAL i32 sA_m[BC_SIZE]; // stack added map B funBl_uc1(B t, B o, B x) { return funBl_im(t, c1(o, c1(t, x))); @@ -1300,9 +1300,9 @@ typedef struct CatchFrame { u64 envDepth; u64 cfDepth; } CatchFrame; -CatchFrame* cf; // points to after end -CatchFrame* cfStart; -CatchFrame* cfEnd; +GLOBAL CatchFrame* cf; // points to after end +GLOBAL CatchFrame* cfStart; +GLOBAL CatchFrame* cfEnd; #if CATCH_ERRORS jmp_buf* prepareCatch() { @@ -1354,7 +1354,7 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes p return s; } -extern bool cbqn_initialized; +extern GLOBAL bool cbqn_initialized; NOINLINE void vm_printPos(Comp* comp, i32 bcPos, i64 pos) { B src = comp->src; if (!q_N(src) && !q_N(comp->indices)) { @@ -1439,10 +1439,10 @@ typedef union Profiler_ent { }; u64 ip; } Profiler_ent; -Profiler_ent* profiler_buf_s; -Profiler_ent* profiler_buf_c; -Profiler_ent* profiler_buf_e; -bool profile_buf_full; +GLOBAL Profiler_ent* profiler_buf_s; +GLOBAL Profiler_ent* profiler_buf_c; +GLOBAL Profiler_ent* profiler_buf_e; +GLOBAL bool profile_buf_full; void profiler_bc_handler(int x) { @@ -1509,8 +1509,8 @@ void* profiler_makeMap(void); i32 profiler_index(void** mapRaw, B comp); void profiler_freeMap(void* mapRaw); -i32 profiler_mode; // 0: freed; 1: bytecode; 2: instruction pointers -bool profiler_active; +GLOBAL i32 profiler_mode; // 0: freed; 1: bytecode; 2: instruction pointers +GLOBAL bool profiler_active; bool profiler_alloc(void) { profiler_buf_s = profiler_buf_c = mmap(NULL, PROFILE_BUFFER*sizeof(Profiler_ent), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); diff --git a/src/vm.h b/src/vm.h index 9893b63f..faf92229 100644 --- a/src/vm.h +++ b/src/vm.h @@ -190,10 +190,10 @@ FORCE_INLINE B execBodyInplaceI(Body* body, Scope* sc, Block* block) { // consum return evalBC(body, sc, block); } -extern u32 bL_m[BC_SIZE]; -extern i32 sD_m[BC_SIZE]; -extern i32 sC_m[BC_SIZE]; -extern i32 sA_m[BC_SIZE]; +extern u32 const bL_m[BC_SIZE]; +extern i32 const sD_m[BC_SIZE]; +extern i32 const sC_m[BC_SIZE]; +extern INIT_GLOBAL i32 sA_m[BC_SIZE]; static u32* nextBC (u32* p) { return p + bL_m[*p]; } static i32 stackAdded (u32* p) { return sA_m[*p]; } static i32 stackDiff (u32* p) { if (*p==LSTO|*p==LSTM|*p==ARMO|*p==ARMM) return 1-p[1]; return sD_m[*p]; } @@ -219,10 +219,10 @@ typedef struct Env { u64 pos; // if top bit set, ((u32)pos)>>1 is an offset into bytecode; otherwise, it's a pointer in the bytecode Scope* sc; } Env; -extern Env* envCurr; -extern Env* envStart; -extern Env* envEnd; -extern u64 envPrevHeight; // envStart+prevEnvHeight gives envCurr+1 from before the error +extern GLOBAL Env* envCurr; +extern GLOBAL Env* envStart; +extern GLOBAL Env* envEnd; +extern GLOBAL u64 envPrevHeight; // envStart+prevEnvHeight gives envCurr+1 from before the error static inline void pushEnv(Scope* sc, u32* bc) { if (envCurr+1==envEnd) thrM("Stack overflow"); Env* e = envCurr+1;