SharedCounters

Monotonically increasing counters used by both MiniKotlinCompiler and ExpressionCompiler to generate names that are unique within a single compilation unit.

A single SharedCounters instance is created by MiniKotlinCompiler at construction time and passed to ExpressionCompiler. This ensures that continuation labels (cont_N), result names (res_N), and variable names (x_N) never collide, even when expression and statement compilation interleave deeply nested CPS lambdas.

Both counters are reset to zero at the start of each MiniKotlinCompiler.compile call so that the generated Java is deterministic for a given input program.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
fun next(): Int

Returns the next unique integer for naming continuations, loop labels, and CPS result variables (cont_N, loop_N, res_N).

Link copied to clipboard
fun nextVar(): Int

Returns the next unique integer for naming local variable arrays (x_N). Kept separate from next so that variable names and continuation names occupy distinct namespaces, making generated code easier to read.

Link copied to clipboard
fun reset()

Resets both counters to zero. Called at the start of each top-level MiniKotlinCompiler.compile invocation to guarantee deterministic output.