Skip to content

Commit

Permalink
compiler.types: print fields of instance types.
Browse files Browse the repository at this point in the history
whitequark committed Aug 27, 2015

Verified

This commit was signed with the committer’s verified signature.
makenowjust Hiroya Fujinami
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
Original file line number Diff line number Diff line change
@@ -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
@@ -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:

0 comments on commit d0fd618

Please sign in to comment.