git @ Cat's Eye Technologies SixtyPical / b63bcfc
Begin introducing shortcut syntax for nested `save`s. Chris Pressey 3 years ago
3 changed file(s) with 48 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
770770 context.set_writeable(instr.dest)
771771
772772 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
779779 self.analyze_block(instr.block, context)
780780 if context.encountered_gotos():
781781 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.
784788 if location == REG_A:
785789 pass
786790 else:
21062106 | }
21072107 = ok
21082108
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
21092123 Not just registers, but also user-defined locations can be saved.
21102124
21112125 | byte foo
600600 = $0816 PLA
601601 = $0817 RTS
602602
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
603625 Compiling `save` on a user-defined location.
604626
605627 | byte foo