compiler: implement ~ operator (fix #836).

This commit is contained in:
whitequark 2017-10-01 19:33:18 +00:00
parent 843786a091
commit f86744c65c
2 changed files with 6 additions and 0 deletions

View File

@ -1289,6 +1289,10 @@ class ARTIQIRGenerator(algorithm.Visitor):
return self.append(ir.Select(cond, return self.append(ir.Select(cond,
ir.Constant(False, builtins.TBool()), ir.Constant(False, builtins.TBool()),
ir.Constant(True, builtins.TBool()))) ir.Constant(True, builtins.TBool())))
elif isinstance(node.op, ast.Invert):
operand = self.visit(node.operand)
return self.append(ir.Arith(ast.BitXor(loc=None),
ir.Constant(-1, operand.type), operand))
elif isinstance(node.op, ast.USub): elif isinstance(node.op, ast.USub):
operand = self.visit(node.operand) operand = self.visit(node.operand)
return self.append(ir.Arith(ast.Sub(loc=None), return self.append(ir.Arith(ast.Sub(loc=None),

View File

@ -41,6 +41,8 @@ assert -1 >> 32 == -1
assert 0x18 & 0x0f == 0x08 assert 0x18 & 0x0f == 0x08
assert 0x18 | 0x0f == 0x1f assert 0x18 | 0x0f == 0x1f
assert 0x18 ^ 0x0f == 0x17 assert 0x18 ^ 0x0f == 0x17
#ARTIQ#assert ~0x18 == -25
#ARTIQ#assert ~int64(0x18) == -25
try: try:
1 / 0 1 / 0