Expression Compiler
Compiles MiniKotlin expression trees into Java continuation-passing style.
Every method in this class follows the CPS pattern:
compileExpr(ctx, env, k: (String) -> String): Stringwhere k is the continuation — a Kotlin lambda that receives a Java expression string representing the value of ctx and returns the Java statement code that should execute next.
For pure expressions (literals, identifiers, arithmetic) k is invoked immediately with a direct Java expression string — no extra lambda is emitted in the output.
For function call expressions the call is rewritten as a CPS call:
// MiniKotlin: var x: Int = factorial(n - 1)
// Generated:
factorial((n - 1), res_0 -> {
Integer[] x_0 = new Integer[]{ res_0 };
...
});Arguments are evaluated left-to-right via compileArgs, each of which may itself contain nested function calls that are recursively lifted.
Short-circuit operators && and || are compiled into named Continuation<Boolean> closures with an inline if guard, matching Kotlin's evaluation semantics.