[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 compilePyneTS compile
BackendNumba nopython or object-mode Python loopJS emit only
Default Runtime.runinterpret (env override)interpret
autotry compile, fallback interpretsame
import / foreign request.*limited; often fallbackinline registered libs; foreign → na
Alerts / drawings / strategyobject-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);
NameRole
compileEligible(tree){ ok, reason? }
transpile / compileScriptEmit + wrap CompiledScript
compiled.run(open, high, low, close, volume, time, extras)Columnar execute
clearCompileCache / compileCacheStatsProcess-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

PathRole
src/runtime/compile/engine.tscompileScript, runScript, cache
src/runtime/compile/emit.tsJS text emit
src/runtime/compile/emit_call.tsBuiltin / UDF calls
src/runtime/compile/emit_udf.tsUser functions
src/runtime/compile/runtime.tsHost helpers used by emitted code
src/runtime/interpret.ts runCompiled / runAutoRuntime.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

  1. Not Numba. Do not document nopython, njit, or PYNE_COMPILE_CACHE_DIR for this package.
  2. 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 (object vs object).
  3. import / foreign request.* stay interpret-or-na. No invented bars.
  4. result.mode reports what ran (interpret or compile). After auto fallback, read compile_fallback_reason.
  5. Compile failures in mode: "compile" return an error envelope; auto falls 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

SymptomCauseFix
CompileIneligibleError / fallbackSurface not emittedinterpret, or extend emit (parity first)
Plots differ interpret vs compileEmit bugAdd test/compile_*.test.ts; Python is still SoT
Expecting Numba speedupsWrong mental modelThis is JS object-mode
Edited compile + interpret togetherReview / merge hazardSplit the change

See also