diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index 53857a5..df7b3da 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -771,17 +771,21 @@ class Analyzer(object): context.set_writeable(instr.dest) def analyze_save(self, instr, context): - if len(instr.locations) != 1: - raise NotImplementedError("Only 1 location in save is supported right now") - location = instr.locations[0] - self.assert_type(TYPE_BYTE, location) + batons = [] + for location in instr.locations: + self.assert_type(TYPE_BYTE, location) + baton = context.extract(location) + batons.append(baton) - baton = context.extract(location) self.analyze_block(instr.block, context) if context.encountered_gotos(): raise IllegalJumpError(instr, instr) - context.re_introduce(baton) + for location in reversed(instr.locations): + baton = batons.pop() + context.re_introduce(baton) + + # FIXME check if A needs to be the outer thing that is saved, I think it does. if location == REG_A: pass else: diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index b4b0b11..7dd97b1 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -2107,6 +2107,20 @@ first in a nested series of `save`s. | } = ok +There is a shortcut syntax for a nested series of `save`s. + + | routine main + | inputs a + | outputs a + | trashes z, n + | { + | save a, x { + | ld a, 0 + | ld x, 1 + | } + | } + = ok + Not just registers, but also user-defined locations can be saved. | byte foo diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 7070374..ee0da72 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -601,6 +601,28 @@ Compiling `save`. = $0816 PLA = $0817 RTS +Compiling `save` with shortcut syntax. + + | routine main + | inputs a + | outputs a + | trashes z, n + | { + | save a, x { + | ld a, 0 + | ld x, 1 + | } + | } + = $080D PHA + = $080E TXA + = $080F PHA + = $0810 LDA #$00 + = $0812 LDX #$01 + = $0814 PLA + = $0815 TAX + = $0816 PLA + = $0817 RTS + Compiling `save` on a user-defined location. | byte foo