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