Documentation

CslibFrontier.Computability.PointerMachine.Defs

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:

Space is State.heap.length, the number of records.

Differences from the source #

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.

  • Value : Type

    Data values.

  • undefined : self.Value

    The content of every data field of a new record.

  • Op : Type

    Names of binary operations. A constant is an operation that ignores its operands.

  • Test : Type

    Names of binary predicates.

  • evalOp : self.Op → self.Value → self.Value → self.Value

    The meaning of each operation.

  • evalTest : self.Test → self.Value → self.Value → Bool

    The meaning of each predicate.

The fixed numbers of registers and of fields per record.

  • ptrRegs : ℕ

    Number of pointer registers.

  • dataRegs : ℕ

    Number of data registers.

  • ptrFields : ℕ

    Number of pointer fields in each record.

  • dataFields : ℕ

    Number of data fields in each record.

@[reducible, inline]

A pointer is null (none) or specifies a record by its position in the heap.

A record.

A machine state.

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.

A new record: null pointers and undefined data.

def Cslib.PointerMachine.State.setPtr {M : Model} {L : Layout} (x : State M L) (r : Fin L.ptrRegs) (p : Pointer) :
State M L

Place a pointer in register r.

def Cslib.PointerMachine.State.setData {M : Model} {L : Layout} (x : State M L) (s : Fin L.dataRegs) (v : M.Value) :
State M L

Place a datum in register s.

def Cslib.PointerMachine.State.deref {M : Model} {L : Layout} (x : State M L) (r : Fin L.ptrRegs) :

The record specified by the contents of r, if any.

def Cslib.PointerMachine.State.modify {M : Model} {L : Layout} (x : State M L) (r : Fin L.ptrRegs) (g : Record M L → Record M L) :
State M L

Change the record specified by the contents of r, if any.

def Cslib.PointerMachine.Instr.effect {M : Model} {L : Layout} (x : State M L) :
Instr M L → State M L

The effect of an instruction on registers and records.

def Cslib.PointerMachine.Instr.next {M : Model} {L : Layout} (x : State M L) :
Instr M L → ℕ

The label of the instruction executed after this one.

def Cslib.PointerMachine.step {M : Model} {L : Layout} (code : List (Instr M L)) (x : State M L) :

Execute one instruction. There is no step from a halt or from outside the program.

@[reducible, inline]
abbrev Cslib.PointerMachine.Runs {M : Model} {L : Layout} (code : List (Instr M L)) :
State M L → State M L → ℕ → Prop

Runs code x y n: the program takes x to y by executing n instructions.

def Cslib.PointerMachine.Executes {M : Model} {L : Layout} (code : List (Instr M L)) (x y : State M L) (time : ℕ) :

Executes code x y time: the program takes x to y and halts there, having executed time instructions including the halt.