mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-03-11 16:31:28 +00:00
Attempt to analyze goto
. Looks like it'll need some rewriting.
This commit is contained in:
parent
69fa91417c
commit
49d07cee5f
@ -256,5 +256,23 @@ def analyze_instr(instr, context, routines):
|
||||
context.set_unmeaningful(REG_A, FLAG_Z, FLAG_N)
|
||||
elif opcode == 'with-sei':
|
||||
analyze_block(instr.block, context, routines)
|
||||
elif opcode == 'goto':
|
||||
location = instr.location
|
||||
type = location.type
|
||||
|
||||
if not isinstance(type, ExecutableType):
|
||||
raise TypeMismatchError(location)
|
||||
|
||||
# assert that the dest routine's inputs are all initialized
|
||||
for ref in type.inputs:
|
||||
context.assert_meaningful(ref)
|
||||
|
||||
# and that the called routine's output constraints are a
|
||||
# superset of this routine's
|
||||
current_type = self.current_routine.type
|
||||
if not (current_type.outputs <= type.outputs):
|
||||
raise IncompatibleConstraintsError(current_type.outputs - type.outputs)
|
||||
if not (current_type.trashes <= type.trashes):
|
||||
raise IncompatibleConstraintsError(current_type.trashes - type.trashes)
|
||||
else:
|
||||
raise NotImplementedError(opcode)
|
||||
|
@ -1148,3 +1148,61 @@ Calling the vector has indeed trashed stuff etc,
|
||||
| call foo
|
||||
| }
|
||||
? UninitializedOutputError: x
|
||||
|
||||
`goto`, if present, must be the final instruction in a routine.
|
||||
|
||||
| routine bar trashes x, z, n {
|
||||
| ld x, 200
|
||||
| }
|
||||
|
|
||||
| routine main trashes x, z, n {
|
||||
| ld x, 0
|
||||
| goto bar
|
||||
| }
|
||||
= ok
|
||||
|
||||
| routine bar trashes x, z, n {
|
||||
| ld x, 200
|
||||
| }
|
||||
|
|
||||
| routine main trashes x, z, n {
|
||||
| goto bar
|
||||
| ld x, 0
|
||||
| }
|
||||
? IllegalJumpError
|
||||
|
||||
| routine bar trashes x, z, n {
|
||||
| ld x, 200
|
||||
| }
|
||||
|
|
||||
| routine main trashes x, z, n {
|
||||
| ld x, 0
|
||||
| if z {
|
||||
| ld x, 1
|
||||
| goto bar
|
||||
| }
|
||||
| }
|
||||
? IllegalJumpError
|
||||
|
||||
Can't `goto` a routine that outputs or trashes more than the current routine.
|
||||
|
||||
| routine bar trashes x, y, z, n {
|
||||
| ld x, 200
|
||||
| ld y, 200
|
||||
| }
|
||||
|
|
||||
| routine main trashes x, z, n {
|
||||
| ld x, 0
|
||||
| goto bar
|
||||
| }
|
||||
? IllegalWriteError: y
|
||||
|
||||
| routine bar outputs y trashes z, n {
|
||||
| ld y, 200
|
||||
| }
|
||||
|
|
||||
| routine main trashes x, z, n {
|
||||
| ld x, 0
|
||||
| goto bar
|
||||
| }
|
||||
? IllegalWriteError: y
|
||||
|
Loading…
x
Reference in New Issue
Block a user