Checkpoint troubleshooting why some operators don't abort correctly.
Chris Pressey
4 years ago
919 | 919 |
reference implementation will display them if `--show-events` is given)
|
920 | 920 |
but this is not a strict requirement.
|
921 | 921 |
|
922 | |
| (reactor (line-terminal) 0
|
923 | |
| (macro (args env)
|
924 | |
| (bind event (head args)
|
925 | |
| (bind event-type (head event)
|
926 | |
| (bind event-payload (head (tail event))
|
927 | |
| (if (equal? event-type (literal readln))
|
928 | |
| (if (equal? (head event-payload) 65)
|
929 | |
| (abort 999999)
|
930 | |
| (list 0 (list (literal writeln) event-payload)))
|
931 | |
| (list 0)))))))
|
932 | |
+ Cat
|
933 | |
+ Dog
|
934 | |
+ Alligator
|
935 | |
+ Bear
|
936 | |
= Cat
|
937 | |
= Dog
|
938 | |
= Bear
|
|
922 |
/| (reactor (line-terminal) 0
|
|
923 |
/| (macro (args env)
|
|
924 |
/| (bind event (head args)
|
|
925 |
/| (bind event-type (head event)
|
|
926 |
/| (bind event-payload (head (tail event))
|
|
927 |
/| (if (equal? event-type (literal readln))
|
|
928 |
/| (if (equal? (head event-payload) 65)
|
|
929 |
/| (abort 999999)
|
|
930 |
/| (list 0 (list (literal writeln) event-payload)))
|
|
931 |
/| (list 0)))))))
|
|
932 |
/+ Cat
|
|
933 |
/+ Dog
|
|
934 |
/+ Alligator
|
|
935 |
/+ Bear
|
|
936 |
/= Cat
|
|
937 |
/= Dog
|
|
938 |
/= Bear
|
939 | 939 |
|
940 | 940 |
Reactors can keep state.
|
941 | 941 |
|
21 | 21 |
prepend :: Evaluable
|
22 | 22 |
prepend env (List [e1, e2]) =
|
23 | 23 |
case (eval env e1, eval env e2) of
|
24 | |
(x1, List x2) -> List (x1:x2)
|
25 | |
(_, other) -> errMsg "expected-list" other
|
|
24 |
((Abort a), _) -> Abort a
|
|
25 |
(_, (Abort a)) -> Abort a
|
|
26 |
(x1, List x2) -> List (x1:x2)
|
|
27 |
(_, other) -> errMsg "expected-list" other
|
26 | 28 |
prepend env other = errMsg "illegal-arguments" other
|
27 | 29 |
|
28 | 30 |
equalP :: Evaluable
|
6 | 6 |
division computes by what integer the second number can be multiplied
|
7 | 7 |
to make it as big as possible without exceeding the first number.
|
8 | 8 |
|
9 | |
| (divide 100 3)
|
|
9 |
| (divide 100 3)
|
10 | 10 |
= 33
|
11 | 11 |
|
12 | |
| (divide (subtract 0 100) 3)
|
|
12 |
| (divide (subtract 0 100) 3)
|
13 | 13 |
= -34
|
14 | 14 |
|
15 | |
| (divide 100 (subtract 0 3))
|
|
15 |
| (divide 100 (subtract 0 3))
|
16 | 16 |
= -34
|
17 | 17 |
|
18 | |
| (divide 33 33)
|
|
18 |
| (divide 33 33)
|
19 | 19 |
= 1
|
20 | 20 |
|
21 | |
| (divide 33 34)
|
|
21 |
| (divide 33 34)
|
22 | 22 |
= 0
|
23 | 23 |
|
24 | |
| (divide 10 0)
|
|
24 |
| (divide 10 0)
|
25 | 25 |
? abort (division-by-zero 10)
|
26 | 26 |
|
27 | 27 |
Division by zero is undefined, and an abort value will be produced.
|
28 | 28 |
|
29 | |
| (divide 10 0)
|
|
29 |
| (divide 10 0)
|
30 | 30 |
? abort (division-by-zero 10)
|
31 | 31 |
|
32 | |
`div` expects exactly two arguments, both numbers.
|
|
32 |
`divide` expects exactly two arguments, both numbers.
|
33 | 33 |
|
34 | |
| (divide 14)
|
|
34 |
| (divide 14)
|
35 | 35 |
? abort (illegal-arguments (14))
|
36 | 36 |
|
37 | |
| (divide 14 23 57)
|
|
37 |
| (divide 14 23 57)
|
38 | 38 |
? abort (illegal-arguments (14 23 57))
|
39 | 39 |
|
40 | |
| (divide 14 #t)
|
|
40 |
| (divide 14 #t)
|
41 | 41 |
? abort (expected-number #t)
|
42 | 42 |
|
43 | |
| (divide #t 51)
|
44 | |
? abort (expected-number #t)
|
|
43 |
/| (divide #t 51)
|
|
44 |
/? abort (expected-number #t)
|
45 | 45 |
|
46 | 46 |
'<<SPEC'
|
47 | 47 |
|
41 | 41 |
| (remainder 14 #t)
|
42 | 42 |
? abort (expected-number #t)
|
43 | 43 |
|
44 | |
| (remainder #t 51)
|
45 | |
? abort (expected-number #t)
|
|
44 |
/| (remainder #t 51)
|
|
45 |
/? abort (expected-number #t)
|
46 | 46 |
|
47 | 47 |
'<<SPEC'
|
48 | 48 |
|
7 | 7 |
APPLIANCES="appliances/robin.md appliances/robin-no-builtins.md"
|
8 | 8 |
fi
|
9 | 9 |
|
|
10 |
if [ "${FALDERAL}x" = "x" ]; then
|
|
11 |
FALDERAL="falderal -b"
|
|
12 |
fi
|
|
13 |
|
10 | 14 |
echo "Running tests on core semantics..."
|
11 | |
falderal -b $APPLIANCES doc/Robin.md || exit 1
|
|
15 |
$FALDERAL $APPLIANCES doc/Robin.md || exit 1
|
12 | 16 |
|
13 | 17 |
if [ "${PACKAGES}x" = "x" ]; then
|
14 | 18 |
PACKAGES="intrinsics small boolean arith list env misc"
|
|
16 | 20 |
|
17 | 21 |
for PACKAGE in $PACKAGES; do
|
18 | 22 |
echo "Running tests on '$PACKAGE' package..."
|
19 | |
falderal -b $APPLIANCES pkg/$PACKAGE.robin || exit 1
|
|
23 |
$FALDERAL $APPLIANCES pkg/$PACKAGE.robin || exit 1
|
20 | 24 |
done
|
21 | 25 |
|
22 | 26 |
if [ "x$FORCE_HUGS" != "x" ] ; then
|