mirror of https://github.com/m-labs/artiq.git
compiler.types: print fields of instance types.
This commit is contained in:
parent
9791cbba4d
commit
d0fd61866f
|
@ -512,6 +512,7 @@ class TypePrinter(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.gen = genalnum()
|
self.gen = genalnum()
|
||||||
self.map = {}
|
self.map = {}
|
||||||
|
self.recurse_guard = set()
|
||||||
|
|
||||||
def name(self, typ):
|
def name(self, typ):
|
||||||
typ = typ.find()
|
typ = typ.find()
|
||||||
|
@ -519,6 +520,14 @@ class TypePrinter(object):
|
||||||
if typ not in self.map:
|
if typ not in self.map:
|
||||||
self.map[typ] = "'%s" % next(self.gen)
|
self.map[typ] = "'%s" % next(self.gen)
|
||||||
return self.map[typ]
|
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):
|
elif isinstance(typ, TMono):
|
||||||
if typ.params == {}:
|
if typ.params == {}:
|
||||||
return typ.name
|
return typ.name
|
||||||
|
@ -545,9 +554,13 @@ class TypePrinter(object):
|
||||||
elif isinstance(typ, TBuiltinFunction):
|
elif isinstance(typ, TBuiltinFunction):
|
||||||
return "<function {}>".format(typ.name)
|
return "<function {}>".format(typ.name)
|
||||||
elif isinstance(typ, (TConstructor, TExceptionConstructor)):
|
elif isinstance(typ, (TConstructor, TExceptionConstructor)):
|
||||||
attrs = ", ".join(["{}: {}".format(attr, self.name(typ.attributes[attr]))
|
if typ.name in self.recurse_guard:
|
||||||
for attr in typ.attributes])
|
return "<constructor {}>".format(typ.name)
|
||||||
return "<constructor {} {{{}}}>".format(typ.name, attrs)
|
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):
|
elif isinstance(typ, TValue):
|
||||||
return repr(typ.value)
|
return repr(typ.value)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue