diff options
| author | 2026-10-14 07:28:39 +0000 | |
|---|---|---|
| committer | 2026-10-14 07:28:39 +0000 | |
| commit | 7451eb090d890fb5ea5e4d40627a1b4df15a49de (patch) | |
| tree | 357bdf4b528e860bffa688865306f656b788d2c2 /src/tools/automap.sh | |
| parent | analyzer: close the ownership gaps that stopped the compiler compiling itself (diff) | |
build: embed images with #embed, keep everything generated in build/
the cores take their genome in with c23 #embed through src/core/genome.h,
so images are plain little-endian word files (genome.bin) instead of
generated c headers. zc0 writes that format, mkgenome checks an image
against its map and shows a compiler's diagnostics when it gets them,
and the javascript vm and the editor's vm host read the same files.
src/tools/findcc.sh picks a compiler with #embed (clang 19 or gcc 15).
zc gets an embed declaration, embed "file" as [type] name, for globals
and locals: a byte string by default, char*, numbers read little-endian,
and arrays of numbers. the compiler and language server carry their
library and source texts through it, so embed.sh and the text it
spliced into compiler.zc are gone.
make writes executables to build/bin, the default map to build/core/map,
the web page to build/web and the extension staging to build/vsix, and
the genome now rebuilds when its sources change. the test suite lays
out its own map and bootstrap and reads nothing from build/.
also: rt.put_s of a byte string in zc0 images, retained function
sources no longer count as live objects, a missing include no longer
cascades into undefined-name errors, consecutive comment lines join
into one hover paragraph, and stale test fixtures follow the include
format.
Diffstat (limited to 'src/tools/automap.sh')
| -rwxr-xr-x | src/tools/automap.sh | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/tools/automap.sh b/src/tools/automap.sh index 69849ca..ff559ac 100755 --- a/src/tools/automap.sh +++ b/src/tools/automap.sh @@ -3,7 +3,8 @@ # src/tools/automap.sh PRESET OUTDIR FILE... # PRESET is run, small, default or lsp. DOCS=1 makes the genome with its doc comments. FILE... are appended after the map's own # rt.zc (and compiler.zc, for the presets that carry the compiler). the result -# is OUTDIR/memmap.h and OUTDIR/genome.h, and they agree with each other. +# is OUTDIR/memmap.h and OUTDIR/genome.bin, and they agree with each other. a core +# compiled with -IOUTDIR --embed-dir=OUTDIR embeds that image (src/core/genome.h). # # a genome's length doesn't depend on where it lives (every address is a one # word literal), so two passes are enough: compile once on the preset's map @@ -14,15 +15,14 @@ # GENMAP can name a genmap that is already built. set -e case "${1:-}" in - --help|-h) printf '%s\n' 'usage: src/tools/automap.sh run|small|default|lsp OUTDIR FILE...' 'builds a genome and memory map sized to the supplied source files.' 'output: OUTDIR/genome.h and OUTDIR/memmap.h' 'environment: CC selects the c compiler; DOCS=1 retains documentation; GENMAP selects genmap.'; exit 0 ;; + --help|-h) printf '%s\n' 'usage: src/tools/automap.sh run|small|default|lsp OUTDIR FILE...' 'builds a genome and memory map sized to the supplied source files.' 'output: OUTDIR/genome.bin and OUTDIR/memmap.h' 'environment: CC selects the c compiler; DOCS=1 retains documentation; GENMAP selects genmap.'; exit 0 ;; -*) echo "automap: unknown option $1; use --help for usage" >&2; exit 2 ;; esac cd "$(dirname "$0")/../.." [[ $# -ge 2 ]] || { echo 'usage: src/tools/automap.sh run|small|default|lsp OUTDIR FILE...' >&2; exit 2; } P=$1; O=$2; shift 2 [ -n "$P" ] && [ -n "$O" ] || { echo "usage: src/tools/automap.sh run|small|default|lsp OUTDIR FILE..." >&2; exit 2; } -CC=${CC:-gcc} -bash src/tools/embed.sh all --check || bash src/tools/embed.sh all +CC=${CC:-$(sh src/tools/findcc.sh)} mkdir -p "$O" ZC0=$O/.zc0 if [ -z "$GENMAP" ]; then @@ -33,32 +33,36 @@ lay() { # $1 = genome slot, or empty for the preset's own rm -rf "$O/map" "$GENMAP" --preset "$P" --grow ${1:+--genome $1} -o "$O/map" >/dev/null 2>&1 $CC -O1 -w -fwrapv src/tools/zc0.c -I"$O/map" -Isrc/core -o "$ZC0" + $CC -O1 -w -fwrapv src/tools/mkgenome.c -I"$O/map" -o "$O/.mkgenome" } build() { - if [ -f "$O/map/compiler.zc" ]; then cat "$O/map/rt.zc" src/core/core.zc "$O/map/compiler.zc" "$@"; else cat "$O/map/rt.zc" src/core/core.zc "$@"; fi | "$ZC0" + if [ -f "$O/map/compiler.zc" ]; then cat "$O/map/rt.zc" src/core/core.zc "$O/map/compiler.zc" "$@"; else cat "$O/map/rt.zc" src/core/core.zc "$@"; fi | "$ZC0" > "$O/image.bin" + "$O/.mkgenome" < "$O/image.bin" > "$O/genome.bin" } # with DOCS=1 the genome is made again with zc0 built for docs (ZC0DOCS), so the # image carries the doc comments of the sources and the program can answer # docofs(). the image is the same code either way; the docs are stored after it. docs() { $CC -O1 -w -fwrapv -DZC0DOCS src/tools/zc0.c -I"$O/map" -Isrc/core -o "$O/.zc0docs" - if [ -f "$O/map/compiler.zc" ]; then cat "$O/map/rt.zc" src/core/core.zc "$O/map/compiler.zc" "$@"; else cat "$O/map/rt.zc" src/core/core.zc "$@"; fi | "$O/.zc0docs" + if [ -f "$O/map/compiler.zc" ]; then cat "$O/map/rt.zc" src/core/core.zc "$O/map/compiler.zc" "$@"; else cat "$O/map/rt.zc" src/core/core.zc "$@"; fi | "$O/.zc0docs" > "$O/image.bin" + "$O/.mkgenome" < "$O/image.bin" > "$O/genome.bin" } -len() { grep -m1 '#define GLEN' "$1" | awk '{print $3}'; } +len() { echo $(( $(wc -c < "$1") / 8 )); } lay "" -build "$@" > "$O/genome.h" -glen=$(len "$O/genome.h") +build "$@" +glen=$(len "$O/genome.bin") slot=$(( (glen + 4095) / 4096 * 4096 )) lay "$slot" -build "$@" > "$O/genome.h" +build "$@" if [ -n "$DOCS" ]; then lay $((slot + 65536)) # room for the image with its docs while it is being made - docs "$@" > "$O/genome.h" - glen=$(len "$O/genome.h") + docs "$@" + glen=$(len "$O/genome.bin") slot=$(( (glen + 4095) / 4096 * 4096 )) lay "$slot" - docs "$@" > "$O/genome.h" + docs "$@" fi -[ "$(len "$O/genome.h")" = "$glen" ] || { echo "automap: the genome changed length with the map" >&2; exit 1; } +rm -f "$O/image.bin" +[ "$(len "$O/genome.bin")" = "$glen" ] || { echo "automap: the genome changed length with the map" >&2; exit 1; } cp "$O/map/memmap.h" "$O/map/map.txt" "$O/" echo "automap $P: genome $glen words in a slot of $slot, $(grep -m1 '^MW' "$O/map/map.txt")" |
