py/parse: Support constant folding of power operator for integers.

Constant expression like "2 ** 3" will now be folded, and the special form
"X = const(2 ** 3)" will now compile because the argument to the const is
now a constant.

Fixes issue #5865.
This commit is contained in:
Damien George
2020-04-07 12:23:08 +10:00
parent 40e9227733
commit 4ede703687
3 changed files with 15 additions and 4 deletions

View File

@@ -30,6 +30,10 @@ print(-123 // 7, -123 % 7)
print(123 // -7, 123 % -7)
print(-123 // -7, -123 % -7)
# power
print(2 ** 3)
print(3 ** 4)
# won't fold so an exception can be raised at runtime
try:
1 << -1

View File

@@ -19,7 +19,7 @@ test_syntax("A = const(1); A = const(2)")
# these operations are not supported within const
test_syntax("A = const(1 @ 2)")
test_syntax("A = const(1 / 2)")
test_syntax("A = const(1 ** 2)")
test_syntax("A = const(1 ** -2)")
test_syntax("A = const(1 << -2)")
test_syntax("A = const(1 >> -2)")
test_syntax("A = const(1 % 0)")