PyneTS compile

JS bar-loop emit for mode compile | auto. Python object-mode analog — not Numba. auto falls back to interpret.

This page

Manuals

Full PDFComplete

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. 0.4.0 emits the later TA, matrix, drawing, strategy, and host names. 0.5.0 emits footprint mocks, plot.style_*, and alert.freq_*. Python Runtime remains the oracle.

Conceptual model

Diagram

Rendering…

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

ts
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.

0.4.0. The later interpret names: ta.uo / rci / dpo / kst / stochrsi / donchian / ichimoku / bb_pct / emv / fractal / atr_stop / zigzag, the bar-mode detectors (hammer, gap_detector, macd_signal, acceleration_factor, stoch_smooth, engulfing, inside_bar_pattern, double_top_bottom, voi, bid_ask_imbalance, rsi_oversold_overbought, rsi_divergence, cumulative_delta, volume_momentum, volume_profile_high / low, volume_thrust), matrix row/col stats, strategy.cash free cash and trade-history fields, timenow, max_bars_back, plot.linestyle_*, bare random, bare security_lower_tf, and drawing getters / *.all / *.copy / chart.point.* / line.fill. array.from collects its arguments.

0.5.0. request.footprint mock, footprint.* / volume_row.* accessors, request.seed, plot.style_*, alert.freq_*.

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

ts
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);
bash
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