Begin introducing shortcut syntax for nested `save`s.
Chris Pressey
3 years ago
770 | 770 | context.set_writeable(instr.dest) |
771 | 771 | |
772 | 772 | def analyze_save(self, instr, context): |
773 | if len(instr.locations) != 1: | |
774 | raise NotImplementedError("Only 1 location in save is supported right now") | |
775 | location = instr.locations[0] | |
776 | self.assert_type(TYPE_BYTE, location) | |
777 | ||
778 | baton = context.extract(location) | |
773 | batons = [] | |
774 | for location in instr.locations: | |
775 | self.assert_type(TYPE_BYTE, location) | |
776 | baton = context.extract(location) | |
777 | batons.append(baton) | |
778 | ||
779 | 779 | self.analyze_block(instr.block, context) |
780 | 780 | if context.encountered_gotos(): |
781 | 781 | raise IllegalJumpError(instr, instr) |
782 | context.re_introduce(baton) | |
783 | ||
782 | ||
783 | for location in reversed(instr.locations): | |
784 | baton = batons.pop() | |
785 | context.re_introduce(baton) | |
786 | ||
787 | # FIXME check if A needs to be the outer thing that is saved, I think it does. | |
784 | 788 | if location == REG_A: |
785 | 789 | pass |
786 | 790 | else: |
2106 | 2106 | | } |
2107 | 2107 | = ok |
2108 | 2108 | |
2109 | There is a shortcut syntax for a nested series of `save`s. | |
2110 | ||
2111 | | routine main | |
2112 | | inputs a | |
2113 | | outputs a | |
2114 | | trashes z, n | |
2115 | | { | |
2116 | | save a, x { | |
2117 | | ld a, 0 | |
2118 | | ld x, 1 | |
2119 | | } | |
2120 | | } | |
2121 | = ok | |
2122 | ||
2109 | 2123 | Not just registers, but also user-defined locations can be saved. |
2110 | 2124 | |
2111 | 2125 | | byte foo |
600 | 600 | = $0816 PLA |
601 | 601 | = $0817 RTS |
602 | 602 | |
603 | Compiling `save` with shortcut syntax. | |
604 | ||
605 | | routine main | |
606 | | inputs a | |
607 | | outputs a | |
608 | | trashes z, n | |
609 | | { | |
610 | | save a, x { | |
611 | | ld a, 0 | |
612 | | ld x, 1 | |
613 | | } | |
614 | | } | |
615 | = $080D PHA | |
616 | = $080E TXA | |
617 | = $080F PHA | |
618 | = $0810 LDA #$00 | |
619 | = $0812 LDX #$01 | |
620 | = $0814 PLA | |
621 | = $0815 TAX | |
622 | = $0816 PLA | |
623 | = $0817 RTS | |
624 | ||
603 | 625 | Compiling `save` on a user-defined location. |
604 | 626 | |
605 | 627 | | byte foo |