From 4b7d4c242500fb0d57c2ed8de207703586323f70 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 11 Jun 2015 04:20:33 +0300 Subject: [PATCH] Add support for BoolOp. --- artiq/py2llvm/typing.py | 26 ++++++++++++++++---------- lit-test/py2llvm/typing/error_unify.py | 5 +++++ lit-test/py2llvm/typing/unify.py | 3 +++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/artiq/py2llvm/typing.py b/artiq/py2llvm/typing.py index 1cfb50c20..a9ab62ffa 100644 --- a/artiq/py2llvm/typing.py +++ b/artiq/py2llvm/typing.py @@ -301,18 +301,24 @@ class Inferencer(algorithm.Transformer): def visit_BoolOp(self, node): node = self.generic_visit(node) - for value, op_loc in zip(node.values, node.op_locs): - def makenotes(printer, typea, typeb, loca, locb): - return [ - diagnostic.Diagnostic("note", - "py2llvm requires boolean operations to have boolean operands", {}, - op_loc) - ] - self._unify(value.type, types.TBool(), - value.loc, None, makenotes) - return asttyped.BoolOpT(type=types.TBool(), + node = asttyped.BoolOpT(type=types.TVar(), op=node.op, values=node.values, op_locs=node.op_locs, loc=node.loc) + def makenotes(printer, typea, typeb, loca, locb): + return [ + diagnostic.Diagnostic("note", + "an operand of type {typea}", + {"typea": printer.name(node.values[0].type)}, + node.values[0].loc), + diagnostic.Diagnostic("note", + "an operand of type {typeb}", + {"typeb": printer.name(typeb)}, + locb) + ] + for value in node.values: + self._unify(node.type, value.type, + node.loc, value.loc, makenotes) + return node # Visitors that just unify types # diff --git a/lit-test/py2llvm/typing/error_unify.py b/lit-test/py2llvm/typing/error_unify.py index 9edf8d82a..a1e8b1d8e 100644 --- a/lit-test/py2llvm/typing/error_unify.py +++ b/lit-test/py2llvm/typing/error_unify.py @@ -11,3 +11,8 @@ a = b [1, []] # CHECK-L: note: a list of type list(elt=int(width='a)) # CHECK-L: note: a list element of type list(elt='b) + +# CHECK-L: ${LINE:+1}: error: cannot unify int(width='a) with bool +1 and False +# CHECK-L: note: an operand of type int(width='a) +# CHECK-L: note: an operand of type bool diff --git a/lit-test/py2llvm/typing/unify.py b/lit-test/py2llvm/typing/unify.py index 2093cc3d0..8ea23dd0e 100644 --- a/lit-test/py2llvm/typing/unify.py +++ b/lit-test/py2llvm/typing/unify.py @@ -38,3 +38,6 @@ j += [1.0] True and False # CHECK-L: True:bool and False:bool:bool + +1 and 0 +# CHECK-L: 1:int(width='g) and 0:int(width='g):int(width='g)