Structured pointer-machine programs #
Flat programs are lists of Instr with numeric labels, which are inconvenient to write and to
reason about. This file makes the pointer machine an instruction set (instructionSet) for the
structured programs of Cslib.Program: its data instructions (Op) and its two tests (Test),
acting on states. Code, Exec and ExecWithin are those of Cslib.Program at this
instruction set, so the sequencing, conditional and loop rules there (Program.ExecWithin.seq,
Program.ExecWithin.loopUntil_invariant, …) apply to them as they are, also by field notation.
This file adds what is specific to the machine: the effect of a data instruction, and the
program counter, validity and field frame of an execution.
Exec c x y n relates states and ignores the program counter: y.pc = x.pc (Exec.pc_eq).
The count n is exactly that of the flat program c assembles to (Exec.runs in Assemble).
The machine jumps when a test holds, so Code.loopUntil t body (while t fails) costs one test
and one jump per iteration; it is the natural loop for while r ≠ null.
Loop-free code is executed by the interpreter Code.eval, which simp evaluates on symbolic
states (ExecWithin.of_eval).
Main definitions #
Op,Test,instructionSet: data instructions, tests and the instruction set they form.Code,Exec,ExecWithin,Code.eval: structured programs, their executions and the interpreter, at this instruction set.
Main results #
Exec.valid,Exec.pc_eq: executions preserve validity and the program counter.Exec.op,ExecWithin.op: a data instruction, with the state it reaches in closed form.State.ptr_setPtr,State.data_setData,State.deref_setDataand the like: simp lemmas for the registers and records after an assignment, for symbolic execution.
Registers and records after an assignment #
The data instructions of a pointer machine: those of Instr other than jumps and halt.
- null {M : Model} {L : Layout} (r : Fin L.ptrRegs) : Op M L
r ← null. - movePtr {M : Model} {L : Layout} (r r' : Fin L.ptrRegs) : Op M L
r ← r'. - moveData {M : Model} {L : Layout} (s s' : Fin L.dataRegs) : Op M L
s ← s'. - loadPtr {M : Model} {L : Layout} (r : Fin L.ptrRegs) (f : Fin L.ptrFields) (base : Fin L.ptrRegs) : Op M L
r ← f(base). - loadData {M : Model} {L : Layout} (s : Fin L.dataRegs) (f : Fin L.dataFields) (base : Fin L.ptrRegs) : Op M L
s ← f(base). - storePtr {M : Model} {L : Layout} (f : Fin L.ptrFields) (base r : Fin L.ptrRegs) : Op M L
f(base) ← r. - storeData {M : Model} {L : Layout} (f : Fin L.dataFields) (base : Fin L.ptrRegs) (s : Fin L.dataRegs) : Op M L
f(base) ← s. - op {M : Model} {L : Layout} (o : M.Op) (s s₁ s₂ : Fin L.dataRegs) : Op M L
s ← s₁ o s₂. - create {M : Model} {L : Layout} (r : Fin L.ptrRegs) : Op M L
Create a record and place a pointer to it in
r.
The tests of a pointer machine.
The pointer machine as an instruction set for structured programs: data instructions and tests on states. No data instruction faults.
Structured pointer-machine programs.
ExecWithin c x y T: the structured program c leads from x to y within T
instructions.
A data instruction is one instruction.
A data instruction executes within one instruction.
A data instruction executes within one instruction, reaching a state given in advance.
A list of data instructions executes within its length, reaching the state that their effects give in order.
When no data instruction of the program allocates or stores field, every execution
preserves that field at every address, including the absence of a record.
Executions within a bound preserve validity.