From 1702251ee56b913dd8e138fae4c9db84c425997c Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 2 Jul 2015 18:44:09 +0300 Subject: [PATCH] Add region field to types. --- artiq/compiler/types.py | 18 +++++++++++++----- artiq/compiler/typing.py | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index 41b3733fa..4db3fa2be 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -67,12 +67,17 @@ class TVar(Type): # any lookups or comparisons. class TMono(Type): - """A monomorphic type, possibly parametric.""" + """ + A monomorphic type, possibly parametric. + + :class:`TMono` is supposed to be subclassed by builtin types, + unlike all other :class:`Type` descendants. + """ attributes = {} - def __init__(self, name, params={}): - self.name, self.params = name, params + def __init__(self, name, params={}, region=None): + self.name, self.params, self.region = name, params, region def find(self): return self @@ -109,6 +114,7 @@ class TTuple(Type): """ attributes = {} + region = None def __init__(self, elts=[]): self.elts = elts @@ -149,8 +155,8 @@ class TFunction(Type): attributes = {} - def __init__(self, args, optargs, ret): - self.args, self.optargs, self.ret = args, optargs, ret + def __init__(self, args, optargs, ret, region=None): + self.args, self.optargs, self.ret, self.region = args, optargs, ret, region def arity(self): return len(self.args) + len(self.optargs) @@ -189,6 +195,8 @@ class TBuiltin(Type): type is treated specially according to its name. """ + region = None + def __init__(self, name): self.name = name self.attributes = {} diff --git a/artiq/compiler/typing.py b/artiq/compiler/typing.py index 3c8c62f76..c7ae71327 100644 --- a/artiq/compiler/typing.py +++ b/artiq/compiler/typing.py @@ -444,7 +444,7 @@ class Inferencer(algorithm.Visitor): def visit_ListT(self, node): self.generic_visit(node) for elt in node.elts: - self._unify(node.type["elt"], elt.type, + self._unify(node.type, builtins.TList(elt.type), node.loc, elt.loc, self._makenotes_elts(node.elts, "a list element")) def visit_AttributeT(self, node):