1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-01-10 17:31:18 +00:00

Unbreak evaluator, but break compiler b/c change in parser.

This commit is contained in:
Chris Pressey 2015-10-20 10:07:28 +01:00
parent 2dc4dd988e
commit b4e0756d7e
3 changed files with 13 additions and 12 deletions

View File

@ -196,8 +196,7 @@ def analyze_instr(instr, context, routines):
context.assert_meaningful(dest, FLAG_C)
context.set_written(dest, FLAG_Z, FLAG_N, FLAG_C)
elif opcode == 'call':
routine = routines[instr.name]
type = routine.location.type
type = instr.location.type
for ref in type.inputs:
context.assert_meaningful(ref)
for ref in type.outputs:

View File

@ -12,7 +12,9 @@ class Context(object):
self._store = {}
def __str__(self):
return '\n'.join("%s: %s" % p for p in sorted(self._store.iteritems()))
return '\n'.join("%s: %s" % (name, value)
for (name, value) in sorted(self._store.iteritems())
if not isinstance(value, Routine))
def get(self, ref):
if isinstance(ref, ConstantRef):
@ -23,11 +25,8 @@ class Context(object):
raise ValueError(ref)
def set(self, ref, value):
# bleah
if isinstance(ref, LocationRef):
self._store[ref.name] = value
else:
self._store[ref] = value
assert isinstance(ref, LocationRef)
self._store[ref.name] = value
def eval_program(program):
@ -35,9 +34,12 @@ def eval_program(program):
context = Context()
for ref in (REG_A, REG_X, REG_Y, FLAG_Z, FLAG_N, FLAG_V, FLAG_C):
context.set(ref, 0)
main = None
for routine in program.routines:
context.set(routine.name, routine)
eval_routine(context['main'], context)
context.set(routine.location, routine)
if routine.name == 'main':
main = routine
eval_routine(main, context)
return context
@ -146,7 +148,7 @@ def eval_instr(instr, context):
context.set(FLAG_N, 1 if result & 128 else 0)
context.set(dest, result)
elif opcode == 'call':
eval_routine(context[instr.name], context)
eval_routine(context.get(instr.location), context)
elif opcode == 'if':
val = context.get(src)
test = (val != 0) if not instr.inverted else (val == 0)

View File

@ -269,7 +269,7 @@ class Parser(object):
raise SyntaxError('Undefined routine "%s"' % name)
if not isinstance(self.symbols[name].model.type, ExecutableType):
raise SyntaxError('Illegal call of non-executable "%s"' % name)
return Instr(opcode=opcode, name=name, dest=None, src=None)
return Instr(opcode=opcode, location=self.symbols[name].model, dest=None, src=None)
elif self.scanner.token in ("copy",):
opcode = self.scanner.token
self.scanner.scan()