From e9416f4707ced2dcff77b2d838989c1b1933e77c Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 16 Jul 2015 14:53:24 +0300 Subject: [PATCH] Convert Slice into typed SliceT. --- artiq/compiler/asttyped.py | 3 +++ artiq/compiler/transforms/asttyped_rewriter.py | 9 +++++++++ artiq/compiler/transforms/inferencer.py | 6 ++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/artiq/compiler/asttyped.py b/artiq/compiler/asttyped.py index f29b59d4a..8e4674c99 100644 --- a/artiq/compiler/asttyped.py +++ b/artiq/compiler/asttyped.py @@ -36,6 +36,9 @@ class ExceptHandlerT(ast.ExceptHandler): _fields = ("filter", "name", "body") # rename ast.ExceptHandler.type _types = ("name_type",) +class SliceT(ast.Slice, commontyped): + pass + class AttributeT(ast.Attribute, commontyped): pass class BinOpT(ast.BinOp, commontyped): diff --git a/artiq/compiler/transforms/asttyped_rewriter.py b/artiq/compiler/transforms/asttyped_rewriter.py index e89e7ac9c..094bce534 100644 --- a/artiq/compiler/transforms/asttyped_rewriter.py +++ b/artiq/compiler/transforms/asttyped_rewriter.py @@ -276,6 +276,15 @@ class ASTTypedRewriter(algorithm.Transformer): dot_loc=node.dot_loc, attr_loc=node.attr_loc, loc=node.loc) return self.visit(node) + def visit_Slice(self, node): + node = self.generic_visit(node) + node = asttyped.SliceT(type=types.TVar(), + lower=node.lower, upper=node.upper, step=node.step, + bound_colon_loc=node.bound_colon_loc, + step_colon_loc=node.step_colon_loc, + loc=node.loc) + return self.visit(node) + def visit_Subscript(self, node): node = self.generic_visit(node) node = asttyped.SubscriptT(type=types.TVar(), diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index dbb9aeb04..45d2cf40e 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -119,10 +119,12 @@ class Inferencer(algorithm.Visitor): self._unify(value.type, builtins.TInt(), value.loc, None) - def visit_Slice(self, node): + def visit_SliceT(self, node): + self._unify(node.type, builtins.TInt(), + node.loc, None) for operand in (node.lower, node.upper, node.step): if operand is not None: - self._unify(operand.type, builtins.TInt(), + self._unify(operand.type, node.type, operand.loc, None) def visit_ExtSlice(self, node):