Notation for structured pointer-machine programs #
pm[ s₁; s₂; … ] writes a structured program (Cslib.PointerMachine.Code) as a sequence of
statements, one per data instruction, in the style of the pseudocode of [Tar79]. Registers
and fields are named by identifiers, for instance local abbreviations of elements of Fin n.
Pointer and data registers are different kinds of registers that may have the same type, so the
assignment sign tells them apart: ← assigns a pointer and := assigns a datum.
The statements on pointers are:
r ← null: clear pointer registerr;r ← r': copy a pointer register;r ← base[f],base[f] ← r: load and store pointer fieldfof the record specified bybase;r ← new: create a record.
The statements on data are:
s := s': copy a data register;s := base[f],base[f] := s: load and store data fieldfof the record specified bybase;s := o s₁ s₂: the operationoof the model on data registerss₁ands₂.
The tests are r = r' and r ≠ r' on pointer registers, and p s₁ s₂ and ¬p s₁ s₂ for a
predicate p of the model on data registers, given by name or as a term in parentheses. The
control statements are:
if t then [ … ] else [ … ],if t then [ … ]: a conditional;while t do [ … ]: a loop;⟪c⟫: the structured programc, for instance a subroutine, or⟪.skip⟫.
The notation unfolds to the constructors of Code, so it adds nothing to the semantics. The
machine jumps when a test holds, so a conditional on a negated test exchanges its alternatives,
and a loop on a negated test is Code.loopUntil, the cheaper loop; while r ≠ nil do [ … ]
costs one test and one jump per iteration.
It is scoped: open Cslib.PointerMachine enables it. Only the categories pmStmt and pmTest
and the syntax abbreviation pmBlock are global, since Lean cannot scope them; without the open
they have no rules. Its only new tokens are pm[ and the internal pm_stmt%, pm_block%,
pm_branch% and pm_while%, so it reserves no identifiers: null and new remain ordinary
names, except that a pointer register cannot be copied from one named null or new.
Main definitions #
pm[ s₁; s₂; … ]: scoped notation for structured pointer-machine programs.
Tactics #
pm_straight(scoped, like the notation): on a goalExecWithin c x ?y Tfor straight-line codec, runs its data instructions in order, so that?ybecomes the state reached, and proves that their number is at mostT.
References #
A block of statements, separated by semicolons.
A structured pointer-machine program, written as a block of statements.
Internal: a nested block of statements, as a structured program.
Internal: a single statement, as a structured program.
Internal: a conditional on a test, with its alternatives as terms.
Internal: a loop on a test, with its body as a term.
A predicate of the model, given by name, holds of two data registers.
A predicate of the model, given as a term, holds of two data registers.
A predicate of the model, given by name, fails on two data registers.
A predicate of the model, given as a term, fails on two data registers.
An operation of the model on two data registers.
A conditional without second alternative.
pm_straight proves a goal ExecWithin c x ?y T for straight-line code c: a sequence of data
instructions. It runs them in order, so that ?y becomes the state reached, in closed form as
nested Op.effect, and proves by omega that their number is at most T. At a conditional, a
loop or a program given by ⟪…⟫ it stops and leaves the execution of that part as a goal.