forked from M-Labs/artiq
1
0
Fork 0

ARTIQIRGenerator: evaluate SubscriptT index in non-assignment context.

This commit is contained in:
whitequark 2015-08-31 23:33:04 -06:00
parent 8762019699
commit 956c1985b1
1 changed files with 22 additions and 4 deletions

View File

@ -799,7 +799,12 @@ class ARTIQIRGenerator(algorithm.Visitor):
self.current_assign = old_assign self.current_assign = old_assign
if isinstance(node.slice, ast.Index): if isinstance(node.slice, ast.Index):
try:
old_assign, self.current_assign = self.current_assign, None
index = self.visit(node.slice.value) index = self.visit(node.slice.value)
finally:
self.current_assign = old_assign
length = self.iterable_len(value, index.type) length = self.iterable_len(value, index.type)
mapped_index = self._map_index(length, index, mapped_index = self._map_index(length, index,
loc=node.begin_loc) loc=node.begin_loc)
@ -814,21 +819,34 @@ class ARTIQIRGenerator(algorithm.Visitor):
length = self.iterable_len(value, node.slice.type) length = self.iterable_len(value, node.slice.type)
if node.slice.lower is not None: if node.slice.lower is not None:
try:
old_assign, self.current_assign = self.current_assign, None
start_index = self.visit(node.slice.lower) start_index = self.visit(node.slice.lower)
finally:
self.current_assign = old_assign
else: else:
start_index = ir.Constant(0, node.slice.type) start_index = ir.Constant(0, node.slice.type)
mapped_start_index = self._map_index(length, start_index, mapped_start_index = self._map_index(length, start_index,
loc=node.begin_loc) loc=node.begin_loc)
if node.slice.upper is not None: if node.slice.upper is not None:
try:
old_assign, self.current_assign = self.current_assign, None
stop_index = self.visit(node.slice.upper) stop_index = self.visit(node.slice.upper)
finally:
self.current_assign = old_assign
else: else:
stop_index = length stop_index = length
mapped_stop_index = self._map_index(length, stop_index, one_past_the_end=True, mapped_stop_index = self._map_index(length, stop_index, one_past_the_end=True,
loc=node.begin_loc) loc=node.begin_loc)
if node.slice.step is not None: if node.slice.step is not None:
try:
old_assign, self.current_assign = self.current_assign, None
step = self.visit(node.slice.step) step = self.visit(node.slice.step)
finally:
self.current_assign = old_assign
self._make_check( self._make_check(
self.append(ir.Compare(ast.NotEq(loc=None), step, ir.Constant(0, step.type))), self.append(ir.Compare(ast.NotEq(loc=None), step, ir.Constant(0, step.type))),
lambda: self.alloc_exn(builtins.TException("ValueError"), lambda: self.alloc_exn(builtins.TException("ValueError"),