git @ Cat's Eye Technologies SixtyPical / 2ffff3b
Make extern routines survive analysis. Chris Pressey 6 years ago
5 changed file(s) with 51 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
114114
115115 def analyze_routine(routine, routines):
116116 assert isinstance(routine, Routine)
117 if routine.block is None:
118 # it's an extern, that's fine
119 return
117120 context = Context(routine.inputs, routine.outputs, routine.trashes)
118121 analyze_block(routine.block, context, routines)
119122 for ref in routine.outputs:
2525 def compile_routine(routine, emitter, routines):
2626 assert isinstance(routine, Routine)
2727 label = emitter.make_label(routine.name)
28 compile_block(routine.block, emitter, routines)
29 emitter.emit(RTS())
28 if routine.block:
29 compile_block(routine.block, emitter, routines)
30 emitter.emit(RTS())
3031 return label
3132
3233
9697 elif opcode == 'shr':
9798 raise NotImplementedError
9899 elif opcode == 'call':
99 raise NotImplementedError
100 raise NotImplementedError(instr.name)
100101 elif opcode == 'if':
101102 raise NotImplementedError
102103 else:
193193 self.scanner.scan()
194194 dest = self.locexpr()
195195 return Instr(opcode=opcode, dest=dest, src=None)
196 elif self.scanner.token in ("call"):
196 elif self.scanner.token in ("call",):
197197 opcode = self.scanner.token
198198 self.scanner.scan()
199199 name = self.scanner.token
661661 | ld a, x
662662 | }
663663 ? UninitializedAccessError: x
664
665 Calling an extern is just the same as calling a defined routine with the
666 same constraints.
667
668 | routine chrout
669 | inputs a
670 | trashes a
671 | @ 65490
672 |
673 | routine main
674 | trashes a, z, n
675 | {
676 | ld a, 65
677 | call chrout
678 | }
679 = ok
680
681 | routine chrout
682 | inputs a
683 | trashes a
684 | @ 65490
685 |
686 | routine main
687 | trashes a, z, n
688 | {
689 | call chrout
690 | }
691 ? UninitializedAccessError: a
692
693 | routine chrout
694 | inputs a
695 | trashes a
696 | @ 65490
697 |
698 | routine main
699 | trashes a, x, z, n
700 | {
701 | ld a, 65
702 | call chrout
703 | ld x, a
704 | }
705 ? UninitializedAccessError: a
664706
665707 ### if ###
666708
3838 |
3939 | routine main
4040 | inputs a
41 | outputs a
42 | trashes c, z, n, v
41 | trashes a, z, n
4342 | {
4443 | ld a, 65
4544 | call chrout