selfhost: migrate tool sources to directory packages

Build w6a and w6l from package-main directories and expose the wcc backend through a narrow package API so w6c and wwdump no longer import implementation files. Retarget the remaining load-bearing fixtures and example sources to directory packages; retain the one intentional flat compiler collision as an explicitly composed raw unit.
This commit is contained in:
2026-08-12 17:12:03 +09:00
parent 90f9d60291
commit c7d9dc92de
38 changed files with 197 additions and 252 deletions

View File

@@ -5,7 +5,7 @@ backend rather than the C bootstrap one.
## Layout
- `lispcore.ww` interpreter module: types, lexer, parser, env,
- `lispcore/` interpreter directory package: types, lexer, parser, env,
eval, apply, printer, REPL. Everything the entry
point and the test driver consume is `export`-ed.
- `lisp.ww` entry point; `use lispcore;` + `main()`.
@@ -15,12 +15,9 @@ backend rather than the C bootstrap one.
runs the binary itself.
- `test_*.lisp` demo source files (`cat test_X.lisp | ./lisp`).
The lispcore.ww + lisp.ww split exists so the tests can `use` the
interpreter functions. Both files combine under the same module name
(the directory's basename, `lisp`), because `ww`'s module resolver
takes the *containing-directory* basename when finding a sibling.
Cross-module type prefixes like `lispcore.value` don't resolve in the
test — use the bare names.
The lispcore/ + lisp.ww split exists so the entry point and tests import
one canonical interpreter directory package. Cross-module type prefixes
like `lispcore.value` don't resolve in the test — use the bare names.
## wwstage cgen workarounds at play

View File

@@ -3,17 +3,14 @@
#
# Layout
# lisp.ww entry point. `use lispcore;` + `main()` = repl().
# lispcore.ww interpreter module. Types/functions are `export`-ed
# lispcore/ interpreter package. Types/functions are `export`-ed
# so both lisp.ww and lisp_test.ww consume them via
# the same `use lispcore;`.
# lisp_test.ww in-process test driver, executed by `make test`
# (which invokes `ww test`).
#
# `ww`'s module resolver uses the *directory's basename* as the module
# name when finding `lispcore.ww` through `-I <dir>`. Passing the
# absolute path of the current directory keeps that name stable
# (otherwise `-I.` collapses to ".", and the cgen mangles symbols as
# `..helper`, which then breaks the assembler).
# The absolute include root makes `import lispcore` resolve the canonical
# lispcore/ directory regardless of the caller's working directory.
# Drive the wwstage cgen (w6c_ww) by default. The C-stage cgen has
# unfixed silent-miscompilation traps that lispcore used to dodge by
@@ -25,7 +22,7 @@ W6CWW := $(shell cd ../..; pwd)/out/bin/w6c_ww
HERE := $(shell pwd)
WWENV := WW_W6C=$(W6CWW)
lisp: lisp.ww lispcore.ww
lisp: lisp.ww lispcore/lispcore.ww
$(WWENV) $(WW) build lisp.ww -I $(HERE)
# `ww test <file.ww>` in single-file mode discards extra args, so we
@@ -34,7 +31,7 @@ lisp: lisp.ww lispcore.ww
test: lisp_test lisp
./lisp_test
lisp_test: lisp_test.ww lispcore.ww
lisp_test: lisp_test.ww lispcore/lispcore.ww
$(WWENV) $(WW) build lisp_test.ww -I $(HERE)
# Demo programs in tree. `make demo` runs every test_*.lisp through

View File

@@ -1,4 +1,4 @@
// lisp — entry point. The interpreter lives in `lispcore.ww`; this
// lisp — entry point. The interpreter lives in the `lispcore` package; this
// file only wires it to `main()` so `ww build lisp.ww` produces the
// REPL binary. The matching tests live in `lisp_test.ww` and pull
// the same module via `use lispcore;`.

View File

@@ -59,7 +59,7 @@
// - `acc /= d` / `acc += f` on f64 locals lower to `acc = d` (drop
// the OP). Write the explicit form `acc = acc OP d`.
package lisp;
package lispcore;
import os;
import rt;
@@ -1784,4 +1784,3 @@ export fn repl() i32 = {
return 0;
};