crosslang/tsm-lean/TsmLean/Compile/Source.lean
Maximus Gorog bd2e14214d Add 'tsm-lean/' from commit '2e9061abead6f2daa464b39a79c17a949db30785'
git-subtree-dir: tsm-lean
git-subtree-mainline: 6592cd058d
git-subtree-split: 2e9061abea
2026-05-12 02:59:14 -06:00

35 lines
1.1 KiB
Text

import TsmLean.Core.Syntax
namespace TsmLean.Compile.Source
/-! # Source language for compilation (v0.4).
Integer/bool literals + arithmetic. The compile function takes an
offset (infrastructure for future control-flow constructs that
require absolute jump addresses). For the constructs in v0.4, the
offset doesn't change the compile output — it's just threaded. -/
inductive Expr where
| intLit : Int → Expr
| boolLit : Bool → Expr
| add : Expr → Expr → Expr
| sub : Expr → Expr → Expr
| mul : Expr → Expr → Expr
deriving Repr, Inhabited
abbrev Value := TsmLean.Core.Value
inductive Eval : Expr → Value → Prop where
| intLit (n : Int) : Eval (.intLit n) (.vInt n)
| boolLit (b : Bool) : Eval (.boolLit b) (.vBool b)
| add {e1 e2 a b}
(h1 : Eval e1 (.vInt a)) (h2 : Eval e2 (.vInt b)) :
Eval (.add e1 e2) (.vInt (a + b))
| sub {e1 e2 a b}
(h1 : Eval e1 (.vInt a)) (h2 : Eval e2 (.vInt b)) :
Eval (.sub e1 e2) (.vInt (a - b))
| mul {e1 e2 a b}
(h1 : Eval e1 (.vInt a)) (h2 : Eval e2 (.vInt b)) :
Eval (.mul e1 e2) (.vInt (a * b))
end TsmLean.Compile.Source