Add tests for compilation, BASIC header, load-n-go script.
Chris Pressey
9 years ago
19 | 19 | from sixtypical.parser import Parser |
20 | 20 | from sixtypical.evaluator import eval_program |
21 | 21 | from sixtypical.analyzer import analyze_program |
22 | from sixtypical.emitter import Emitter | |
22 | from sixtypical.emitter import Emitter, Byte, Word | |
23 | 23 | from sixtypical.compiler import compile_program |
24 | 24 | |
25 | 25 | |
28 | 28 | |
29 | 29 | optparser.add_option("--analyze", |
30 | 30 | action="store_true", dest="analyze", default=False, |
31 | help="") | |
32 | optparser.add_option("--basic-header", | |
33 | action="store_true", dest="basic_header", default=False, | |
31 | 34 | help="") |
32 | 35 | optparser.add_option("--compile", |
33 | 36 | action="store_true", dest="compile", default=False, |
58 | 61 | else: |
59 | 62 | traceback.print_exception(e.__class__, e, None) |
60 | 63 | sys.exit(1) |
61 | print 'ok' | |
62 | 64 | |
63 | 65 | if options.compile: |
64 | emitter = Emitter(41952) | |
66 | start_addr = 0xc000 | |
67 | header = [] | |
68 | if options.basic_header: | |
69 | start_addr = 0x0801 | |
70 | header = [0x10, 0x08, 0xc9, 0x07, 0x9e, 0x32, | |
71 | 0x30, 0x36, 0x31, 0x00, 0x00, 0x00] | |
72 | emitter = Emitter(start_addr) | |
73 | # we are outputting a .PRG, so output the load address first | |
74 | emitter.emit(Word(start_addr)) | |
75 | for byte in header: | |
76 | emitter.emit(Byte(byte)) | |
65 | 77 | compile_program(program, emitter) |
66 | 78 | if options.debug: |
67 | 79 | print repr(emitter.accum) |
0 | 0 | routine add_four |
1 | 1 | inputs a |
2 | 2 | outputs a |
3 | trashes c | |
3 | trashes c, z, n, v | |
4 | 4 | { |
5 | 5 | st off, c |
6 | 6 | add a, 4 |
0 | #!/bin/sh | |
1 | ||
2 | SRC=$1 | |
3 | OUT=/tmp/a-out.prg | |
4 | bin/sixtypical --analyze --compile --basic-header $SRC > $OUT || exit 1 | |
5 | x64 $OUT | |
6 | rm -f $OUT |
1 | 1 | |
2 | 2 | falderal --substring-error \ |
3 | 3 | tests/SixtyPical\ Execution.md \ |
4 | tests/SixtyPical\ Analysis.md | |
4 | tests/SixtyPical\ Analysis.md \ | |
5 | tests/SixtyPical\ Compilation.md |
6 | 6 | [Falderal]: http://catseye.tc/node/Falderal |
7 | 7 | |
8 | 8 | -> Functionality "Analyze SixtyPical program" is implemented by |
9 | -> shell command "bin/sixtypical --analyze %(test-body-file)" | |
9 | -> shell command "bin/sixtypical --analyze %(test-body-file) && echo ok" | |
10 | 10 | |
11 | 11 | -> Tests for functionality "Analyze SixtyPical program" |
12 | 12 |
0 | Sixtypical Compilation | |
1 | ====================== | |
2 | ||
3 | This is a test suite, written in [Falderal][] format, for compiling | |
4 | Sixtypical to 6502 machine code. | |
5 | ||
6 | [Falderal]: http://catseye.tc/node/Falderal | |
7 | ||
8 | -> Functionality "Compile Sixtypical program" is implemented by | |
9 | -> shell command "bin/sixtypical --compile %(test-body-file) | fa-bin-to-hex" | |
10 | ||
11 | -> Tests for functionality "Compile Sixtypical program" | |
12 | ||
13 | Null program. | |
14 | ||
15 | | routine main | |
16 | | { | |
17 | | } | |
18 | = 00c060 | |
19 | ||
20 | Rudimentary program. | |
21 | ||
22 | | routine main | |
23 | | inputs a | |
24 | | outputs a | |
25 | | trashes c, z, n, v | |
26 | | { | |
27 | | st off, c | |
28 | | add a, 4 | |
29 | | } | |
30 | = 00c018690460 |