Build a little web-based demo with Haste compiler.
Chris Pressey
5 years ago
0 | 0 |
*.o
|
1 | 1 |
*.hi
|
|
2 |
*.jsmod
|
2 | 3 |
/bin/*.exe
|
3 | 4 |
/pkg/*
|
|
5 |
/demo/*.js
|
5 | 5 |
A way to evaluate a Robin expression and display it, mainly
|
6 | 6 |
to make the tests more concise - don't need to say `(display ...)` always.
|
7 | 7 |
|
8 | |
Build a Javascript version with the Haste compiler.
|
|
8 |
Make the Javascript version display all errors.
|
9 | 9 |
|
10 | 10 |
Environments as abstract maps, alist->env, env->alist
|
11 | 11 |
|
8 | 8 |
echo "ghc not found, not building $PROG.exe"
|
9 | 9 |
fi
|
10 | 10 |
|
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
|