1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-02-16 15:30:26 +00:00

Make extern routines survive analysis.

This commit is contained in:
Chris Pressey 2015-10-17 14:54:28 +01:00
parent 49d90dfae0
commit 2ffff3bbdb
5 changed files with 51 additions and 6 deletions

View File

@ -115,6 +115,9 @@ def analyze_program(program):
def analyze_routine(routine, routines):
assert isinstance(routine, Routine)
if routine.block is None:
# it's an extern, that's fine
return
context = Context(routine.inputs, routine.outputs, routine.trashes)
analyze_block(routine.block, context, routines)
for ref in routine.outputs:

View File

@ -26,8 +26,9 @@ def compile_program(program, emitter):
def compile_routine(routine, emitter, routines):
assert isinstance(routine, Routine)
label = emitter.make_label(routine.name)
compile_block(routine.block, emitter, routines)
emitter.emit(RTS())
if routine.block:
compile_block(routine.block, emitter, routines)
emitter.emit(RTS())
return label
@ -97,7 +98,7 @@ def compile_instr(instr, emitter, routines):
elif opcode == 'shr':
raise NotImplementedError
elif opcode == 'call':
raise NotImplementedError
raise NotImplementedError(instr.name)
elif opcode == 'if':
raise NotImplementedError
else:

View File

@ -194,7 +194,7 @@ class Parser(object):
self.scanner.scan()
dest = self.locexpr()
return Instr(opcode=opcode, dest=dest, src=None)
elif self.scanner.token in ("call"):
elif self.scanner.token in ("call",):
opcode = self.scanner.token
self.scanner.scan()
name = self.scanner.token

View File

@ -663,6 +663,48 @@ calling it.
| }
? UninitializedAccessError: x
Calling an extern is just the same as calling a defined routine with the
same constraints.
| routine chrout
| inputs a
| trashes a
| @ 65490
|
| routine main
| trashes a, z, n
| {
| ld a, 65
| call chrout
| }
= ok
| routine chrout
| inputs a
| trashes a
| @ 65490
|
| routine main
| trashes a, z, n
| {
| call chrout
| }
? UninitializedAccessError: a
| routine chrout
| inputs a
| trashes a
| @ 65490
|
| routine main
| trashes a, x, z, n
| {
| ld a, 65
| call chrout
| ld x, a
| }
? UninitializedAccessError: a
### if ###
Both blocks of an `if` are analyzed.

View File

@ -39,8 +39,7 @@ Call extern.
|
| routine main
| inputs a
| outputs a
| trashes c, z, n, v
| trashes a, z, n
| {
| ld a, 65
| call chrout