SpecDraft 0.1
Sections

Lena storage 0.1

This document is draft 0.1. This module depends on Lena core 0.1.

1 Storage boundary and operations

storage 0.1 defines cell declarations and the operations that store and consume values. A cell ID is unique within the program boundary. Cell IDs and binding IDs belong to separate namespaces. A value cell holds either one value of a fixed type or nothing. A marker cell has only an occupied state, kept for bookkeeping. A marker cannot be passed as a core value, an argument, or a return value.

When the storage boundary opens, every cell is empty. A standalone storage program consists of a core signature, cell declarations, ordered actions, and a final result expression. Arguments are bound as core parameters. The result expression and the operands of actions may use core expressions and storage access expressions. An early return inside them ends the whole program.

Operation Meaning
cell read id Returns the current value of a value cell. The cell keeps it.
cell take id Returns the current value of a value cell and empties the cell.
cell write id e Evaluates e first. If it yields a value, the cell takes that value whatever it held before.
write-marker Puts a declared marker cell into the occupied state.
cell drop id Empties a value cell or a marker cell. A cell that is already empty stays as it is.

For a known cell, a type mismatch between the declaration and the operation is a structural contract violation. An access expression states its expected type. In every cell operation, reaching an undeclared ID is InvalidCell. A write checks the ID after its expression yields a value. Reading or consuming a declared value cell that is empty is EmptySlotAccess. These two names are the canonical defect codes of this module. The defect module is lena-storage-0.1, and the cell ID involved is an auxiliary diagnostic.

Well-typed marker writes and drops do not change observations in 0.1. The match between source statements and marker actions is checked in the lowering record. Lena text that reads or consumes a marker is a structural contract violation. If the source reads, consumes, or moves a marker, the adapter rejects it as unsupported.

Conformance tests observe · repeated reads and a read after a take, overwrites and a drop of an empty cell, undeclared cells, marker type constraints, and stopping when a write expression fails.

2 Text form

Canonical output and token rules follow core §10. Numeric cell IDs have the same range as U in the core. E is the core expression grammar with the two access expressions added at every expression position.

Storage = (lena-storage-0.1 W (params Param*) T (cells Cell*) Actions E)
Cell    = (cell U T) | (cell U marker)
Actions = (actions Action*)
Action  = (write U E) | (write-marker U) | (drop U)
E       = Expr[E] | (read U T) | (take U T)

Expr[E] means the core grammar with E applied again to its subexpressions. The arguments of an access expression are the cell ID and then the expected type.

Conformance tests observe · the distinction between access expressions and actions, preservation of declaration and action order, and the structural round trip including extension expressions.

Source revision 4259231 ·