forked from M-Labs/artiq
Add inference for Index, Slice and ExtSlice.
This commit is contained in:
parent
c724e024ce
commit
227f97f8a3
@ -108,9 +108,38 @@ class Inferencer(algorithm.Visitor):
|
||||
collection.loc, [])
|
||||
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):
|
||||
self.generic_visit(node)
|
||||
self._unify_iterable(element=node, collection=node.value)
|
||||
if isinstance(node.slice, ast.Index):
|
||||
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):
|
||||
self.generic_visit(node)
|
||||
|
10
lit-test/compiler/inferencer/error_subscript.py
Normal file
10
lit-test/compiler/inferencer/error_subscript.py
Normal 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]
|
Loading…
Reference in New Issue
Block a user