Files
ww/selfhost/test/sym_link.ww
Hojun-Cho 7a8acfb952 lib/ww,wcc: consolidate frontend into one syntax package (Go-compiler model, #74)
The ww compiler frontend was split across packages lex (lex+tok), ww
(ast+sym+typ), and parse — mirroring Hare's ref/hare/hare/{ast,lex,parse}.
That split's only payoff is third-party reuse, which ww has zero of: the
frontend is consumed by exactly one client, the wcc backend. The split's
cost is a wide cross-package export surface — every fn over a sibling
package's type must export it, and under separate compilation that
re-triggers check_exported_type, plus a phantom `import tok;` (tok lives
in package lex). Consolidate into ONE package lib/ww/syntax/, modelled on
Go's cmd/compile/internal/syntax. The 9 files move in (package syntax);
the intra-frontend mutual references become same-package; wcc and the
tool mains import syntax. No cstage C change (the C frontend mangles from
the source package clause). Internal data shapes (AST kinds, token model,
lexer/parser state) still mirror ref/hare/hare per rule 6/12 — only the
module decomposition collapses; the stdlib is untouched.

USER-approved (#74); spec .ai/rob-frontend-reorg.md (drew2 fidelity-
confirmed). Rule-6 carve-out documented in CLAUDE.md. Dissolves the tok
phantom import; collapses the intra-frontend export sprawl. Byte-id
rebaseline (lex.X/parse.X/ww.X -> syntax.X); cs==ww held. The residual
syntax->wcc export surface (10 types) + the unqualified-ref question are
separate follow-ups (#72/#75).
2026-06-16 19:56:34 +09:00

41 lines
1.1 KiB
Plaintext

// selfhost/test/sym_link.ww — link-and-run probe for the ww-cgen
// against the sym/typ/ast dep stack. Exercises hashtable scope
// (sym), and pulls in typ/ast as type carriers.
// Returns 42 on success; smaller values name the probe that broke.
package test;
import syntax;
export fn main() i32 = {
let s: *scope = newscope(nil);
if (s == nil) { return 2; };
let n1: str = "foo";
let r1: *sym = scopedefine(s, n1, skind.SK_VAR, nil, nil);
if (r1 == nil) { return 3; };
let n2: str = "bar";
let r2: *sym = scopedefine(s, n2, skind.SK_TYPE, nil, nil);
if (r2 == nil) { return 4; };
// Duplicate define in same scope must fail.
let r3: *sym = scopedefine(s, n1, skind.SK_VAR, nil, nil);
if (r3 != nil) { return 5; };
let l1: *sym = scopelookup(s, n1);
if (l1 == nil) { return 6; };
if (l1.skind != skind.SK_VAR) { return 7; };
let l2: *sym = scopelookup(s, n2);
if (l2 == nil) { return 8; };
if (l2.skind != skind.SK_TYPE) { return 9; };
// Not-found lookup returns nil.
let n3: str = "baz";
let l3: *sym = scopelookup(s, n3);
if (l3 != nil) { return 10; };
return 42;
};