Add inference for Index, Slice and ExtSlice.

This commit is contained in:
whitequark 2015-07-16 04:21:21 +03:00
parent c724e024ce
commit 227f97f8a3
2 changed files with 40 additions and 1 deletions

View File

@ -108,9 +108,38 @@ class Inferencer(algorithm.Visitor):
collection.loc, []) collection.loc, [])
self.engine.process(diag) self.engine.process(diag)
def visit_Index(self, node):
value = node.value
if types.is_tuple(value.type):
diag = diagnostic.Diagnostic("error",
"multi-dimensional slices are not supported", {},
node.loc, [])
self.engine.process(diag)
else:
self._unify(value.type, builtins.TInt(),
value.loc, None)
def visit_Slice(self, node):
for operand in (node.lower, node.upper, node.step):
if operand is not None:
self._unify(operand.type, builtins.TInt(),
operand.loc, None)
def visit_ExtSlice(self, node):
diag = diagnostic.Diagnostic("error",
"multi-dimensional slices are not supported", {},
node.loc, [])
self.engine.process(diag)
def visit_SubscriptT(self, node): def visit_SubscriptT(self, node):
self.generic_visit(node) self.generic_visit(node)
if isinstance(node.slice, ast.Index):
self._unify_iterable(element=node, collection=node.value) self._unify_iterable(element=node, collection=node.value)
elif isinstance(node.slice, ast.Slice):
self._unify(node.type, node.value.type,
node.loc, node.value.loc)
else: # ExtSlice
pass # error emitted above
def visit_IfExpT(self, node): def visit_IfExpT(self, node):
self.generic_visit(node) self.generic_visit(node)

View File

@ -0,0 +1,10 @@
# RUN: %python -m artiq.compiler.testbench.inferencer +diag %s >%t
# RUN: OutputCheck %s --file-to-check=%t
x = []
# CHECK-L: ${LINE:+1}: error: multi-dimensional slices are not supported
x[1,2]
# CHECK-L: ${LINE:+1}: error: multi-dimensional slices are not supported
x[1:2,3:4]