From d08598fa0f075e2f997245e4add8aeb036723ed8 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 6 Jun 2015 15:12:40 +0300 Subject: [PATCH] Add support for NameConstant. --- artiq/py2llvm/types.py | 11 +++++++++-- artiq/py2llvm/typing.py | 9 ++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/artiq/py2llvm/types.py b/artiq/py2llvm/types.py index dc15c5cb5..078051883 100644 --- a/artiq/py2llvm/types.py +++ b/artiq/py2llvm/types.py @@ -155,6 +155,10 @@ class TValue(Type): def __ne__(self, other): return not (self == other) +def TNone(): + """The type of None.""" + return TMono("NoneType") + def TBool(): """A boolean type.""" return TMono("bool") @@ -193,8 +197,11 @@ class TypePrinter(object): self.map[typ] = "'%s" % next(self.gen) return self.map[typ] elif isinstance(typ, TMono): - return "%s(%s)" % (typ.name, ", ".join( - ["%s=%s" % (k, self.name(typ.params[k])) for k in typ.params])) + if typ.params == {}: + return typ.name + else: + return "%s(%s)" % (typ.name, ", ".join( + ["%s=%s" % (k, self.name(typ.params[k])) for k in typ.params])) elif isinstance(typ, TTuple): if len(typ.elts) == 1: return "(%s,)" % self.name(typ.elts[0]) diff --git a/artiq/py2llvm/typing.py b/artiq/py2llvm/typing.py index 9c9bfcc4c..da793f6d3 100644 --- a/artiq/py2llvm/typing.py +++ b/artiq/py2llvm/typing.py @@ -215,6 +215,13 @@ class Inferencer(algorithm.Transformer): return asttyped.NameT(type=self._find_name(node.id, node.loc), id=node.id, ctx=node.ctx, loc=node.loc) + def visit_NameConstant(self, node): + if node.value is True or node.value is False: + typ = types.TBool() + elif node.value is None: + typ = types.TNone() + return asttyped.NameConstantT(type=typ, value=node.value, loc=node.loc) + def visit_Tuple(self, node): node = self.generic_visit(node) return asttyped.TupleT(type=types.TTuple([x.type for x in node.elts]), @@ -303,7 +310,7 @@ class Printer(algorithm.Visitor): def generic_visit(self, node): if hasattr(node, "type"): self.rewriter.insert_after(node.loc, - ":%s".format(self.type_printer.name(node.type))) + ":{}".format(self.type_printer.name(node.type))) super().generic_visit(node)