pineforge-codegen 1.6.2rc1__tar.gz → 1.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/CHANGELOG.md +71 -0
  2. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/CONTRIBUTING.md +68 -1
  3. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/LEGAL.md +2 -2
  4. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/LICENSE +3 -3
  5. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/PKG-INFO +5 -5
  6. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/README.md +1 -1
  7. pineforge_codegen-1.7.0/VERSION +1 -0
  8. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/docs/PUBLIC_CONTRACT.md +44 -0
  9. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/base.py +17 -1
  10. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/emit_top.py +34 -1
  11. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/helpers.py +14 -1
  12. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/host_members.py +1 -0
  13. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/security.py +6 -3
  14. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/types.py +16 -5
  15. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/visit_call.py +111 -2
  16. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/visit_expr.py +34 -4
  17. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/visit_stmt.py +5 -0
  18. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/parser.py +29 -5
  19. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/pine_libraries.py +1 -1
  20. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/support_checker.py +21 -0
  21. pineforge_codegen-1.6.2rc1/VERSION +0 -1
  22. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/.gitignore +0 -0
  23. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/docs/codegen-coverage-gaps.md +0 -0
  24. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/docs/pine-cap-activation.md +0 -0
  25. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/__init__.py +0 -0
  26. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/analyzer/__init__.py +0 -0
  27. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/analyzer/base.py +0 -0
  28. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/analyzer/call_handlers.py +0 -0
  29. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/analyzer/contracts.py +0 -0
  30. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/analyzer/diagnostics.py +0 -0
  31. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/analyzer/tables.py +0 -0
  32. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/analyzer/types.py +0 -0
  33. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/ast_nodes.py +0 -0
  34. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/block_locals.py +0 -0
  35. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/builtin_keywords.py +0 -0
  36. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/__init__.py +0 -0
  37. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/capabilities.py +0 -0
  38. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/checked_settings.py +0 -0
  39. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/collection_history.py +0 -0
  40. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/constant_fold.py +0 -0
  41. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/drawing.py +0 -0
  42. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/helpers_syminfo.py +0 -0
  43. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/input.py +0 -0
  44. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/order_shapes.py +0 -0
  45. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/run_stops.py +0 -0
  46. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/session_market.py +0 -0
  47. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/ta.py +0 -0
  48. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/tables.py +0 -0
  49. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/codegen/tv_number_format.py +0 -0
  50. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/collection_history.py +0 -0
  51. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/cpp_allowlist.py +0 -0
  52. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/diagnostic_codes.py +0 -0
  53. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/diagnostics_catalog.json +0 -0
  54. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/errors.py +0 -0
  55. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/external_requests.py +0 -0
  56. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/finite_ta_length.py +0 -0
  57. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/lexer.py +0 -0
  58. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/library_inline.py +0 -0
  59. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/library_modules.py +0 -0
  60. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/library_v5.py +0 -0
  61. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/limits.py +0 -0
  62. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/matrix_overloads.py +0 -0
  63. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/method_binding.py +0 -0
  64. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/pine_spelling.py +0 -0
  65. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/pragmas.py +0 -0
  66. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/request_discovery.py +0 -0
  67. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/request_feed_inventory.py +0 -0
  68. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/security_contexts.py +0 -0
  69. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/session_reads.py +0 -0
  70. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/signatures.py +0 -0
  71. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/symbols.py +0 -0
  72. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/timeframe_token_cli.py +0 -0
  73. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/tokens.py +0 -0
  74. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pineforge_codegen/tv_input_choices.py +0 -0
  75. {pineforge_codegen-1.6.2rc1 → pineforge_codegen-1.7.0}/pyproject.toml +0 -0
@@ -20,6 +20,77 @@ supported as exact pairs; on the 0.x line they are independent. See the
20
20
  the release commit. A prerelease note describes changes since the preceding
21
21
  prerelease or stable tag; the final stable note consolidates the series.
22
22
 
23
+ ## 1.7.0 — 2026-10-25
24
+
25
+ A minor release of the exact engine/codegen pair, paired with engine `v1.7.0`
26
+ and dated 2026-10-25. This entry records what changed in this repository since
27
+ 1.6.3, and nothing else: three pull requests merged after `v1.6.3`, one of which
28
+ changes the emitted C++ and the other two only the repository's own CI.
29
+
30
+ ### Compatibility and migration
31
+
32
+ - Pairs with engine `v1.7.0` exactly. Regenerate strategy C++ with this release
33
+ and relink every strategy library against the engine `v1.7.0` headers and
34
+ `libpineforge.a`; this applies even when the C ABI number is unchanged
35
+ (README [Engine pairing](README.md#engine-pairing)). Replacing the archive
36
+ alone does not update a statically linked strategy library.
37
+ - The emitted C++ changes, as described below: every generated library gains a
38
+ new exported function, the generated constructor gains a guarded statement
39
+ for scripts that do not read closed-trade rows, and the set of reserved names
40
+ grows. The Python API, the diagnostic codes and severities, and the catalog
41
+ schema are not changed; the order-shapes receipt's `host_reads` list gains
42
+ `set_trade_history_streamable` for scripts that do not read closed-trade rows.
43
+ - Engine behavior changes are described in the paired engine's own release
44
+ notes; this entry does not summarize them.
45
+
46
+ ### Changes since 1.6.3
47
+
48
+ - Declare whether the emitted code reads closed-trade rows, and let scripts that
49
+ do not read them opt into streamed trade history
50
+ ([#213](https://github.com/pineforge-4pass/pineforge-codegen-oss/pull/213)).
51
+ Generated libraries now export `int strategy_reads_trade_history(void)`: `1`
52
+ when the emitted code reads a `strategy.closedtrades.*` accessor, `0` when it
53
+ does not. The closed-trade count (`strategy.closedtrades` alone) and the
54
+ open-trade accessors (`strategy.opentrades.*`) do not count as reads. For a
55
+ script that does not read closed-trade rows, the generated constructor calls
56
+ `this->set_trade_history_streamable(true)`, guarded by
57
+ `#if defined(PINEFORGE_HAS_TRADE_HISTORY_POLICY_V1)` so that it compiles
58
+ against engine headers that lack the setter; a script that reads closed-trade
59
+ rows emits no such call, and the order-shapes receipt's `host_reads` names the
60
+ setter for non-readers only. The constructor's host calls are now qualified
61
+ (`this->configure_pine_strategy(cfg)`). A library generated by an earlier
62
+ release has no such export, and its absence does not establish that the
63
+ script is a non-reader. What the engine does with the streaming setting is
64
+ described in the engine `v1.7.0` release notes.
65
+ - Reserve more names in generated C++ and escape them as `pf_safe_<name>` when a
66
+ Pine identifier uses one (same pull request, documented in the new
67
+ "Identifiers in generated C++" section of
68
+ [docs/PUBLIC_CONTRACT.md](docs/PUBLIC_CONTRACT.md)): the engine namespaces and
69
+ types that `using namespace pineforge;` brings into scope (`report`,
70
+ `report_sink`, `report_sequence`, `source`, `native_calendar`, `pine_color`,
71
+ `RunFailureCode`, `RunFailureInfo`, `QtyType`, `CommissionType`, `XLoc`,
72
+ `YLoc`, `normalize_timezone_for_posix`), the generated C exports
73
+ (`strategy_create`, `strategy_create_checked`, `run_backtest`,
74
+ `run_backtest_full`, `run_backtest_full_checked`, `strategy_free`,
75
+ `report_free`, `strategy_set_input`, `strategy_set_input_checked`,
76
+ `strategy_set_override`, `strategy_set_override_checked`,
77
+ `strategy_set_magnifier_volume_weighted` and the new
78
+ `strategy_reads_trade_history`), the feature macros
79
+ `PINEFORGE_HAS_TRADE_HISTORY_POLICY_V1` and
80
+ `PINEFORGE_HAS_SYMBOL_SECURITY_EVAL_V1`, and the host member
81
+ `set_trade_history_streamable`. A Pine `type report`, for example, now becomes
82
+ `struct pf_safe_report`; before, such a script could fail to compile against the
83
+ 1.7.0 engine headers with an ambiguous reference. User-defined type handles
84
+ and `request.security` evaluators use the escaped spelling too. An identifier
85
+ that does not collide keeps its spelling. The existing `CPP_RESERVED` export lists the new
86
+ names; no new reserved-name API is introduced.
87
+ - Repository and CI only, no effect on emitted C++ or on the Python and JSON
88
+ contract: the `promote-baseline` workflow refuses untrusted heads and actors
89
+ (SEC846,
90
+ [#242](https://github.com/pineforge-4pass/pineforge-codegen-oss/pull/242)),
91
+ and `test.yml` adopts the organization's CI canon (CR-241,
92
+ [#243](https://github.com/pineforge-4pass/pineforge-codegen-oss/pull/243)).
93
+
23
94
  ## 1.6.1 — 2026-10-18
24
95
 
25
96
  A patch release of the exact engine/codegen pair, paired with engine `v1.6.1`
@@ -4,7 +4,7 @@ This is the source-available PineScript v6 to C++ translator. Read the
4
4
  [license and contribution terms](LEGAL.md) before sending a material change.
5
5
  Contributions use the Developer Certificate of Origin: add a `Signed-off-by`
6
6
  line with `git commit -s`. Material contributions also require a Contributor
7
- License Agreement so pineforge, LLC can include them in its commercial licenses;
7
+ License Agreement so PINEFORGE LLC can include them in its commercial licenses;
8
8
  contact luis@4pass.com.tw before opening a material pull request.
9
9
 
10
10
  ## Local setup
@@ -109,6 +109,73 @@ the Python `build` frontend, run `python -m build`, assemble the npm payload,
109
109
  then run `npm pack --dry-run` from `npm/`. These commands build local artifacts;
110
110
  publishing is a separate release operation.
111
111
 
112
+ `promote-baseline.yml` runs from the base repository on `pull_request_target`
113
+ closes and `workflow_dispatch`, and its credential job depends on
114
+ `promote-guard`. The guard has empty job permissions, holds no secrets, and
115
+ checks out no code. Every pull request close first requires a head in this
116
+ repository with `fork == false`, even when unmerged. An author outside
117
+ `OWNER`/`MEMBER`/`COLLABORATOR` and the
118
+ `dependabot[bot]`/`pineforge-app[bot]` allowlist must have
119
+ `admin`/`maintain`/`write` permission returned by GitHub, including a
120
+ `CONTRIBUTOR` whose organization membership is private. A failed author
121
+ lookup, an empty permission, or a non-write permission refuses the close
122
+ before any unmerged exit or merger check.
123
+ A merged pull request also requires an allowlisted merger or a successful
124
+ `admin`/`maintain`/`write` permission lookup for the merger. An empty merger,
125
+ a failed merger lookup, or an empty or non-write merger permission refuses
126
+ promotion.
127
+ An unmerged close of our own allowed pull request passes the guard with
128
+ promotion skipped. Manual dispatch requires repository write access, and
129
+ every other event is refused.
130
+
131
+ ## npm publication (operators)
132
+
133
+ The release and npm publication workflows run on GitHub-hosted runners.
134
+ Run both workflows with `workflow_dispatch` on `main`.
135
+ `release.yml` publishes to PyPI, commits and pushes the release tag, then
136
+ creates the GitHub Release and notifies the release hub. After the tag exists
137
+ on main and the release job is green, the operator doing the cut, using a
138
+ GitHub account with write access, publishes npm with this separate dispatch:
139
+
140
+ ```sh
141
+ gh workflow run publish-pyodide.yml --repo pineforge-4pass/pineforge-codegen-oss --ref main -f tag=<tag> -f dry_run=false
142
+ ```
143
+
144
+ Use the existing release tag in place of `<tag>`. Set `dry_run=true` to
145
+ validate first. A tag push alone publishes nothing. A green `release.yml`
146
+ run does not mean npm published; watch the `publish-pyodide.yml` run.
147
+ Every npm run requires an existing release tag, including dry runs and
148
+ placeholder claims. Its first job, `tag-guard`, has only Contents read
149
+ permission and checks out main with credentials persistence disabled. It
150
+ checks the dispatch ref is `refs/heads/main`, validates the release pattern
151
+ (`vX.Y.Z` or `vX.Y.Z-{alpha,beta,rc}.N`) before using the input in git,
152
+ fetches tags and full main history, peels the tag to a 40-hex commit and
153
+ checks that commit is an ancestor of `refs/remotes/origin/main`.
154
+ A missing tag, a tag that cannot peel to a commit, an invalid name or a tag
155
+ outside main fails the run before either npm job can start. Publish checks
156
+ out the verified commit SHA with credentials persistence disabled, verifies
157
+ its `VERSION`, and runs the gate before publishing. The workflow run stays
158
+ at `refs/heads/main` while its checkout uses the pinned commit; moving the tag
159
+ after verification does not change what gets built.
160
+
161
+ For a manual npm dry run, dispatch `publish-pyodide.yml` on `main` with
162
+ `dry_run=true` and an existing release `tag` on main. For a real npm retry
163
+ after a successful tag push, dispatch on `main` with the existing release
164
+ `tag` and `dry_run=false`. A placeholder claim uses `claim_placeholder=true`
165
+ and the same required tag guard. The guard fails a dispatch at another ref;
166
+ both npm jobs also retain their main-ref job conditions and require the
167
+ guard to succeed.
168
+ The guard and job conditions live in the workflow file on `main`, but GitHub
169
+ executes the file from the dispatched ref, so they alone cannot stop a user
170
+ with write access who pushes and dispatches a modified workflow on another
171
+ branch. The server-side bound is the GitHub environment `npm-publish`: both npm
172
+ jobs (`publish` and `claim-npm`) run in it, and it carries a `main`-only
173
+ deployment-branch policy, so a run from any other ref is refused by GitHub. The
174
+ npm trusted publisher for the package is set by the repository owner to require
175
+ that environment (owner decision NPM-TP; that setting lives on npmjs.com and
176
+ cannot be read from this repository), so a publish from a workflow that does not
177
+ declare the environment fails at npm.
178
+
112
179
  ## Change and review notes
113
180
 
114
181
  - Add or update tests for behavior changes. Keep the engine corpus compiling;
@@ -19,7 +19,7 @@ The PineForge Source License 1.1 replaced 1.0, and 1.2 replaces 1.1, for the cod
19
19
 
20
20
  ## Copyright and licensor
21
21
 
22
- The licensor is **pineforge, LLC**, a Delaware limited liability company. It holds the copyright in `pineforge-codegen`; the founder's rights in the software are assigned to it. Commercial licenses are granted by pineforge, LLC.
22
+ The licensor is **PINEFORGE LLC**, a Delaware limited liability company. It holds the copyright in `pineforge-codegen`; the founder's rights in the software are assigned to it. Commercial licenses are granted by PINEFORGE LLC.
23
23
 
24
24
  ## What this repository is
25
25
 
@@ -35,7 +35,7 @@ The transpiler has **no runtime dependencies** (`transpile()` and `transpile_ful
35
35
 
36
36
  ## Contributions
37
37
 
38
- Contributions are accepted under a Developer Certificate of Origin (`Signed-off-by`). Because this project is **dual-licensed** (source-available + a sold commercial license), material contributions require a Contributor License Agreement granting pineforge, LLC the right to include the contribution in its commercial licenses; otherwise it cannot be accepted. See [CONTRIBUTING.md](CONTRIBUTING.md) (or contact luis@4pass.com.tw) before opening a material PR.
38
+ Contributions are accepted under a Developer Certificate of Origin (`Signed-off-by`). Because this project is **dual-licensed** (source-available + a sold commercial license), material contributions require a Contributor License Agreement granting PINEFORGE LLC the right to include the contribution in its commercial licenses; otherwise it cannot be accepted. See [CONTRIBUTING.md](CONTRIBUTING.md) (or contact luis@4pass.com.tw) before opening a material PR.
39
39
 
40
40
  ## No warranty
41
41
 
@@ -9,9 +9,9 @@ person's own account or capital. In the Commercial Use section, the
9
9
  definition of investment capital now covers the capital in such an
10
10
  account, real or simulated.
11
11
 
12
- Copyright 2025-2026 pineforge, LLC
12
+ Copyright 2025-2026 PINEFORGE LLC
13
13
 
14
- Required Notice: Copyright 2025-2026 pineforge, LLC (https://github.com/pineforge-4pass/pineforge-codegen-oss)
14
+ Required Notice: Copyright 2025-2026 PINEFORGE LLC (https://github.com/pineforge-4pass/pineforge-codegen-oss)
15
15
 
16
16
  The software is free of charge for the permitted purposes below, including
17
17
  Personal Trading. Commercial Use, defined below, needs a separate commercial
@@ -242,7 +242,7 @@ kind of legal claim.***
242
242
 
243
243
  ## Definitions
244
244
 
245
- The **licensor** is pineforge, LLC, and the **software** is the software the
245
+ The **licensor** is PINEFORGE LLC, and the **software** is the software the
246
246
  licensor makes available under these terms.
247
247
 
248
248
  **You** refers to the individual or entity agreeing to these terms.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pineforge-codegen
3
- Version: 1.6.2-rc.1
3
+ Version: 1.7.0
4
4
  Summary: PineScript v6 to C++ transpiler that targets the pineforge-engine runtime.
5
5
  Project-URL: Homepage, https://github.com/pineforge-4pass/pineforge-codegen-oss
6
6
  Project-URL: Issues, https://github.com/pineforge-4pass/pineforge-codegen-oss/issues
@@ -18,9 +18,9 @@ License: PineForge Source License 1.2
18
18
  definition of investment capital now covers the capital in such an
19
19
  account, real or simulated.
20
20
 
21
- Copyright 2025-2026 pineforge, LLC
21
+ Copyright 2025-2026 PINEFORGE LLC
22
22
 
23
- Required Notice: Copyright 2025-2026 pineforge, LLC (https://github.com/pineforge-4pass/pineforge-codegen-oss)
23
+ Required Notice: Copyright 2025-2026 PINEFORGE LLC (https://github.com/pineforge-4pass/pineforge-codegen-oss)
24
24
 
25
25
  The software is free of charge for the permitted purposes below, including
26
26
  Personal Trading. Commercial Use, defined below, needs a separate commercial
@@ -251,7 +251,7 @@ License: PineForge Source License 1.2
251
251
 
252
252
  ## Definitions
253
253
 
254
- The **licensor** is pineforge, LLC, and the **software** is the software the
254
+ The **licensor** is PINEFORGE LLC, and the **software** is the software the
255
255
  licensor makes available under these terms.
256
256
 
257
257
  **You** refers to the individual or entity agreeing to these terms.
@@ -931,7 +931,7 @@ use `python -m pytest --collect-only -q` for the current collection count.
931
931
  ## License
932
932
 
933
933
  Source-available under the [PineForge Source License 1.2](https://github.com/pineforge-4pass/pineforge-codegen-oss/blob/main/LICENSE);
934
- the `LICENSE` file is the controlling text. The licensor is pineforge, LLC.
934
+ the `LICENSE` file is the controlling text. The licensor is PINEFORGE LLC.
935
935
 
936
936
  - **Free for noncommercial use:** any noncommercial purpose, and use by a
937
937
  charitable organization, educational institution, public research
@@ -646,7 +646,7 @@ use `python -m pytest --collect-only -q` for the current collection count.
646
646
  ## License
647
647
 
648
648
  Source-available under the [PineForge Source License 1.2](https://github.com/pineforge-4pass/pineforge-codegen-oss/blob/main/LICENSE);
649
- the `LICENSE` file is the controlling text. The licensor is pineforge, LLC.
649
+ the `LICENSE` file is the controlling text. The licensor is PINEFORGE LLC.
650
650
 
651
651
  - **Free for noncommercial use:** any noncommercial purpose, and use by a
652
652
  charitable organization, educational institution, public research
@@ -0,0 +1 @@
1
+ 1.7.0
@@ -7,6 +7,50 @@ Text marked **since 1.5.0** describes diagnostic additions that 1.4.0 and
7
7
  earlier releases do not have: the `note` severity, the `user_message` template
8
8
  and the eleven codes that became notes.
9
9
 
10
+ ## Identifiers in generated C++
11
+
12
+ Legal Pine identifiers that collide with C++ keywords, engine names or emitter
13
+ temporaries are escaped in generated C++; they remain valid Pine names. The
14
+ existing `pineforge_codegen.codegen.CPP_RESERVED` export contains the explicit
15
+ reserved names. `_safe_name` also escapes emitter temporary patterns and
16
+ allocates a distinct name when the script already uses the preferred escape.
17
+ An identifier that does not collide keeps its spelling.
18
+
19
+ The imported engine names `report`, `report_sink`, `report_sequence`, `source`,
20
+ `native_calendar`, `pine_color`, `RunFailureCode`, `RunFailureInfo`, `QtyType`,
21
+ `CommissionType`, `XLoc`, `YLoc` and `normalize_timezone_for_posix` are reserved
22
+ because `using namespace pineforge;` brings them into unqualified lookup. A Pine
23
+ `type report`, for example, becomes `struct pf_safe_report` and its references
24
+ use that name. These names live in `codegen/helpers.py`'s
25
+ `CPP_EMITTER_NAMES`, which also reserves the generated C export
26
+ `strategy_reads_trade_history`. A Pine type or function of that name uses
27
+ `pf_safe_strategy_reads_trade_history`; the export keeps its public spelling.
28
+ The same set explicitly reserves the exports `strategy_create`,
29
+ `strategy_create_checked`, `run_backtest`, `run_backtest_full`, `strategy_free`,
30
+ `report_free`, `strategy_set_input`, `strategy_set_override`,
31
+ `strategy_set_magnifier_volume_weighted`, `strategy_set_input_checked`,
32
+ `strategy_set_override_checked` and `run_backtest_full_checked`. Pine identifiers
33
+ use `pf_safe_<name>`; these exports keep their public spellings.
34
+ `CPP_STANDARD_MACROS` reserves `PINEFORGE_HAS_TRADE_HISTORY_POLICY_V1`, so a Pine
35
+ variable of that name uses `pf_safe_PINEFORGE_HAS_TRADE_HISTORY_POLICY_V1`
36
+ instead of expanding the engine's feature macro in a declaration. It also
37
+ explicitly reserves `PINEFORGE_HAS_SYMBOL_SECURITY_EVAL_V1`, using the same
38
+ `pf_safe_` escape for a Pine identifier.
39
+ `codegen/host_members.py`'s `HOST_MEMBER_NAMES` separately reserves the public or
40
+ protected host members the emitter spells, including
41
+ `set_trade_history_streamable`, inherited from `BacktestEngine`. All three sets
42
+ feed the existing `CPP_RESERVED` export; no new reserved-name API is introduced.
43
+
44
+ Since the 1.7.0 trade-history policy addition, generated libraries export
45
+ `int strategy_reads_trade_history(void)`: `1` means the emitted code reads
46
+ closed-trade rows, and `0` means no such read was emitted. A closed-trade count
47
+ alone does not require those rows. For a non-reader, the constructor calls
48
+ `set_trade_history_streamable(true)` under
49
+ `PINEFORGE_HAS_TRADE_HISTORY_POLICY_V1`; a reader emits no policy call.
50
+ The order-shapes receipt's `host_reads` therefore includes the setter only for
51
+ non-readers. Older generated libraries can lack the export; its absence does
52
+ not establish that the script is a non-reader.
53
+
10
54
  ## Optional compiled execution capabilities
11
55
 
12
56
  Availability: **since 1.2.0**, with engine `v1.2.0`'s capability extension and
@@ -413,6 +413,11 @@ class CodeGen(CallVisitor, ExprVisitor, StmtVisitor, TopLevelEmitter, SecurityEm
413
413
  # Set when a chart expression calls ``_pf_session_market_``; its type
414
414
  # and member are emitted once the whole TU is lowered.
415
415
  self._uses_session_market: bool = False
416
+ # Set while lowering a closed-trade accessor. The constructor is
417
+ # emitted before user bodies, so _generate_cpp resolves the deferred
418
+ # policy marker after every expression (including security evaluators
419
+ # and @pf-trace expressions) has been emitted.
420
+ self._reads_trade_history: bool = False
416
421
  # session.* reads inside a request.security payload already warned.
417
422
  self._warned_security_session_sites: set[int] = set()
418
423
  # Top-level lazy-edge TA sites hoisted to every-bar evaluation for the
@@ -905,6 +910,10 @@ class CodeGen(CallVisitor, ExprVisitor, StmtVisitor, TopLevelEmitter, SecurityEm
905
910
  self._security_calls: list[dict] = [self._normalize_security_call(item) for item in ctx.security_calls]
906
911
  # Current function parameter types (set during _emit_func_def)
907
912
  self._current_func_param_types: dict[str, str] = {}
913
+ # The emitted C++ type of each tuple-destructuring binding, so a field
914
+ # read can recognise a chart.point binding whose TypeSpec is a
915
+ # deliberate tombstone.
916
+ self._tuple_binding_cpp_types_by_name: dict[str, str] = {}
908
917
  self._current_func_param_specs: dict[str, "TypeSpec"] = {}
909
918
  # Copy-on-write lexical collection inventory for the function/method
910
919
  # currently being emitted. Activated by _emit_func_def and restored
@@ -1980,7 +1989,7 @@ class CodeGen(CallVisitor, ExprVisitor, StmtVisitor, TopLevelEmitter, SecurityEm
1980
1989
  if udt_spec is not None
1981
1990
  else member_udt_type
1982
1991
  )
1983
- handle_cpp = DRAWING_TYPE_TO_CPP.get(udt_t, udt_t)
1992
+ handle_cpp = DRAWING_TYPE_TO_CPP.get(udt_t, self._safe_name(udt_t))
1984
1993
  lines.append(f" {handle_cpp} {cloned_safe} = {handle_cpp}{{}};")
1985
1994
  elif vname in self._runtime_scalar_var_init_members:
1986
1995
  # Declaration-site state may remain unreached while COOF
@@ -5454,6 +5463,13 @@ class CodeGen(CallVisitor, ExprVisitor, StmtVisitor, TopLevelEmitter, SecurityEm
5454
5463
  # 11b. security evaluators
5455
5464
  self._emit_security_evaluators(lines)
5456
5465
 
5466
+ # ``_emit_constructor`` runs before function bodies and security
5467
+ # evaluators, while the trade-history read flag is set by the call
5468
+ # visitor. Resolve its constructor marker only after all emission is
5469
+ # complete so no generated path can accidentally opt a reader into
5470
+ # streaming.
5471
+ self._settle_trade_history_policy(lines)
5472
+
5457
5473
  # 12. Close class
5458
5474
  lines.append("};")
5459
5475
  lines.append("")
@@ -40,6 +40,9 @@ Mixin contract — host class must provide the following attributes
40
40
  - ``self._map_vars`` (``set[str]``): map-typed var members.
41
41
  - ``self._strategy_series_vars`` (``set[str]``): series mirrors of
42
42
  ``strategy.*`` member values pushed every bar.
43
+ - ``self._reads_trade_history`` (``bool``): set when emitted code reads a
44
+ ``strategy.closedtrades.*`` accessor; drives the deferred retention policy
45
+ and the exported reader bit.
43
46
  - ``self._timeframe_period_vars`` (``set[str]``): identifiers that
44
47
  resolve to ``script_tf_`` in ``configure_security_evaluators``.
45
48
  - ``self._udt_defs`` (``dict[str, list]``): UDT name -> field info,
@@ -106,6 +109,9 @@ from .drawing import DRAWING_LIFETIME_CPP
106
109
  from .tv_number_format import TV_NUMBER_FORMAT_CPP
107
110
 
108
111
 
112
+ _TRADE_HISTORY_POLICY_MARKER = " /* __PINEFORGE_TRADE_HISTORY_POLICY__ */"
113
+
114
+
109
115
  class TopLevelEmitter:
110
116
  """Mixin owning the top-level C++ section emitters and the
111
117
  per-function emitters used by regular Pine functions and UDT
@@ -1234,7 +1240,12 @@ class TopLevelEmitter:
1234
1240
  if self._script_has_input_source():
1235
1241
  ctor_body.append(" cfg.src_series_active = true;")
1236
1242
 
1237
- ctor_body.append(" configure_pine_strategy(cfg);")
1243
+ # The call is resolved after all bodies have been lowered because
1244
+ # closed-trade reads are discovered by the expression visitor. Keep a
1245
+ # marker in the constructor so the policy cannot be enabled for a
1246
+ # reader merely because the constructor is emitted first.
1247
+ ctor_body.append(_TRADE_HISTORY_POLICY_MARKER)
1248
+ ctor_body.append(" this->configure_pine_strategy(cfg);")
1238
1249
 
1239
1250
  if init_parts and ctor_body:
1240
1251
  lines.append(f" explicit GeneratedStrategy() : {', '.join(init_parts)} {{")
@@ -1895,6 +1906,25 @@ class TopLevelEmitter:
1895
1906
  )
1896
1907
  lines.append(f"{pad}}}")
1897
1908
 
1909
+ def _settle_trade_history_policy(self, lines: list[str]) -> None:
1910
+ """Resolve the constructor's deferred trade-history policy marker."""
1911
+ try:
1912
+ marker = lines.index(_TRADE_HISTORY_POLICY_MARKER)
1913
+ except ValueError as exc: # pragma: no cover - generation invariant
1914
+ raise AssertionError(
1915
+ "generated constructor lost its trade-history policy marker"
1916
+ ) from exc
1917
+
1918
+ if self._reads_trade_history:
1919
+ del lines[marker]
1920
+ return
1921
+
1922
+ lines[marker:marker + 1] = [
1923
+ "#if defined(PINEFORGE_HAS_TRADE_HISTORY_POLICY_V1)",
1924
+ " this->set_trade_history_streamable(true);",
1925
+ "#endif",
1926
+ ]
1927
+
1898
1928
  def _emit_extern_c(self, lines: list[str]) -> None:
1899
1929
  lines.append('extern "C" {')
1900
1930
  lines.append("#if defined(PINEFORGE_HAS_RUN_FAILURE_CODES_V1) && defined(PF_SETTINGS_API_VERSION)")
@@ -2016,6 +2046,9 @@ class TopLevelEmitter:
2016
2046
  from .checked_settings import emit_settings_exports
2017
2047
  emit_settings_exports(lines)
2018
2048
  self._capabilities_export_at = len(lines)
2049
+ lines.append(" int strategy_reads_trade_history(void) {")
2050
+ lines.append(f" return {1 if self._reads_trade_history else 0};")
2051
+ lines.append(" }")
2019
2052
  if self._declares_bar_magnifier():
2020
2053
  # TradingView runs a script that declares use_bar_magnifier = true
2021
2054
  # on its bar magnifier; the host reads this export to run it on
@@ -263,6 +263,8 @@ CPP_STANDARD_MACROS = frozenset("""
263
263
  PINEFORGE_HAS_AUX_SECURITY_FEED_V1 PINEFORGE_HAS_SCRIPT_RUN_PREPARE_V1
264
264
  PINEFORGE_HAS_EXPLICIT_PINE_CAP_V1
265
265
  PINEFORGE_HAS_RUN_FAILURE_CODES_V1
266
+ PINEFORGE_HAS_TRADE_HISTORY_POLICY_V1
267
+ PINEFORGE_HAS_SYMBOL_SECURITY_EVAL_V1
266
268
  _PF_NO_DATA_STOP _PF_OTHER_SYMBOL_STOP _PF_ARRAY_STOP _PF_COLLECTION_STOP
267
269
  _PF_NA_STOP _PF_LIMIT_STOP _PF_UNSUPPORTED_STOP _PF_STRING_STOP
268
270
  _PF_ENGINE_INVARIANT _PF_INVARIANT_AT _PF_SETTING_FAILURE
@@ -279,11 +281,16 @@ CPP_STANDARD_MACROS = frozenset("""
279
281
  # Identifiers used by the emitter as class/type names, namespaces, and
280
282
  # generated or inherited methods. A user member with one of these names can
281
283
  # hide a type/callee, or (GeneratedStrategy) conflict with the constructor.
284
+ # Engine namespaces, types and callees are imported by ``using namespace
285
+ # pineforge``; an authored UDT can make its unqualified type reads ambiguous.
282
286
  CPP_EMITTER_NAMES = frozenset("""
283
287
  GeneratedStrategy BacktestEngine Bar Series PineArray PineMap PineMatrix
284
288
  PineGenericMatrix PineStrategyConfig PineStrategyHost StrategyOverrides
285
289
  SymInfo ReportC MagnifierDistribution ChartPoint Line Box Label Linefill
286
- std pineforge ta math
290
+ std pineforge ta math report report_sink report_sequence
291
+ source native_calendar RunFailureCode
292
+ pine_color QtyType CommissionType XLoc YLoc RunFailureInfo
293
+ normalize_timezone_for_posix
287
294
  on_bar on_source_bar prepare_script_run configure_pine_strategy
288
295
  configure_security_evaluators snapshot_script_state restore_script_state
289
296
  commit_script_state set_strategy_override set_input
@@ -292,6 +299,12 @@ CPP_EMITTER_NAMES = frozenset("""
292
299
  strategy_confirmed_bar_api_version strategy_confirmed_bar_receipt
293
300
  strategy_order_shapes_api_version strategy_order_shapes_receipt
294
301
  strategy_settings_api_version strategy_get_effective_settings
302
+ strategy_create strategy_create_checked strategy_free report_free
303
+ run_backtest run_backtest_full run_backtest_full_checked
304
+ strategy_set_input strategy_set_input_checked
305
+ strategy_set_override strategy_set_override_checked
306
+ strategy_set_magnifier_volume_weighted
307
+ strategy_reads_trade_history
295
308
  precalculate
296
309
  strategy_entry strategy_close strategy_close_all strategy_exit
297
310
  strategy_exit_cancel_bracket strategy_cancel strategy_cancel_all strategy_order
@@ -150,6 +150,7 @@ HOST_MEMBER_NAMES = frozenset({
150
150
  "set_pine_risk_max_position_size",
151
151
  "set_recorded_series",
152
152
  "set_strategy_override",
153
+ "set_trade_history_streamable",
153
154
  "signed_position_size",
154
155
  "snapshot_script_state",
155
156
  "strategy_cancel",
@@ -1074,21 +1074,24 @@ class SecurityEmitter:
1074
1074
  for name, bound in frame.items():
1075
1075
  if not isinstance(bound, str):
1076
1076
  continue
1077
+ # Match the expression visitor's C++ spelling, as the
1078
+ # mutable-global rewrite above does.
1079
+ safe = self._safe_name(name)
1077
1080
  series_name = self._security_series_binding_target(bound)
1078
1081
  if series_name is not None:
1079
1082
  ref = self._security_helper_series_ref(series_name)
1080
1083
  result = sub(
1081
- rf"\b{re.escape(name)}\b(?=\s*\[)",
1084
+ rf"\b{re.escape(safe)}\b(?=\s*\[)",
1082
1085
  ref.replace("\\", "\\\\"),
1083
1086
  result,
1084
1087
  )
1085
1088
  result = sub(
1086
- rf"\b{re.escape(name)}\b(?!\s*\[)",
1089
+ rf"\b{re.escape(safe)}\b(?!\s*\[)",
1087
1090
  f"{ref}[0]".replace("\\", "\\\\"),
1088
1091
  result,
1089
1092
  )
1090
1093
  else:
1091
- result = sub(rf"\b{re.escape(name)}\b", bound, result)
1094
+ result = sub(rf"\b{re.escape(safe)}\b", bound, result)
1092
1095
  return result
1093
1096
 
1094
1097
  def _security_lookup_helper_binding(
@@ -507,16 +507,25 @@ class TypeInferer:
507
507
  def _default_for_spec(self, spec: TypeSpec | None) -> str:
508
508
  """Default initialiser for a TypeSpec; vector/map specs get ``T()``.
509
509
 
510
- UDT specs always brace-init (``T{}``) regardless of whether the UDT was
511
- declared in the current translation unit — imported / forward-declared
512
- UDTs would otherwise fall through to ``0`` which is type-incompatible.
510
+ A user type brace-inits its struct name when the type is declared in
511
+ this translation unit (an imported type is inlined before codegen).
512
+ An enum element defaults to the double ``na`` (its slot is a double);
513
+ an undeclared name is not a C++ type and falls back to its slot's
514
+ default.
513
515
  """
514
516
  if spec is not None and spec.kind == "udt" and spec.name:
515
517
  # Drawing handle default (P2): brace-init the C++ struct name
516
518
  # (Line{} = na handle), NOT the lowercase Pine name (line{}).
517
519
  if spec.name in DRAWING_TYPE_TO_CPP:
518
520
  return f"{DRAWING_TYPE_TO_CPP[spec.name]}{{}}"
519
- return f"{self._safe_name(spec.name)}{{}}"
521
+ if spec.name in getattr(self, "_enum_defs", ()):
522
+ # An enum's element slot is a double (``_type_spec_to_cpp``);
523
+ # the absent value is na<double>(), not the first member and
524
+ # not the integer sentinel, which a double does not carry.
525
+ return "na<double>()"
526
+ if spec.name in getattr(self, "_udt_defs", ()):
527
+ return f"{self._safe_name(spec.name)}{{}}"
528
+ return self._default_for_type(self._type_spec_to_cpp(spec))
520
529
  cpp_type = self._type_spec_to_cpp(spec)
521
530
  if cpp_type.startswith("std::vector") or cpp_type.startswith("PineMap"):
522
531
  return f"{cpp_type}()"
@@ -4047,7 +4056,9 @@ class TypeInferer:
4047
4056
  return "int"
4048
4057
  # format.* constants emit std::string literals (consumed by
4049
4058
  # pine_str_tostring); bare reads must declare std::string.
4050
- if ename == "format":
4059
+ if ename in ("format", "currency", "order"):
4060
+ return "std::string"
4061
+ if ename == "session" and node.member in ("regular", "extended"):
4051
4062
  return "std::string"
4052
4063
  if ename == "alert" and node.member in ALERT_FREQ_VALUES:
4053
4064
  return "std::string"
@@ -196,6 +196,50 @@ from .tables import (
196
196
  _merge_kwargs,
197
197
  )
198
198
 
199
+ # Pine member names the codegen has a lowering for somewhere. A method the
200
+ # type resolver cannot route back to one of these tables (a history read of a
201
+ # UDT collection field, for example) keeps its historical pass-through
202
+ # spelling; anything else is not a Pine method and must not become C++ text.
203
+ PINEFORGE_MEMBER_NAMES = frozenset(
204
+ ARRAY_METHODS
205
+ ) | frozenset(MAP_METHODS) | frozenset(MATRIX_METHODS) | frozenset(
206
+ ALL_DRAWING_METHODS
207
+ )
208
+
209
+
210
+ def _spec_for_cpp_param(cpp: str | None):
211
+ """A TypeSpec for an untyped parameter's emitted C++ type, if known.
212
+
213
+ Only ``std::string`` is resolved: it carries C++ members of its own, so a
214
+ Pine method name that collides (``copy``, ``size``, ``clear``) must not
215
+ pass through. A numeric parameter has no such members; a collection
216
+ parameter is resolved by its own spec before this fallback.
217
+ """
218
+ if cpp == "std::string":
219
+ return TypeSpec.primitive("string")
220
+ return None
221
+
222
+
223
+ def _member_name_has_lowering(recv_spec, name: str) -> bool:
224
+ """Whether ``name`` is a Pine method of a receiver of ``recv_spec``.
225
+
226
+ A resolved receiver admits only its own namespace's table: a string has no
227
+ Pine methods, so a name like ``size`` or ``copy`` must not reach
228
+ ``std::string``. An unresolved receiver keeps the historical pass-through
229
+ for any Pine method name.
230
+ """
231
+ if recv_spec is None:
232
+ return name in PINEFORGE_MEMBER_NAMES
233
+ if recv_spec.kind == "array":
234
+ return name in ARRAY_METHODS
235
+ if recv_spec.kind == "map":
236
+ return name in MAP_METHODS
237
+ if recv_spec.kind == "matrix":
238
+ return name in MATRIX_METHODS
239
+ if recv_spec.kind == "udt" and recv_spec.name in DRAWING_TYPE_TO_CPP:
240
+ return name in ALL_DRAWING_METHODS
241
+ return False
242
+
199
243
 
200
244
  def _parse_pine_datestring_ms(text: str) -> int | None:
201
245
  """Parse a Pine ``timestamp(dateString)`` literal to Unix milliseconds.
@@ -310,6 +354,25 @@ class CallVisitor:
310
354
  # Function-call dispatch
311
355
  # ------------------------------------------------------------------
312
356
 
357
+ def _reject_unknown_element_type(self, node, element_spec) -> None:
358
+ """Refuse an element type that is not a type this unit can name.
359
+
360
+ The support checker normally refuses it; a switch arm downgrades that
361
+ error to a warning, so the emitter checks again and never defaults an
362
+ undeclared name.
363
+ """
364
+ if (element_spec is not None and element_spec.kind == "udt"
365
+ and element_spec.name
366
+ and element_spec.name not in self._udt_defs
367
+ and element_spec.name not in self._enum_defs
368
+ and element_spec.name not in DRAWING_TYPE_TO_CPP
369
+ and element_spec.name not in ("table", "polyline")):
370
+ full = element_spec.name
371
+ self._codegen_error(
372
+ node,
373
+ f"{full}(...) is not implemented in PineForge runtime.",
374
+ )
375
+
313
376
  def _udt_method_call_emit_name(self, fi, node: FuncCall) -> str:
314
377
  """Resolve a UDT method call through the ordinary UDF clone graph."""
315
378
  base = self._emit_udt_method_cpp_name(fi)
@@ -1794,6 +1857,17 @@ class CallVisitor:
1794
1857
  self._array_method_args(meth, arg_nodes, recv_spec),
1795
1858
  recv_spec, node,
1796
1859
  )
1860
+ if recv_spec is None:
1861
+ # A builtin namespace's constant lowers to a string
1862
+ # temporary; its emitted type is what the member
1863
+ # would be called on.
1864
+ recv_spec = _spec_for_cpp_param(self._infer_type(obj))
1865
+ if not _member_name_has_lowering(recv_spec, meth):
1866
+ full = meth
1867
+ self._codegen_error(
1868
+ node,
1869
+ f"{full}(...) is not implemented in PineForge runtime.",
1870
+ )
1797
1871
  args = ", ".join(raw_args)
1798
1872
  if meth == "delete":
1799
1873
  meth = "_delete_"
@@ -1943,6 +2017,16 @@ class CallVisitor:
1943
2017
  force_stage=self._binds_fresh_array_to_reference(
1944
2018
  fi_u, rest_nodes, first_param=1),
1945
2019
  )
2020
+ if recv_spec is None:
2021
+ recv_spec = _spec_for_cpp_param(
2022
+ self._current_func_param_types.get(obj.name)
2023
+ ) or _spec_for_cpp_param(self._infer_type(obj))
2024
+ if not _member_name_has_lowering(recv_spec, meth_raw):
2025
+ full = meth_raw
2026
+ self._codegen_error(
2027
+ node,
2028
+ f"{full}(...) is not implemented in PineForge runtime.",
2029
+ )
1946
2030
  args = ", ".join(self._visit_expr(a) for a in node.args)
1947
2031
  recv = self._visit_expr(obj)
1948
2032
  meth = meth_raw
@@ -2166,6 +2250,7 @@ class CallVisitor:
2166
2250
  spec = self._widen_array_spec_for_name(target, spec)
2167
2251
  cpp_type = self._type_spec_to_cpp(spec)
2168
2252
  elem_spec = spec.element if spec.element is not None else TypeSpec.primitive("float")
2253
+ self._reject_unknown_element_type(node, elem_spec)
2169
2254
  init_default = self._default_for_spec(elem_spec)
2170
2255
  if node.args:
2171
2256
  size_arg = self._visit_expr(node.args[0])
@@ -2214,6 +2299,7 @@ class CallVisitor:
2214
2299
  spec = declared
2215
2300
  spec = self._widen_array_spec_for_name(target, spec)
2216
2301
  elem_spec = spec.element
2302
+ self._reject_unknown_element_type(node, elem_spec)
2217
2303
  for a in node.args:
2218
2304
  self._warn_narrow_int_element(a, spec, a)
2219
2305
  elems = ", ".join(
@@ -2738,6 +2824,13 @@ class CallVisitor:
2738
2824
  if func_name == "new":
2739
2825
  targs = self._template_args_from_call(node)
2740
2826
  elem_spec = self._type_spec_from_hint_name(targs[0]) if targs else TypeSpec.primitive("float")
2827
+ if elem_spec is None:
2828
+ full = targs[0]
2829
+ self._codegen_error(
2830
+ node,
2831
+ f"{full}(...) is not implemented in PineForge runtime.",
2832
+ )
2833
+ self._reject_unknown_element_type(node, elem_spec)
2741
2834
  args_e = [self._visit_expr(a) for a in node.args]
2742
2835
  rows = args_e[0] if args_e else "0"
2743
2836
  cols = args_e[1] if len(args_e) > 1 else "0"
@@ -2952,6 +3045,16 @@ class CallVisitor:
2952
3045
  hint="Check the spelling; this namespace may not be supported "
2953
3046
  "by PineForge.",
2954
3047
  )
3048
+ elif namespace is not None:
3049
+ # A UDT name is a value type, not a namespace: its constructor,
3050
+ # copy and typed methods return above. Anything left is a call
3051
+ # the codegen cannot lower; emitting it raw would write the
3052
+ # user's type name as a C++ namespace qualifier.
3053
+ full = f"{namespace}.{func_name}"
3054
+ self._codegen_error(
3055
+ node,
3056
+ f"{full}(...) is not implemented in PineForge runtime.",
3057
+ )
2955
3058
 
2956
3059
  # Generic function call (user-defined or unknown)
2957
3060
  # Determine which params are series (need Series<double> arg, not scalar)
@@ -3126,7 +3229,8 @@ class CallVisitor:
3126
3229
  # Mirror Pine default `timeframe.period` instead of hard-coding 15m.
3127
3230
  all_args.append("script_tf_")
3128
3231
  ordered_arg_nodes.append(None)
3129
- prefix = f"{namespace}::" if namespace else ""
3232
+ # Every non-null namespace is refused above (unknown namespace, or a
3233
+ # member call on a user type), so the emitted head is never qualified.
3130
3234
  # Use safe name for user-defined functions to avoid member name collision
3131
3235
  emit_name = self._func_safe_name(func_name) if func_name in self._func_names else func_name
3132
3236
  # Per-call-site variant: if this function has TA/series calls, call the correct variant
@@ -3155,7 +3259,7 @@ class CallVisitor:
3155
3259
  # Inside a per-call-site variant: propagate call-site index to
3156
3260
  # sub-functions that also have variants (for state isolation)
3157
3261
  emit_name = f"{self._func_safe_name(func_name)}_cs{self._active_call_site_idx}"
3158
- call_head = f"{prefix}{emit_name}"
3262
+ call_head = emit_name
3159
3263
  if namespace is None and func_name in self._func_names:
3160
3264
  return self._ordered_user_call_expr(
3161
3265
  call_head,
@@ -3504,6 +3608,11 @@ class CallVisitor:
3504
3608
  if node.args else "0"
3505
3609
  )
3506
3610
  is_open = inner.member == "opentrades"
3611
+ if not is_open:
3612
+ # Closed-trade accessors require the resident trade rows;
3613
+ # counts and history reads are lowered by visit_expr and
3614
+ # never enter this branch.
3615
+ self._reads_trade_history = True
3507
3616
  # Open trades have no exit metadata in Pine
3508
3617
  if is_open and func_name in (
3509
3618
  "exit_price", "exit_time", "exit_comment", "exit_id", "exit_bar_index",
@@ -1177,14 +1177,44 @@ class ExprVisitor:
1177
1177
  or name in self._current_func_locals
1178
1178
  or name in self._udt_var_types
1179
1179
  ):
1180
- safe = self._call_site_var_name(
1181
- node.object, self._safe_name(name)
1180
+ # A member the codegen has no lowering for. A user type's
1181
+ # field is a real C++ member (chart.point keeps its fields
1182
+ # this way); a builtin-backed receiver has no Pine member, so
1183
+ # writing the name raw would read arbitrary C++ state.
1184
+ recv_spec = self._type_spec_from_expr(node.object)
1185
+ tuple_cpp = getattr(
1186
+ self, "_tuple_binding_cpp_types_by_name", {}
1187
+ ).get(name)
1188
+ point = (
1189
+ (recv_spec is not None and recv_spec.name == "chart.point")
1190
+ or self._infer_type(node.object) == "ChartPoint"
1191
+ or tuple_cpp == "ChartPoint"
1192
+ )
1193
+ if point and node.member in ("time", "index", "price"):
1194
+ safe = self._call_site_var_name(
1195
+ node.object, self._safe_name(name)
1196
+ )
1197
+ return f"{safe}.{node.member}"
1198
+ full = f"{name}.{node.member}"
1199
+ self._codegen_error(
1200
+ node,
1201
+ f"{full}(...) is not implemented in PineForge runtime.",
1182
1202
  )
1183
- return f"{safe}.{node.member}"
1184
1203
  if name not in self.ctx.series_vars:
1185
1204
  # Unknown identifier — likely an enum value
1186
1205
  return f'std::string("{self._cpp_string_escape(node.member)}")'
1187
- return f"{obj}.{node.member}"
1206
+ recv_spec = self._type_spec_from_expr(node.object)
1207
+ point = (
1208
+ (recv_spec is not None and recv_spec.name == "chart.point")
1209
+ or self._infer_type(node.object) == "ChartPoint"
1210
+ )
1211
+ if point and node.member in ("time", "index", "price"):
1212
+ return f"{obj}.{node.member}"
1213
+ full = f"{node.member}"
1214
+ self._codegen_error(
1215
+ node,
1216
+ f"{full}(...) is not implemented in PineForge runtime.",
1217
+ )
1188
1218
 
1189
1219
  def _operand_na_kind(self, node, cpp_type: str) -> str | None:
1190
1220
  """Classify a relational operand by the ``na`` sentinel it can carry.
@@ -315,6 +315,11 @@ class StmtVisitor:
315
315
  # unrelated same-named global/callable UDT must not target-
316
316
  # type a later ``name := na`` as ``State{}``.
317
317
  self._lexical_udt_types[name] = None
318
+ self._tuple_binding_cpp_types_by_name[name] = (
319
+ tuple_cpp_types[index]
320
+ if index < len(tuple_cpp_types)
321
+ else "double"
322
+ )
318
323
  if (getattr(self, "_active_func_name", None) is not None
319
324
  and not self._decl_binding_is_series(
320
325
  id(node), name
@@ -650,6 +650,11 @@ class Parser:
650
650
 
651
651
  def _parse_type_hint_string(self) -> str:
652
652
  """Parse primitive, UDT, array<T>, map<K,V>, or postfix-array (``T[]``) hints."""
653
+ # A type hint is a type grammar, never an arbitrary token's value: a
654
+ # string or number here would reach the emitted C++ type position.
655
+ if (self._current().type not in TYPE_KEYWORDS
656
+ and self._current().type != TokenType.IDENT):
657
+ self._consume(TokenType.IDENT) # raises a located ParseError
653
658
  base = self._advance().value
654
659
  # Library type qualified by its import alias: ``lib.Type``.
655
660
  while self._check(TokenType.DOT) and self._peek().type == TokenType.IDENT:
@@ -676,8 +681,12 @@ class Parser:
676
681
  continue
677
682
  if tok.type == TokenType.COMMA:
678
683
  parts.append(",")
679
- else:
684
+ elif (tok.type in TYPE_KEYWORDS
685
+ or tok.type in (TokenType.IDENT, TokenType.DOT)):
680
686
  parts.append(str(tok.value))
687
+ else:
688
+ # A string/number/operator inside <...> is not a type.
689
+ self._consume(TokenType.IDENT)
681
690
  self._advance()
682
691
  base = f"{base}<{''.join(parts)}>"
683
692
 
@@ -712,11 +721,20 @@ class Parser:
712
721
  break
713
722
  depth -= 1
714
723
  current.append(">")
715
- elif tok.type == TokenType.COMMA and depth == 0:
716
- args.append("".join(current).strip())
717
- current = []
718
- else:
724
+ elif tok.type == TokenType.COMMA:
725
+ # A comma at depth 0 separates arguments; inside a nested
726
+ # <...> it belongs to that type (map<string, float>).
727
+ if depth == 0:
728
+ args.append("".join(current).strip())
729
+ current = []
730
+ else:
731
+ current.append(",")
732
+ elif (tok.type in TYPE_KEYWORDS
733
+ or tok.type in (TokenType.IDENT, TokenType.DOT)):
719
734
  current.append(str(tok.value))
735
+ else:
736
+ # Template arguments are type names, not literal text.
737
+ self._consume(TokenType.IDENT)
720
738
  self._advance()
721
739
  return args
722
740
 
@@ -740,6 +758,12 @@ class Parser:
740
758
  return i + 1 < len(self.tokens) and self.tokens[i + 1].type == TokenType.LPAREN
741
759
  elif tt in (TokenType.NEWLINE, TokenType.EOF_TOKEN) and depth > 0:
742
760
  return False
761
+ elif tt not in TYPE_KEYWORDS and tt not in (
762
+ TokenType.IDENT, TokenType.DOT, TokenType.COMMA,
763
+ ):
764
+ # Not the type grammar: this '<' is an ordinary comparison,
765
+ # not the opening of template arguments.
766
+ return False
743
767
  i += 1
744
768
  return False
745
769
 
@@ -18,7 +18,7 @@ A script's imports resolve only through its own manifest, never through the
18
18
  case-wide directory alone: otherwise a probe that pins no library would
19
19
  transpile on a shard neighbour's pin, and measure differently by case
20
20
  composition. ``transpile()`` is handed the source text, not a slug (the frozen
21
- verifier, pineforge-lab 3bac0b7b ``scripts/verify-engine-local.py:1698``, calls
21
+ campaign verifier (commit 3bac0b7b, ``scripts/verify-engine-local.py:1698``) calls
22
22
  ``transpile((d / "strategy.pine").read_text())``), so the manifest is found by
23
23
  content: the one ``requests.json`` whose ``probe.strategySha256`` is the sha256
24
24
  of the script. That sha is of the strategy file's bytes, and ``read_text()``
@@ -1932,6 +1932,27 @@ class SupportChecker:
1932
1932
  self._err(node, f"array.{name}(...) is not implemented in PineForge runtime.")
1933
1933
  self._visit_children(node)
1934
1934
  return
1935
+ if ns == "array" and name in ("new", "from"):
1936
+ # The element type names a C++ type in the emitted default
1937
+ # initialiser; it must be a Pine type, never arbitrary text.
1938
+ targs = (getattr(node.callee, "annotations", None) or {}).get("template_args") or []
1939
+ targs = [str(t).replace(" ", "") for t in targs]
1940
+ if targs:
1941
+ t = targs[0]
1942
+ allowed_prim = {"float", "int", "bool", "string", "color"}
1943
+ allowed_udt = {
1944
+ "line", "label", "box", "linefill", "chart.point",
1945
+ "table", "polyline",
1946
+ }
1947
+ if ("<" not in t and ">" not in t
1948
+ and t not in allowed_prim
1949
+ and t not in self._user_types
1950
+ and t not in self._user_enums
1951
+ and t not in allowed_udt):
1952
+ full = t
1953
+ self._err(node, f"{full}(...) is not implemented in PineForge runtime.")
1954
+ self._visit_children(node)
1955
+ return
1935
1956
  if ns == "map" and name not in SUPPORTED_MAP:
1936
1957
  self._err(node, f"map.{name}(...) is not implemented in PineForge runtime.")
1937
1958
  self._visit_children(node)
@@ -1 +0,0 @@
1
- 1.6.2-rc.1