git @ Cat's Eye Technologies SixtyPical / 0194d37
`forward` modifier on location expression, instead of `assign`. Chris Pressey 3 years ago
3 changed file(s) with 24 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
44 ----
55
66 * Can `call` and `goto` routines that are defined further down in the source code.
7 * `assign`, a form of `copy` that can copy (to a vector) a routine that is defined further down.
7 * The `forward` modifier can also be used to indicate that the symbol being copied
8 in a `copy` to a vector is a routine that is defined further down in the source.
89
910 0.9
1011 ---
6363 if not isinstance(self.symbols[name].model.type, ExecutableType):
6464 raise SyntaxError('Illegal call of non-executable "%s"' % name)
6565 instr.location = self.symbols[name].model
66 if instr.opcode in ('assign',):
66 if instr.opcode in ('copy',) and isinstance(instr.src, basestring):
6767 name = instr.src
6868 if name not in self.symbols:
6969 raise SyntaxError('Undefined routine "%s"' % name)
7070 if not isinstance(self.symbols[name].model.type, ExecutableType):
71 raise SyntaxError('Illegal assign of non-executable "%s"' % name)
71 raise SyntaxError('Illegal copy of non-executable "%s"' % name)
7272 instr.src = self.symbols[name].model
73 instr.opcode = 'copy'
7473
7574 return Program(defns=defns, routines=routines)
7675
204203 return loc
205204
206205 def indlocexpr(self):
207 if self.scanner.consume('['):
206 if self.scanner.consume('forward'):
207 return self.label()
208 elif self.scanner.consume('['):
208209 loc = self.locexpr()
209210 self.scanner.expect(']')
210211 self.scanner.expect('+')
292293 src = self.indlocexpr()
293294 self.scanner.expect(',')
294295 dest = self.indlocexpr()
295 return Instr(opcode=opcode, dest=dest, src=src)
296 elif self.scanner.token == 'assign':
297 opcode = self.scanner.token
298 self.scanner.scan()
299 src = self.label()
300 self.scanner.expect(',')
301 dest = self.indlocexpr()
302296 instr = Instr(opcode=opcode, dest=dest, src=src)
303297 self.backpatch_instrs.append(instr)
304298 return instr
355355 | }
356356 = ok
357357
358 A routine can be copied into a vector before the routine appears in the program.
359 *However*, in order to do this currently, one needs to use the special opcode
360 form `assign`, which is equivalent to `copy` except that the routine need not
361 have already appeared in the program.
362
363 | vector cinv
364 | inputs cinv, a
365 | outputs cinv, x
366 | trashes a, x, z, n
367 | @ 788
368 |
358 A routine can be copied into a vector before the routine appears in the program,
359 *however*, it must be marked as such with the keyword `forward`.
360
361 | vector cinv inputs cinv, a outputs cinv, x trashes a, x, z, n @ 788
369362 | routine main {
370363 | with interrupts off {
371 | assign foo, cinv
364 | copy foo, cinv
365 | }
366 | call cinv
367 | }
368 | routine foo {
369 | ld a, 0
370 | }
371 ? SyntaxError: Undefined symbol
372
373 | vector cinv inputs cinv, a outputs cinv, x trashes a, x, z, n @ 788
374 | routine main {
375 | with interrupts off {
376 | copy forward foo, cinv
372377 | }
373378 | call cinv
374379 | }