Compiler architecture
Goalchemy centralizes source semantics before target emission. Each backend consumes the same typed representation and implements the required runtime contracts.
Compilation pipeline
Section titled “Compilation pipeline”- Load packages.
internal/frontenduses Go package loading and typing under the pinned source profile. - Check the gate.
internal/subsetrejects unsupported source with stable diagnostics and remedies. - Lower and verify.
internal/lowerconstructsinternal/ir, making sequencing, value copies, storage, and runtime operations explicit. - Emit native source.
internal/emitcontains the target emitters;internal/namingmanages legal and deterministic identifiers. - Link the runtime.
internal/linkincludes only required operation files and shared representations, then records inventories, contracts, and hashes. - Map diagnostics.
internal/sourcemapconnects generated positions with source locations.
internal/driver coordinates compilation. The public CLI is in cmd/goalchemy. The binary embeds the catalog and runtime assets so compilation does not require a source checkout.
Runtime architecture
Section titled “Runtime architecture”| Layer | Source of behavior |
|---|---|
| Source semantics | Language specification, checked features, and typed IR. |
| Canonical contracts | YAML under specs/types/ and specs/runtime/, validated against schemas. |
| Target mappings | targets/<target>/target.yaml, representation code, operation implementations, and harnesses. |
| Shared source packages | std/, compiled with the user program. |
| Native capabilities | lib/ declarations and native implementations per target. |
Contracts refine operations without replacing the language specification. An emitter must not silently adopt different host semantics.
Verification layers
Section titled “Verification layers”Native Go acts as an oracle for accepted source fixtures. Runtime harnesses check operation contracts independently. Corpus regressions retain reduced failures; integration tests exercise native public consumers, dependency delivery, and host lifecycle behavior.
See testing and hardening and compiler CI for commands and coverage. The adding a target guide provides the implementation and acceptance sequence.
Inspect the intermediate representation
Section titled “Inspect the intermediate representation”go run ./cmd/goalchemy compile -target ir ./examples/calcIR output is written to standard output and does not require -out. The design plan records the broader compiler design and roadmap; historical phase descriptions are not a replacement for the current feature manifest.