From 90e2e22765d005c4fa9cbeba5674e4b4f041e86d Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 11 Apr 2017 03:16:34 +0000 Subject: [PATCH] artiq_compile: make print() write to core log, not an invalid op. Fixes #710. --- artiq/compiler/embedding.py | 5 +++-- artiq/coredevice/core.py | 6 ++++-- artiq/frontend/artiq_compile.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index f28c68d2d..745e7deb8 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -699,7 +699,7 @@ class TypedtreeHasher(algorithm.Visitor): return hash(tuple(freeze(getattr(node, field_name)) for field_name in fields)) class Stitcher: - def __init__(self, core, dmgr, engine=None): + def __init__(self, core, dmgr, engine=None, print_as_rpc=True): self.core = core self.dmgr = dmgr if engine is None: @@ -715,7 +715,8 @@ class Stitcher: # We don't want some things from the prelude as they are provided in # the host Python namespace and gain special meaning when quoted. self.prelude = prelude.globals() - self.prelude.pop("print") + if print_as_rpc: + self.prelude.pop("print") self.prelude.pop("array") self.functions = {} diff --git a/artiq/coredevice/core.py b/artiq/coredevice/core.py index 26dd31c71..9f2f0adc2 100644 --- a/artiq/coredevice/core.py +++ b/artiq/coredevice/core.py @@ -81,11 +81,13 @@ class Core: self.core = self self.comm.core = self - def compile(self, function, args, kwargs, set_result=None, attribute_writeback=True): + def compile(self, function, args, kwargs, set_result=None, + attribute_writeback=True, print_as_rpc=True): try: engine = _DiagnosticEngine(all_errors_are_fatal=True) - stitcher = Stitcher(engine=engine, core=self, dmgr=self.dmgr) + stitcher = Stitcher(engine=engine, core=self, dmgr=self.dmgr, + print_as_rpc=print_as_rpc) stitcher.stitch_call(function, args, kwargs, set_result) stitcher.finalize() diff --git a/artiq/frontend/artiq_compile.py b/artiq/frontend/artiq_compile.py index ef801516c..2822bf512 100755 --- a/artiq/frontend/artiq_compile.py +++ b/artiq/frontend/artiq_compile.py @@ -55,7 +55,7 @@ def main(): object_map, kernel_library, _, _ = \ core.compile(exp.run, [exp_inst], {}, - attribute_writeback=False) + attribute_writeback=False, print_as_rpc=False) except CompileError as error: return finally: