2014-05-08 15:58:39 +00:00
|
|
|
# test constant optimisation
|
|
|
|
|
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)
|
|
|
|
|
2021-03-15 19:27:36 +05:30
|
|
|
|
2014-05-08 15:58:39 +00:00
|
|
|
def f():
|
|
|
|
print(X, Y + 1)
|
|
|
|
|
2021-03-15 19:27:36 +05:30
|
|
|
|
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)
|
|
|
|
|
2021-03-15 19:27:36 +05:30
|
|
|
|
2016-06-06 17:28:32 +01:00
|
|
|
class A:
|
|
|
|
Z = const(1)
|
|
|
|
_Z = const(2)
|
|
|
|
print(Z, _Z)
|
|
|
|
|
2021-03-15 19:27:36 +05:30
|
|
|
|
|
|
|
print(hasattr(A, "Z"), hasattr(A, "_Z"))
|