Const
const
Const
Bases: Generic[_T]
Marks the value as a compile-time constant and can be used for any type defined by the frontend. Compile-time constants can be expressions and are evaluated at compile time. They cannot be redefined in the same program or shadowed by other variables.
a: Const[i64] = 123 # i64 constant equal to 123
b: Const[i32] = len([1, 2, 3]) # i32 constant equal to 3
c: Const[f32] = 123 / 0 # compile-time error, division by zero
d: Const[i64] = a + b # i64 constant, equal to 6
def foo(a: i64): # compile-time error, cannot reuse the name
# of a constant
d = 3 # compile-time error, cannot assign to a constant
e: Const[i16] = b + 2 # i16 constant, equal to 5
Source code in xdsl/frontend/pyast/utils/const.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
is_constant(node: ast.expr) -> bool
Returns True if the AST node is a Const type.
Source code in xdsl/frontend/pyast/utils/const.py
35 36 37 38 39 40 41 | |
is_constant_stmt(node: ast.stmt) -> bool
Returns True if the AST statement is a Const expression.
Source code in xdsl/frontend/pyast/utils/const.py
44 45 46 | |