@pineforge/codegen-pyodide 0.10.4 → 1.0.0-rc.1

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 (50) hide show
  1. package/README.md +16 -16
  2. package/glue.py +24 -16
  3. package/package.json +1 -1
  4. package/pineforge_codegen/__init__.py +125 -34
  5. package/pineforge_codegen/analyzer/__init__.py +2 -0
  6. package/pineforge_codegen/analyzer/base.py +754 -76
  7. package/pineforge_codegen/analyzer/call_handlers.py +260 -40
  8. package/pineforge_codegen/analyzer/contracts.py +37 -0
  9. package/pineforge_codegen/analyzer/diagnostics.py +30 -4
  10. package/pineforge_codegen/analyzer/tables.py +49 -8
  11. package/pineforge_codegen/analyzer/types.py +33 -1
  12. package/pineforge_codegen/ast_nodes.py +32 -1
  13. package/pineforge_codegen/block_locals.py +185 -0
  14. package/pineforge_codegen/builtin_keywords.py +42 -0
  15. package/pineforge_codegen/codegen/base.py +896 -156
  16. package/pineforge_codegen/codegen/constant_fold.py +131 -0
  17. package/pineforge_codegen/codegen/drawing.py +221 -79
  18. package/pineforge_codegen/codegen/emit_top.py +946 -213
  19. package/pineforge_codegen/codegen/helpers.py +435 -14
  20. package/pineforge_codegen/codegen/host_members.py +162 -0
  21. package/pineforge_codegen/codegen/input.py +252 -85
  22. package/pineforge_codegen/codegen/security.py +4372 -377
  23. package/pineforge_codegen/codegen/session_market.py +71 -0
  24. package/pineforge_codegen/codegen/ta.py +1188 -100
  25. package/pineforge_codegen/codegen/tables.py +193 -71
  26. package/pineforge_codegen/codegen/tv_number_format.py +270 -0
  27. package/pineforge_codegen/codegen/types.py +1882 -78
  28. package/pineforge_codegen/codegen/visit_call.py +920 -131
  29. package/pineforge_codegen/codegen/visit_expr.py +738 -57
  30. package/pineforge_codegen/codegen/visit_stmt.py +595 -49
  31. package/pineforge_codegen/external_requests.py +877 -0
  32. package/pineforge_codegen/lexer.py +104 -22
  33. package/pineforge_codegen/library_inline.py +1304 -0
  34. package/pineforge_codegen/library_modules.py +126 -0
  35. package/pineforge_codegen/library_v5.py +683 -0
  36. package/pineforge_codegen/limits.py +138 -0
  37. package/pineforge_codegen/method_binding.py +33 -0
  38. package/pineforge_codegen/parser.py +384 -68
  39. package/pineforge_codegen/pine_libraries.py +266 -0
  40. package/pineforge_codegen/pine_spelling.py +216 -0
  41. package/pineforge_codegen/pragmas.py +64 -10
  42. package/pineforge_codegen/security_contexts.py +1585 -0
  43. package/pineforge_codegen/session_reads.py +84 -0
  44. package/pineforge_codegen/signatures.py +48 -23
  45. package/pineforge_codegen/support_checker.py +1106 -85
  46. package/pineforge_codegen-1.0.0-rc.1.tar.gz +0 -0
  47. package/release.json +2 -2
  48. package/tables.json +23 -21
  49. package/transpile.worker.mjs +24 -16
  50. package/pineforge_codegen-0.10.4.tar.gz +0 -0
@@ -0,0 +1,71 @@
1
+ """C++ emitted for a chart bar's session.ismarket when the run has no
2
+ timeframe.
3
+
4
+ TradingView flags a bar by its own open time: on an extended-hours
5
+ NASDAQ:AAPL 60 chart the 09:00 bar, which holds the 09:30 open, is
6
+ pre-market and the 16:00 bar post-market. It reads a session's day mask per
7
+ session day, so an overnight session's Sunday-evening open belongs to
8
+ Monday's, and a ``0000-2400`` day is in market throughout; a D/W/M bar holds
9
+ whole session days, and a bar that opens in a break and holds the reopen is
10
+ in market (``tests/test_e2e_session_ismarket.py`` and
11
+ ``tests/test_e2e_session_windows.py`` replay the tapes).
12
+
13
+ The kernel's per-bar fact ``session_ismarket_`` gives all of that: it reads a
14
+ bar at its interval's first eligible instant, which is the bar's open unless
15
+ the bar opens in a break, and it is what a chart's session.ismarket reads. A
16
+ run whose timeframe the engine cannot detect (one bar, none given; its
17
+ ``script_tf_`` is empty) gets no session-day facts, and there the lowering
18
+ asks the engine's session calendar instead: ``native_calendar``'s session day
19
+ at the bar's open, on the calendar the kernel builds for the run from the same
20
+ session and timezone (the adapter reads an empty session as ``24x7`` and an
21
+ empty timezone as ``UTC``), resolved once per session day and read as the
22
+ kernel reads it (a day the calendar cannot resolve is out of session). The
23
+ time-of-day predicate ``pine_session_ismarket`` is a second reading of the
24
+ session string, which the kernel does not run (until engine lane
25
+ W11-ENG-TIME-COLOR it tested a day mask on the instant's own weekday and did
26
+ not parse ``2400``).
27
+
28
+ ``SESSION_MARKET_CPP`` precedes the strategy class; each strategy holds one
29
+ ``SESSION_MARKET_MEMBER`` after its checkpointed script state (a cache of an
30
+ answer that depends on the session, the timezone and the instant only). A
31
+ session the calendar cannot parse, which the kernel would not run, keeps the
32
+ time-of-day predicate.
33
+ """
34
+
35
+ SESSION_MARKET_CPP = r"""
36
+ struct _PFSessionMarket {
37
+ std::string session_key;
38
+ std::string tz_key;
39
+ bool parsed = false;
40
+ std::optional<native_calendar::SessionCalendar> calendar;
41
+ std::optional<native_calendar::NativeSessionDay> day;
42
+
43
+ bool operator()(const std::string& session, const std::string& tz,
44
+ const std::string& chart_tf, int64_t bar_ms) {
45
+ if (tf_is_daily_or_higher(chart_tf)) return true;
46
+ if (!parsed || session_key != session || tz_key != tz) {
47
+ parsed = false;
48
+ day.reset();
49
+ calendar = native_calendar::parse_session(
50
+ session.empty() ? std::string_view("24x7") : std::string_view(session),
51
+ tz.empty() ? std::string_view("UTC") : std::string_view(tz));
52
+ session_key = session;
53
+ tz_key = tz;
54
+ parsed = true;
55
+ }
56
+ if (!calendar) return pine_session_ismarket(session, tz, bar_ms);
57
+ if (day && day->holds(bar_ms)) return day->in_session_at(bar_ms);
58
+ try {
59
+ auto found = native_calendar::session_day_at(*calendar, bar_ms);
60
+ if (!found) return false;
61
+ const bool in_market = found->in_session_at(bar_ms);
62
+ if (found->holds(bar_ms)) day = std::move(found);
63
+ return in_market;
64
+ } catch (...) {
65
+ return false;
66
+ }
67
+ }
68
+ };
69
+ """
70
+
71
+ SESSION_MARKET_MEMBER = " mutable _PFSessionMarket _pf_session_market_;"