-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
41 lines (35 loc) · 985 Bytes
/
Main.hs
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
module Main where
import Data.Foldable(for_)
import Data.IORef(newIORef)
import GHC.IsList(IsList(..))
import Prelude
import System.Environment(getArgs)
import Language.Wasm.Module
import Language.Wasm.Examples
main :: IO ()
main = do
args <- getArgs
r <- newIORef [1 .. 10]
let
examples =
[ ("countTo10", countTo10)
, ("functions", functions)
, ("recursion", recursion)
, ("outOfBOunds", outOfBounds)
, ("divByZero", divByZero)
, ("fibonacci", fibonacci)
, ("factorial", factorial 10)
, ("mutualRecursion", mutualRecursion)
, ("squareAll", squareAll r)
]
selected =
case args of
[] -> fst <$> examples -- If 'args' is empty, get the names of all 'examples'
_ -> args
for_ selected \name ->
case lookup name examples of
Nothing -> putStrLn $ "Unknown example: " <> name <> "\n"
Just mod -> do
putStrLn $ name <> ": "
runWasm mod
putStrLn ""