diff options
| author | Chloe Brown <chloe.brown.00@outlook.com> | 2021-07-28 16:56:07 +0100 | 
|---|---|---|
| committer | Chloe Brown <chloe.brown.00@outlook.com> | 2021-07-28 16:56:07 +0100 | 
| commit | a3a8a44b4bc0d60164452826645066a5ffed5bc5 (patch) | |
| tree | 9ca46d3cce42037dd26051a3952d77bef15b0ec8 /src/Wasm/Validation/Context.agda | |
| parent | 9812bb2ae394b59ae9fcb7cf9b78fd260aa3e92a (diff) | |
Complete Section 3 - Validation.
Diffstat (limited to 'src/Wasm/Validation/Context.agda')
| -rw-r--r-- | src/Wasm/Validation/Context.agda | 63 | 
1 files changed, 63 insertions, 0 deletions
| diff --git a/src/Wasm/Validation/Context.agda b/src/Wasm/Validation/Context.agda new file mode 100644 index 0000000..f7c2564 --- /dev/null +++ b/src/Wasm/Validation/Context.agda @@ -0,0 +1,63 @@ +{-# OPTIONS --without-K --safe #-} + +------------------------------------------------------------------------ +-- Type Context + +module Wasm.Validation.Context where + +open import Data.Fin using (Fin; toℕ; fromℕ<) +open import Data.List using (List; length; lookup) +open import Data.Maybe using (Maybe; just; nothing) +open import Data.Nat using (_<?_; _^_) +open import Data.Unit using (⊤) +open import Relation.Nullary using (yes; no) +open import Wasm.Constants +open import Wasm.Expression.Types +open import Wasm.Expression.Utilities using (module Indices) + +record Context : Set where +  field +    types : List FuncType +    funcs : List FuncType +    tables : List TableType +    mems   : List MemType +    globals : List GlobalType +    elems   : List RefType +    datas   : List ⊤ +    locals  : List ValType +    labels  : List ResultType +    return  : Maybe ResultType +    refs    : List Indices.FuncIdx + +  private +    get : ∀ {A} → List A → Fin 2^32 → Maybe A +    get xs idx with toℕ idx <? length xs +    ... | yes idx<∣xs∣ = just (lookup xs (fromℕ< idx<∣xs∣)) +    ... | no _         = nothing + +  getType : Indices.TypeIdx → Maybe FuncType +  getType = get types + +  getFunc : Indices.FuncIdx → Maybe FuncType +  getFunc = get funcs + +  getTable : Indices.TableIdx → Maybe TableType +  getTable = get tables + +  getMem : Indices.MemIdx → Maybe MemType +  getMem = get mems + +  getGlobal : Indices.GlobalIdx → Maybe GlobalType +  getGlobal = get globals + +  getElem : Indices.ElemIdx → Maybe RefType +  getElem = get elems + +  getData : Indices.DataIdx → Maybe ⊤ +  getData = get datas + +  getLocal : Indices.LocalIdx → Maybe ValType +  getLocal = get locals + +  getLabel : Indices.LabelIdx → Maybe ResultType +  getLabel = get labels | 
