summaryrefslogtreecommitdiff
path: root/pp2cc.py
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-12-07 08:27:15 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-12-07 08:27:15 +0000
commit97d67c978678ea6009212ec2b868ebc7bc543585 (patch)
tree42b731d2c435ef40431947d575b2a128a9fdc07a /pp2cc.py
parentf53bf21c6ad9fb3d2f1a40e2ce06816a6b2e3106 (diff)
downloadpp2cc-97d67c978678ea6009212ec2b868ebc7bc543585.tar.gz
Proper fix for calculating negative constants
Diffstat (limited to 'pp2cc.py')
-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":