std:EVM/State/Layout

lib/EVM/State/Layout.omg

lib/EVM/State/Layout.omg75 lines
1{- Source-owned storage placement. Candidate descriptions are ordinary data;
2   a Selection contains its source structure, description, and validity proof.
3   Automatic and explicit choices satisfy exactly the same invariant.
4-}
5let D = std:EVM/State/Layout/Description
6let V = std:EVM/State/Layout/Validate
7let Derive = std:EVM/State/Layout/Derive
8let R = std:Region
9let Validation = std:Validation
10let Result = std:Result
11let Valid
12    : forall {A : Type} -> D.Of A -> D.Description -> Type
13    = \{A} source -> Validation.Valid (V.problems source)
14let Selection
15    : Type -> Type
16    = \(A : Type) -> exists (source : D.Of A) * Validation.Checked (V.problems source)
17let describe : forall {A : Type} -> Selection A -> D.Description = \{A} selection -> selection.2.1
18let source : forall {A : Type} -> Selection A -> D.Of A = \{A} selection -> selection.1
19let validity
20    : forall {A : Type} (selection : Selection A) -> Valid selection.1 selection.2.1
21    = \{A} selection -> selection.2.2
22let select
23    : forall {A : Type}
24             (source : D.Of A)
25             (description : D.Description)
26             {valid : Valid source description}
27      -> Selection A
28    = \{A} source description {valid} -> (source, (description, valid))
29let checked
30    : forall {A : Type} -> D.Of A -> D.Description -> Result.Result (List Text) (Selection A)
31    = \{A} source description ->
32        Result.map
33          (\(selection : Validation.Checked (V.problems source)) ->
34             ((source, selection) : Selection A))
35          (Validation.check (V.problems source) description)
36-- The selection moved to another reservation (`relocate`), checked again.
37let inRegion
38    : forall {A : Type}
39             (space : R.Region)
40             (selection : Selection A)
41             {valid : Valid selection.1 (Derive.relocate space (describe selection))}
42      -> Selection A
43    = \{A} space selection {valid} ->
44        select selection.1 (Derive.relocate space (describe selection)) @valid
45let Derived
46    : forall {A : Type} -> D.Of A -> Type
47    = \{A} source -> Valid source (Derive.automatic source)
48let derive
49    : forall {A : Type} (source : D.Of A) {valid : Derived source} -> Selection A
50    = \{A} source {valid} -> select source (Derive.automatic source) @valid
51in  { Scalar = D.Scalar
52    , Member = D.Member
53    , Alternative = D.Alternative
54    , Addressing = D.Addressing
55    , Form = D.Form
56    , Node = D.Node
57    , Hashing = D.Hashing
58    , Description = D.Description
59    , Of = D.Of
60    , Valid
61    , Derived
62    , Selection
63    , problems = V.problems
64    , describe
65    , source
66    , validity
67    , select
68    , checked
69    , inRegion
70    , automatic = Derive.automatic
71    , confine = Derive.confine
72    , relocate = Derive.relocate
73    , reservationSize = Derive.reservationSize
74    , derive
75    }
Your result
Complete file: lib/EVM/State/Layout.omg · with imports