From 63f75a26b496435d836895f917607d9b4f45c3b4 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Tue, 12 Dec 2017 15:34:51 +0000 Subject: [PATCH] Initialized `word` type memory locations. --- HISTORY.md | 1 + README.md | 1 - src/sixtypical/compiler.py | 11 +++++++++-- tests/SixtyPical Analysis.md | 18 ++++++++++++++++++ tests/SixtyPical Compilation.md | 20 ++++++++++++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index f5dc81c..d542246 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,7 @@ History of SixtyPical * Can `call` and `goto` routines that are defined further down in the source code. * The `forward` modifier can also be used to indicate that the symbol being copied in a `copy` to a vector is a routine that is defined further down in the source. +* Initialized `word` memory locations. * Fixed bug which was preventing `if` branches to diverge in what they initialized, if it was already initialized when going into the `if`. * Fixed a bug which was making it crash when trying to analyze `repeat forever` loops. diff --git a/README.md b/README.md index ab72cbf..2e117eb 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,6 @@ This should be tracked in the abstract interpretation. * always analyze before executing or compiling, unless told not to * `trash` instruction. * `interrupt` routines -- to indicate that "the supervisor" has stored values on the stack, so we can trash them. -* pre-initialized `word` variables * error messages that include the line number of the source code * have `copy` instruction able to copy a byte to a user-def mem loc, etc. * add absolute addressing in shl/shr, absolute-indexed for add, sub, etc. diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index 1bce2b9..5a0952d 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -6,7 +6,7 @@ from sixtypical.model import ( TYPE_BIT, TYPE_BYTE, TYPE_BYTE_TABLE, TYPE_WORD, TYPE_WORD_TABLE, BufferType, PointerType, RoutineType, VectorType, REG_A, REG_X, REG_Y, FLAG_C ) -from sixtypical.emitter import Byte, Label, Offset, LowAddressByte, HighAddressByte +from sixtypical.emitter import Byte, Word, Label, Offset, LowAddressByte, HighAddressByte from sixtypical.gen6502 import ( Immediate, Absolute, AbsoluteX, AbsoluteY, ZeroPage, Indirect, IndirectY, Relative, LDA, LDX, LDY, STA, STX, STY, @@ -72,7 +72,14 @@ class Compiler(object): for defn in program.defns: if defn.initial is not None: label = self.labels[defn.name] - initial_data = Byte(defn.initial) # TODO: support other types than Byte + initial_data = None + type_ = defn.location.type + if type_ == TYPE_BYTE: + initial_data = Byte(defn.initial) + elif type_ == TYPE_WORD: + initial_data = Word(defn.initial) + else: + raise NotImplementedError(type_) label.set_length(initial_data.size()) self.emitter.resolve_label(label) self.emitter.emit(initial_data) diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index 0c0998b..5c8262b 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -89,6 +89,24 @@ If a routine modifies a location, it needs to either output it or trash it. | } = ok +If a routine reads or writes a user-define memory location, it needs to declare that too. + + | byte b1 @ 60000 + | byte b2 : 3 + | word w1 @ 60001 + | word w2 : 2000 + | + | routine main + | inputs b1, w1 + | outputs b2, w2 + | trashes a, z, n + | { + | ld a, b1 + | st a, b2 + | copy w1, w2 + | } + = ok + ### ld ### Can't `ld` from a memory location that isn't initialized. diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 2823eb8..ae21a7e 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -117,6 +117,26 @@ Memory location with initial value. = $0810 RTS = $0811 .byte $03 +Word memory locations with explicit address, initial value. + + | word w1 @ 60001 + | word w2 : 3003 + | + | routine main + | inputs w1 + | outputs w2 + | trashes a, z, n + | { + | copy w1, w2 + | } + = $080D LDA $EA61 + = $0810 STA $081A + = $0813 LDA $EA62 + = $0816 STA $081B + = $0819 RTS + = $081A .byte $BB + = $081B .byte $0B + Some instructions. | byte foo