← SPL reference

JIT — fast numeric loops

Optional loop compiler for tight numeric code. When a loop matches the pattern, SPL runs it in a small stack VM instead of walking the AST every iteration. Same results as the interpreter — just fewer Python trips.

Off by default. Set SPL_JIT=1 in the shell before run-spl. The CLI banner shows [JIT] when it is on. Browser / Pyodide runs stay interpreted.

Enable

# shell
SPL_JIT=1 run-spl myscript.spl

# see compile hits vs fallbacks on stderr
SPL_JIT=trace run-spl myscript.spl

What compiles

Examples

Sum 1…100 — classic JIT win:

sum.setVar(0);
test.forLoop(1, 100, i):
  sum.setVar(math.add(sum, i));
end;
print.number(sum);

Multi-statement body (both lines compile):

a.setVar(0);
b.setVar(0);
test.forLoop(1, 5, i):
  a.setVar(math.add(a, i));
  b.setVar(math.add(b, 1));
end;

Numeric while:

n.setVar(0);
test.while(test.isLess(n, 10)):
  n.setVar(math.add(n, 1));
end;

What falls back

Anything else keeps using the normal interpreter — no error, just no speedup. Common reasons:

Use SPL_JIT=trace to print fallback reasons to stderr (e.g. forloop fallback: body not all numeric setVar).

Semantics

Test locally

SPL_JIT=1 run-spl tests/jit/bench_sum.spl
python3 -m unittest tests.test_jit

Implementation: someProgrammingLanguage/spl_jit.py · backlog: JIT_ROADMAP.md