From d0e3dfbf84e6125dfda1968829cbc4bfae3946a3 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Sat, 17 Oct 2015 12:28:39 +0100 Subject: [PATCH] Add tests for compilation, BASIC header, load-n-go script. --- bin/sixtypical | 18 +++++++++++++++--- eg/add-pass.60p | 2 +- loadngo.sh | 7 +++++++ test.sh | 3 ++- tests/SixtyPical Analysis.md | 2 +- tests/SixtyPical Compilation.md | 31 +++++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 6 deletions(-) create mode 100755 loadngo.sh create mode 100644 tests/SixtyPical Compilation.md diff --git a/bin/sixtypical b/bin/sixtypical index 837933f..3ff56bb 100755 --- a/bin/sixtypical +++ b/bin/sixtypical @@ -20,7 +20,7 @@ import traceback from sixtypical.parser import Parser from sixtypical.evaluator import eval_program from sixtypical.analyzer import analyze_program -from sixtypical.emitter import Emitter +from sixtypical.emitter import Emitter, Byte, Word from sixtypical.compiler import compile_program @@ -30,6 +30,9 @@ if __name__ == '__main__': optparser.add_option("--analyze", action="store_true", dest="analyze", default=False, help="") + optparser.add_option("--basic-header", + action="store_true", dest="basic_header", default=False, + help="") optparser.add_option("--compile", action="store_true", dest="compile", default=False, help="") @@ -59,10 +62,19 @@ if __name__ == '__main__': else: traceback.print_exception(e.__class__, e, None) sys.exit(1) - print 'ok' if options.compile: - emitter = Emitter(41952) + start_addr = 0xc000 + header = [] + if options.basic_header: + start_addr = 0x0801 + header = [0x10, 0x08, 0xc9, 0x07, 0x9e, 0x32, + 0x30, 0x36, 0x31, 0x00, 0x00, 0x00] + emitter = Emitter(start_addr) + # we are outputting a .PRG, so output the load address first + emitter.emit(Word(start_addr)) + for byte in header: + emitter.emit(Byte(byte)) compile_program(program, emitter) if options.debug: print repr(emitter.accum) diff --git a/eg/add-pass.60p b/eg/add-pass.60p index 03873fa..16a18ab 100644 --- a/eg/add-pass.60p +++ b/eg/add-pass.60p @@ -1,7 +1,7 @@ routine add_four inputs a outputs a - trashes c + trashes c, z, n, v { st off, c add a, 4 diff --git a/loadngo.sh b/loadngo.sh new file mode 100755 index 0000000..2182ca2 --- /dev/null +++ b/loadngo.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +SRC=$1 +OUT=/tmp/a-out.prg +bin/sixtypical --analyze --compile --basic-header $SRC > $OUT || exit 1 +x64 $OUT +rm -f $OUT diff --git a/test.sh b/test.sh index 98b1f2b..587e14a 100755 --- a/test.sh +++ b/test.sh @@ -2,4 +2,5 @@ falderal --substring-error \ tests/SixtyPical\ Execution.md \ - tests/SixtyPical\ Analysis.md + tests/SixtyPical\ Analysis.md \ + tests/SixtyPical\ Compilation.md diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index 069e238..13607aa 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -7,7 +7,7 @@ static analysis rules. [Falderal]: http://catseye.tc/node/Falderal -> Functionality "Analyze SixtyPical program" is implemented by - -> shell command "bin/sixtypical --analyze %(test-body-file)" + -> shell command "bin/sixtypical --analyze %(test-body-file) && echo ok" -> Tests for functionality "Analyze SixtyPical program" diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md new file mode 100644 index 0000000..3fbdaf9 --- /dev/null +++ b/tests/SixtyPical Compilation.md @@ -0,0 +1,31 @@ +Sixtypical Compilation +====================== + +This is a test suite, written in [Falderal][] format, for compiling +Sixtypical to 6502 machine code. + +[Falderal]: http://catseye.tc/node/Falderal + + -> Functionality "Compile Sixtypical program" is implemented by + -> shell command "bin/sixtypical --compile %(test-body-file) | fa-bin-to-hex" + + -> Tests for functionality "Compile Sixtypical program" + +Null program. + + | routine main + | { + | } + = 00c060 + +Rudimentary program. + + | routine main + | inputs a + | outputs a + | trashes c, z, n, v + | { + | st off, c + | add a, 4 + | } + = 00c018690460