mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 03:30:14 +01:00
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:
@@ -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
|
||||
|
||||
@@ -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)")
|
||||
|
||||
Reference in New Issue
Block a user