@@ -57,15 +57,15 @@ import Act.Syntax.Timing as Act.Syntax.Typed
5757import Act.Syntax.Untyped as Act.Syntax.Typed (Pn , Interface (.. ), EthEnv (.. ), Decl (.. ), SlotType (.. ), ArgType (.. ), Pointer (.. ), makeIface , argToAbiType )
5858
5959-- AST post typechecking
60- data Act t = Act Store [Contract t ]
60+ data Act t = Act StorageTyping [Contract t ]
6161 deriving (Show , Eq )
6262
6363data Contract t = Contract (Constructor t ) [Behaviour t ]
6464 deriving (Show , Eq )
6565
66- -- For each contract, it stores the type of a storage variables and
67- -- the order in which they are declared
68- type Store = Map Id (Map Id (SlotType , Integer ))
66+ -- For each contract, we store the type of a storage variables and the order in
67+ -- which they are declared
68+ type StorageTyping = Map Id (Map Id (ValueType , Integer ))
6969
7070
7171-- | Represents a contract level invariant. The invariant is defined in the
@@ -93,49 +93,47 @@ data InvariantPred (t :: Timing) where
9393deriving instance Show (InvariantPred t )
9494deriving instance Eq (InvariantPred t )
9595
96+ type Cases a = [(Exp ABoolean Untimed , a )]
97+
9698data Constructor t = Constructor
9799 { _cname :: Id
98100 , _cinterface :: Interface
99101 , _cpreconditions :: [Exp ABoolean t ]
102+ , _ccases :: Cases [StorageUpdate t ]
100103 , _cpostconditions :: [Exp ABoolean t ]
101104 , _invariants :: [Invariant t ]
102- , _initialStorage :: [StorageUpdate t ]
103105 } deriving (Show , Eq )
104-
105-
106+
106107-- After typing each behavior may be split to multiple behaviors, one for each case branch.
107108-- In this case, only the `_caseconditions`, `_stateUpdates`, and `_returns` fields are different.
108109data Behaviour t = Behaviour
109110 { _name :: Id
110111 , _contract :: Id
111112 , _interface :: Interface
112113 , _preconditions :: [Exp ABoolean t ] -- if preconditions are not satisfied execution is reverted
113- , _caseconditions :: [ Exp ABoolean t ] -- if preconditions are satisfied and the case conditions are not, some other instance of the behavior should apply
114+ , _cases :: Cases ([ StorageUpdate t ], Maybe ( TypedExp Timed ))
114115 , _postconditions :: [Exp ABoolean Timed ]
115- , _stateUpdates :: [StorageUpdate t ]
116- , _returns :: Maybe (TypedExp Timed )
117116 } deriving (Show , Eq )
118117
119118data StorageUpdate (t :: Timing ) where
120- Update :: TValueType a -> TItem a Storage t -> Exp a t -> StorageUpdate t
119+ Update :: TValueType a -> Ref Storage t -> Exp a t -> StorageUpdate t
121120deriving instance Show (StorageUpdate t )
122121
123122instance Eq (StorageUpdate t ) where
124123 (==) :: StorageUpdate t -> StorageUpdate t -> Bool
125124 Update vt1@ VType i1 e1 == Update vt2@ VType i2 e2 = eqS'' vt1 vt2 && eqS' i1 i2 && eqS e1 e2
126125
127- _Update :: TItem a Storage t -> Exp a t -> StorageUpdate t
128- _Update item@ (Item t@ VType _) expr = Update t item expr
129-
130- data Location (t :: Timing ) where
131- Loc :: TValueType a -> SRefKind k -> TItem a k t -> Location t
132- deriving instance Show (Location t )
126+ _Update :: Ref Storage t -> Exp a t -> StorageUpdate t
127+ _Update ref expr = Update (getValueType ref) ref expr
133128
134- instance Eq (Location t ) where
135- Loc vt1@ VType SRefKind i1 == Loc vt2@ VType SRefKind i2 = eqS'' vt1 vt2 && eqTypeKind i1 i2
129+ data TypedRef (t :: Timing ) where
130+ TRef :: TValueType a -> SRefKind k -> Ref k t -> TypedRef t
131+ deriving instance Show (TypedRef t )
136132
137- _Loc :: SRefKind k -> TItem a k t -> Location t
138- _Loc k item@ (Item t@ VType _) = Loc t k item
133+ instance Eq (TypedRef t ) where
134+ TRef vt1@ VType SRefKind i1 == TRef vt2@ VType SRefKind i2 = eqS'' vt1 vt2 && eqTypeKind i1 i2
135+ _TRef :: SRefKind k -> Ref k t -> TypedRef t
136+ _TRef k item@ (Item t@ VType _) = TRef t k item
139137
140138-- | Distinguish the type of Refs to calldata variables and storage
141139data RefKind = Storage | Calldata
@@ -197,21 +195,6 @@ instance Eq (Ref k t) where
197195 SField _ r c x == SField _ r' c' x' = r == r' && c == c' && x == x'
198196 _ == _ = False
199197
200- -- | Item is a reference together with its Act type. The type is
201- -- parametrized on a timing `t`, a type `a`, and the reference kind
202- -- `k`. `t` can be either `Timed` or `Untimed` and indicates whether
203- -- any indices that reference items in storage explicitly refer to the
204- -- pre-/post-state, or not. `a` is the type of the item that is
205- -- referenced. Items are also annotated with the original ValueType
206- -- that carries more precise type information (e.g., the exact
207- -- contract type).
208- data TItem (a :: ActType ) (k :: RefKind ) (t :: Timing ) where
209- Item :: TValueType a -> Ref k t -> TItem a k t
210- deriving instance Show (TItem a k t )
211- deriving instance Eq (TItem a k t )
212-
213- -- _Item :: SingI a => ValueType -> Ref k t -> TItem a k t
214- -- _Item = Item sing
215198
216199-- | Expressions for which the return type is known.
217200data TypedExp t
0 commit comments