Module

compiler.partial_eval_loops

Static for-loop unrolling for partial evaluation.

Classes

LoopProperties 7 ▼
Compile-time stand-in for runtime loop-context properties.

Compile-time stand-in for runtime loop-context properties.

Attributes

Name Type Description
index0 int —
index int —
first bool —
last bool —
length int —
revindex int —
revindex0 int —
LoopUnrollingMixin 8 ▼
Partial-evaluator phase for statically known for-loops.

Partial-evaluator phase for statically known for-loops.

Attributes

Name Type Description
_ctx dict[str, Any] —
_defs dict[str, Def] —

Methods

Internal Methods 6 ▼
_try_eval 2 Any ▼
Evaluate an expression against the current static context.
abstract
def _try_eval(self, expr: Expr, depth: int = 0) -> Any
Parameters
Name Type Description
expr —
depth — Default:0
Returns
Any
_transform_body 1 Sequence[Node] ▼
Transform a sequence of template nodes.
abstract
def _transform_body(self, body: Sequence[Node]) -> Sequence[Node]
Parameters
Name Type Description
body —
Returns
Sequence[Node]
_make_sub_evaluator 1 Self ▼
Create an evaluator that shares this evaluator's configuration.
abstract
def _make_sub_evaluator(self, ctx: dict[str, Any]) -> Self
Parameters
Name Type Description
ctx —
Returns
Self
_transform_for 1 Node | None ▼
Unroll a for-loop when its iterable is statically known.
def _transform_for(self, node: For) -> Node | None
Parameters
Name Type Description
node —
Returns
Node | None
_try_unroll_for 2 Node | None ▼
Return statically expanded loop nodes when unrolling is safe.
def _try_unroll_for(self, node: For, iter_val: Any) -> Node | None
Parameters
Name Type Description
node —
iter_val —
Returns
Node | None
_build_iter_context 2 dict[str, Any] ▼
Map loop target names to one statically known item.
def _build_iter_context(self, target_names: tuple[str, ...], item: Any) -> dict[str, Any]
Parameters
Name Type Description
target_names —
item —
Returns
dict[str, Any]