Skip to content

Commit

Permalink
compiler.types: print fields of instance types.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Aug 27, 2015
1 parent 9791cbb commit d0fd618
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions artiq/compiler/types.py
Expand Up @@ -512,13 +512,22 @@ class TypePrinter(object):
def __init__(self):
self.gen = genalnum()
self.map = {}
self.recurse_guard = set()

def name(self, typ):
typ = typ.find()
if isinstance(typ, TVar):
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
Expand All @@ -545,9 +554,13 @@ def name(self, typ):
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:
Expand Down

0 comments on commit d0fd618

Please sign in to comment.