Monorepo: golang-lean (TGC) + octive-lean (TOC) + tsm-lean (TSM) + common-lean (cross-language apex).
Find a file
Maximus Gorog 3174918193 Add executable evaluator (Phase A) and type system + soundness infra (Phase B).
Phase A — GolangLean/Core/Eval.lean:
  def eval : Nat -> Heap -> Env -> Term -> Option (Value x Heap)
  Fuel-bounded recursive evaluator, total over the fuel.
  theorem eval_sound: eval succeeds => BigStep holds.
  Bridges executable computation to inductive specification.

Phase B — GolangLean/Core/Types.lean:
  inductive Ty {unit, int, bool, arrow, ref}
  TyEnv := List (String x Ty); BinOp.typeOf
  inductive HasType : TyEnv -> Term -> Ty -> Prop
  Standard simply-typed lambda calculus + ML-style references.

Phase B — GolangLean/Core/TypeSoundness.lean:
  abbrev HeapTy := Array Ty
  mutual inductive HasTypeV / HasTypeEnv  (value & env typing under heap-typing)
  def HasTypeH                            (heap conforms to heap-typing)
  def HeapTy.extends                       (prefix-extension of heap-typings)
  thm HeapTy.extends_refl, extends_trans
  thm HasTypeV.weaken, HasTypeEnv.weaken   (mutual; under heap-typing extension)
  thm HasTypeEnv.lookup_correspondence    (well-typed env yields well-typed values)

The preservation theorem itself
  HasType /\ HasTypeH /\ HasTypeEnv /\ BigStep
    ==> ∃ ht', extends /\ HasTypeH' /\ HasTypeV' /\ HasTypeEnv'
is the next deliverable; the infrastructure here is what its proof
case-analysis depends on.

Zero sorries / axioms / admits across the project. Full lake build clean.
2026-05-10 03:51:14 -06:00
corpus Initial scaffold: Lean 4 reimplementation of Go. 2026-05-10 02:12:19 -06:00
GolangLean Add executable evaluator (Phase A) and type system + soundness infra (Phase B). 2026-05-10 03:51:14 -06:00
.gitignore Initial scaffold: Lean 4 reimplementation of Go. 2026-05-10 02:12:19 -06:00
CorpusCheck.lean Initial scaffold: Lean 4 reimplementation of Go. 2026-05-10 02:12:19 -06:00
GolangLean.lean Add executable evaluator (Phase A) and type system + soundness infra (Phase B). 2026-05-10 03:51:14 -06:00
justfile Initial scaffold: Lean 4 reimplementation of Go. 2026-05-10 02:12:19 -06:00
lake-manifest.json Initial scaffold: Lean 4 reimplementation of Go. 2026-05-10 02:12:19 -06:00
lakefile.toml Initial scaffold: Lean 4 reimplementation of Go. 2026-05-10 02:12:19 -06:00
lean-toolchain Initial scaffold: Lean 4 reimplementation of Go. 2026-05-10 02:12:19 -06:00
Main.lean Initial scaffold: Lean 4 reimplementation of Go. 2026-05-10 02:12:19 -06:00
README.md Initial scaffold: Lean 4 reimplementation of Go. 2026-05-10 02:12:19 -06:00

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:

  1. Working Go interpreter for a useful subset (start: pure Go, no goroutines).
  2. Formal semantics layered on top: BigStep / PureEval / ValueEquiv so proofs about Go programs are first-class.
  3. Cross-language layer — once both this and octive-lean have 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:

  1. Implement Scanner.scan against go-upstream/src/go/scanner/scanner.go.
  2. Implement Parser.parseFile recursive-descent against go-upstream/src/go/parser/parser.go.
  3. Implement Eval for the pure subset (no goroutines, no defer, no panic/recover).
  4. Mirror octive-lean's BigStep / ValueEquiv triple.

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)