1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-14 08:29:33 +00:00

Begin introducing shortcut syntax for nested saves.

This commit is contained in:
Chris Pressey 2018-09-07 09:36:51 +01:00
parent 0593ce6a66
commit b63bcfcd2b
3 changed files with 46 additions and 6 deletions

View File

@ -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:

View File

@ -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

View File

@ -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