git @ Cat's Eye Technologies Robin / b6a9299
Build a little web-based demo with Haste compiler. Chris Pressey 5 years ago
5 changed file(s) with 53 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
00 *.o
11 *.hi
2 *.jsmod
23 /bin/*.exe
34 /pkg/*
5 /demo/*.js
55 A way to evaluate a Robin expression and display it, mainly
66 to make the tests more concise - don't need to say `(display ...)` always.
77
8 Build a Javascript version with the Haste compiler.
8 Make the Javascript version display all errors.
99
1010 Environments as abstract maps, alist->env, env->alist
1111
88 echo "ghc not found, not building $PROG.exe"
99 fi
1010
11 ./build-packages.sh
11 if command -v hastec >/dev/null 2>&1; then
12 echo "building $PROG.js with hastec"
13 (cd src && hastec --make HasteMain.hs -o ../demo/$PROG.js) || exit 1
14 else
15 echo "hastec not found, not building $PROG.js"
16 fi
0 <!DOCTYPE html>
1 <head>
2 <meta charset="utf-8">
3 <title>Robin interpreter</title>
4 </head>
5 <body>
6
7 <h1>Robin interpreter</h1>
8
9 <div id="installation">
10 <textarea id="prog" rows="10" cols="80"></textarea>
11 <div><button id="run-button">Run</button></div>
12 <pre id="result"></pre>
13 </div>
14
15 <script src="robin.js"></script>
16 </body>
0 module Main where
1
2 import Haste
3 import Haste.DOM
4 import Haste.Events
5
6 import Language.Robin.Env (mergeEnvs)
7 import Language.Robin.Parser (parseRobin)
8 import Language.Robin.Intrinsics (robinIntrinsics)
9 import Language.Robin.Builtins (robinBuiltins)
10 import qualified Language.Robin.TopLevel as TopLevel
11
12
13 main = withElems ["prog", "result", "run-button"] driver
14
15 driver [progElem, resultElem, runButtonElem] = do
16 onEvent runButtonElem Click $ \_ -> execute
17 where
18 execute = do
19 Just program <- getValue progElem
20 case parseRobin program of
21 Right topExprs -> do
22 let env = (mergeEnvs robinIntrinsics robinBuiltins)
23 let (env', reactors, results) = TopLevel.collect topExprs env [] []
24 setProp resultElem "textContent" $ (foldl (\a x -> x ++ "\n" ++ a) "" (map (show) results))
25 Left problem -> do
26 setProp resultElem "textContent" $ show $ problem