A surface language for the verified RAM AST #
ram_expr% quotes an expression, ram% { ... } quotes a statement block, and
ram_fun% (parameters) { ... return expression; } quotes a function. Its locals
can be introduced with let, let mut, or a call-result binding. The explicit
locals (locals) header is also supported. Function syntax assigns local register numbers only at
variable occurrences, not by introducing Lean bindings around the body.
call f(args); and let _ ← call f(args); execute a call without binding its
returned value. Word and array results allocate one or two anonymous destination
slots in the same frame; Unit results allocate none. The actual call and frame
costs remain part of the compiled execution.
Outside that syntax, identifiers refer to ordinary Lean bindings of type
Ram.Reg; legacy call targets refer to Lean Nat bindings. Function targets
and const(t) retain their enclosing Lean scope, even when a parameter has
the same spelling. Complexity.Computability.Ram.Source.Named.Basic adds a
separately resolved named function table.
Named functions additionally support xs : array parameters. A handle occupies
two ordinary word parameters, exposed as xs.base and xs.length; xs[i]
loads from its base. Named calls check the declared parameter kinds and pass
both fields for an array argument. Named result signatures similarly determine
the number of fields received by a call binding. An array handle is not a word expression.
let window : array := subslice(xs, offset, count); binds a local handle in two
fresh registers. let other : array := window; copies that handle, while
array(base, length) constructs one from word expressions. These same array
expressions can be passed directly to named calls. The first argument to
subslice must be an already bound array handle, optionally parenthesized;
bind a constructed or nested handle with let before slicing it. This keeps
earlier descriptor computations explicit rather than silently discarding them.
subslice adds the offset to the base and uses the chosen count; it does not
check bounds, truncate, allocate or copy elements. Its address addition retains
word overflow semantics.
Immutable array bindings protect their descriptor fields, not their heap cells;
let mut permits descriptor-field assignment. Standalone ram_fun% parameters
remain word-valued, but its scoped body can construct local array handles.
for x in xs { ... } traverses a typed array handle. It copies the base and
length into fresh cursor locals and loads an immutable x for each iteration;
the generated cursor updates do not modify the array descriptor. Elements are
read from memory at each iteration, not snapshotted before the loop.
for i, x in xs { ... } additionally binds an immutable zero-based index in
the loop body, with a real initialization and an increment after each body.
Lexical declarations allocate fresh frame slots, including when shadowing an
outer name. An initializer sees the previous scope; branch and loop bindings
do not escape their blocks. let bindings reject later assignment, while
parameters, header locals and let mut bindings are mutable. Allocation is
static: a loop-local initializer executes again each iteration, without growing
the frame. Raw ram% and ram_stmt% have no function frame to allocate and
continue to use caller-provided register names.
The macros produce only the existing Expr, Stmt, and Func constructors.
There is no host-language callback, implicit bulk operation, cost annotation,
or alternate evaluator. const(t) embeds a compile-time natural constant;
plain identifiers always read registers. Array indexing is the existing word
addition followed by one-word load, and a[i] := e is its one-word store form.
Arithmetic retains unsigned machine-word semantics, including wrapping
subtraction, unsigned division/remainder, and logical shifts. &&&, |||, and
^^^ are bitwise operations, not short-circuit Boolean operators. A condition
uses the existing zero/nonzero convention. A return occurs only at the end
of a function, matching Func.results; this syntax does not pretend that the
current statement AST has early returns, break, or continue.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
- Ram.DSL.ramExpr_ = Lean.ParserDescr.node `Ram.DSL.ramExpr_ 1024 (Lean.ParserDescr.const `num)
Instances For
Equations
- Ram.DSL.ramExpr__1 = Lean.ParserDescr.node `Ram.DSL.ramExpr__1 1024 (Lean.ParserDescr.const `ident)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Ram.DSL.ramTrueLiteral = Lean.ParserDescr.node `Ram.DSL.ramTrueLiteral 1024 (Lean.ParserDescr.nonReservedSymbol "true" false)
Instances For
Equations
- Ram.DSL.ramFalseLiteral = Lean.ParserDescr.node `Ram.DSL.ramFalseLiteral 1024 (Lean.ParserDescr.nonReservedSymbol "false" false)
Instances For
Equations
- Ram.DSL.«ramExpr()» = Lean.ParserDescr.node `Ram.DSL.«ramExpr()» 1024 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "(") (Lean.ParserDescr.symbol ")"))
Instances For
Construct a by-value array handle from two word expressions, without allocating memory.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Shift a bound array handle's base and select its length; bounds are proof obligations.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Ram.DSL.ramExpr!_ = Lean.ParserDescr.node `Ram.DSL.ramExpr!_ 80 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "!") (Lean.ParserDescr.cat `ramExpr 80))
Instances For
Equations
- Ram.DSL.«ramExpr-_» = Lean.ParserDescr.node `Ram.DSL.«ramExpr-_» 80 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "-") (Lean.ParserDescr.cat `ramExpr 80))
Instances For
Equations
- Ram.DSL.«ramExpr_*_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_*_» 70 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " * ") (Lean.ParserDescr.cat `ramExpr 71))
Instances For
Equations
- Ram.DSL.«ramExpr_/_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_/_» 70 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " / ") (Lean.ParserDescr.cat `ramExpr 71))
Instances For
Equations
- Ram.DSL.«ramExpr_%_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_%_» 70 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " % ") (Lean.ParserDescr.cat `ramExpr 71))
Instances For
Equations
- Ram.DSL.«ramExpr_+_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_+_» 65 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " + ") (Lean.ParserDescr.cat `ramExpr 66))
Instances For
Equations
- Ram.DSL.«ramExpr_-_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_-_» 65 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " - ") (Lean.ParserDescr.cat `ramExpr 66))
Instances For
Equations
- Ram.DSL.«ramExpr_<<_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_<<_» 60 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " << ") (Lean.ParserDescr.cat `ramExpr 61))
Instances For
Equations
- Ram.DSL.«ramExpr_>>_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_>>_» 60 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " >> ") (Lean.ParserDescr.cat `ramExpr 61))
Instances For
Equations
- Ram.DSL.«ramExpr_&&&_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_&&&_» 55 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " &&& ") (Lean.ParserDescr.cat `ramExpr 56))
Instances For
Equations
- Ram.DSL.«ramExpr_^^^_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_^^^_» 54 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ^^^ ") (Lean.ParserDescr.cat `ramExpr 55))
Instances For
Equations
- Ram.DSL.«ramExpr_|||_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_|||_» 53 0 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ||| ") (Lean.ParserDescr.cat `ramExpr 54))
Instances For
Equations
- Ram.DSL.«ramExpr_==_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_==_» 50 51 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " == ") (Lean.ParserDescr.cat `ramExpr 51))
Instances For
Equations
- Ram.DSL.«ramExpr_!=_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_!=_» 50 51 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " != ") (Lean.ParserDescr.cat `ramExpr 51))
Instances For
Equations
- Ram.DSL.«ramExpr_<_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_<_» 50 51 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " < ") (Lean.ParserDescr.cat `ramExpr 51))
Instances For
Equations
- Ram.DSL.«ramExpr_<=_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_<=_» 50 51 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " <= ") (Lean.ParserDescr.cat `ramExpr 51))
Instances For
Equations
- Ram.DSL.«ramExpr_>_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_>_» 50 51 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " > ") (Lean.ParserDescr.cat `ramExpr 51))
Instances For
Equations
- Ram.DSL.«ramExpr_>=_» = Lean.ParserDescr.trailingNode `Ram.DSL.«ramExpr_>=_» 50 51 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " >= ") (Lean.ParserDescr.cat `ramExpr 51))
Instances For
Quote a RAM expression; identifiers denote registers and numerals denote
word constants. The result is the existing Ram.Expr AST.
Equations
- Ram.DSL.«termRam_expr%_» = Lean.ParserDescr.node `Ram.DSL.«termRam_expr%_» 1024 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "ram_expr% ") (Lean.ParserDescr.cat `ramExpr 0))
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
- Ram.DSL.«ramStmtSkip;» = Lean.ParserDescr.node `Ram.DSL.«ramStmtSkip;» 1024 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "skip") (Lean.ParserDescr.symbol ";"))
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute a source call, receiving any discarded fields into fresh frame slots.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Execute a source call without introducing a lexical result binding.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bind a fresh immutable word local for the rest of the enclosing block.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bind a fresh mutable word local for the rest of the enclosing block.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bind a fresh immutable array handle for the rest of the enclosing block.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bind an array handle whose base and length fields may be assigned.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Bind the result of a real source call, not a host-language computation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Traverse a typed array handle with an immutable block-local element and an optional immutable, zero-based index.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Quote a RAM statement block. Braces delimit control-flow bodies; atomic
statements end in semicolons. Empty blocks are Stmt.skip.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Quote a single surface statement. Usually used through ram% { ... }.
Equations
- Ram.DSL.«termRam_stmt%_» = Lean.ParserDescr.node `Ram.DSL.«termRam_stmt%_» 1024 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "ram_stmt% ") (Lean.ParserDescr.cat `ramStmt 0))
Instances For
A declared parameter before local-register allocation.
- name : Lean.TSyntax `ident
- kind : ValueKind
Instances For
Equations
Instances For
Equations
Equations
Instances For
Equations
Instances For
Resolve a call using its signature and the caller's lexical bindings.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Ram.DSL.localRegisterCount scope = Array.foldl (fun (count : Nat) (binding : Ram.DSL.LocalBinding) => max count (binding.register + binding.kind.width)) 0 scope
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Ram.DSL.makeLocalScope names = Ram.DSL.makeParameterScope (Array.map (fun (name : Lean.TSyntax `ident) => { name := name }) names)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Lower an array-valued source expression to its two ordinary word arguments. A subslice starts from an existing handle, so no earlier field computation is discarded.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Lower a value to its actual returned or argument fields. Unit expressions are literals or bound Unit values, so omitting their zero fields drops no computation.
Equations
- One or more equations did not get rendered due to their size.
- Ram.DSL.valueArgument scope strict Ram.DSL.ValueKind.word expr = do let __do_lift ← Ram.DSL.lowerExpr scope strict expr pure #[__do_lift]
- Ram.DSL.valueArgument scope strict Ram.DSL.ValueKind.array expr = Ram.DSL.arrayArgument scope strict expr
Instances For
An internal lexical location within one lowered function or main block.
Equations
Instances For
A lexical position recorded by the same traversal that emits the executable code.
A source statement has source = some stmt. A block anchor has source = none
and synthetic = false; a compiler-generated fragment has source = none and
synthetic = true. Block anchors retain even an empty body's lexical scope.
emitted contains the actual terms already produced by lowering, not code
reconstructed from source names. children names immediate nested positions.
Parent and child fragments overlap: this is a source map, not an execution
trace to concatenate or a traversal whose entries can all be charged once.
The root block has path []. Its source statements append their zero-based
position. A control statement's bodies append 0 (and 1 for an else body).
An indexed foreach additionally uses child 1 for its generated initialization.
A generated block tail follows the last source statement. Paths are internal
source locations, not register numbers or a stable user-facing naming scheme.
- path : ProofPath
- source : Option (Lean.TSyntax `ramStmt)
- beforeScope : LocalScope
- afterScope : LocalScope
- emitted : Array (Lean.TSyntax `term)
- synthetic : Bool
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
A lowered lexical block and the bindings visible after it. Branch-local
bindings are discarded on exit, but their allocated slots remain in the frame.
The flat proofSites array retains their lexical positions separately from code.
- term : Lean.TSyntax `term
- scope : LocalScope
- nextRegister : Nat
Instances For
Equations
Equations
Instances For
Lower lexical declarations with the same expression and statement translator. Words receive one fresh frame slot, array handles receive two, and Unit receives none; initializers refer to the previous scope, leaving shadowed bindings untouched. An already-lowered tail joins the same right-associated statement fold without resolving names again.
The function term and source bindings produced by one lowering.
- term : Lean.TSyntax `term
- scope : LocalScope
- registers : Nat
Instances For
Lower a function and retain its lexical bindings for generated proof names.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Declare function-local register names without hand-numbering them.
Parameters occupy the initial registers, followed by the declared locals.
The final return expression is the single field of the existing Func.results.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Function locals may instead be introduced where used with let or let mut.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Examples #
See Examples.Ram.Syntax for source programs and their definitional expansions.
The resulting functions use the same compiler and correctness judgments as
handwritten syntax trees.