1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-25 23:49:17 +00:00

forward modifier on location expression, instead of assign.

This commit is contained in:
Chris Pressey 2017-12-12 14:23:34 +00:00
parent b7b28830d7
commit 0194d37bbd
3 changed files with 23 additions and 23 deletions

View File

@ -5,7 +5,8 @@ History of SixtyPical
----
* Can `call` and `goto` routines that are defined further down in the source code.
* `assign`, a form of `copy` that can copy (to a vector) a routine that is defined further down.
* The `forward` modifier can also be used to indicate that the symbol being copied
in a `copy` to a vector is a routine that is defined further down in the source.
0.9
---

View File

@ -64,14 +64,13 @@ class Parser(object):
if not isinstance(self.symbols[name].model.type, ExecutableType):
raise SyntaxError('Illegal call of non-executable "%s"' % name)
instr.location = self.symbols[name].model
if instr.opcode in ('assign',):
if instr.opcode in ('copy',) and isinstance(instr.src, basestring):
name = instr.src
if name not in self.symbols:
raise SyntaxError('Undefined routine "%s"' % name)
if not isinstance(self.symbols[name].model.type, ExecutableType):
raise SyntaxError('Illegal assign of non-executable "%s"' % name)
raise SyntaxError('Illegal copy of non-executable "%s"' % name)
instr.src = self.symbols[name].model
instr.opcode = 'copy'
return Program(defns=defns, routines=routines)
@ -205,7 +204,9 @@ class Parser(object):
return loc
def indlocexpr(self):
if self.scanner.consume('['):
if self.scanner.consume('forward'):
return self.label()
elif self.scanner.consume('['):
loc = self.locexpr()
self.scanner.expect(']')
self.scanner.expect('+')
@ -293,13 +294,6 @@ class Parser(object):
src = self.indlocexpr()
self.scanner.expect(',')
dest = self.indlocexpr()
return Instr(opcode=opcode, dest=dest, src=src)
elif self.scanner.token == 'assign':
opcode = self.scanner.token
self.scanner.scan()
src = self.label()
self.scanner.expect(',')
dest = self.indlocexpr()
instr = Instr(opcode=opcode, dest=dest, src=src)
self.backpatch_instrs.append(instr)
return instr

View File

@ -356,20 +356,25 @@ A vector can name itself in its inputs, outputs, and trashes.
| }
= ok
A routine can be copied into a vector before the routine appears in the program.
*However*, in order to do this currently, one needs to use the special opcode
form `assign`, which is equivalent to `copy` except that the routine need not
have already appeared in the program.
A routine can be copied into a vector before the routine appears in the program,
*however*, it must be marked as such with the keyword `forward`.
| vector cinv
| inputs cinv, a
| outputs cinv, x
| trashes a, x, z, n
| @ 788
|
| vector cinv inputs cinv, a outputs cinv, x trashes a, x, z, n @ 788
| routine main {
| with interrupts off {
| assign foo, cinv
| copy foo, cinv
| }
| call cinv
| }
| routine foo {
| ld a, 0
| }
? SyntaxError: Undefined symbol
| vector cinv inputs cinv, a outputs cinv, x trashes a, x, z, n @ 788
| routine main {
| with interrupts off {
| copy forward foo, cinv
| }
| call cinv
| }