git @ Cat's Eye Technologies SixtyPical / b7b2883
Introducing a new pseudo-opcode is rarely an elegant solution. Chris Pressey 3 years ago
4 changed file(s) with 40 addition(s) and 5 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.
78
89 0.9
910 ---
4545 the joystick (i.e. bring it up to par with the original demo game that was written
4646 for SixtyPical)
4747
48 ### `copy` (to vectors) routines that are defined further down in the source code
49
50 We might have a graph of states that refer to each other and that want to `goto`
51 each other. Thus we need this. We have it for other things.
52
5348 ### Allow branches to diverge in what they touch
5449
5550 For example, if the routine inputs and outputs `foo`, and one branch of an `if`
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',):
67 name = instr.src
68 if name not in self.symbols:
69 raise SyntaxError('Undefined routine "%s"' % name)
70 if not isinstance(self.symbols[name].model.type, ExecutableType):
71 raise SyntaxError('Illegal assign of non-executable "%s"' % name)
72 instr.src = self.symbols[name].model
73 instr.opcode = 'copy'
6674
6775 return Program(defns=defns, routines=routines)
6876
285293 self.scanner.expect(',')
286294 dest = self.indlocexpr()
287295 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()
302 instr = Instr(opcode=opcode, dest=dest, src=src)
303 self.backpatch_instrs.append(instr)
304 return instr
288305 elif self.scanner.consume("with"):
289306 self.scanner.expect("interrupts")
290307 self.scanner.expect("off")
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 |
369 | routine main {
370 | with interrupts off {
371 | assign foo, cinv
372 | }
373 | call cinv
374 | }
375 | routine foo {
376 | ld a, 0
377 | }
378 = ok
379
358380 goto.
359381
360382 | routine foo {