diff --git a/.gitignore b/.gitignore index 6d444ad6..01500327 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ libcbqn.so /build/obj/ /build/singeliLocal /build/replxxLocal +/build/bytecodeLocal /src/singeli/gen # files generated by CBQN or other utilities @@ -31,7 +32,8 @@ CBQNHeapDump compile_commands.json /.cache/ -# things not used anymore, but still may be present in existing clones: +# things not used anymore, but still may be present in existing clones /Singeli/ /SingeliClone/ -/obj/ \ No newline at end of file +/obj/ +/src/gen/ \ No newline at end of file diff --git a/README.md b/README.md index e749fbee..8f928058 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,6 @@ ## Configuration options -- `some-other-bqn-implementation ./genRuntime path/to/mlochbaum/BQN` can be used to avoid pulling precompiled bytecode with git from `remotes/origin/bytecode`. - This creates the dummy file `src/gen/customRuntime`, which will disable automated bytecode retrieval, leading to the bytecode going out-of-sync whenever it needs updating. - `make clean-runtime` (which is included in `make clean`) can be used to reset this to the default state. - Different build types: - `make o3` - `-O3`, the default build - `make o3n` - `-O3 -march=native` diff --git a/genRuntime b/genRuntime index 45182f54..a75972fb 100755 --- a/genRuntime +++ b/genRuntime @@ -1,13 +1,14 @@ #!/usr/bin/env bqn -# to revert to using precompiled bytecode, remove the file src/gen/customRuntime args←•args -"Usage: ./getRuntime.bqn path/to/mlochbaum/BQN"!1≤≠args -path←⊑•args -CC ← {𝕨 •FChars ⟨1,path,𝕩⟩ •Import "cc.bqn"} -"src/gen/src" •FChars "#define RT_SRC 0"∾@+10 - "src/gen/compiles"CC"cc" - "src/gen/runtime0"CC"r0" - "src/gen/runtime1"CC"r1" -"src/gen/formatter"CC"f" -"src/gen/explain"CC"eu" -"src/gen/customRuntime"•FChars"" +"Usage: ./getRuntime.bqn path/to/mlochbaum/BQN output/path"!2≤≠args +bqnSrc‿outputPath←2↑•args + +rtSrc ← ⊑(<"src")∊2↓•args + +CC ← {𝕨 •FChars (⟨1,bqnSrc⟩∾(rtSrc/⟨"-i"⟩)∾⟨𝕩⟩) •Import "cc.bqn"} +(outputPath•file.At "gen/src" )•FChars "#define RT_SRC "∾('0'+rtSrc)∾@+10 +(outputPath•file.At "gen/compiles" )CC"cc" +(outputPath•file.At "gen/runtime0" )CC"r0" +(outputPath•file.At "gen/runtime1" )CC"r1" +(outputPath•file.At "gen/formatter")CC"f" +(outputPath•file.At "gen/explain" )CC"eu" diff --git a/genRuntimeSrc b/genRuntimeSrc index 03149de2..6f15032c 100755 --- a/genRuntimeSrc +++ b/genRuntimeSrc @@ -1,13 +1,3 @@ #!./BQN # a version of genRuntime that also generates source maps, so that errors in the runtime or compiler get error messages -args←•args -"Usage: ./getRuntime.bqn path/to/mlochbaum/BQN"!1≤≠args -path←⊑•args -CC ← {𝕨 •FChars ⟨1,path,"-i",𝕩⟩ •Import "cc.bqn"} -"src/gen/src" •FChars "#define RT_SRC 1"∾@+10 - "src/gen/compiles"CC"cc" - "src/gen/runtime0"CC"r0" - "src/gen/runtime1"CC"r1" -"src/gen/formatter"CC"f" -"src/gen/explain"CC"eu" -"src/gen/customRuntime"•FChars"" +({𝕩∾<"src"}⍟(2≤≠) •args) •Import "genRuntime" \ No newline at end of file diff --git a/makefile b/makefile index 82f0da0e..436ffe9c 100644 --- a/makefile +++ b/makefile @@ -120,6 +120,10 @@ endif ifeq ($(i_singeli),1) SINGELI_DIR = $(shell if [ -d build/singeliLocal ]; then echo build/singeliLocal; else echo build/singeliSubmodule; fi) endif +BYTECODE_DIR = $(shell if [ -d build/bytecodeLocal ]; then echo bytecodeLocal; else echo bytecodeSubmodule; fi) +ifeq ($(BYTECODE_DIR),bytecodeLocal) + custom = 1 +endif i_LD = $(i_CC) @@ -130,7 +134,7 @@ else NOWARN = -Wno-parentheses endif -ALL_CC_FLAGS = -std=gnu11 -Wall -Wno-unused-function -fms-extensions -ffp-contract=off -fno-math-errno $(CCFLAGS) $(f) $(i_f) $(NOWARN) -DSINGELI=$(i_singeli) -DFFI=$(i_FFI) $(SHARED_CCFLAGS) +ALL_CC_FLAGS = -std=gnu11 -Wall -Wno-unused-function -fms-extensions -ffp-contract=off -fno-math-errno $(CCFLAGS) $(f) $(i_f) $(NOWARN) -DBYTECODE_DIR=$(BYTECODE_DIR) -DSINGELI=$(i_singeli) -DFFI=$(i_FFI) $(SHARED_CCFLAGS) ALL_LD_FLAGS = $(LDFLAGS) $(lf) $(i_lf) $(i_PIE) $(i_LD_LIBS) ifneq (${manualJobs},1) @@ -150,7 +154,7 @@ ifeq ($(custom),) else @[ -x "$$(command -v sha256sum)" ] && hashInput="sha256sum"; \ [ -x "$$(command -v shasum)" ] && hashInput="shasum -a 256"; \ - printf "%s\0%s\0%s\0%s\0%s\0%s\0%s\0%s" "${i_CC}" "${ALL_CC_FLAGS}" "${ALL_LD_FLAGS}" "${REPLXX}" "${REPLXX_FLAGS}" "${i_CXX}" "${REPLXX_DIR}" "${SINGELI_DIR}" | $$hashInput | grep -oE '[0-9a-z]{64}' | head -c32 + printf "%s\0%s\0%s\0%s\0%s\0%s\0%s\0%s\0%s" "${i_CC}" "${ALL_CC_FLAGS}" "${ALL_LD_FLAGS}" "${REPLXX}" "${REPLXX_FLAGS}" "${i_CXX}" "${BYTECODE_DIR}" "${REPLXX_DIR}" "${SINGELI_DIR}" | $$hashInput | grep -oE '[0-9a-z]{64}' | head -c32 endif else @printf "%s" "$(force_build_dir)" @@ -186,6 +190,10 @@ endif ifeq ($(REPLXX_DIR),build/replxxSubmodule) @git submodule update --init build/replxxSubmodule endif +ifeq ($(BYTECODE_DIR),bytecodeSubmodule) + @echo "Using precompiled bytecode; see readme for how to build your own" + @git submodule update --init build/bytecodeSubmodule +endif @export bd=$$(${MAKE} builddir); \ mkdir -p "$$bd"; \ @@ -233,12 +241,6 @@ ${bd}/%.o: src/builtins/%.c .INTERMEDIATE: core base utils jit builtins -src/gen/customRuntime: - @echo "Copying precompiled bytecode from the bytecode branch" - git checkout remotes/origin/bytecode src/gen/{compiles,formatter,runtime0,runtime1,src,explain} - git reset src/gen/{compiles,formatter,runtime0,runtime1,src,explain} -${bd}/load.o: src/gen/customRuntime - # singeli @@ -313,8 +315,6 @@ clean-singeli: rm -rf src/singeli/gen/ rm -rf build/obj/singeli/ @${MAKE} clean-specific bd=build/obj/presingeli -clean-runtime: - rm -f src/gen/customRuntime clean-build: rm -f build/obj/*/*.o rm -f build/obj/*/*.d @@ -328,4 +328,4 @@ clean-submodules: git submodule deinit build/singeliSubmodule/ build/replxxSubmodule/ -clean: clean-build clean-runtime clean-singeli +clean: clean-build clean-singeli diff --git a/src/gen/.gitignore b/src/gen/.gitignore deleted file mode 100644 index d6b7ef32..00000000 --- a/src/gen/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/src/load.c b/src/load.c index 843103df..6adc2ffc 100644 --- a/src/load.c +++ b/src/load.c @@ -4,6 +4,10 @@ #include "ns.h" #include "builtins.h" +#define PRECOMPILED_FILE0(X) #X +#define PRECOMPILED_FILE1(X) PRECOMPILED_FILE0(X) +#define PRECOMPILED_FILE(END) PRECOMPILED_FILE1(../build/BYTECODE_DIR/gen/END) + #define FOR_INIT(F) F(base) F(harr) F(mutF) F(fillarr) F(tyarr) F(hash) F(sfns) F(fns) F(arith) F(md1) F(md2) F(derv) F(comp) F(rtWrap) F(ns) F(nfn) F(sysfn) F(inverse) F(slash) F(search) F(load) F(sysfnPost) F(dervPost) F(ffi) F(mmap) F(typesFinished) #define F(X) void X##_init(void); FOR_INIT(F) @@ -114,7 +118,7 @@ Block* load_compObj(B x, B src, B path, Scope* sc) { // consumes x,src return r; } -#include "gen/src" +#include PRECOMPILED_FILE(src) #if RT_SRC Block* load_compImport(char* name, B bc, B objs, B blocks, B bodies, B inds, B src) { // consumes all return compile(bc, objs, blocks, bodies, inds, bi_N, src, m_c8vec_0(name), NULL); @@ -380,14 +384,14 @@ void load_init() { // very last init function B runtime_0[] = {bi_floor,bi_ceil,bi_stile,bi_lt,bi_gt,bi_ne,bi_ge,bi_rtack,bi_ltack,bi_join,bi_pair,bi_take,bi_drop,bi_select,bi_const,bi_swap,bi_each,bi_fold,bi_atop,bi_over,bi_before,bi_after,bi_cond,bi_repeat}; #else Block* runtime0_b = load_compImport("(self-hosted runtime0)", - #include "gen/runtime0" + #include PRECOMPILED_FILE(runtime0) ); B r0r = evalFunBlock(runtime0_b, 0); ptr_dec(runtime0_b); B* runtime_0 = toHArr(r0r)->a; #endif Block* runtime_b = load_compImport("(self-hosted runtime1)", - #include "gen/runtime1" + #include PRECOMPILED_FILE(runtime1) ); #ifdef ALL_R0 @@ -465,7 +469,7 @@ void load_init() { // very last init function #ifdef PRECOMP Block* c = compile( - #include "gen/interp" + #include PRECOMPILED_FILE(interp) , bi_N, bi_N, bi_N, bi_N, NULL ); B interp = evalFunBlock(c, 0); ptr_dec(c); @@ -483,7 +487,7 @@ void load_init() { // very last init function B prevAsrt = runtime[n_asrt]; runtime[n_asrt] = bi_casrt; // horrible but GC is off so it's fiiiiiine Block* comp_b = load_compImport("(compiler)", - #include "gen/compiles" + #include PRECOMPILED_FILE(compiles) ); runtime[n_asrt] = prevAsrt; load_glyphs = m_hVec3(m_c32vec_0(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!"), m_c32vec_0(U"˙˜˘¨⌜⁼´˝`"), m_c32vec_0(U"∘○⊸⟜⌾⊘◶⎉⚇⍟⎊")); @@ -494,7 +498,7 @@ void load_init() { // very last init function #if FORMATTER Block* fmt_b = load_compImport("(formatter)", - #include "gen/formatter" + #include PRECOMPILED_FILE(formatter) ); B fmtM = evalFunBlock(fmt_b, 0); ptr_dec(fmt_b); B fmtR = c1(fmtM, m_caB(4, (B[]){incG(bi_type), incG(bi_decp), incG(bi_glyph), incG(bi_repr)})); @@ -532,7 +536,7 @@ B bqn_explain(B str, B path) { if (load_explain.u==0) { B* runtime = harr_ptr(load_rtObj); Block* expl_b = load_compImport("(explain)", - #include "gen/explain" + #include PRECOMPILED_FILE(explain) ); load_explain = evalFunBlock(expl_b, 0); ptr_dec(expl_b); gc_add(load_explain);