summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpp2cc.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/pp2cc.py b/pp2cc.py
index 81f6a79..b270191 100755
--- a/pp2cc.py
+++ b/pp2cc.py
@@ -1315,13 +1315,11 @@ class Parse(object):
else:
operand = self.determineConstValue(LinkedNode(node.expr,
linked_node))
- if op == "-":
- # negating a value in PP2 is flipping the WORDSIZE-th bit
- value = -operand
- #(operand ^ (pow(2, self.WORDSIZE) - 1)) + 1
- elif op == "~":
- # invert all bits
+ if op in ("-", "~"):
value = operand ^ (pow(2, self.WORDSIZE) - 1)
+ # negating a value in PP2 is inverting the bits and adding 1
+ if op == "-":
+ value += 1
else:
value = int(getattr(operator, op)(operand))
elif linked_node.type == "BinaryOp":