git @ Cat's Eye Technologies ZOWIE / de44cfa
Update test suite. Update implementation to run under Python 3. Chris Pressey 1 year, 11 days ago
6 changed file(s) with 106 addition(s) and 103 deletion(s). Raw diff Collapse all Expand all
2121 return x
2222
2323
24 def unichr_compat(code):
25 try:
26 return unichr(code)
27 except NameError:
28 return chr(code)
29
30
2431 def output(code):
2532 try:
26 sys.stdout.write(unichr(code))
33 sys.stdout.write(unichr_compat(code))
2734 except UnicodeEncodeError:
2835 sys.stdout.write("&#%d;" % code)
2936
4249 pass
4350
4451 def skulpt_output(code):
45 print "&#%d;" % code
52 print("&#%d;" % code)
4653
4754 output = skulpt_output
4855
393400
394401
395402 def rpython_output(code):
396 os.write(0, unichr(code).encode('utf-8'))
403 os.write(0, unichr_compat(code).encode('utf-8'))
397404
398405
399406 def rpython_load(filename):
400 fd = os.open(filename, os.O_RDONLY, 0644)
407 fd = os.open(filename, os.O_RDONLY, 0o644)
401408 text = ''
402409 chunk = os.read(fd, 1024)
403410 text += chunk
00 #!/bin/sh
11
2 FIXTURES=''
2 APPLIANCES="tests/appliances/zowie.py2.md tests/appliances/zowie.py3.md"
33 if [ ! `which rpython`X = X ]; then
4 FIXTURES="$FIXTURES tests/rpython-fixture.markdown"
4 APPLIANCES="$APPLIANCES tests/appliances/zowie-c.md"
55 if [ ! -e ./zowie-c ]; then
66 ./build.sh || exit $?
77 fi
88 fi
99
10 falderal --substring-error $FIXTURES tests/ZOWIE.markdown
10 falderal $APPLIANCES tests/ZOWIE.md
+0
-82
tests/ZOWIE.markdown less more
0 Tests for ZOWIE
1 ===============
2
3 This non-exhaustive test suite is written in format of Falderal 0.9.
4
5 -> Tests for functionality "Interpret ZOWIE Program"
6
7 -> Functionality "Interpret ZOWIE Program" is implemented by
8 -> shell command
9 -> "python src/zowie.py %(test-body-file)"
10
11 Display the Roman alphabet in reverse.
12
13 | MOV R10, 90 ; initially it's "Z"
14 | MOV R1, R1 ; BEGIN TRANSACTION for "REPEAT"
15 | MOV R0, R10 ; output character
16 | MOV R8, R10 ; decrement character
17 | MOV R5, 1
18 | MOV R10, R8
19 | MOV R8, R10 ; test if character is above "@"
20 | MOV R5, 64
21 | MOV R3, R8 ; COMMIT AND REPEAT if non-zero
22 = ZYXWVUTSRQPONMLKJIHGFEDCBA
23
24 Compute a factorial.
25
26 | MOV R11, 5 ; let's find 5!
27 | MOV R10, 1 ; accumulator
28 |
29 | MOV R8, R11 ; increase multiplicand
30 | MOV R4, 1
31 | MOV R11, R8
32 |
33 | MOV R1, R1 ; BEGIN TRANSACTION for "REPEAT"
34 |
35 | MOV R8, R11 ; decrease multiplicand
36 | MOV R5, 1
37 | MOV R11, R8
38 |
39 | MOV R1, R1 ; BEGIN TRANSACTION for "IF"
40 |
41 | MOV R8, R10 ; accumulator
42 | MOV R6, R11 ; multiplied
43 | MOV R10, R8
44 |
45 | MOV R2, R11 ; COMMIT if multiplicand above zero, or ROLLBACK otherwise
46 | MOV R3, R11 ; COMMIT AND REPEAT if multiplicand above zero
47 |
48 | MOV R0, R10 ; output accumulator (as single Unicode character)
49 = x
50
51 The only command in the language is `MOV` and it must be in uppercase.
52
53 | cmp R11, 5
54 ?
55
56 | mov R11, 5
57 ?
58
59 Register names must be uppercase, too.
60
61 | MOV r11, 5
62 ?
63
64 The destination cannot be an immediate.
65
66 | MOV 5, R11
67 ?
68
69 Retrieve indirect reference.
70
71 | MOV R11, 65
72 | MOV R12, 11
73 | MOV R0, R[R12]
74 = A
75
76 Store indirect reference.
77
78 | MOV R12, 11
79 | MOV R[R12], 65
80 | MOV R0, R11
81 = A
0 Tests for ZOWIE
1 ===============
2
3 This non-exhaustive test suite is written in format of Falderal 0.9.
4
5 -> Tests for functionality "Interpret ZOWIE Program"
6
7 Display the Roman alphabet in reverse.
8
9 | MOV R10, 90 ; initially it's "Z"
10 | MOV R1, R1 ; BEGIN TRANSACTION for "REPEAT"
11 | MOV R0, R10 ; output character
12 | MOV R8, R10 ; decrement character
13 | MOV R5, 1
14 | MOV R10, R8
15 | MOV R8, R10 ; test if character is above "@"
16 | MOV R5, 64
17 | MOV R3, R8 ; COMMIT AND REPEAT if non-zero
18 = ZYXWVUTSRQPONMLKJIHGFEDCBA
19
20 Compute a factorial.
21
22 | MOV R11, 5 ; let's find 5!
23 | MOV R10, 1 ; accumulator
24 |
25 | MOV R8, R11 ; increase multiplicand
26 | MOV R4, 1
27 | MOV R11, R8
28 |
29 | MOV R1, R1 ; BEGIN TRANSACTION for "REPEAT"
30 |
31 | MOV R8, R11 ; decrease multiplicand
32 | MOV R5, 1
33 | MOV R11, R8
34 |
35 | MOV R1, R1 ; BEGIN TRANSACTION for "IF"
36 |
37 | MOV R8, R10 ; accumulator
38 | MOV R6, R11 ; multiplied
39 | MOV R10, R8
40 |
41 | MOV R2, R11 ; COMMIT if multiplicand above zero, or ROLLBACK otherwise
42 | MOV R3, R11 ; COMMIT AND REPEAT if multiplicand above zero
43 |
44 | MOV R0, R10 ; output accumulator (as single Unicode character)
45 = x
46
47 The only command in the language is `MOV` and it must be in uppercase.
48
49 | cmp R11, 5
50 ?
51
52 | mov R11, 5
53 ?
54
55 Register names must be uppercase, too.
56
57 | MOV r11, 5
58 ?
59
60 The destination cannot be an immediate.
61
62 | MOV 5, R11
63 ?
64
65 Retrieve indirect reference.
66
67 | MOV R11, 65
68 | MOV R12, 11
69 | MOV R0, R[R12]
70 = A
71
72 Store indirect reference.
73
74 | MOV R12, 11
75 | MOV R[R12], 65
76 | MOV R0, R11
77 = A
0 This Falderal fixture tests the compiled-with-RPython version of the ZOWIE
1 reference interpreter.
2
3 This requires `fa-under-pty`, which is a part of Falderal version 0.10.
4
5 It requires `fa-under-pty` because, for whatever reason, executables produced
6 by RPython from PyPy version 2.3.1 do not handle having their stdout redirected
7 very well. Specifically, they dump core. It is for this very reason that
8 `fa-under-pty` was written, in fact.
9
10 -> Functionality "Interpret ZOWIE Program" is implemented by
11 -> shell command
12 -> "fa-under-pty ./zowie-c %(test-body-file)"
13
+0
-14
tests/rpython-fixture.markdown less more
0 This Falderal fixture tests the compiled-with-RPython version of the ZOWIE
1 reference interpreter.
2
3 This requires `fa-under-pty`, which is a part of Falderal version 0.10.
4
5 It requires `fa-under-pty` because, for whatever reason, executables produced
6 by RPython from PyPy version 2.3.1 do not handle having their stdout redirected
7 very well. Specifically, they dump core. It is for this very reason that
8 `fa-under-pty` was written, in fact.
9
10 -> Functionality "Interpret ZOWIE Program" is implemented by
11 -> shell command
12 -> "fa-under-pty ./zowie-c %(test-body-file)"
13