Pointer machines #
The pointer machine of [Tar79], §2: finitely many registers and an expandable pool of records with identical fields. Registers and fields hold either pointers or data. Memory is reached only by following a pointer held in a register; no instruction computes on pointers.
Main definitions #
This file contains the whole model and no proofs:
Model: the data and the operations and predicates allowed on them.Layout: the number of registers and of fields per record.State,State.Valid: registers and records, and the states that make sense.Instr,Instr.effect,Instr.next: the instructions and their meaning.step,Runs,Executes: execution, charging one unit per instruction.
Space is State.heap.length, the number of records.
Differences from the source #
- Labels start at zero. Running past the last instruction is not a successful halt.
- The source halts on using an undefined register or field. Here new pointer fields are null
and data operations/predicates are total, including on
undefined. Source-faithful programs must initialize before reading; no transfer theorem is proved. - Equality of data is a predicate the
Modelmay supply, not a separate instruction. - Pointers are positions in the list of records, but no instruction takes or returns a position.
Invariants are in Basic, data invariants in Data and Renaming, and symbols in Symbols.
References #
[Tar77], §2, and [Tar79], §2. The total semantics here relax the source’s undefined-value traps; see the differences above.
The data of a pointer machine and the primitives allowed on them.
A pointer is null (none) or specifies a record by its position in the heap.
A state is valid if every nonnull pointer in a register or in a record specifies a record.
States are meant to be valid, and execution keeps them so (Runs.valid in Basic). In other
states a pointer that specifies no record acts like null until a later create gives it one.
Instructions. Below, r and base are pointer registers, s is a data register and f is
a field; f(base) is field f of the record specified by base. As in the source, a load or
store does nothing when base is null.
- null {M : Model} {L : Layout} (r : Fin L.ptrRegs) : Instr M L
r ← null. - movePtr {M : Model} {L : Layout} (r r' : Fin L.ptrRegs) : Instr M L
r ← r'. - moveData {M : Model} {L : Layout} (s s' : Fin L.dataRegs) : Instr M L
s ← s'. - loadPtr {M : Model} {L : Layout} (r : Fin L.ptrRegs) (f : Fin L.ptrFields) (base : Fin L.ptrRegs) : Instr M L
r ← f(base). - loadData {M : Model} {L : Layout} (s : Fin L.dataRegs) (f : Fin L.dataFields) (base : Fin L.ptrRegs) : Instr M L
s ← f(base). - storePtr {M : Model} {L : Layout} (f : Fin L.ptrFields) (base r : Fin L.ptrRegs) : Instr M L
f(base) ← r. - storeData {M : Model} {L : Layout} (f : Fin L.dataFields) (base : Fin L.ptrRegs) (s : Fin L.dataRegs) : Instr M L
f(base) ← s. - op {M : Model} {L : Layout} (o : M.Op) (s s₁ s₂ : Fin L.dataRegs) : Instr M L
s ← s₁ o s₂. - create {M : Model} {L : Layout} (r : Fin L.ptrRegs) : Instr M L
Create a record and place a pointer to it in
r. - goto {M : Model} {L : Layout} (label : ℕ) : Instr M L
Go to
label. - ifPtrEq {M : Model} {L : Layout} (r₁ r₂ : Fin L.ptrRegs) (label : ℕ) : Instr M L
If
r₁ = r₂, go tolabel. - ifTest {M : Model} {L : Layout} (p : M.Test) (s₁ s₂ : Fin L.dataRegs) (label : ℕ) : Instr M L
If
p(s₁, s₂), go tolabel. - halt {M : Model} {L : Layout} : Instr M L
Cease execution.
A new record: null pointers and undefined data.