diff --git a/src/Language/Wasm/Interpreter.hs b/src/Language/Wasm/Interpreter.hs new file mode 100644 index 0000000..e47c473 --- /dev/null +++ b/src/Language/Wasm/Interpreter.hs @@ -0,0 +1,44 @@ +{-# LANGUAGE DuplicateRecordFields #-} + +module Language.Wasm.Interpreter ( + instantiate +) where + +import qualified Data.Map as Map +import qualified Data.Text.Lazy as TL + +import Data.Vector (Vector) +import qualified Data.Vector as Vector +import Data.IORef (IORef) +import Data.Array.IO (IOArray, newArray, readArray, writeArray) +import Data.Word (Word32, Word64) + +import Language.Wasm.Structure + +data Value = + VI32 Word32 + | VI62 Word64 + | VF32 Float + | VF64 Double + +type Address = Int + +data Ref a = Imported TL.Text TL.Text | Local a + +type TableInstance = Vector (Maybe Address) + +type MemoryInstance = IOArray Int Word32 + +data GlobalInstance = GConst Value | GMut (IORef Value) + +data ModuleInstance = ModuleInstance { + types :: Vector FuncType, + functions :: Vector (Ref Function), + tables :: Vector (Ref TableInstance), + mems :: Vector (Ref MemoryInstance), + globals :: Vector (Ref Global), + exports :: Map.Map TL.Text ExportDesc +} + +instantiate :: Module -> ModuleInstance +instantiate mod = undefined \ No newline at end of file diff --git a/wasm.cabal b/wasm.cabal index c08ea56..ccf4761 100644 --- a/wasm.cabal +++ b/wasm.cabal @@ -30,6 +30,7 @@ library , transformers >=0.4 && <0.6 , utf8-string >=1.0 , cereal >= 0.5 + , vector >= 0.12 build-tools: alex >=3.1.3 , happy >=1.9.4 @@ -39,6 +40,7 @@ library Language.Wasm.Structure Language.Wasm.Binary Language.Wasm.Validate + Language.Wasm.Interpreter Language.Wasm other-modules: Paths_wasm