Catch exceptions, propogate them. This is less than fantastic.
Chris Pressey
5 years ago
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 | |
Make the Javascript version display all errors.
|
9 | |
|
10 | 8 |
Environments as abstract maps, alist->env, env->alist
|
11 | 9 |
|
12 | 10 |
Values of "opaque" type, to support that.
|
21 | 21 |
Right topExprs -> do
|
22 | 22 |
let env = (mergeEnvs robinIntrinsics robinBuiltins)
|
23 | 23 |
let (env', reactors, results) = TopLevel.collect topExprs env [] []
|
24 | |
setProp resultElem "textContent" $ (foldl (\a x -> x ++ "\n" ++ a) "" (map (show) results))
|
|
24 |
setProp resultElem "textContent" $ showResults results
|
25 | 25 |
Left problem -> do
|
26 | 26 |
setProp resultElem "textContent" $ show $ problem
|
|
27 |
showResults results =
|
|
28 |
(foldl (\a x -> x ++ "\n" ++ a) "" (map (showResult) results))
|
|
29 |
showResult (Right result) = show result
|
|
30 |
showResult (Left result) = "ERROR: " ++ (show result)
|
8 | 8 |
collect [] env reactors results = (env, reactors, results)
|
9 | 9 |
|
10 | 10 |
collect ((List [Symbol "display", expr]):rest) env reactors results =
|
11 | |
collect rest env reactors (eval (IEnv stop) env expr id:results)
|
|
11 |
let
|
|
12 |
result = case eval (IEnv catchException) env expr id of
|
|
13 |
e@(List [(Symbol "uncaught-exception"), expr]) -> Left e
|
|
14 |
other -> Right other
|
|
15 |
in
|
|
16 |
collect rest env reactors (result:results)
|
|
17 |
where
|
|
18 |
catchException expr = List [(Symbol "uncaught-exception"), expr]
|
12 | 19 |
|
13 | 20 |
collect ((List [Symbol "assert", expr]):rest) env reactors results =
|
14 | 21 |
case eval (IEnv stop) env expr id of
|
4 | 4 |
import System.Environment
|
5 | 5 |
import System.Exit
|
6 | 6 |
|
|
7 |
import Language.Robin.Expr
|
7 | 8 |
import Language.Robin.Env (mergeEnvs)
|
8 | 9 |
import Language.Robin.Parser (parseRobin)
|
9 | 10 |
import Language.Robin.Intrinsics (robinIntrinsics)
|
|
49 | 50 |
|
50 | 51 |
|
51 | 52 |
writeResults [] = return ()
|
52 | |
writeResults (result:results) = do
|
|
53 |
writeResults ((Right result):results) = do
|
53 | 54 |
putStrLn $ show result
|
54 | 55 |
writeResults results
|
|
56 |
writeResults ((Left (List [(Symbol "uncaught-exception"), expr])):results) =
|
|
57 |
error $ "uncaught exception: " ++ show expr
|
|
58 |
writeResults ((Left expr):results) =
|
|
59 |
error $ show expr
|
55 | 60 |
|
56 | 61 |
|
57 | 62 |
runReactors [] showEvents = return ()
|