From d0fd61866fc296846c3e360a8f800a573d1d3912 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 27 Aug 2015 17:25:01 -0500 Subject: [PATCH] compiler.types: print fields of instance types. --- artiq/compiler/types.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/artiq/compiler/types.py b/artiq/compiler/types.py index 1a9856478..d4cb47aef 100644 --- a/artiq/compiler/types.py +++ b/artiq/compiler/types.py @@ -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 "".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 "".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 "".format(typ.name) elif isinstance(typ, (TConstructor, TExceptionConstructor)): - attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr])) - for attr in typ.attributes]) - return "".format(typ.name, attrs) + if typ.name in self.recurse_guard: + return "".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 "".format(typ.name, attrs) elif isinstance(typ, TValue): return repr(typ.value) else: