git @ Cat's Eye Technologies Robin / 252005a
Refactor to note TODO centrally and avoid `where` more. Chris Pressey 5 years ago
3 changed file(s) with 18 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
2727
2828 Opaque type might also be useful for internals, e.g. signaling
2929 to runtime system that an error occurred.
30
31 Exceptions
32 ----------
33
34 Raising a list that looks like `(uncaught-exception ...)`, and
35 then catching anything that looks like that, is less than fantastic.
36 (We do this in `display` and in reactors). Should we have a
37 dedicated `error` type Expr?
3038
3139 Stdlib
3240 ------
1414 body :: Expr -- body takes three arguments: event state
1515 } deriving (Show, Eq)
1616
17
1817 update :: Reactor -> Expr -> (Reactor, [Expr])
1918 update reactor@Reactor{rid=rid, env=env, state=state, body=body} event =
2019 let
2120 env' = setExceptionHandler (Intrinsic "(exception-handler)" catchException) env
22 in
23 case eval env' (List [body, event, state]) id of
24 command@(List [(Symbol "uncaught-exception"), expr]) ->
25 (reactor, [command])
26 (List (state':commands)) ->
27 (reactor{ state=state' }, applyStop commands)
28 expr ->
29 (reactor, [List [(Symbol "malformed-response"), expr]])
30 where
3121 catchException env expr k = List [(Symbol "uncaught-exception"), expr]
3222
3323 -- If the reactor issued a 'stop' command, decorate that command
3828 (List [Symbol "stop", Number rid]:applyStop commands)
3929 applyStop (command:commands) =
4030 (command:applyStop commands)
31 in
32 case eval env' (List [body, event, state]) id of
33 command@(List [(Symbol "uncaught-exception"), expr]) ->
34 (reactor, [command])
35 (List (state':commands)) ->
36 (reactor{ state=state' }, applyStop commands)
37 expr ->
38 (reactor, [List [(Symbol "malformed-response"), expr]])
4139
4240
4341 updateMany :: [Reactor] -> Expr -> ([Reactor], [Expr])
1010
1111 collect ((List [Symbol "display", expr]):rest) env reactors results =
1212 let
13 catchException env expr k = List [(Symbol "uncaught-exception"), expr]
1314 env' = setExceptionHandler (Intrinsic "(exception-handler)" catchException) env
1415 result = case eval env' expr id of
15 -- TODO This is less than fantastic. Should we have a dedicated error Expr?
16 e@(List [(Symbol "uncaught-exception"), expr]) -> Left expr
16 (List [(Symbol "uncaught-exception"), expr]) -> Left expr
1717 other -> Right other
1818 in
1919 collect rest env reactors (result:results)
20 where
21 catchException env expr k = List [(Symbol "uncaught-exception"), expr]
2220
2321 collect ((List [Symbol "assert", expr]):rest) env reactors results =
2422 case eval env expr id of