|
@@ -31,6 +31,10 @@ class SelectInstruction(Instruction):
|
|
|
('then', Instruction),
|
|
|
('else', Instruction))
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: SelectInstruction(@%r, @%r, @%r)' % (
|
|
|
+ id(self), id(self.condition), id(self.if_clause), id(self.else_clause))
|
|
|
+
|
|
|
class WhileInstruction(Instruction):
|
|
|
"""Represents a 'while' instruction."""
|
|
|
def __init__(self, condition, body):
|
|
@@ -42,6 +46,10 @@ class WhileInstruction(Instruction):
|
|
|
('cond', Instruction),
|
|
|
('body', Instruction))
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: WhileInstruction(@%r, @%r)' % (
|
|
|
+ id(self), id(self.condition), id(self.body))
|
|
|
+
|
|
|
class BreakInstruction(Instruction):
|
|
|
"""Represents a 'break' instruction."""
|
|
|
def __init__(self, loop):
|
|
@@ -50,6 +58,10 @@ class BreakInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = (('while', WhileInstruction),)
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: BreakInstruction(@%r)' % (
|
|
|
+ id(self), id(self.loop))
|
|
|
+
|
|
|
class ContinueInstruction(Instruction):
|
|
|
"""Represents a 'continue' instruction."""
|
|
|
def __init__(self, loop):
|
|
@@ -58,6 +70,10 @@ class ContinueInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = (('while', WhileInstruction),)
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: ContinueInstruction(@%r)' % (
|
|
|
+ id(self), id(self.loop))
|
|
|
+
|
|
|
class ReturnInstruction(Instruction):
|
|
|
"""Represents a 'return' instruction, which terminates the current function
|
|
|
and optionally returns a value."""
|
|
@@ -67,6 +83,10 @@ class ReturnInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = (('value', Instruction),)
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: ReturnInstruction(@%r)' % (
|
|
|
+ id(self), id(self.value))
|
|
|
+
|
|
|
class CallInstruction(Instruction):
|
|
|
"""Represents a 'call' instruction, which calls a function with an argument
|
|
|
list, encoded as a list of name-instruction tuples."""
|
|
@@ -75,6 +95,11 @@ class CallInstruction(Instruction):
|
|
|
self.target = target
|
|
|
self.argument_list = argument_list
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: CallInstruction(@%r, [%s])' % (
|
|
|
+ id(self), id(self.target),
|
|
|
+ ', '.join(['%s=@%r' % (name, value) for name, value in self.argument_list]))
|
|
|
+
|
|
|
class ConstantInstruction(Instruction):
|
|
|
"""Represents a 'constant' instruction, which produces a reference
|
|
|
to a constant node."""
|
|
@@ -84,6 +109,9 @@ class ConstantInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = (('node', int),)
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: ConstantInstruction(%r)' % (id(self), self.constant_id)
|
|
|
+
|
|
|
class InputInstruction(Instruction):
|
|
|
"""Represents an 'input' instruction, which pops a node from the input
|
|
|
queue."""
|
|
@@ -92,6 +120,9 @@ class InputInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = ()
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: InputInstruction()' % id(self)
|
|
|
+
|
|
|
class OutputInstruction(Instruction):
|
|
|
"""Represents an 'output' instruction, which pushes a node onto the output
|
|
|
queue."""
|
|
@@ -101,6 +132,10 @@ class OutputInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = (('value', Instruction),)
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: OutputInstruction(@%r)' % (
|
|
|
+ id(self), id(self.value))
|
|
|
+
|
|
|
class DeclareInstruction(Instruction):
|
|
|
"""Represents a 'declare' instruction, which declares a local variable."""
|
|
|
def __init__(self, variable):
|
|
@@ -109,6 +144,10 @@ class DeclareInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = (('var', VariableNode),)
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: DeclareInstruction(%r)' % (
|
|
|
+ id(self), self.variable)
|
|
|
+
|
|
|
class GlobalInstruction(Instruction):
|
|
|
"""Represents a 'global' instruction, which declares a global variable."""
|
|
|
def __init__(self, variable):
|
|
@@ -117,6 +156,10 @@ class GlobalInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = (('var', VariableNode),)
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: GlobalInstruction(%r)' % (
|
|
|
+ id(self), self.variable)
|
|
|
+
|
|
|
class ResolveInstruction(Instruction):
|
|
|
"""Represents a 'resolve' instruction, which resolves a variable node/name as
|
|
|
either a local or global variable."""
|
|
@@ -126,6 +169,10 @@ class ResolveInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = (('var', VariableNode),)
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: ResolveInstruction(%r)' % (
|
|
|
+ id(self), self.variable)
|
|
|
+
|
|
|
class AccessInstruction(Instruction):
|
|
|
"""Represents an 'access' instruction, which loads the node pointed to by a
|
|
|
pointer node."""
|
|
@@ -135,6 +182,10 @@ class AccessInstruction(Instruction):
|
|
|
|
|
|
constructor_parameters = (('var', Instruction),)
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: AccessInstruction(@%r)' % (
|
|
|
+ id(self), id(self.pointer))
|
|
|
+
|
|
|
class AssignInstruction(Instruction):
|
|
|
"""Represents an 'assign' instruction, which sets the node pointed to by a
|
|
|
pointer node to the given node."""
|
|
@@ -147,6 +198,10 @@ class AssignInstruction(Instruction):
|
|
|
('var', Instruction),
|
|
|
('value', Instruction))
|
|
|
|
|
|
+ def __repr__(self):
|
|
|
+ return '@%r: AssignInstruction(@%r, @%r)' % (
|
|
|
+ id(self), id(self.pointer), id(self.value))
|
|
|
+
|
|
|
INSTRUCTION_TYPE_MAPPING = {
|
|
|
'if' : SelectInstruction,
|
|
|
'while' : WhileInstruction,
|