Monorepo: golang-lean (TGC) + octive-lean (TOC) + tsm-lean (TSM) + common-lean (cross-language apex).
GolangLean/Core/ holds a small calculus that surface Go is intended to
desugar into. Three files:
Syntax.lean - Term, BinOp; thirteen syntactic forms covering
let-binding, lambda, application, references
(Go's & / *), conditionals, sequencing.
Semantics.lean - Value, EnvList, Heap, BinOp.apply, BigStep relation.
Heap is Array Value; references are indices.
Closures capture EnvList lexically, as in Go.
Fourteen big-step constructors, one per syntactic form
(with ifte split into ifTR / ifFR).
Determinism.lean - theorem BigStep.deterministic:
BigStep h env e v1 h1 -> BigStep h env e v2 h2 ->
v1 = v2 /\ h1 = h2
Proof by induction on the first derivation, case
analysis on the second. The ifTR/ifFR cross-cases
close by contradiction via Bool.noConfusion.
No sorries, no axioms, no admits. The kernel is small enough to extend
compositionally: each new syntactic form adds one constructor and one
case to each proof. Type system and concurrency layer come later.
Strategic note: this kernel is shaped so the same construction will
work for any sequential calculus. When octive-lean grows a parallel
Tiny Octave Core, the determinism proof's structure will line up
case-for-case where the languages share constructors. That alignment
is the seed of the cross-language layer.
|
||
|---|---|---|
| corpus | ||
| GolangLean | ||
| .gitignore | ||
| CorpusCheck.lean | ||
| GolangLean.lean | ||
| justfile | ||
| lake-manifest.json | ||
| lakefile.toml | ||
| lean-toolchain | ||
| Main.lean | ||
| README.md | ||
golang-lean
A Lean 4 reimplementation of the Go programming language — using the upstream reference compiler/parser as the source of truth, the way octive-lean uses GNU Octave.
Built parallel to octive-lean. Goals:
- Working Go interpreter for a useful subset (start: pure Go, no goroutines).
- Formal semantics layered on top:
BigStep/PureEval/ValueEquivso proofs about Go programs are first-class. - Cross-language layer — once both this and
octive-leanhave a real evaluator and big-step semantics, factor a shared core out of two concrete points rather than guessing the abstraction in advance.
Build
lake build
Requires the Lean toolchain pinned in lean-toolchain. elan will pick it up automatically.
Run
# REPL stub
lake exe golang-lean
# Run a .go script (not yet implemented)
lake exe golang-lean path/to/script.go
# Verify the corpus against expected outputs
lake build corpus-check
lake exe corpus-check
Layout
| Path | What's there |
|---|---|
GolangLean/ |
Library: Token, Scanner, AST, Parser, Value, Env, Eval, Builtins, REPL, BigStep, PureEval, ValueEquiv, Error |
Main.lean |
Entry point — REPL or file runner |
CorpusCheck.lean |
Test driver for corpus/ |
corpus/ |
.go test cases paired with .expected outputs |
go-upstream/ |
Shallow clone of golang/go (gitignored, used as reference) |
Status
Scaffold. Module skeleton in place. Token and AST are real ports of go/token and go/ast. Scanner / Parser / Eval are stubs that throw notImpl so the project compiles.
Next:
- Implement
Scanner.scanagainstgo-upstream/src/go/scanner/scanner.go. - Implement
Parser.parseFilerecursive-descent againstgo-upstream/src/go/parser/parser.go. - Implement
Evalfor the pure subset (no goroutines, no defer, no panic/recover). - Mirror octive-lean's
BigStep/ValueEquivtriple.
Reference
go-upstream/ is a shallow clone of https://github.com/golang/go. Key paths:
| Path | What's there |
|---|---|
go-upstream/src/go/token/ |
Token kinds, position tracking |
go-upstream/src/go/scanner/ |
Lexer |
go-upstream/src/go/ast/ |
AST node types |
go-upstream/src/go/parser/ |
Recursive-descent parser |
go-upstream/src/go/types/ |
Type-checker (later) |
go-upstream/src/runtime/ |
Runtime / scheduler / GC (much later) |