From 19461bc2056292ec523e36032dedb18e0d43238c Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Fri, 7 Sep 2018 11:27:42 +0100 Subject: [PATCH] Support `save X, Y, Z {}` as a shortcut syntax for nested `save`s. --- HISTORY.md | 5 +++- TODO.md | 14 ---------- src/sixtypical/compiler.py | 53 +++++++++++++++++++++----------------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index cf902e3..7d7b22f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,9 +4,12 @@ History of SixtyPical 0.17 ---- +* `save X, Y, Z { }` now allowed as a shortcut for nested `save`s. * Split TODO off into own file. * `sixtypical` no longer writes the compiled binary to standard - output. The `--output` command-line argument should be given. + output. The `--output` command-line argument should be given + to get a compiled binary; otherwise only analysis is run. +* Internal cleanups, including a hierarchy of `Outputters`. * All tests pass when `sixtypical` is run under Python 3.5.2. 0.16 diff --git a/TODO.md b/TODO.md index 7e8d116..ebdff52 100644 --- a/TODO.md +++ b/TODO.md @@ -16,20 +16,6 @@ Is that consistent with `st`? Well, probably it is, but we have to explain it. It might make more sense, then, for it to be "part of the operation" instead of "part of the reference"; something like `st.hi x, word`; `st.lo y, word`. Dunno. -### Save multiple values in single block - -As a shortcut for the idiom - - save a { save var { - ... - } } - -allow - - save a, var { - ... - } - ### Save values to other-than-the-stack Allow diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index faed525..3061443 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -618,27 +618,32 @@ class Compiler(object): self.emitter.emit(CLI()) def compile_save(self, instr): - location = instr.locations[0] - if location == REG_A: - self.emitter.emit(PHA()) - self.compile_block(instr.block) - self.emitter.emit(PLA()) - elif location == REG_X: - self.emitter.emit(TXA()) - self.emitter.emit(PHA()) - self.compile_block(instr.block) - self.emitter.emit(PLA()) - self.emitter.emit(TAX()) - elif location == REG_Y: - self.emitter.emit(TYA()) - self.emitter.emit(PHA()) - self.compile_block(instr.block) - self.emitter.emit(PLA()) - self.emitter.emit(TAY()) - else: - src_label = self.get_label(location.name) - self.emitter.emit(LDA(Absolute(src_label))) - self.emitter.emit(PHA()) - self.compile_block(instr.block) - self.emitter.emit(PLA()) - self.emitter.emit(STA(Absolute(src_label))) + for location in instr.locations: + if location == REG_A: + self.emitter.emit(PHA()) + elif location == REG_X: + self.emitter.emit(TXA()) + self.emitter.emit(PHA()) + elif location == REG_Y: + self.emitter.emit(TYA()) + self.emitter.emit(PHA()) + else: + src_label = self.get_label(location.name) + self.emitter.emit(LDA(Absolute(src_label))) + self.emitter.emit(PHA()) + + self.compile_block(instr.block) + + for location in reversed(instr.locations): + if location == REG_A: + self.emitter.emit(PLA()) + elif location == REG_X: + self.emitter.emit(PLA()) + self.emitter.emit(TAX()) + elif location == REG_Y: + self.emitter.emit(PLA()) + self.emitter.emit(TAY()) + else: + src_label = self.get_label(location.name) + self.emitter.emit(PLA()) + self.emitter.emit(STA(Absolute(src_label)))