Representing shared source objects in RAM memory #
One fixed mathematical placement gives each source object a RAM base address. The complete current object is represented at that address: arrays contain their scalar cells, while immutable nodes contain a head, an option tag and the actual placement of their tail. Borrowed array views derive their base and length without copying contents or storing an object table. Views of the same object may overlap or coincide. Distinct objects have disjoint actual cells, with no condition on empty objects' unused addresses.
Natural cells must fit the target word and Boolean cells use their exact
zero-or-one encoding. Object intervals retain the existing non-strict endpoint
bound. A view's length needs its own word-range premise only when exposed as a
two-word ArrayRef. No injectivity of source handle encoding is asserted.
The read and write theorems relate the existing source heap operations to the existing RAM memory update. They do not add an evaluator, allocation, a loader, statement syntax, instruction prices or a complete buffer-lowering theorem.
Exact mathematical scalar observation of a source object cell.
Equations
- Ram.LanguageCompiler.cellToNat value = value
- Ram.LanguageCompiler.cellToNat value = if value = true then 1 else 0
Instances For
One actual word for a source cell; exactness is a separate range fact.
Equations
- Ram.LanguageCompiler.cellWord w value = BitVec.ofNat w (Ram.LanguageCompiler.cellToNat value)
Instances For
Encode the existing native array elementwise, without loading any memory.
Equations
- Ram.LanguageCompiler.objectWords w values = Array.map (Ram.LanguageCompiler.cellWord w) values
Instances For
Complete storage of either object kind. The optional link contains an
actual address, not a numeric source identifier; none uses a separate zero tag.
Equations
- Ram.LanguageCompiler.heapObjectWords placement (Complexity.Language.HeapObject.buffer τ values) = Ram.LanguageCompiler.objectWords w values
- Ram.LanguageCompiler.heapObjectWords placement (Complexity.Language.HeapObject.node τ head none) = #[Ram.LanguageCompiler.cellWord w head, 0, 0]
- Ram.LanguageCompiler.heapObjectWords placement (Complexity.Language.HeapObject.node τ head (some tail)) = #[Ram.LanguageCompiler.cellWord w head, 1, placement tail.object]
Instances For
Exact scalar payloads and node tags. Link addresses already have type Word.
Equations
- Ram.LanguageCompiler.heapObjectFits w (Complexity.Language.HeapObject.buffer τ values) = ∀ (index : ℕ) (bound : index < values.size), Ram.LanguageCompiler.cellToNat values[index] < 2 ^ w
- Ram.LanguageCompiler.heapObjectFits w (Complexity.Language.HeapObject.node τ head tail) = (Ram.LanguageCompiler.cellToNat head < 2 ^ w ∧ 1 < 2 ^ w)
Instances For
Storage extent depends on the object, not its placement or referenced addresses.
Two-word metadata for a view of a placed object. This is not a runtime conversion and does not recover the source object's identity from the fields.
Equations
- Ram.LanguageCompiler.bufferRef placement buffer = { base := Ram.arrayAddr (placement buffer.object) buffer.offset, length := BitVec.ofNat w buffer.length }
Instances For
A fitting cell is observed as its exact mathematical value, not a residue.
Complete typed objects, their scalar ranges and separation of actual cells. The placement is fixed across heap updates and real function calls.
- stored {id : ℕ} {object : Complexity.Language.HeapObject} : heap.objects[id]? = some object → Source.ArrayAt heapLimit (placement id) (heapObjectWords placement object).toList target
Every actual object occupies its complete encoded interval.
- fit {id : ℕ} {object : Complexity.Language.HeapObject} : heap.objects[id]? = some object → heapObjectFits w object
Every payload and tag has its exact value at the selected width.
- disjoint {id other : ℕ} {object otherObject : Complexity.Language.HeapObject} : heap.objects[id]? = some object → heap.objects[other]? = some otherObject → id ≠ other → ∀ index < (heapObjectWords placement object).size, ∀ otherIndex < (heapObjectWords placement otherObject).size, arrayAddr (placement id) index ≠ arrayAddr (placement other) otherIndex
Every pair of distinct objects has disjoint storage, regardless of kind.
- backward {τ : Complexity.Language.CellTy} {id : ℕ} {head : Complexity.Language.CellValue τ} {tail : Complexity.Language.NodeRef τ} : heap.node? τ id = some (head, some tail) → tail.object < id
A live node's actual link points into its earlier object prefix.
Instances For
Typed array observation is a projection of complete object representation.
Every represented array cell retains the original exact scalar range interface.
The original array separation interface follows from separation of all objects.
A node lookup exposes all three real words, including its placed optional tail.
A stored backward link always names an existing object, without requiring the numeric source identifier to fit a RAM word.
Parameter binding retains the same complete shared-heap representation.
Receiving actual return fields changes no represented heap cell.
Updating one local register changes no represented shared object.
Caller restoration keeps the callee's final heap, not the caller's old heap.
A view's current native contents use the existing contiguous-array assertion. Even an empty view at the allocation endpoint is admitted.
A word-sized view is exactly the existing by-value ArrayRef together
with its actual native contents. The descriptor allocates and copies nothing.
Every successful source read is the exact represented RAM cell, lies below the heap boundary and returns a source scalar fitting the target word.
A successful source write is represented by the same single RAM memory update. Complete objects, scalar ranges and separation all survive; aliases are not assumed disjoint, and other objects retain their actual contents.