Documentation

CslibFrontier.Computability.PointerMachine.WordRAM.Compiler

Compiling pointer-machine instructions to word RAM #

Nodes occupy fixed blocks of memory, with zero reserved for null. The compiler implements pointer access and allocation using ordinary word-RAM instructions. Scalar operations and tests come with their own word-RAM implementations and costs; no heap operation is assumed implemented. Field accesses reuse Cslib.WordRAM.readAt and Cslib.WordRAM.writeAt. Allocation uses a layout-specific initializer: Cslib.WordRAM.alloc zeroes every field, whereas scalar fields require encode M.undefined, which need not be zero. It also takes six distinct register parameters, whereas this initializer uses the base and two scratch registers, leaving the next-free and zero registers unchanged until the final frontier update. The fixed field list is unrolled, giving the stated layout-dependent constant cost.

Source instructions compile into equally sized code blocks, with jumps directly relocated to the corresponding block. Padding is never executed by a simulated successful run.

A scalar routine returns one value and preserves memory and all other source/administrative registers. Temporary registers may change.

  • result : y.regs dst = v

    Returned word.

  • memory : y.mem = x.mem

    Scalar computation does not change the heap.

  • frame (r : Fin (regCount L)) : ↑r < L.ptrRegs + L.dataRegs + 2 → r ≠ dst → y.regs r = x.regs r

    Source registers, allocation pointer and null register are preserved except for dst.

Writing the destination register alone meets the scalar routine's frame contract.

Implementations of the scalar basis in the standard word RAM. The admissibility predicates state any additional headroom needed by scalar routines. They concern scalar operands only; all pointer operations are implemented by the compiler below.

def Cslib.PointerMachine.WordRAM.Scalars.Safe {M : Model} {L : Layout} (S : Scalars M L) (w : ℕ) (x : State M L) :
Instr M L → Prop

Scalar admissibility of the instruction about to execute.

Fill the listed offsets of a fresh record with their initial values. The list is fixed by the source layout, not supplied by the running program.

Pointer fields are initialized to null; scalar fields to the model's undefined value.

A null access does nothing; a nonnull access loads the fixed offset before body.

The register/memory part of one source instruction. A test also computes its Boolean answer in a temporary register for the terminal branch.

Cost bound for the compiled register/memory part, independent of input size.

Live code of one instruction, including the relocated terminal control instructions.

A program-dependent fixed block size.

Pad a live instruction block to the common block size.

Compile the whole source program to a finite standard word-RAM program.

Uniform overhead per continuing source instruction, including terminal branches/jumps.