From d981870038c3ffa531f5c1d07e4aec855e061491 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Wed, 14 Oct 2026 08:45:35 +0330 Subject: build: generate everything into build/, keep src/ free of generated files src/ carried 8.4 MB of build output: the genome header, the javascript vm and its layout, and the language-server image, plus a second copy of the extension server under editors/vscode/server/. none of it is source. - move the genome from src/core/genome.h to build/core/genome.h and compile with -Ibuild/core; `make all` bootstraps one when it is missing - write genome.json, layout.ts, layout.js and lsp.json to build/js/ - compile tinyvm.ts to build/js/, typed by a tracked src/js/layout.d.ts so the vm needs no generated file beside its source - build the wasm server into build/editors/vscode/server/ and stage the whole server into editors/vscode/server/ only while mkvsix.sh packages it - redirect the test suite, image_run.js, tinyvm.sh, tinyvm.bat, test_win.ps1 and the baremetal build at the new paths, and add make lspimage and make vsix - stop tracking every generated file also fix a build blocker: lookup_raw compared skind against K_VAR, which was never declared, so `make genome` could not run at all. the guard is about emitted program globals, which are K_GVAR and K_GARR. tests/test.sh -q reports 159 passed and 21 failed both before and after this change; every failure is pre-existing and comes from the checked-in genome being stale relative to src/, plus the bootstrap above. --- Makefile | 70 ++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 22 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b0e0df1..6a3898d 100644 --- a/Makefile +++ b/Makefile @@ -5,15 +5,20 @@ # make test the whole suite (tests/test.sh) # make check the minimal suite, for iterating (tests/test.sh -q) # make test JOBS=4 the same, four sections at a time -# make genome rebuild src/core/genome.h from src/ and check the fixpoint +# make genome rebuild build/core/genome.h from src/ and check the fixpoint # make lsp bin/zclsp, the language server # make web src/web/zc.wasm (needs clang with the wasm32 target) -# make js src/js/genome.json, for the javascript vm +# make js build/js/genome.json and the vm, for the javascript vm # make run PROG=examples/hello.zc # compile one program into a run-only image on a memory # map sized to it (src/tools/automap.sh) -> build/run/zymr +# make vsix the vscode extension, server and all # make clean remove bin/ and build/ and the web build # +# nothing built is kept in the tree: the genome, the javascript vm and its +# layout, and the packed editor server all land in build/ (the web build keeps +# its historical src/web/zc.wasm path because the page loads it by name). +# # CC picks the compiler (cc by default; clang works too). CC ?= cc @@ -32,6 +37,11 @@ endif BIN := bin B := build +JS := $(B)/js +# the hand-written core headers, then the generated genome beside them +COREINC := -Isrc/core -I$(B)/core +# the sources the compiler genome is built from +ZC_SRC := src/runtime/rt.zc src/core/core.zc src/compiler/compiler.zc TOOLS := $(BIN)/zc0$(EXE) $(BIN)/mkgenome$(EXE) $(BIN)/genmap$(EXE) PROGS := $(BIN)/zy$(EXE) $(BIN)/zym$(EXE) $(BIN)/zclsp$(EXE) @@ -49,11 +59,11 @@ $(BIN)/genmap$(EXE): src/tools/genmap.c | $(BIN) $(CC) $(CFLAGS) src/tools/genmap.c -Isrc/core -o $@ # the interpreter: the vm core with the compiler genome inside -$(BIN)/zy$(EXE): src/core/core.c $(IO) src/core/genome.h src/core/memmap.h src/core/fops.h src/core/bops.h src/core/stack.h | $(BIN) - $(CC) $(CFLAGS) -DJTYPE=int src/core/core.c $(IO) -Isrc/core -o $@ +$(BIN)/zy$(EXE): src/core/core.c $(IO) $(B)/core/genome.h src/core/memmap.h src/core/fops.h src/core/bops.h src/core/stack.h | $(BIN) + $(CC) $(CFLAGS) -DJTYPE=int src/core/core.c $(IO) $(COREINC) -o $@ # the portable microcore -$(BIN)/zym$(EXE): src/micro/micro.c src/micro/micro_port.h $(PORT) src/core/genome.h src/core/memmap.h src/core/fops.h src/core/bops.h src/core/stack.h | $(BIN) - $(CC) $(CFLAGS) $(MICRO_THREADS) src/micro/micro.c $(PORT) -Isrc/core -Isrc/micro -o $@ +$(BIN)/zym$(EXE): src/micro/micro.c src/micro/micro_port.h $(PORT) $(B)/core/genome.h src/core/memmap.h src/core/fops.h src/core/bops.h src/core/stack.h | $(BIN) + $(CC) $(CFLAGS) $(MICRO_THREADS) src/micro/micro.c $(PORT) $(COREINC) -Isrc/micro -o $@ # the language server is the compiler in check mode plus src/lsp/server.zc, on a map # sized to it @@ -66,33 +76,49 @@ src/compiler/compiler.zc: src/lib/std.zc src/lib/icon.zc src/tools/embed.sh bash src/tools/embed.sh all # bootstrap: zc0 compiles the compiler to g0, g0 compiles it to g1, g1 to g2. -# g1 and g2 must be identical (the fixpoint), and g1 becomes src/core/genome.h. +# g1 and g2 must be identical (the fixpoint), and g1 becomes build/core/genome.h. +# run this by hand after editing a .zc source; `make check` reports a stale genome. genome: $(BIN)/zc0$(EXE) $(BIN)/mkgenome$(EXE) src/compiler/compiler.zc | $(B) - mkdir -p $(B)/s0 $(B)/s1 + mkdir -p $(B)/s0 $(B)/s1 $(B)/core cp src/core/core.c $(IO) src/core/memmap.h src/core/fops.h src/core/bops.h src/core/stack.h $(B)/s0/ cp src/core/core.c $(IO) src/core/memmap.h src/core/fops.h src/core/bops.h src/core/stack.h $(B)/s1/ - cat src/runtime/rt.zc src/core/core.zc src/compiler/compiler.zc | $(BIN)/zc0$(EXE) > $(B)/s0/genome.h + cat $(ZC_SRC) | $(BIN)/zc0$(EXE) > $(B)/s0/genome.h $(CC) $(CFLAGS) -DJTYPE=int $(B)/s0/core.c $(B)/s0/$(notdir $(IO)) -o $(B)/zy0$(EXE) - (cat src/tools/build.zc; printf '`'; cat src/runtime/rt.zc src/core/core.zc src/compiler/compiler.zc) | $(B)/zy0$(EXE) > $(B)/g1.bin + (cat src/tools/build.zc; printf '`'; cat $(ZC_SRC)) | $(B)/zy0$(EXE) > $(B)/g1.bin $(BIN)/mkgenome$(EXE) < $(B)/g1.bin > $(B)/s1/genome.h $(CC) $(CFLAGS) -DJTYPE=int $(B)/s1/core.c $(B)/s1/$(notdir $(IO)) -o $(B)/zy1$(EXE) - (cat src/tools/build.zc; printf '`'; cat src/runtime/rt.zc src/core/core.zc src/compiler/compiler.zc) | $(B)/zy1$(EXE) > $(B)/g2.bin + (cat src/tools/build.zc; printf '`'; cat $(ZC_SRC)) | $(B)/zy1$(EXE) > $(B)/g2.bin cmp $(B)/g1.bin $(B)/g2.bin - cp $(B)/s1/genome.h src/core/genome.h - @echo "fixpoint: $$(( $$(wc -c < $(B)/g1.bin) / 8 )) words, src/core/genome.h updated" + cp $(B)/s1/genome.h $(B)/core/genome.h + @echo "fixpoint: $$(( $$(wc -c < $(B)/g1.bin) / 8 )) words, $(B)/core/genome.h updated" + +# a fresh clone has no genome, so bootstrap one on demand. it is deliberately +# not rebuilt from source dependencies: the fixpoint run is expensive, and +# `make genome` is the explicit way to refresh it after editing a .zc file. +$(B)/core/genome.h: + $(MAKE) genome -js: src/js/genome.json src/js/layout.ts src/js/layout.js src/js/tinyvm.js -src/js/genome.json: src/core/genome.h src/core/memmap.h src/js/extract_genome.js src/js/mapvalues.js +js: $(JS)/genome.json $(JS)/layout.js $(JS)/tinyvm.js +$(JS): + mkdir -p $@ +$(JS)/genome.json: $(B)/core/genome.h src/core/memmap.h src/js/extract_genome.js src/js/mapvalues.js | $(JS) node src/js/extract_genome.js -src/js/layout.ts: src/js/genome.json +$(JS)/layout.ts $(JS)/layout.js: $(JS)/genome.json @test -f $@ || node src/js/extract_genome.js -src/js/layout.js: src/js/layout.ts - @test -f $@ || node src/js/extract_genome.js -src/js/tinyvm.js: src/js/tinyvm.ts src/js/layout.ts - tsc src/js/tinyvm.ts --target es2020 --lib es2020,dom --module commonjs --outDir src/js +$(JS)/tinyvm.js: src/js/tinyvm.ts src/js/layout.d.ts | $(JS) + tsc src/js/tinyvm.ts --target es2020 --lib es2020,dom --module commonjs --outDir $(JS) + +# the language server image for the javascript vm, and the wasm server +lspimage: $(JS)/lsp.json +$(JS)/lsp.json: $(BIN)/zclsp$(EXE) src/js/extract_lsp.js src/js/mapvalues.js | $(JS) + node src/js/extract_lsp.js + +# the vscode extension, with the server and its image inside it +vsix: | $(B) + bash src/tools/mkvsix.sh web: src/web/zc.wasm -src/web/zc.wasm: src/micro/micro.c src/micro/micro_port.h src/web/port_wasm.c src/web/build.sh src/core/genome.h src/core/memmap.h src/core/fops.h src/core/bops.h src/core/stack.h +src/web/zc.wasm: src/micro/micro.c src/micro/micro_port.h src/web/port_wasm.c src/web/build.sh $(B)/core/genome.h src/core/memmap.h src/core/fops.h src/core/bops.h src/core/stack.h bash src/web/build.sh $@ # one program as a run-only image: the runtime, the program, and a map exactly @@ -115,4 +141,4 @@ check: clean: rm -rf $(BIN) $(B) src/web/zc.wasm -.PHONY: all lsp genome js web run test check clean +.PHONY: all lsp genome js lspimage vsix web run test check clean -- cgit v1.2.3