Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add builder for if, block and loop #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
27 changes: 14 additions & 13 deletions src/Language/Wasm/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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, (.=)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resolver: lts-16.5
resolver: lts-20.23
packages:
- '.'
extra-deps: []
Expand Down
8 changes: 4 additions & 4 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions wasm.cabal
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down