MCPcopy Index your code
hub / github.com/python/mypy / ForBuilder

Class ForBuilder

mypyc/irbuild/ll_builder.py:3048–3078  ·  view source on GitHub ↗

Builder for simple for loops.

Source from the content-addressed store, hash-verified

3046
3047
3048class ForBuilder:
3049 """Builder for simple for loops."""
3050
3051 def __init__(
3052 self, builder: LowLevelIRBuilder, start: Value, end: Value, step: Value, *, signed: bool
3053 ) -> None:
3054 self.builder = builder
3055 self.start = start
3056 self.end = end
3057 self.step = step
3058 self.signed = signed
3059 self.index = Register(start.type)
3060 self.top = BasicBlock()
3061 self.body = BasicBlock()
3062 self.loop_exit = BasicBlock()
3063
3064 def begin(self) -> None:
3065 builder = self.builder
3066 builder.assign(self.index, self.start)
3067 builder.goto_and_activate(self.top)
3068 op = ComparisonOp.SLT if self.signed else ComparisonOp.ULT
3069 comp = ComparisonOp(self.index, self.end, op, line=-1)
3070 builder.add(comp)
3071 builder.add(Branch(comp, self.body, self.loop_exit, Branch.BOOL))
3072 builder.goto_and_activate(self.body)
3073
3074 def finish(self) -> None:
3075 builder = self.builder
3076 builder.assign(self.index, builder.int_add(self.index, self.step))
3077 builder.goto(self.top)
3078 builder.activate_block(self.loop_exit)

Callers 1

begin_forMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…