Documentation

Complexity.Computability.Ram.Source.Syntax

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
    • 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

          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

                Quote a RAM expression; identifiers denote registers and numerals denote word constants. The result is the existing Ram.Expr AST.

                Equations
                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
                                    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
                                                                Instances For

                                                                  A declared parameter before local-register allocation.

                                                                  Instances For

                                                                    One lexical binding and the first register of its representation.

                                                                    Instances For
                                                                      @[reducible, inline]
                                                                      Equations
                                                                      Instances For
                                                                        @[reducible, inline]

                                                                        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
                                                                          Instances For
                                                                            Equations
                                                                            • One or more equations did not get rendered due to their size.
                                                                            Instances For
                                                                              Equations
                                                                              Instances For
                                                                                def Ram.DSL.resolveLocal (scope : LocalScope) (strict : Bool) (name : Lean.TSyntax `ident) :
                                                                                Equations
                                                                                • One or more equations did not get rendered due to their size.
                                                                                Instances For
                                                                                  partial def Ram.DSL.lowerExpr (scope : LocalScope) (strict : Bool) (expr : Lean.TSyntax `ramExpr) :
                                                                                  partial def Ram.DSL.arrayArgument (scope : LocalScope) (strict : Bool) (expr : Lean.TSyntax `ramExpr) :

                                                                                  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
                                                                                    def Ram.DSL.valueArgument (scope : LocalScope) (strict : Bool) (kind : ValueKind) (expr : Lean.TSyntax `ramExpr) :

                                                                                    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
                                                                                    Instances For
                                                                                      partial def Ram.DSL.lowerStmt (scope : LocalScope) (strict : Bool) (function : FunctionResolver) (stmt : Lean.TSyntax `ramStmt) :
                                                                                      partial def Ram.DSL.lowerBlock (scope : LocalScope) (strict : Bool) (function : FunctionResolver) (body : Array (Lean.TSyntax `ramStmt)) :
                                                                                      @[reducible, inline]

                                                                                      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.

                                                                                        Instances For
                                                                                          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.

                                                                                            Instances For
                                                                                              Equations
                                                                                              Instances For
                                                                                                partial def Ram.DSL.lowerScopedBlock (scope : LocalScope) (immutable : Array Lean.Name) (nextRegister : Nat) (strict : Bool) (function : FunctionResolver) (body : Array (Lean.TSyntax `ramStmt)) (tail : Option (Lean.TSyntax `term) := none) (path : ProofPath := []) :

                                                                                                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.

                                                                                                Instances For
                                                                                                  def Ram.DSL.lowerFunctionWithScope (strict : Bool) (function : FunctionResolver) (params : Array Parameter) (localNames : Array (Lean.TSyntax `ident)) (body : Array (Lean.TSyntax `ramStmt)) (result : Option (Lean.TSyntax `ramExpr)) (resultKind : ValueKind := ValueKind.word) :

                                                                                                  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
                                                                                                    def Ram.DSL.lowerFunction (strict : Bool) (function : FunctionResolver) (params localNames : Array (Lean.TSyntax `ident)) (localsKeyword : Lean.TSyntax `ident) (body : Array (Lean.TSyntax `ramStmt)) (result : Lean.TSyntax `ramExpr) :
                                                                                                    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.