[PyneTS compile]
JS bar-loop emit for mode compile | auto. Python object-mode analog — not Numba. auto falls back to interpret.
PyneTS compile
Abstract
PyneTS compile (mode: "compile" / "auto") emits a JavaScript bar-loop function. It is the analog of Python object-mode compile, not Numba nopython. There is no LLVM, no numba, no disk IR cache like PYNE_COMPILE_CACHE_DIR.
Landed in @hoox-sh/pynets 0.2.0. Interpret is unchanged. This PYNE checkout’s pynets/ pin is v0.2.0 and includes src/runtime/compile/. Python Runtime remains the oracle.
Conceptual model
| Python compile | PyneTS compile | |
|---|---|---|
| Backend | Numba nopython or object-mode Python loop | JS emit only |
Default Runtime.run | interpret (env override) | interpret |
auto | try compile, fallback interpret | same |
import / foreign request.* | limited; often fallback | inline registered libs; foreign → na |
| Alerts / drawings / strategy | object-mode path | __h.strategy, drawings, alertcondition |
Interface surface
import {
compileScript,
transpile,
compileEligible,
clearCompileCache,
compileCacheStats,
runScript,
CompileError,
} from "@hoox-sh/pynets";
new Runtime("AAPL", { mode: "compile" }).run(src, bars);
new Runtime("AAPL", { mode: "auto" }).run(src, bars);
| Name | Role |
|---|---|
compileEligible(tree) | { ok, reason? } |
transpile / compileScript | Emit + wrap CompiledScript |
compiled.run(open, high, low, close, volume, time, extras) | Columnar execute |
clearCompileCache / compileCacheStats | Process-local emit cache |
CLI: pynets run script.pine --mode compile or --mode auto.
What emit covers (0.2.0)
Strategy object-mode (__h.strategy / fills / events), UDF series state (src[1], var locals), array / map / matrix, UDT (Type.new, field get-set, method), drawings (label / line / box), named UDF kwargs, input overrides, color.*, enums, request.security same-symbol passthrough (foreign → na), barstate.* / syminfo stubs, calendar, str.* / str.format, import (inline registered sources; unresolved → na), session.* / chart.*, log.*, ticker.new / standard / heikinashi, request.currency_rate, alertcondition.
mode: "auto" no longer skips compile when inputs are set.
Internals
| Path | Role |
|---|---|
src/runtime/compile/engine.ts | compileScript, runScript, cache |
src/runtime/compile/emit.ts | JS text emit |
src/runtime/compile/emit_call.ts | Builtin / UDF calls |
src/runtime/compile/emit_udf.ts | User functions |
src/runtime/compile/runtime.ts | Host helpers used by emitted code |
src/runtime/interpret.ts runCompiled / runAuto | Runtime.run wiring |
Do not edit src/runtime/compile/* and src/runtime/interpret.ts in the same agent turn. Parent wires Runtime.run({ mode }).
Invariants & edge cases
- Not Numba. Do not document
nopython,njit, orPYNE_COMPILE_CACHE_DIRfor this package. - Python still wins if compiled plots disagree with Python interpret on the same script+bars — unless Python compile is the thing being compared, in which case compare apples to apples (
objectvsobject). import/ foreignrequest.*stay interpret-or-na. No invented bars.result.modereports what ran (interpretorcompile). Afterautofallback, readcompile_fallback_reason.- Compile failures in
mode: "compile"return an error envelope;autofalls back.
Worked examples
const interpret = new Runtime("AAPL", { mode: "interpret" }).run(src, bars);
const compiled = new Runtime("AAPL", { mode: "compile" }).run(src, bars);
const auto = new Runtime("AAPL", { mode: "auto" }).run(src, bars);
if (compiled.error) {
// inspect compiled.error / error_kind
}
console.log(auto.mode, auto.auto_backend, auto.compile_fallback_reason);
pynets run script.pine --mode auto --json
Failure modes
| Symptom | Cause | Fix |
|---|---|---|
CompileIneligibleError / fallback | Surface not emitted | interpret, or extend emit (parity first) |
| Plots differ interpret vs compile | Emit bug | Add test/compile_*.test.ts; Python is still SoT |
| Expecting Numba speedups | Wrong mental model | This is JS object-mode |
| Edited compile + interpret together | Review / merge hazard | Split the change |