Inch toward compiling statics.
Chris Pressey
7 years ago
30 | 30 | self.routines = {} |
31 | 31 | self.labels = {} |
32 | 32 | self.trampolines = {} # Location -> Label |
33 | self.current_routine = None | |
33 | 34 | |
34 | 35 | # helper methods |
35 | 36 | |
57 | 58 | return length |
58 | 59 | |
59 | 60 | def get_label(self, name): |
61 | if self.current_routine and hasattr(self.current_routine, 'statics'): | |
62 | for static in self.current_routine.statics: | |
63 | if static.location.name == name: | |
64 | raise NotImplementedError("static " + name) | |
60 | 65 | return self.labels[name] |
61 | 66 | |
62 | 67 | # visitor methods |
111 | 116 | |
112 | 117 | |
113 | 118 | def compile_routine(self, routine): |
119 | self.current_routine = routine | |
114 | 120 | assert isinstance(routine, Routine) |
115 | 121 | if routine.block: |
116 | 122 | self.emitter.resolve_label(self.get_label(routine.name)) |
117 | 123 | self.compile_block(routine.block) |
118 | 124 | self.emitter.emit(RTS()) |
125 | self.current_routine = None | |
119 | 126 | |
120 | 127 | def compile_block(self, block): |
121 | 128 | assert isinstance(block, Block) |