refactor interpreter types
This commit is contained in:
@@ -6,12 +6,14 @@ module Language.Wasm.Interpreter (
|
|||||||
|
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
import qualified Data.Text.Lazy as TL
|
import qualified Data.Text.Lazy as TL
|
||||||
|
import qualified Data.ByteString.Lazy as LBS
|
||||||
|
|
||||||
import Data.Vector (Vector)
|
import Data.Vector (Vector)
|
||||||
import qualified Data.Vector as Vector
|
import qualified Data.Vector as Vector
|
||||||
import Data.IORef (IORef)
|
import Data.IORef (IORef)
|
||||||
import Data.Array.IO (IOArray, newArray, readArray, writeArray)
|
import Data.Array.IO (IOArray, newArray, readArray, writeArray)
|
||||||
import Data.Word (Word32, Word64)
|
import Data.Word (Word32, Word64)
|
||||||
|
import Numeric.Natural (Natural)
|
||||||
|
|
||||||
import Language.Wasm.Structure
|
import Language.Wasm.Structure
|
||||||
|
|
||||||
@@ -20,6 +22,19 @@ data Value =
|
|||||||
| VI62 Word64
|
| VI62 Word64
|
||||||
| VF32 Float
|
| VF32 Float
|
||||||
| VF64 Double
|
| VF64 Double
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
data AdminInstr =
|
||||||
|
I Instruction
|
||||||
|
| Trap
|
||||||
|
| Invoke Address
|
||||||
|
| InitElem Address Word32 [Natural]
|
||||||
|
| InitData Address Word32 LBS.ByteString
|
||||||
|
| Label [AdminInstr] [AdminInstr]
|
||||||
|
| IFrame Frame [AdminInstr]
|
||||||
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
data Frame = Frame { locals :: Vector Value, mod :: ModuleInstance } deriving (Eq, Show)
|
||||||
|
|
||||||
type Address = Int
|
type Address = Int
|
||||||
|
|
||||||
@@ -31,14 +46,27 @@ type MemoryInstance = IOArray Int Word32
|
|||||||
|
|
||||||
data GlobalInstance = GConst Value | GMut (IORef Value)
|
data GlobalInstance = GConst Value | GMut (IORef Value)
|
||||||
|
|
||||||
data ModuleInstance = ModuleInstance {
|
data FunctionInstance = FunctionInstance {
|
||||||
types :: Vector FuncType,
|
funcType :: FuncType,
|
||||||
functions :: Vector (Ref Function),
|
moduleInstance :: ModuleInstance,
|
||||||
tables :: Vector (Ref TableInstance),
|
code :: Function
|
||||||
mems :: Vector (Ref MemoryInstance),
|
} deriving (Show, Eq)
|
||||||
globals :: Vector (Ref Global),
|
|
||||||
exports :: Map.Map TL.Text ExportDesc
|
data Store = Store {
|
||||||
|
functions :: Vector FunctionInstance,
|
||||||
|
tables :: Vector TableInstance,
|
||||||
|
mems :: Vector MemoryInstance,
|
||||||
|
globals :: Vector Global
|
||||||
}
|
}
|
||||||
|
|
||||||
instantiate :: Module -> ModuleInstance
|
data ModuleInstance = ModuleInstance {
|
||||||
|
types :: Vector FuncType,
|
||||||
|
functions :: Vector Address,
|
||||||
|
tables :: Vector Address,
|
||||||
|
mems :: Vector Address,
|
||||||
|
globals :: Vector Address,
|
||||||
|
exports :: Map.Map TL.Text ExportDesc
|
||||||
|
} deriving (Eq, Show)
|
||||||
|
|
||||||
|
instantiate :: Store -> Module -> (ModuleInstance, Store)
|
||||||
instantiate mod = undefined
|
instantiate mod = undefined
|
||||||
Reference in New Issue
Block a user