summaryrefslogtreecommitdiff
path: root/src/Wasm/Type.agda
blob: 6e94a717fccd7ef7828bae45f36b49c2fd6eaf12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{-# OPTIONS --safe --without-K #-}

module Wasm.Type where

open import Data.Fin using (Fin; Fin′; inject)
open import Data.List using (List)
open import Data.Maybe using (Maybe; nothing; just; maybe)
open import Data.Nat using (ℕ)
open import Wasm.Value using (I32)

infix 4 _⟶_ _,_

record Limits (k : ℕ) : Set where
  constructor _,_
  field
    max     : Maybe (Fin k)
    min     : maybe Fin′ (Fin k) max

  min′ : Fin k
  min′ with max     | min
  ...     | nothing | m = m
  ...     | just _  | m = inject m

data NumType : Set where
  i32 : NumType
  i64 : NumType
  f32 : NumType
  f64 : NumType

data RefType : Set where
  funcref   : RefType
  externref : RefType

data ValType : Set where
  num : NumType → ValType
  ref : RefType → ValType

record FuncType : Set where
  constructor _⟶_
  field
    from : List ValType
    to   : List ValType

data Mutability : Set where
  const : Mutability
  var   : Mutability

record GlobalType : Set where
  constructor _,_
  field
    mut  : Mutability
    type : ValType

record TableType : Set where
  field
    limits : Limits 4294967295
    type   : RefType

record MemType : Set where
  field
    limits : Limits 65536