forked from M-Labs/artiq
1
0
Fork 0

compiler.types: print fields of instance types.

This commit is contained in:
whitequark 2015-08-27 17:25:01 -05:00
parent 9791cbba4d
commit d0fd61866f
1 changed files with 16 additions and 3 deletions

View File

@ -512,6 +512,7 @@ class TypePrinter(object):
def __init__(self):
self.gen = genalnum()
self.map = {}
self.recurse_guard = set()
def name(self, typ):
typ = typ.find()
@ -519,6 +520,14 @@ class TypePrinter(object):
if typ not in self.map:
self.map[typ] = "'%s" % next(self.gen)
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):
if typ.params == {}:
return typ.name
@ -545,9 +554,13 @@ class TypePrinter(object):
elif isinstance(typ, TBuiltinFunction):
return "<function {}>".format(typ.name)
elif isinstance(typ, (TConstructor, TExceptionConstructor)):
attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr]))
for attr in typ.attributes])
return "<constructor {} {{{}}}>".format(typ.name, attrs)
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]))
for attr in typ.attributes])
return "<constructor {} {{{}}}>".format(typ.name, attrs)
elif isinstance(typ, TValue):
return repr(typ.value)
else: