정적 연산¶
Static¶
static 연산은 컴파일 시점에 평가되는 연산입니다. static 연산 코드는 실행 가능한 바이너리로 직접 변환되지는 않지만, 바이너리로 변환되는 코드를 만드는 데 쓸 수 있습니다.
for_each¶
1 | |
Apply a function to each element of an iterable at compile time.
This loop is evaluated statically; the body will be unrolled during compilation.
Parameters:
iterable(Value): Interpreted iterable value. Typically created withlegato.range.func(Value): Interpreted callable taking one argument (the current element) and returning an interpreted callable that accepts theCodeGeneratorwhen invoked by the compiler.
Returns:
result(Value): An interpreted callable that, when executed by the compiler, evaluates the unrolled loop.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
empty_list¶
1 | |
Create an empty list of the given type at compile time.
Parameters:
dtype(Value): Constexpr value representing the type of the list.
Returns:
result(Value): Constexpr value representing the empty list.
Example:
1 2 3 | |
fold_back¶
1 | |
Fold an iterable from the right at compile time.
Parameters:
iterable(Value): Interpreted iterable value to fold.func(Value): Interpreted callable of two arguments(acc, current)returning the updated accumulator as an interpreted value. Note the reversed argument order compared tofold.initial(Value): Interpreted initial accumulator value.
Returns:
result(Value): An interpreted value representing the right-fold result.
Example:
1 2 3 4 | |
fold¶
1 | |
Fold an iterable into a single value at compile time.
Parameters:
iterable(Value): Interpreted iterable value to fold, e.g. fromlegato.range.func(Value): Interpreted callable of two arguments(current, acc)returning the updated accumulator as an interpreted value.initial(Value): Interpreted initial accumulator value.
Returns:
result(Value): An interpreted value representing the folded result.
Example:
1 2 3 4 5 6 7 8 | |
append¶
1 | |
Append a value to a list at compile time.
Parameters:
lhs_list(Value): Constexpr value representing the list to append to.value(Value): Constexpr value representing the value to append.
Returns:
result(Value): Constexpr value representing the list with the value appended.
Example:
1 2 3 4 | |
if_else¶
1 | |
Compile-time conditional that executes one of two branches.
Parameters:
condition(Value): Interpreted boolean condition.if_true(Value): Interpreted callable returning a zero-arg function to be executed when condition is true.if_false(Value): Interpreted callable returning a zero-arg function to be executed when condition is false.
Returns:
result(Value): An interpreted callable that, when run by the compiler, executes the selected branch.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |