ARTIQIRGenerator.polymorphic_print: str([x]) uses repr(x), not str(x).

This commit is contained in:
whitequark 2015-08-09 20:27:04 +03:00
parent f7b64db8f4
commit dfc91a35f2
1 changed files with 7 additions and 4 deletions

View File

@ -1489,7 +1489,7 @@ class ARTIQIRGenerator(algorithm.Visitor):
tail = self.current_block = self.add_block() tail = self.current_block = self.add_block()
self.append(ir.BranchIf(cond, tail, if_failed), block=head) self.append(ir.BranchIf(cond, tail, if_failed), block=head)
def polymorphic_print(self, values, separator, suffix=""): def polymorphic_print(self, values, separator, suffix="", as_repr=False):
format_string = "" format_string = ""
args = [] args = []
def flush(): def flush():
@ -1508,7 +1508,7 @@ class ARTIQIRGenerator(algorithm.Visitor):
format_string += "("; flush() format_string += "("; flush()
self.polymorphic_print([self.append(ir.GetAttr(value, index)) self.polymorphic_print([self.append(ir.GetAttr(value, index))
for index in range(len(value.type.elts))], for index in range(len(value.type.elts))],
separator=", ") separator=", ", as_repr=True)
if len(value.type.elts) == 1: if len(value.type.elts) == 1:
format_string += ",)" format_string += ",)"
else: else:
@ -1538,6 +1538,9 @@ class ARTIQIRGenerator(algorithm.Visitor):
format_string += "%g" format_string += "%g"
args.append(value) args.append(value)
elif builtins.is_str(value.type): elif builtins.is_str(value.type):
if as_repr:
format_string += "\"%s\""
else:
format_string += "%s" format_string += "%s"
args.append(value) args.append(value)
elif builtins.is_list(value.type): elif builtins.is_list(value.type):
@ -1547,7 +1550,7 @@ class ARTIQIRGenerator(algorithm.Visitor):
last = self.append(ir.Arith(ast.Sub(loc=None), length, ir.Constant(1, length.type))) last = self.append(ir.Arith(ast.Sub(loc=None), length, ir.Constant(1, length.type)))
def body_gen(index): def body_gen(index):
elt = self.iterable_get(value, index) elt = self.iterable_get(value, index)
self.polymorphic_print([elt], separator="") self.polymorphic_print([elt], separator="", as_repr=True)
is_last = self.append(ir.Compare(ast.Lt(loc=None), index, last)) is_last = self.append(ir.Compare(ast.Lt(loc=None), index, last))
head = self.current_block head = self.current_block