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

Inputs/outputs/trashes are now part of the type information only.

This commit is contained in:
Chris Pressey 2015-10-19 18:44:20 +01:00
parent 98524e931a
commit 3010435add
2 changed files with 20 additions and 20 deletions

View File

@ -134,12 +134,13 @@ def analyze_routine(routine, routines):
if routine.block is None:
# it's an extern, that's fine
return
context = Context(routine.inputs, routine.outputs, routine.trashes)
type = routine.location.type
context = Context(type.inputs, type.outputs, type.trashes)
analyze_block(routine.block, context, routines)
for ref in routine.outputs:
for ref in type.outputs:
context.assert_meaningful(ref, exception_class=UninitializedOutputError)
for ref in context.each_touched():
if ref not in routine.outputs and ref not in routine.trashes:
if ref not in type.outputs and ref not in type.trashes:
raise IllegalWriteError(ref.name)
@ -192,11 +193,12 @@ def analyze_instr(instr, context, routines):
context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C)
elif opcode == 'call':
routine = routines[instr.name]
for ref in routine.inputs:
type = routine.location.type
for ref in type.inputs:
context.assert_meaningful(ref)
for ref in routine.outputs:
for ref in type.outputs:
context.set_written(ref)
for ref in routine.trashes:
for ref in type.trashes:
context.assert_writeable(ref)
context.set_touched(ref)
context.set_unmeaningful(ref)

View File

@ -109,20 +109,14 @@ class Parser(object):
name = defn.name
if name in self.symbols:
raise SyntaxError('Symbol "%s" already declared' % name)
self.symbols[name] = SymEntry(defn, LocationRef(defn.type, name))
self.symbols[name] = SymEntry(defn, defn.location)
defns.append(defn)
while self.scanner.on('routine'):
routine = self.routine()
name = routine.name
if name in self.symbols:
raise SyntaxError(name)
ref = LocationRef(
RoutineType(inputs=routine.inputs,
outputs=routine.outputs,
trashes=routine.trashes
), name
)
self.symbols[name] = SymEntry(routine, ref)
raise SyntaxError('Symbol "%s" already declared' % name)
self.symbols[name] = SymEntry(routine, routine.location)
routines.append(routine)
self.scanner.check_type('EOF')
return Program(defns=defns, routines=routines)
@ -150,9 +144,9 @@ class Parser(object):
if self.scanner.consume('@'):
self.scanner.check_type('integer literal')
addr = int(self.scanner.token)
self.scanner.scan()
return Defn(name=name, type=type, addr=addr,
inputs=inputs, outputs=outputs, trashes=trashes)
self.scanner.scan()
location = LocationRef(type, name)
return Defn(name=name, addr=addr, location=location)
def constraints(self):
inputs = []
@ -179,9 +173,13 @@ class Parser(object):
else:
block = self.block()
addr = None
location = LocationRef(
RoutineType(inputs=inputs, outputs=outputs, trashes=trashes),
name
)
return Routine(
name=name, inputs=inputs, outputs=outputs, trashes=trashes,
block=block, addr=addr
name=name, block=block, addr=addr,
location=location
)
def locexprs(self):