Commit graph

1 commit

Author SHA1 Message Date
Maximus Gorog
fff0091f89 Add source-to-TSM compiler with proven correctness (v0.1).
The CompCert-style substrate-projection theorem at miniature scale:
source-level evaluation and TSM-bytecode execution agree on the value
produced.

TsmLean/Compile/ — three files:

  Source.lean       - small expression language. v0.1 covers integer
                      literals only; the framework is structured so
                      arithmetic, comparison, control flow, and
                      variables extend mechanically.

  Compile.lean      - compile : Source.Expr -> TSM.Code
                      v0.1: intLit n -> #[push n]

  Correctness.lean  - theorem compile_correct:
                        Source.Eval e v ->
                        forall pre suf rest,
                          MultiStep
                            { code := pre ++ compile e ++ suf,
                              pc := pre.size, stack := rest }
                            { code := same,
                              pc := pre.size + (compile e).size,
                              stack := v :: rest }
                      Plus a standalone corollary for the no-prefix case.

The infrastructure is in place for compositional extension:

  MultiStep.trans       - transitive closure of multi-step
  MultiStep.single      - lift single step to multi-step
  step_push             - per-instruction step lemma (push)
  getElem_compile       - lookup-in-larger-code helper

Adding a constructor to Source (e.g., add) requires:
  - one constructor in Source.Expr
  - one rule in Source.Eval
  - one match arm in compile
  - one step_X helper (one-liner)
  - one case in compile_correct's induction

Demonstrates the pipeline:
  - Source language with big-step semantics
  - Compiler producing TSM bytecode
  - Correctness theorem bridging the two

Zero sorries / axioms / admits across the entire project.
2026-05-10 05:38:01 -06:00