2014-05-08 15:58:39 +00:00
|
|
|
# test constant optimisation
|
2020-07-13 19:22:58 +09:00
|
|
|
# This test will only work when MICROPY_COMP_CONST is enabled.
|
2014-05-08 15:58:39 +00:00
|
|
|
|
2016-09-27 13:34:21 +10:00
|
|
|
from micropython import const
|
|
|
|
|
2014-05-08 15:58:39 +00:00
|
|
|
X = const(123)
|
|
|
|
Y = const(X + 456)
|
|
|
|
|
|
|
|
print(X, Y + 1)
|
|
|
|
|
2020-03-22 21:26:08 -05:00
|
|
|
|
2014-05-08 15:58:39 +00:00
|
|
|
def f():
|
|
|
|
print(X, Y + 1)
|
|
|
|
|
2020-03-22 21:26:08 -05:00
|
|
|
|
2014-05-08 15:58:39 +00:00
|
|
|
f()
|
2016-06-06 17:28:32 +01:00
|
|
|
|
|
|
|
_X = const(12)
|
|
|
|
_Y = const(_X + 34)
|
|
|
|
|
|
|
|
print(_X, _Y)
|
|
|
|
|
2020-03-22 21:26:08 -05:00
|
|
|
|
2016-06-06 17:28:32 +01:00
|
|
|
class A:
|
|
|
|
Z = const(1)
|
|
|
|
_Z = const(2)
|
|
|
|
print(Z, _Z)
|
|
|
|
|
2020-03-22 21:26:08 -05:00
|
|
|
|
2016-06-06 17:28:32 +01:00
|
|
|
print(hasattr(A, "Z"), hasattr(A, "_Z"))
|