git @ Cat's Eye Technologies SixtyPical / af0e1b4
Forward-reference resolution becomes increasingly general. Chris Pressey 3 years ago
5 changed file(s) with 37 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
44 ----
55
66 * `save X, Y, Z { }` now allowed as a shortcut for nested `save`s.
7 * Trying to call or goto a non-routine-typed symbol is now an
8 analysis error, not a syntax error.
79 * Split TODO off into own file.
810 * `sixtypical` no longer writes the compiled binary to standard
911 output. The `--output` command-line argument should be given
549549 context.invalidate_range(dest)
550550 elif opcode == 'call':
551551 type = instr.location.type
552 if not isinstance(type, (RoutineType, VectorType)):
553 raise TypeMismatchError(instr, instr.location)
552554 if isinstance(type, VectorType):
553555 type = type.of_type
554556 for ref in type.inputs:
114114 for node in program.all_children():
115115 if isinstance(node, SingleOp):
116116 instr = node
117 if isinstance(instr.src, ForwardReference):
118 instr.src = self.lookup(instr.src.name)
117119 if instr.opcode in ('call', 'goto'):
118 forward_reference = instr.location
119 name = forward_reference.name
120 model = self.lookup(name)
121 if not isinstance(model.type, (RoutineType, VectorType)):
122 self.syntax_error('Illegal call of non-executable "%s"' % name)
123 instr.location = model
124 if instr.opcode in ('copy',):
125 if isinstance(instr.src, ForwardReference):
126 instr.src = self.lookup(instr.src.name)
120 if isinstance(instr.location, ForwardReference):
121 instr.location = self.lookup(instr.location.name)
127122
128123 return program
129124
194194 | copy w1, w2
195195 | }
196196 = ok
197
198 ### call ###
199
200 You can't call a non-routine.
201
202 | byte up
203 |
204 | routine main outputs x, y trashes z, n {
205 | ld x, 0
206 | ld y, 1
207 | call up
208 | }
209 ? TypeMismatchError: up
210
211 | routine main outputs x, y trashes z, n {
212 | ld x, 0
213 | ld y, 1
214 | call x
215 | }
216 ? TypeMismatchError: x
217
218 Nor can you goto a non-routine.
219
220 | byte foo
221 |
222 | routine main {
223 | goto foo
224 | }
225 ? TypeMismatchError: foo
197226
198227 ### ld ###
199228
403403 | }
404404 ? SyntaxError
405405
406 And you can't call a non-routine.
407
408 | byte up
409 |
410 | routine main {
411 | ld x, 0
412 | ld y, 1
413 | call up
414 | }
415 ? SyntaxError
416
417 | routine main {
418 | ld x, 0
419 | ld y, 1
420 | call x
421 | }
422 ? SyntaxError
423
424406 But you can call a routine that is yet to be defined, further on.
425407
426408 | routine main {
588570 | }
589571 ? SyntaxError
590572
591 | byte foo
592 |
593 | routine main {
594 | goto foo
595 | }
596 ? SyntaxError
597
598573 Buffers and pointers.
599574
600575 | buffer[2048] buf