|
@@ -284,7 +284,7 @@ class CallInstruction(Instruction):
|
|
|
arg.generate_python_def(code_generator)
|
|
|
|
|
|
code_generator.append_line(
|
|
|
- '%s = %s(%s) ' % (
|
|
|
+ '%s = %s(%s)' % (
|
|
|
code_generator.get_result_name(self),
|
|
|
self.target.generate_python_use(code_generator),
|
|
|
', '.join([arg.generate_python_use(code_generator) for arg in self.argument_list])))
|
|
@@ -323,23 +323,49 @@ class JitCallInstruction(Instruction):
|
|
|
arg_list.append(
|
|
|
'**%s' % self.kwarg.generate_python_use(code_generator))
|
|
|
|
|
|
+ own_name = code_generator.get_result_name(self)
|
|
|
code_generator.append_line('try:')
|
|
|
code_generator.increase_indentation()
|
|
|
code_generator.append_line(
|
|
|
- 'gen = %s(%s) ' % (
|
|
|
+ '%s_gen = %s(%s)' % (
|
|
|
+ own_name,
|
|
|
self.target.generate_python_use(code_generator),
|
|
|
', '.join(arg_list)))
|
|
|
- code_generator.append_line('inp = None')
|
|
|
+ code_generator.append_line('%s_inp = None' % own_name)
|
|
|
code_generator.append_line('while 1:')
|
|
|
code_generator.increase_indentation()
|
|
|
- code_generator.append_line('inp = yield gen.send(inp)')
|
|
|
+ code_generator.append_line(
|
|
|
+ '%s_inp = yield %s_gen.send(%s_inp)' % (own_name, own_name, own_name))
|
|
|
code_generator.decrease_indentation()
|
|
|
code_generator.decrease_indentation()
|
|
|
- code_generator.append_line('except PrimitiveFinished as ex:')
|
|
|
+ code_generator.append_line('except PrimitiveFinished as %s_ex:' % own_name)
|
|
|
code_generator.increase_indentation()
|
|
|
- code_generator.append_line('%s = ex.result' % code_generator.get_result_name(self))
|
|
|
+ code_generator.append_line('%s = %s_ex.result' % (own_name, own_name))
|
|
|
code_generator.decrease_indentation()
|
|
|
|
|
|
+class PrintInstruction(Instruction):
|
|
|
+ """An instruction that prints a value."""
|
|
|
+ def __init__(self, argument):
|
|
|
+ Instruction.__init__(self)
|
|
|
+ self.argument = argument
|
|
|
+
|
|
|
+ def has_result(self):
|
|
|
+ """Tells if this instruction has a result."""
|
|
|
+ return False
|
|
|
+
|
|
|
+ def simplify(self):
|
|
|
+ """Applies basic simplification to this instruction and its children."""
|
|
|
+ return PrintInstruction(self.argument.simplify())
|
|
|
+
|
|
|
+ def generate_python_def(self, code_generator):
|
|
|
+ """Generates Python code for this instruction."""
|
|
|
+ if self.argument.has_definition():
|
|
|
+ self.argument.generate_python_def(code_generator)
|
|
|
+
|
|
|
+ code_generator.append_line(
|
|
|
+ 'print(%s)' % (
|
|
|
+ self.argument.generate_python_use(code_generator)))
|
|
|
+
|
|
|
class BinaryInstruction(Instruction):
|
|
|
"""An instruction that performs a binary operation."""
|
|
|
def __init__(self, lhs, operator, rhs):
|
|
@@ -958,6 +984,17 @@ def create_block(*statements):
|
|
|
statements[0],
|
|
|
create_block(*statements[1:]))
|
|
|
|
|
|
+def with_debug_info_trace(instruction, debug_info):
|
|
|
+ """Prepends the given instruction with a tracing instruction that prints
|
|
|
+ the given debug information."""
|
|
|
+ if debug_info is None:
|
|
|
+ return instruction
|
|
|
+ else:
|
|
|
+ return create_block(
|
|
|
+ PrintInstruction(
|
|
|
+ LiteralInstruction('TRACE: %s(JIT)' % debug_info)),
|
|
|
+ instruction)
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
example_tree = SelectInstruction(
|
|
|
LiteralInstruction(True),
|