diff options
Diffstat (limited to 'src/tools')
| -rwxr-xr-x | src/tools/bootstrap-check.sh | 2 | ||||
| -rw-r--r-- | src/tools/genmap.c | 37 | ||||
| -rwxr-xr-x | src/tools/mklsp.sh | 2 | ||||
| -rw-r--r-- | src/tools/zc0.c | 6 |
4 files changed, 37 insertions, 10 deletions
diff --git a/src/tools/bootstrap-check.sh b/src/tools/bootstrap-check.sh index 7acd74c..8d5c327 100755 --- a/src/tools/bootstrap-check.sh +++ b/src/tools/bootstrap-check.sh @@ -11,7 +11,7 @@ esac cd "$(dirname "$0")/../.." make -s build/bin/zc0 build/bin/mkgenome CC=${CC:-$(sh src/tools/findcc.sh)} -SRC="src/runtime/rt.zc src/core/core.zc src/compiler/compiler.zc" +SRC="src/runtime/rt.zc src/core/core.zc $(tr -d '\r' < src/compiler/parts | sed 's|^|src/compiler/|')" mkdir -p build/s0 build/s1 cat $SRC | build/bin/zc0 > build/s0/g0.bin build/bin/mkgenome < build/s0/g0.bin > build/s0/genome.bin diff --git a/src/tools/genmap.c b/src/tools/genmap.c index d063d36..d515778 100644 --- a/src/tools/genmap.c +++ b/src/tools/genmap.c @@ -1,6 +1,6 @@ /* one layout for every memory size. addresses in a genome are literals, so each size is its own image. this tool writes that image's memmap.h and - the runtime (and, for a compiler build, compiler.zc) with the same const + the runtime (and, for a compiler build, the compiler parts) with the same const names as the checked-in 1,048,576-word sources. run from the repo root: @@ -58,6 +58,33 @@ static char *slurp(const char *path) return b; } +/* the compiler source is the files listed in src/compiler/parts, one per line, + joined in that order */ +static char *slurp_compiler(void) +{ + char *list = slurp("src/compiler/parts"), *out = malloc(1), *line, *next; + size_t n = 0; + if (!out) die("oom"); + out[0] = 0; + for (line = list; *line; line = next) { + char path[512], *part, *e = line + strcspn(line, "\n"); + size_t k; + next = *e ? e + 1 : e; + while (e > line && (e[-1] == '\r' || e[-1] == ' ' || e[-1] == '\t')) e--; + if (e == line) continue; + snprintf(path, sizeof path, "src/compiler/%.*s", (int)(e - line), line); + part = slurp(path); + k = strlen(part); + out = realloc(out, n + k + 1); + if (!out) die("oom"); + memcpy(out + n, part, k + 1); + n += k; + free(part); + } + free(list); + return out; +} + static void emit_file(const char *path, const char *s) { FILE *f = fopen(path, "wb"); @@ -613,7 +640,7 @@ static void check_sources(const Map *m) default map's header is generated into build/core and never kept in the tree */ FILE *mf = fopen("memmap.h", "rb"); const char *mm_path = mf ? (fclose(mf), "memmap.h") : 0; - char *rt = slurp("src/runtime/rt.zc"), *cc = slurp("src/compiler/compiler.zc"), *mm = mm_path ? slurp(mm_path) : 0; + char *rt = slurp("src/runtime/rt.zc"), *cc = slurp_compiler(), *mm = mm_path ? slurp(mm_path) : 0; char *rtb = between(rt, "// @map-rt", "// @end-map"); char *ccb = between(cc, "// @map-cc", "// @end-map"); static const char *rt_names[] = { @@ -644,13 +671,13 @@ static void check_sources(const Map *m) if (!rtb || !ccb) die("map markers missing from the checked-in sources"); snprintf(lfa_old, sizeof lfa_old, "ld %d", DEFAULT_ZFP); if (!strstr(rt, lfa_old)) die("src/runtime/rt.zc no longer has the default lfa immediate"); - if (!strstr(cc, "ZFP - 16384")) die("src/compiler/compiler.zc lost its initial type-area formula"); + if (!strstr(cc, "ZFP - 16384")) die("src/compiler lost its initial type-area formula"); for (i = 0; rt_names[i]; i++) expect_hex(rtb, "src/runtime/rt.zc", rt_names[i], rt_vals[i]); for (i = 0; mm && rt_names[i]; i++) { if (!strcmp(rt_names[i], "MAGIC") || !strcmp(rt_names[i], "HEAP_GROW")) continue; expect_hex(mm, mm_path, !strcmp(rt_names[i], "MW") ? "PW" : rt_names[i], rt_vals[i]); } - if (m->R_ASM) for (i = 0; cc_names[i]; i++) expect_hex(ccb, "src/compiler/compiler.zc", cc_names[i], cc_vals[i]); + if (m->R_ASM) for (i = 0; cc_names[i]; i++) expect_hex(ccb, "src/compiler", cc_names[i], cc_vals[i]); free(rt); free(cc); free(mm); free(rtb); free(ccb); } @@ -668,7 +695,7 @@ static void write_sources(const char *dir, const Spec *s, const Map *m) free(rt); free(block); free(spliced); free(done); if (!s->compiler) return; { - char *cc = slurp("src/compiler/compiler.zc"); + char *cc = slurp_compiler(); block = cc_block(m); spliced = splice(cc, "// @map-cc", "// @end-map", block); if (s->type_formula) { diff --git a/src/tools/mklsp.sh b/src/tools/mklsp.sh index 1c44998..81cabcc 100755 --- a/src/tools/mklsp.sh +++ b/src/tools/mklsp.sh @@ -1,6 +1,6 @@ #!/bin/bash # builds the language server: src/tools/mklsp.sh [outdir] leaves outdir/zclsp. -# the server is the real compiler (src/compiler/compiler.zc) in check mode plus +# the server is the real compiler (src/compiler/, listed in parts) in check mode plus # src/lsp/server.zc. its memory map is sized to that program by src/tools/automap.sh, # so the genome slot is as big as it needs to be and no bigger. the image carries # the doc comments (DOCS=1) and, through embed declarations in server.zc, its own diff --git a/src/tools/zc0.c b/src/tools/zc0.c index b0ab29f..ba5081d 100644 --- a/src/tools/zc0.c +++ b/src/tools/zc0.c @@ -1,9 +1,9 @@ /* zc0: stage 0 of the bootstrap. a small c compiler for the subset of zc that - compiler.zc is written in. it reads zc source on stdin and writes a genome + the compiler (src/compiler/) is written in. it reads zc source on stdin and writes a genome image (vm words placed at GORG, as little-endian 64-bit words) on stdout, in the same image layout the resident compiler's image mode produces. the cores embed that file with #embed (src/core/genome.h). no lifetime analysis, no quote, no - parse words, no block expressions: those only exist in compiler.zc. tags + parse words, no block expressions: those only exist in the compiler. tags (m, d, -> u) and casts (as u, as d) are parsed and recorded in signatures but not checked. */ #include <stdio.h> @@ -341,7 +341,7 @@ static int64_t cexpr(void) /* ---- types ---- zc0 has no types: a type is read and thrown away. all it has to know is the shape, so that T[n] still reserves n words and the rest reserve one. the - grammar is the compiler's own (see ptype in compiler.zc): + grammar is the compiler's own (see ptype in src/compiler/types.zc): ptype a type, then any number of (params): int(int, int) is a function type ptype0 a type with its stars: int*, vec<T>*, point** ptype1 a base: T[n], T[?], fixed T[?], fn, a name, or a generic instance |
