Skip to content

feat(engine): add get_input_source and get_input_color helpers for Pine input mapping #23

Closed

Description

@luisleo526

Context

Cross-repo blocker for pineforge-codegen #9. Two Pine v6 input variants currently route to wrong/scalar engine getters because no proper helper exists.

Missing helpers

1. `get_input_source(name, const Series& default_series) -> const Series&`

Problem: Codegen routes `input.source` to `get_input_double` (scalar). Generated C++ emits e.g. `double src = 0.0; src = get_input_double("Source", current_bar_.close);` — `current_bar_.close` is captured ONCE at the call site, so any downstream `ta.sma(src, 14)` sees the same bar-0 close every bar = frozen scalar instead of a live series.

Required behavior: Engine receives a string key ("open" / "high" / "low" / "close" / "hl2" / etc.) at runtime, resolves to the matching native OHLCV Series reference, returns that reference. If no input override, returns the default series passed in (typically `_s_close`).

Analyzer contract (already enforced in pineforge-codegen): `input.source` defval MUST be a native chart series (open/high/low/close/hl2/hlc3/ohlc4/...). See codegen `_validate_plain_input_source`.

2. `get_input_color(name, int32_t default_rgba) -> int32_t`

Problem: Codegen routes `input.color` to `get_input_int`. Acceptable for now because the analyzer guard in codegen PR #13 restricts defval to `color.` / `color.new(...)` / `color.rgb(...)` — all of which already lower to packed rgba int32 via `pine_color::new_color`. The semantic gap: the runtime key→value lookup is via string parsing (`std::stoi`) which works for integer literal but is semantically wrong for a color input.

Required behavior: Mirror `get_input_int` but document the value contract as packed rgba (R<<24 | G<<16 | B<<8 | A). Could be the same impl as `get_input_int` with a renamed entry point so codegen can route per-type.

Lower priority than get_input_source — current behavior produces correct values for the constrained defval set.

Out of scope

  • `input.time` already fixed via `get_input_int64` (PR #22, merged 2026-05-28).

When this lands

After both helpers are in the engine, pineforge-codegen `_input_type_to_getter` (`pineforge_codegen/codegen/input.py:102-122`) routes:

  • `func_name == "source"` → `get_input_source`
  • `func_name == "color"` → `get_input_color`

Then codegen #9 closes fully.

Activity

  1. luisleo526 commented on May 31, 2026

    @luisleo526
    CollaboratorAuthor

    Resolved by #25 (+ codegen pineforge-4pass/pineforge-codegen#18).

    • get_input_source added: nine base source series (_src_open_.._src_hlcc4_) advanced once per script bar (gated by _src_series_active_), resolves a runtime override string to the matching native series. Codegen routes input.source to it.
    • get_input_color: intentionally NOT added. The real input.color bug was codegen-side (defval lowered to "0"); fixed there, with input.color routed to get_input_int64 (packed ARGB overflows int32). get_input_int64 already returns the correct value, so a dedicated color getter added no value.

    Verification: ctest 45/45 (new test_get_input_source); corpus 231 excellent + 1 anomaly, no regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions