Skip to content

Commit dfc91a3

Browse files
author
whitequark
committedAug 9, 2015
ARTIQIRGenerator.polymorphic_print: str([x]) uses repr(x), not str(x).
1 parent f7b64db commit dfc91a3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

Diff for: ‎artiq/compiler/transforms/artiq_ir_generator.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ def visit_Assert(self, node):
14891489
tail = self.current_block = self.add_block()
14901490
self.append(ir.BranchIf(cond, tail, if_failed), block=head)
14911491

1492-
def polymorphic_print(self, values, separator, suffix=""):
1492+
def polymorphic_print(self, values, separator, suffix="", as_repr=False):
14931493
format_string = ""
14941494
args = []
14951495
def flush():
@@ -1508,7 +1508,7 @@ def flush():
15081508
format_string += "("; flush()
15091509
self.polymorphic_print([self.append(ir.GetAttr(value, index))
15101510
for index in range(len(value.type.elts))],
1511-
separator=", ")
1511+
separator=", ", as_repr=True)
15121512
if len(value.type.elts) == 1:
15131513
format_string += ",)"
15141514
else:
@@ -1538,7 +1538,10 @@ def flush():
15381538
format_string += "%g"
15391539
args.append(value)
15401540
elif builtins.is_str(value.type):
1541-
format_string += "%s"
1541+
if as_repr:
1542+
format_string += "\"%s\""
1543+
else:
1544+
format_string += "%s"
15421545
args.append(value)
15431546
elif builtins.is_list(value.type):
15441547
format_string += "["; flush()
@@ -1547,7 +1550,7 @@ def flush():
15471550
last = self.append(ir.Arith(ast.Sub(loc=None), length, ir.Constant(1, length.type)))
15481551
def body_gen(index):
15491552
elt = self.iterable_get(value, index)
1550-
self.polymorphic_print([elt], separator="")
1553+
self.polymorphic_print([elt], separator="", as_repr=True)
15511554
is_last = self.append(ir.Compare(ast.Lt(loc=None), index, last))
15521555
head = self.current_block
15531556

0 commit comments

Comments
 (0)
Please sign in to comment.