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. * 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 0.9
--- ---

View File

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

View File

@ -356,20 +356,25 @@ A vector can name itself in its inputs, outputs, and trashes.
| } | }
= ok = ok
A routine can be copied into a vector before the routine appears in the program. 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 *however*, it must be marked as such with the keyword `forward`.
form `assign`, which is equivalent to `copy` except that the routine need not
have already appeared in the program.
| vector cinv | vector cinv inputs cinv, a outputs cinv, x trashes a, x, z, n @ 788
| inputs cinv, a
| outputs cinv, x
| trashes a, x, z, n
| @ 788
|
| routine main { | routine main {
| with interrupts off { | 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 | call cinv
| } | }