2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-26 03:38:25 +08:00

Add region field to types.

This commit is contained in:
whitequark 2015-07-02 18:44:09 +03:00
parent 86cdc84f7e
commit 1702251ee5
2 changed files with 14 additions and 6 deletions

View File

@ -67,12 +67,17 @@ class TVar(Type):
# any lookups or comparisons. # any lookups or comparisons.
class TMono(Type): 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 = {} attributes = {}
def __init__(self, name, params={}): def __init__(self, name, params={}, region=None):
self.name, self.params = name, params self.name, self.params, self.region = name, params, region
def find(self): def find(self):
return self return self
@ -109,6 +114,7 @@ class TTuple(Type):
""" """
attributes = {} attributes = {}
region = None
def __init__(self, elts=[]): def __init__(self, elts=[]):
self.elts = elts self.elts = elts
@ -149,8 +155,8 @@ class TFunction(Type):
attributes = {} attributes = {}
def __init__(self, args, optargs, ret): def __init__(self, args, optargs, ret, region=None):
self.args, self.optargs, self.ret = args, optargs, ret self.args, self.optargs, self.ret, self.region = args, optargs, ret, region
def arity(self): def arity(self):
return len(self.args) + len(self.optargs) return len(self.args) + len(self.optargs)
@ -189,6 +195,8 @@ class TBuiltin(Type):
type is treated specially according to its name. type is treated specially according to its name.
""" """
region = None
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
self.attributes = {} self.attributes = {}

View File

@ -444,7 +444,7 @@ class Inferencer(algorithm.Visitor):
def visit_ListT(self, node): def visit_ListT(self, node):
self.generic_visit(node) self.generic_visit(node)
for elt in node.elts: 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")) node.loc, elt.loc, self._makenotes_elts(node.elts, "a list element"))
def visit_AttributeT(self, node): def visit_AttributeT(self, node):