forked from M-Labs/artiq
compiler.types: print fields of instance types.
This commit is contained in:
parent
9791cbba4d
commit
d0fd61866f
|
@ -512,6 +512,7 @@ class TypePrinter(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.gen = genalnum()
|
self.gen = genalnum()
|
||||||
self.map = {}
|
self.map = {}
|
||||||
|
self.recurse_guard = set()
|
||||||
|
|
||||||
def name(self, typ):
|
def name(self, typ):
|
||||||
typ = typ.find()
|
typ = typ.find()
|
||||||
|
@ -519,6 +520,14 @@ class TypePrinter(object):
|
||||||
if typ not in self.map:
|
if typ not in self.map:
|
||||||
self.map[typ] = "'%s" % next(self.gen)
|
self.map[typ] = "'%s" % next(self.gen)
|
||||||
return self.map[typ]
|
return self.map[typ]
|
||||||
|
elif isinstance(typ, TInstance):
|
||||||
|
if typ.name in self.recurse_guard:
|
||||||
|
return "<instance {}>".format(typ.name)
|
||||||
|
else:
|
||||||
|
self.recurse_guard.add(typ.name)
|
||||||
|
attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr]))
|
||||||
|
for attr in typ.attributes])
|
||||||
|
return "<instance {} {{{}}}>".format(typ.name, attrs)
|
||||||
elif isinstance(typ, TMono):
|
elif isinstance(typ, TMono):
|
||||||
if typ.params == {}:
|
if typ.params == {}:
|
||||||
return typ.name
|
return typ.name
|
||||||
|
@ -545,6 +554,10 @@ class TypePrinter(object):
|
||||||
elif isinstance(typ, TBuiltinFunction):
|
elif isinstance(typ, TBuiltinFunction):
|
||||||
return "<function {}>".format(typ.name)
|
return "<function {}>".format(typ.name)
|
||||||
elif isinstance(typ, (TConstructor, TExceptionConstructor)):
|
elif isinstance(typ, (TConstructor, TExceptionConstructor)):
|
||||||
|
if typ.name in self.recurse_guard:
|
||||||
|
return "<constructor {}>".format(typ.name)
|
||||||
|
else:
|
||||||
|
self.recurse_guard.add(typ.name)
|
||||||
attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr]))
|
attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr]))
|
||||||
for attr in typ.attributes])
|
for attr in typ.attributes])
|
||||||
return "<constructor {} {{{}}}>".format(typ.name, attrs)
|
return "<constructor {} {{{}}}>".format(typ.name, attrs)
|
||||||
|
|
Loading…
Reference in New Issue