mirror of https://github.com/m-labs/artiq.git
Add support for BoolOp.
This commit is contained in:
parent
b8ce3f85bd
commit
4b7d4c2425
|
@ -301,18 +301,24 @@ class Inferencer(algorithm.Transformer):
|
||||||
|
|
||||||
def visit_BoolOp(self, node):
|
def visit_BoolOp(self, node):
|
||||||
node = self.generic_visit(node)
|
node = self.generic_visit(node)
|
||||||
for value, op_loc in zip(node.values, node.op_locs):
|
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):
|
def makenotes(printer, typea, typeb, loca, locb):
|
||||||
return [
|
return [
|
||||||
diagnostic.Diagnostic("note",
|
diagnostic.Diagnostic("note",
|
||||||
"py2llvm requires boolean operations to have boolean operands", {},
|
"an operand of type {typea}",
|
||||||
op_loc)
|
{"typea": printer.name(node.values[0].type)},
|
||||||
|
node.values[0].loc),
|
||||||
|
diagnostic.Diagnostic("note",
|
||||||
|
"an operand of type {typeb}",
|
||||||
|
{"typeb": printer.name(typeb)},
|
||||||
|
locb)
|
||||||
]
|
]
|
||||||
self._unify(value.type, types.TBool(),
|
for value in node.values:
|
||||||
value.loc, None, makenotes)
|
self._unify(node.type, value.type,
|
||||||
return asttyped.BoolOpT(type=types.TBool(),
|
node.loc, value.loc, makenotes)
|
||||||
op=node.op, values=node.values,
|
return node
|
||||||
op_locs=node.op_locs, loc=node.loc)
|
|
||||||
|
|
||||||
# Visitors that just unify types
|
# Visitors that just unify types
|
||||||
#
|
#
|
||||||
|
|
|
@ -11,3 +11,8 @@ a = b
|
||||||
[1, []]
|
[1, []]
|
||||||
# CHECK-L: note: a list of type list(elt=int(width='a))
|
# 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: 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
|
||||||
|
|
|
@ -38,3 +38,6 @@ j += [1.0]
|
||||||
|
|
||||||
True and False
|
True and False
|
||||||
# CHECK-L: True:bool and False:bool:bool
|
# 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)
|
||||||
|
|
Loading…
Reference in New Issue