2024-02-07 22:51:08 -08:00
|
|
|
|
module Language where
|
|
|
|
|
|
2024-04-13 18:39:38 -07:00
|
|
|
|
open import Language.Base public
|
|
|
|
|
open import Language.Semantics public
|
|
|
|
|
open import Language.Graphs public
|
2024-04-20 20:25:40 -07:00
|
|
|
|
open import Language.Properties public
|
2024-04-13 18:39:38 -07:00
|
|
|
|
|
|
|
|
|
open import Data.Fin using (Fin; suc; zero)
|
|
|
|
|
open import Data.Fin.Properties as FinProp using (suc-injective)
|
|
|
|
|
open import Data.List as List using (List; []; _∷_)
|
|
|
|
|
open import Data.List.Membership.Propositional as ListMem using ()
|
2024-03-09 13:59:48 -08:00
|
|
|
|
open import Data.List.Relation.Unary.All using (All; []; _∷_)
|
2024-03-10 16:41:21 -07:00
|
|
|
|
open import Data.List.Relation.Unary.Any as RelAny using ()
|
2024-04-13 18:39:38 -07:00
|
|
|
|
open import Data.Nat using (ℕ; suc)
|
|
|
|
|
open import Data.Product using (_,_; Σ; proj₁; proj₂)
|
|
|
|
|
open import Data.Product.Properties as ProdProp using ()
|
|
|
|
|
open import Data.String using (String) renaming (_≟_ to _≟ˢ_)
|
|
|
|
|
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
|
2024-03-09 13:59:48 -08:00
|
|
|
|
open import Relation.Nullary using (¬_)
|
|
|
|
|
|
|
|
|
|
open import Lattice
|
2024-04-13 18:39:38 -07:00
|
|
|
|
open import Utils using (Unique; push; Unique-map; x∈xs⇒fx∈fxs)
|
|
|
|
|
open import Lattice.MapSet _≟ˢ_ using ()
|
2024-03-09 13:59:48 -08:00
|
|
|
|
renaming
|
|
|
|
|
( MapSet to StringSet
|
|
|
|
|
; to-List to to-Listˢ
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
z≢sf : ∀ {n : ℕ} (f : Fin n) → ¬ (zero ≡ suc f)
|
|
|
|
|
z≢sf f ()
|
|
|
|
|
|
2024-04-13 18:39:38 -07:00
|
|
|
|
z≢mapsfs : ∀ {n : ℕ} (fs : List (Fin n)) → All (λ sf → ¬ zero ≡ sf) (List.map suc fs)
|
2024-03-09 13:59:48 -08:00
|
|
|
|
z≢mapsfs [] = []
|
|
|
|
|
z≢mapsfs (f ∷ fs') = z≢sf f ∷ z≢mapsfs fs'
|
|
|
|
|
|
|
|
|
|
indices : ∀ (n : ℕ) → Σ (List (Fin n)) Unique
|
2024-04-13 18:39:38 -07:00
|
|
|
|
indices 0 = ([] , Utils.empty)
|
2024-03-09 13:59:48 -08:00
|
|
|
|
indices (suc n') =
|
|
|
|
|
let
|
|
|
|
|
(inds' , unids') = indices n'
|
|
|
|
|
in
|
2024-04-13 18:39:38 -07:00
|
|
|
|
( zero ∷ List.map suc inds'
|
2024-03-09 13:59:48 -08:00
|
|
|
|
, push (z≢mapsfs inds') (Unique-map suc suc-injective unids')
|
|
|
|
|
)
|
|
|
|
|
|
2024-04-13 18:39:38 -07:00
|
|
|
|
indices-complete : ∀ (n : ℕ) (f : Fin n) → f ListMem.∈ (proj₁ (indices n))
|
2024-03-10 18:13:01 -07:00
|
|
|
|
indices-complete (suc n') zero = RelAny.here refl
|
|
|
|
|
indices-complete (suc n') (suc f') = RelAny.there (x∈xs⇒fx∈fxs suc (indices-complete n' f'))
|
|
|
|
|
|
2024-03-09 13:59:48 -08:00
|
|
|
|
record Program : Set where
|
|
|
|
|
field
|
2024-04-13 14:08:40 -07:00
|
|
|
|
rootStmt : Stmt
|
2024-04-13 13:39:15 -07:00
|
|
|
|
|
|
|
|
|
private
|
2024-04-13 19:33:58 -07:00
|
|
|
|
buildResult = buildCfg rootStmt empty
|
2024-04-13 13:39:15 -07:00
|
|
|
|
|
|
|
|
|
graph : Graph
|
|
|
|
|
graph = proj₁ buildResult
|
|
|
|
|
|
|
|
|
|
State : Set
|
|
|
|
|
State = Graph.Index graph
|
|
|
|
|
|
|
|
|
|
initialState : State
|
2024-04-13 18:39:38 -07:00
|
|
|
|
initialState = Utils.proj₁ (proj₁ (proj₂ buildResult))
|
2024-04-13 13:39:15 -07:00
|
|
|
|
|
|
|
|
|
finalState : State
|
2024-04-13 18:39:38 -07:00
|
|
|
|
finalState = Utils.proj₂ (proj₁ (proj₂ buildResult))
|
2024-03-09 13:59:48 -08:00
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
vars-Set : StringSet
|
2024-04-13 14:08:40 -07:00
|
|
|
|
vars-Set = Stmt-vars rootStmt
|
2024-03-09 13:59:48 -08:00
|
|
|
|
|
|
|
|
|
vars : List String
|
|
|
|
|
vars = to-Listˢ vars-Set
|
|
|
|
|
|
|
|
|
|
vars-Unique : Unique vars
|
|
|
|
|
vars-Unique = proj₂ vars-Set
|
|
|
|
|
|
|
|
|
|
states : List State
|
2024-04-13 13:39:15 -07:00
|
|
|
|
states = proj₁ (indices (Graph.size graph))
|
2024-03-09 13:59:48 -08:00
|
|
|
|
|
2024-04-13 18:39:38 -07:00
|
|
|
|
states-complete : ∀ (s : State) → s ListMem.∈ states
|
2024-04-13 13:39:15 -07:00
|
|
|
|
states-complete = indices-complete (Graph.size graph)
|
2024-03-10 18:13:01 -07:00
|
|
|
|
|
2024-03-09 13:59:48 -08:00
|
|
|
|
states-Unique : Unique states
|
2024-04-13 13:39:15 -07:00
|
|
|
|
states-Unique = proj₂ (indices (Graph.size graph))
|
2024-03-09 13:59:48 -08:00
|
|
|
|
|
2024-04-13 13:39:15 -07:00
|
|
|
|
code : State → List BasicStmt
|
|
|
|
|
code st = graph [ st ]
|
2024-03-10 16:41:21 -07:00
|
|
|
|
|
2024-04-13 18:39:38 -07:00
|
|
|
|
-- vars-complete : ∀ {k : String} (s : State) → k ∈ᵇ (code s) → k ListMem.∈ vars
|
2024-04-03 22:29:58 -07:00
|
|
|
|
-- vars-complete {k} s = ∈⇒∈-Stmts-vars {length} {k} {stmts} {s}
|
2024-03-10 16:41:21 -07:00
|
|
|
|
|
2024-03-09 13:59:48 -08:00
|
|
|
|
_≟_ : IsDecidable (_≡_ {_} {State})
|
2024-04-13 18:39:38 -07:00
|
|
|
|
_≟_ = FinProp._≟_
|
2024-03-09 23:06:47 -08:00
|
|
|
|
|
2024-04-13 13:39:15 -07:00
|
|
|
|
_≟ᵉ_ : IsDecidable (_≡_ {_} {Graph.Edge graph})
|
2024-04-13 18:39:38 -07:00
|
|
|
|
_≟ᵉ_ = ProdProp.≡-dec _≟_ _≟_
|
2024-04-13 13:39:15 -07:00
|
|
|
|
|
2024-04-13 18:39:38 -07:00
|
|
|
|
open import Data.List.Membership.DecPropositional _≟ᵉ_ using (_∈?_)
|
2024-03-09 23:06:47 -08:00
|
|
|
|
|
|
|
|
|
incoming : State → List State
|
2024-04-13 18:39:38 -07:00
|
|
|
|
incoming idx = List.filter (λ idx' → (idx' , idx) ∈? (Graph.edges graph)) states
|