diff --git a/README.md b/README.md index c24b60a..75f6410 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,10 @@ * [ ] Text Representation pretty-printer * [ ] Command line tool for calling interpreter/compiler/validator * [ ] Codegen interface for type enforced generating valid WASM code + * [ ] Support for building if, loop, block ## Development -Clond sources to directory and use `stack` for running tests: +Clone sources to directory and use `stack` for running tests: ``` stack build && stack test ``` diff --git a/src/Language/Wasm/Builder.hs b/src/Language/Wasm/Builder.hs index caa158a..a0e343f 100644 --- a/src/Language/Wasm/Builder.hs +++ b/src/Language/Wasm/Builder.hs @@ -41,7 +41,8 @@ module Language.Wasm.Builder ( memorySize, growMemory, nop, Language.Wasm.Builder.drop, select, call, callIndirect, finish, br, brIf, brTable, - {-if', loop, block, when, for, while,-} + if', + {-, loop, block, when, for, while,-} trap, unreachable, appendExpr, after, Producer, OutType, produce, Consumer, (.=) @@ -51,7 +52,7 @@ import Prelude hiding (and, or) import qualified Data.List as List import qualified Data.Maybe as Maybe import Control.Monad.State (State, execState, get, gets, put, modify) -import Control.Monad.Reader (ReaderT, ask, runReaderT) +import Control.Monad.Reader (ReaderT, ask, asks, runReaderT) import Numeric.Natural import Data.Word (Word32, Word64) import Data.Int (Int32, Int64) @@ -709,17 +710,17 @@ while pred body = do label :: GenFun (Label t) label = Label <$> ask --- if' :: (Producer pred, OutType pred ~ Proxy I32, Returnable res) --- => res --- -> pred --- -> GenFun res --- -> GenFun res --- -> GenFun res --- if' res pred true false = do --- produce pred --- deep <- (+1) <$> ask --- appendExpr [If (asResultValue res) (genExpr deep $ true) (genExpr deep $ false)] --- return returnableValue +if' :: (Producer pred, OutType pred ~ Proxy I32, Returnable res) + => BlockType + -> pred + -> GenFun res + -> GenFun res + -> GenFun res +if' blockType pred true false = do + produce pred + deep <- asks (+1) + appendExpr [If blockType (genExpr deep true) (genExpr deep false)] + return returnableValue -- loop :: (Returnable res) => res -> GenFun res -> GenFun res -- loop res body = do diff --git a/stack.yaml b/stack.yaml index 9d0d27a..84e1882 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-16.5 +resolver: lts-20.23 packages: - '.' extra-deps: [] diff --git a/stack.yaml.lock b/stack.yaml.lock index 1890a3b..a4a15c4 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - size: 531707 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/5.yaml - sha256: 9751e25e0af5713a53ddcfcc79564b082c71b1b357fadef0d85672a5b5ba3703 - original: lts-16.5 + sha256: 4c972e067bae16b95961dbfdd12e07f1ee6c8fffabbfa05c3d65100b03f548b7 + size: 650253 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/23.yaml + original: lts-20.23 diff --git a/wasm.cabal b/wasm.cabal index 04d6fa1..8b35d0c 100644 --- a/wasm.cabal +++ b/wasm.cabal @@ -1,6 +1,6 @@ cabal-version: 2.2 name: wasm -version: 1.1.2 +version: 1.1.3 synopsis: WebAssembly Language Toolkit and Interpreter description: Library for parsing and interpreting WebAssembly, including: @@ -16,9 +16,9 @@ license: MIT license-file: LICENSE build-type: Simple category: Language -homepage: https:github.com/SPY/haskell-wasm -bug-reports: https:github.com/SPY/haskell-wasm/issues -tested-with: GHC==8.6.5, GHC==8.8.4, GHC==8.10.4 +homepage: https://github.com/SPY/haskell-wasm +bug-reports: https://github.com/SPY/haskell-wasm/issues +tested-with: GHC==8.6.5, GHC==8.8.4, GHC==8.10.4, GHC==9.2.7 extra-source-files: README.md src/Language/Wasm/Parser.y