From 1465fe6f8196a2b454fdf3f3409aabc4e9790fa3 Mon Sep 17 00:00:00 2001 From: whitequark Date: Mon, 15 Feb 2016 21:17:54 +0000 Subject: [PATCH] Add channel name as the first argument to rtio_log (#206). --- artiq/compiler/transforms/artiq_ir_generator.py | 12 +++++++++--- artiq/compiler/transforms/inferencer.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index 74040ca54..886f3e92f 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -1608,10 +1608,16 @@ class ARTIQIRGenerator(algorithm.Visitor): return self.append(ir.Builtin("round", [arg], node.type)) else: assert False - elif types.is_builtin(typ, "print") or types.is_builtin(typ, "rtio_log"): + elif types.is_builtin(typ, "print"): self.polymorphic_print([self.visit(arg) for arg in node.args], - separator=" ", suffix="\n", - as_rtio=types.is_builtin(typ, "rtio_log")) + separator=" ", suffix="\n") + return ir.Constant(None, builtins.TNone()) + elif types.is_builtin(typ, "rtio_log"): + prefix, *args = node.args + self.polymorphic_print([self.visit(prefix)], + separator=" ", suffix="\x1E", as_rtio=True) + self.polymorphic_print([self.visit(arg) for arg in args], + separator=" ", suffix="\n", as_rtio=True) return ir.Constant(None, builtins.TNone()) elif types.is_builtin(typ, "now"): if len(node.args) == 0 and len(node.keywords) == 0: diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index fd226a7c5..7d109236b 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -753,7 +753,7 @@ class Inferencer(algorithm.Visitor): node.loc, None) else: diagnose(valid_forms()) - elif types.is_builtin(typ, "print") or types.is_builtin(typ, "rtio_log"): + elif types.is_builtin(typ, "print"): valid_forms = lambda: [ valid_form("print(args...) -> None"), ] @@ -766,6 +766,21 @@ class Inferencer(algorithm.Visitor): pass else: diagnose(valid_forms()) + elif types.is_builtin(typ, "rtio_log"): + valid_forms = lambda: [ + valid_form("rtio_log(channel:str, args...) -> None"), + ] + + self._unify(node.type, builtins.TNone(), + node.loc, None) + + if len(node.args) >= 1 and len(node.keywords) == 0: + arg = node.args[0] + + self._unify(arg.type, builtins.TStr(), + arg.loc, None) + else: + diagnose(valid_forms()) elif types.is_builtin(typ, "now"): simple_form("now() -> float", [], builtins.TFloat())