From 78aad93db3d7029e0a9a8517a2db92533fd1f401 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Tue, 15 Feb 2022 17:04:28 +0000 Subject: Make expressions unable to change state. --- src/Helium/Data/Pseudocode/Core.agda | 61 +++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 7 deletions(-) (limited to 'src/Helium/Data') diff --git a/src/Helium/Data/Pseudocode/Core.agda b/src/Helium/Data/Pseudocode/Core.agda index a50fb84..8a0c4e3 100644 --- a/src/Helium/Data/Pseudocode/Core.agda +++ b/src/Helium/Data/Pseudocode/Core.agda @@ -13,13 +13,16 @@ open import Data.Fin using (Fin; #_) open import Data.Nat as ℕ using (ℕ; zero; suc) open import Data.Nat.Properties using (+-comm) open import Data.Product using (∃; _,_; proj₂; uncurry) +open import Data.Sum using ([_,_]′; inj₁; inj₂) open import Data.Vec using (Vec; []; _∷_; lookup; map) -open import Data.Vec.Relation.Unary.All using (All; []; _∷_; reduce; all?) +open import Data.Vec.Relation.Unary.All using (All; []; _∷_; reduce) +open import Data.Vec.Relation.Unary.Any using (Any; here; there) open import Function as F using (_∘_; _∘′_; _∋_) open import Relation.Binary.PropositionalEquality using (_≡_; refl) open import Relation.Nullary using (yes; no) -open import Relation.Nullary.Decidable.Core using (True; map′) +open import Relation.Nullary.Decidable.Core using (True; False; toWitness; fromWitness; map′) open import Relation.Nullary.Product using (_×-dec_) +open import Relation.Nullary.Sum using (_⊎-dec_) open import Relation.Unary using (Decidable) --- The set of types and boolean properties of them @@ -95,10 +98,15 @@ data Literal : Type → Set where module Code {o} (Σ : Vec Type o) where data Expression {n} (Γ : Vec Type n) : Type → Set - data CanAssign {n} {Γ} : ∀ {t} → Expression {n} Γ t → Set + data CanAssign {n Γ} : ∀ {t} → Expression {n} Γ t → Set canAssign? : ∀ {n Γ t} → Decidable (CanAssign {n} {Γ} {t}) canAssignAll? : ∀ {n Γ m ts} → Decidable {A = All (Expression {n} Γ) {m} ts} (All (CanAssign ∘ proj₂) ∘ (reduce (λ {x} e → x , e))) + data AssignsState {n Γ} : ∀ {t e} → CanAssign {n} {Γ} {t} e → Set + assignsState? : ∀ {n Γ t e} → Decidable (AssignsState {n} {Γ} {t} {e}) + assignsStateAny? : ∀ {n Γ m ts es} → Decidable {A = All (CanAssign ∘ proj₂) (reduce {P = Expression {n} Γ} (λ {x} e → x , e) {m} {ts} es)} (Any (AssignsState ∘ proj₂) ∘ reduce (λ {x} a → x , a)) data Statement {n} (Γ : Vec Type n) : Set + data ChangesState {n Γ} : Statement {n} Γ → Set + changesState? : ∀ {n Γ} → Decidable (ChangesState {n} {Γ}) data Function {n} (Γ : Vec Type n) (ret : Type) : Set data Procedure {n} (Γ : Vec Type n) : Set @@ -134,7 +142,6 @@ module Code {o} (Σ : Vec Type o) where _^_ : ∀ {t} {isNumeric : True (isNumeric? t)} → Expression Γ t → ℕ → Expression Γ t _>>_ : Expression Γ int → ℕ → Expression Γ int rnd : Expression Γ real → Expression Γ int - -- get : ℕ → Expression Γ int → Expression Γ bit fin : ∀ {k ms n} → (All (Fin) ms → Fin n) → Expression Γ (tuple k (map fin ms)) → Expression Γ (fin n) asInt : ∀ {m} → Expression Γ (fin m) → Expression Γ int tup : ∀ {m ts} → All (Expression Γ) ts → Expression Γ (tuple m ts) @@ -176,7 +183,6 @@ module Code {o} (Σ : Vec Type o) where canAssign? (e ^ e₁) = no λ () canAssign? (e >> e₁) = no λ () canAssign? (rnd e) = no λ () - -- canAssign? (get x e) = no λ () canAssign? (fin x e) = no λ () canAssign? (asInt e) = no λ () canAssign? (tup es) = map′ tup (λ { (tup es) → es }) (canAssignAll? es) @@ -186,6 +192,29 @@ module Code {o} (Σ : Vec Type o) where canAssignAll? [] = yes [] canAssignAll? (e ∷ es) = map′ (uncurry _∷_) (λ { (e ∷ es) → e , es }) (canAssign? e ×-dec canAssignAll? es) + data AssignsState where + state : ∀ i {i