Skip to content

Commit d0fd618

Browse files
author
whitequark
committedAug 27, 2015
compiler.types: print fields of instance types.
1 parent 9791cbb commit d0fd618

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed
 

Diff for: ‎artiq/compiler/types.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,22 @@ class TypePrinter(object):
512512
def __init__(self):
513513
self.gen = genalnum()
514514
self.map = {}
515+
self.recurse_guard = set()
515516

516517
def name(self, typ):
517518
typ = typ.find()
518519
if isinstance(typ, TVar):
519520
if typ not in self.map:
520521
self.map[typ] = "'%s" % next(self.gen)
521522
return self.map[typ]
523+
elif isinstance(typ, TInstance):
524+
if typ.name in self.recurse_guard:
525+
return "<instance {}>".format(typ.name)
526+
else:
527+
self.recurse_guard.add(typ.name)
528+
attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr]))
529+
for attr in typ.attributes])
530+
return "<instance {} {{{}}}>".format(typ.name, attrs)
522531
elif isinstance(typ, TMono):
523532
if typ.params == {}:
524533
return typ.name
@@ -545,9 +554,13 @@ def name(self, typ):
545554
elif isinstance(typ, TBuiltinFunction):
546555
return "<function {}>".format(typ.name)
547556
elif isinstance(typ, (TConstructor, TExceptionConstructor)):
548-
attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr]))
549-
for attr in typ.attributes])
550-
return "<constructor {} {{{}}}>".format(typ.name, attrs)
557+
if typ.name in self.recurse_guard:
558+
return "<constructor {}>".format(typ.name)
559+
else:
560+
self.recurse_guard.add(typ.name)
561+
attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr]))
562+
for attr in typ.attributes])
563+
return "<constructor {} {{{}}}>".format(typ.name, attrs)
551564
elif isinstance(typ, TValue):
552565
return repr(typ.value)
553566
else:

0 commit comments

Comments
 (0)
Please sign in to comment.