move precompiled bytecode to submodule

This commit is contained in:
dzaima 2022-11-17 22:15:34 +02:00
parent 274d02b98b
commit 5c65a1a7eb
7 changed files with 39 additions and 47 deletions

4
.gitignore vendored
View File

@ -10,6 +10,7 @@ libcbqn.so
/build/obj/ /build/obj/
/build/singeliLocal /build/singeliLocal
/build/replxxLocal /build/replxxLocal
/build/bytecodeLocal
/src/singeli/gen /src/singeli/gen
# files generated by CBQN or other utilities # files generated by CBQN or other utilities
@ -31,7 +32,8 @@ CBQNHeapDump
compile_commands.json compile_commands.json
/.cache/ /.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/ /Singeli/
/SingeliClone/ /SingeliClone/
/obj/ /obj/
/src/gen/

View File

@ -17,9 +17,6 @@
## Configuration options ## 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: - Different build types:
- `make o3` - `-O3`, the default build - `make o3` - `-O3`, the default build
- `make o3n` - `-O3 -march=native` - `make o3n` - `-O3 -march=native`

View File

@ -1,13 +1,14 @@
#!/usr/bin/env bqn #!/usr/bin/env bqn
# to revert to using precompiled bytecode, remove the file src/gen/customRuntime
args←•args args←•args
"Usage: ./getRuntime.bqn path/to/mlochbaum/BQN"!1≤≠args "Usage: ./getRuntime.bqn path/to/mlochbaum/BQN output/path"!2≤≠args
path←⊑•args bqnSrc‿outputPath←2↑•args
CC ← {𝕨 •FChars ⟨1,path,𝕩⟩ •Import "cc.bqn"}
"src/gen/src" •FChars "#define RT_SRC 0"∾@+10 rtSrc ← ⊑(<"src")∊2↓•args
"src/gen/compiles"CC"cc"
"src/gen/runtime0"CC"r0" CC ← {𝕨 •FChars (⟨1,bqnSrc⟩∾(rtSrc/⟨"-i"⟩)∾⟨𝕩⟩) •Import "cc.bqn"}
"src/gen/runtime1"CC"r1" (outputPath•file.At "gen/src" )•FChars "#define RT_SRC "∾('0'+rtSrc)∾@+10
"src/gen/formatter"CC"f" (outputPath•file.At "gen/compiles" )CC"cc"
"src/gen/explain"CC"eu" (outputPath•file.At "gen/runtime0" )CC"r0"
"src/gen/customRuntime"•FChars"" (outputPath•file.At "gen/runtime1" )CC"r1"
(outputPath•file.At "gen/formatter")CC"f"
(outputPath•file.At "gen/explain" )CC"eu"

View File

@ -1,13 +1,3 @@
#!./BQN #!./BQN
# a version of genRuntime that also generates source maps, so that errors in the runtime or compiler get error messages # a version of genRuntime that also generates source maps, so that errors in the runtime or compiler get error messages
args←•args ({𝕩∾<"src"}⍟(2≤≠) •args) •Import "genRuntime"
"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""

View File

@ -120,6 +120,10 @@ endif
ifeq ($(i_singeli),1) ifeq ($(i_singeli),1)
SINGELI_DIR = $(shell if [ -d build/singeliLocal ]; then echo build/singeliLocal; else echo build/singeliSubmodule; fi) SINGELI_DIR = $(shell if [ -d build/singeliLocal ]; then echo build/singeliLocal; else echo build/singeliSubmodule; fi)
endif 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) i_LD = $(i_CC)
@ -130,7 +134,7 @@ else
NOWARN = -Wno-parentheses NOWARN = -Wno-parentheses
endif 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) ALL_LD_FLAGS = $(LDFLAGS) $(lf) $(i_lf) $(i_PIE) $(i_LD_LIBS)
ifneq (${manualJobs},1) ifneq (${manualJobs},1)
@ -150,7 +154,7 @@ ifeq ($(custom),)
else else
@[ -x "$$(command -v sha256sum)" ] && hashInput="sha256sum"; \ @[ -x "$$(command -v sha256sum)" ] && hashInput="sha256sum"; \
[ -x "$$(command -v shasum)" ] && hashInput="shasum -a 256"; \ [ -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 endif
else else
@printf "%s" "$(force_build_dir)" @printf "%s" "$(force_build_dir)"
@ -186,6 +190,10 @@ endif
ifeq ($(REPLXX_DIR),build/replxxSubmodule) ifeq ($(REPLXX_DIR),build/replxxSubmodule)
@git submodule update --init build/replxxSubmodule @git submodule update --init build/replxxSubmodule
endif 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); \ @export bd=$$(${MAKE} builddir); \
mkdir -p "$$bd"; \ mkdir -p "$$bd"; \
@ -233,12 +241,6 @@ ${bd}/%.o: src/builtins/%.c
.INTERMEDIATE: core base utils jit builtins .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 # singeli
@ -313,8 +315,6 @@ clean-singeli:
rm -rf src/singeli/gen/ rm -rf src/singeli/gen/
rm -rf build/obj/singeli/ rm -rf build/obj/singeli/
@${MAKE} clean-specific bd=build/obj/presingeli @${MAKE} clean-specific bd=build/obj/presingeli
clean-runtime:
rm -f src/gen/customRuntime
clean-build: clean-build:
rm -f build/obj/*/*.o rm -f build/obj/*/*.o
rm -f build/obj/*/*.d rm -f build/obj/*/*.d
@ -328,4 +328,4 @@ clean-submodules:
git submodule deinit build/singeliSubmodule/ build/replxxSubmodule/ git submodule deinit build/singeliSubmodule/ build/replxxSubmodule/
clean: clean-build clean-runtime clean-singeli clean: clean-build clean-singeli

2
src/gen/.gitignore vendored
View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -4,6 +4,10 @@
#include "ns.h" #include "ns.h"
#include "builtins.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 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); #define F(X) void X##_init(void);
FOR_INIT(F) FOR_INIT(F)
@ -114,7 +118,7 @@ Block* load_compObj(B x, B src, B path, Scope* sc) { // consumes x,src
return r; return r;
} }
#include "gen/src" #include PRECOMPILED_FILE(src)
#if RT_SRC #if RT_SRC
Block* load_compImport(char* name, B bc, B objs, B blocks, B bodies, B inds, B src) { // consumes all 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); 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}; 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 #else
Block* runtime0_b = load_compImport("(self-hosted runtime0)", 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 r0r = evalFunBlock(runtime0_b, 0); ptr_dec(runtime0_b);
B* runtime_0 = toHArr(r0r)->a; B* runtime_0 = toHArr(r0r)->a;
#endif #endif
Block* runtime_b = load_compImport("(self-hosted runtime1)", Block* runtime_b = load_compImport("(self-hosted runtime1)",
#include "gen/runtime1" #include PRECOMPILED_FILE(runtime1)
); );
#ifdef ALL_R0 #ifdef ALL_R0
@ -465,7 +469,7 @@ void load_init() { // very last init function
#ifdef PRECOMP #ifdef PRECOMP
Block* c = compile( Block* c = compile(
#include "gen/interp" #include PRECOMPILED_FILE(interp)
, bi_N, bi_N, bi_N, bi_N, NULL , bi_N, bi_N, bi_N, bi_N, NULL
); );
B interp = evalFunBlock(c, 0); ptr_dec(c); B interp = evalFunBlock(c, 0); ptr_dec(c);
@ -483,7 +487,7 @@ void load_init() { // very last init function
B prevAsrt = runtime[n_asrt]; B prevAsrt = runtime[n_asrt];
runtime[n_asrt] = bi_casrt; // horrible but GC is off so it's fiiiiiine runtime[n_asrt] = bi_casrt; // horrible but GC is off so it's fiiiiiine
Block* comp_b = load_compImport("(compiler)", Block* comp_b = load_compImport("(compiler)",
#include "gen/compiles" #include PRECOMPILED_FILE(compiles)
); );
runtime[n_asrt] = prevAsrt; runtime[n_asrt] = prevAsrt;
load_glyphs = m_hVec3(m_c32vec_0(U"+-×÷⋆√⌊⌈|¬∧∨<>≠=≤≥≡≢⊣⊢⥊∾≍⋈↑↓↕«»⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔!"), m_c32vec_0(U"˙˜˘¨⌜⁼´˝`"), m_c32vec_0(U"∘○⊸⟜⌾⊘◶⎉⚇⍟⎊")); 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 #if FORMATTER
Block* fmt_b = load_compImport("(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 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)})); 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) { if (load_explain.u==0) {
B* runtime = harr_ptr(load_rtObj); B* runtime = harr_ptr(load_rtObj);
Block* expl_b = load_compImport("(explain)", Block* expl_b = load_compImport("(explain)",
#include "gen/explain" #include PRECOMPILED_FILE(explain)
); );
load_explain = evalFunBlock(expl_b, 0); ptr_dec(expl_b); load_explain = evalFunBlock(expl_b, 0); ptr_dec(expl_b);
gc_add(load_explain); gc_add(load_explain);