pineforge-codegen 1.9.0__py3-none-any.whl → 1.10.0__py3-none-any.whl

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 (60) hide show
  1. pineforge_codegen/__init__.py +50 -4
  2. pineforge_codegen/analyzer/base.py +1442 -28
  3. pineforge_codegen/analyzer/call_handlers.py +66 -7
  4. pineforge_codegen/analyzer/contracts.py +11 -0
  5. pineforge_codegen/analyzer/operators.py +276 -0
  6. pineforge_codegen/analyzer/types.py +261 -91
  7. pineforge_codegen/analyzer/value_bindings.py +359 -0
  8. pineforge_codegen/codegen/array_field_width.py +441 -0
  9. pineforge_codegen/codegen/ascii.py +101 -0
  10. pineforge_codegen/codegen/base.py +117 -25
  11. pineforge_codegen/codegen/bool_text.py +337 -0
  12. pineforge_codegen/codegen/capabilities.py +8 -19
  13. pineforge_codegen/codegen/closed_trade_fold.py +399 -0
  14. pineforge_codegen/codegen/collection_history.py +2 -1
  15. pineforge_codegen/codegen/color_constants.py +89 -0
  16. pineforge_codegen/codegen/constant_fold.py +208 -1
  17. pineforge_codegen/codegen/constant_values.py +173 -0
  18. pineforge_codegen/codegen/drawing.py +21 -19
  19. pineforge_codegen/codegen/emit_top.py +71 -34
  20. pineforge_codegen/codegen/endless_for.py +507 -0
  21. pineforge_codegen/codegen/for_loops.py +17 -0
  22. pineforge_codegen/codegen/graph_journal.py +3 -11
  23. pineforge_codegen/codegen/helpers.py +49 -1
  24. pineforge_codegen/codegen/host_members.py +2 -0
  25. pineforge_codegen/codegen/input.py +16 -47
  26. pineforge_codegen/codegen/order_shapes.py +70 -2
  27. pineforge_codegen/codegen/security.py +1944 -77
  28. pineforge_codegen/codegen/strategy_declaration.py +184 -0
  29. pineforge_codegen/codegen/tables.py +17 -8
  30. pineforge_codegen/codegen/timeframe_values.py +370 -0
  31. pineforge_codegen/codegen/types.py +1236 -193
  32. pineforge_codegen/codegen/visit_call.py +264 -122
  33. pineforge_codegen/codegen/visit_expr.py +205 -66
  34. pineforge_codegen/codegen/visit_stmt.py +400 -51
  35. pineforge_codegen/collection_history.py +26 -15
  36. pineforge_codegen/cpp_allowlist.py +18 -0
  37. pineforge_codegen/cpp_names.py +17 -0
  38. pineforge_codegen/diagnostics_catalog.json +86 -0
  39. pineforge_codegen/errors.py +17 -0
  40. pineforge_codegen/external_requests.py +3 -2
  41. pineforge_codegen/function_overloads.py +337 -0
  42. pineforge_codegen/intrinsic_binding.py +50 -0
  43. pineforge_codegen/lexer.py +140 -22
  44. pineforge_codegen/library_inline.py +10 -0
  45. pineforge_codegen/library_modules.py +2 -0
  46. pineforge_codegen/limits.py +6 -0
  47. pineforge_codegen/loop_types.py +468 -0
  48. pineforge_codegen/method_binding.py +48 -3
  49. pineforge_codegen/parser.py +179 -98
  50. pineforge_codegen/pine_spelling.py +18 -0
  51. pineforge_codegen/security_contexts.py +136 -27
  52. pineforge_codegen/signatures.py +153 -27
  53. pineforge_codegen/support_checker.py +47 -17
  54. pineforge_codegen/symbols.py +33 -2
  55. {pineforge_codegen-1.9.0.dist-info → pineforge_codegen-1.10.0.dist-info}/METADATA +1 -1
  56. pineforge_codegen-1.10.0.dist-info/RECORD +86 -0
  57. pineforge_codegen-1.9.0.dist-info/RECORD +0 -70
  58. {pineforge_codegen-1.9.0.dist-info → pineforge_codegen-1.10.0.dist-info}/WHEEL +0 -0
  59. {pineforge_codegen-1.9.0.dist-info → pineforge_codegen-1.10.0.dist-info}/entry_points.txt +0 -0
  60. {pineforge_codegen-1.9.0.dist-info → pineforge_codegen-1.10.0.dist-info}/licenses/LICENSE +0 -0
@@ -5,18 +5,26 @@ from collections.abc import Mapping
5
5
  from .lexer import Lexer
6
6
  from .parser import Parser
7
7
  from .analyzer import Analyzer
8
+ from .analyzer.value_bindings import ValueBindings
8
9
  from .codegen import CodeGen
10
+ from .cpp_allowlist import REASONS, check_generated_cpp
9
11
  from .diagnostic_codes import diagnostics_catalog, render_diagnostic
10
- from .errors import CompileError, Level, Phase
12
+ from .errors import (
13
+ CodegenInvariantError, CompileError, Diagnostic, Level, Phase, SourceLocation,
14
+ )
11
15
  from .external_requests import lower_no_data_requests
12
16
  from .builtin_keywords import bind_builtin_keywords
13
17
  from .finite_ta_length import expand_finite_choice_extrema_lengths
18
+ from .function_overloads import bind_scalar_overloads
14
19
  from .library_inline import inline_libraries
15
20
  from .limits import TimeBudget, check_ast_depth, check_source_size, ensure_recursion_headroom
21
+ from .method_binding import validate_call_argument_order
16
22
  from .pragmas import extract_pf_trace_pragmas
17
23
  from .request_discovery import discover_requests, request_sites
18
24
  from .request_feed_inventory import build_request_feed_inventory
19
- from .security_contexts import specialize_security_contexts
25
+ from .security_contexts import (
26
+ specialize_method_security_payloads, specialize_security_contexts,
27
+ )
20
28
  from .block_locals import rename_block_locals
21
29
  from .support_checker import check_support as _support_diagnostics
22
30
  from .support_checker import check_support_or_raise
@@ -39,6 +47,7 @@ def _parse_bounded(pine_source: str, filename: str, budget: TimeBudget | None =
39
47
  budget=budget).parse()
40
48
  check_ast_depth(ast, filename)
41
49
  budget.check(phase=Phase.PARSER)
50
+ validate_call_argument_order(ast, filename=filename)
42
51
  return ast, pragmas, budget
43
52
 
44
53
 
@@ -68,6 +77,7 @@ def _generate(pine_source: str, check_support: bool, filename: str,
68
77
  ast, pragmas, budget = _parse_bounded(pine_source, filename, budget)
69
78
  ast = inline_libraries(ast, pine_source, libraries=libraries,
70
79
  filename=filename, budget=budget)
80
+ ast = bind_scalar_overloads(ast, budget=budget)
71
81
  rename_block_locals(ast, renamed)
72
82
  support_diagnostics = []
73
83
  if check_support:
@@ -75,6 +85,7 @@ def _generate(pine_source: str, check_support: bool, filename: str,
75
85
  if any(d.level == Level.ERROR for d in support_diagnostics):
76
86
  raise CompileError(support_diagnostics)
77
87
  budget.check(phase=Phase.ANALYZER)
88
+ ValueBindings(ast, filename, budget).resolve()
78
89
  sites = request_sites(ast)
79
90
  ast = lower_no_data_requests(ast)
80
91
  ast = specialize_security_contexts(ast, filename=filename)
@@ -83,14 +94,37 @@ def _generate(pine_source: str, check_support: bool, filename: str,
83
94
  budget.check(phase=Phase.ANALYZER)
84
95
  ctx = Analyzer(ast, filename=filename, budget=budget,
85
96
  session_clones=clones).analyze()
97
+ # Typed receiver dispatch is known only after analysis. Resolve method
98
+ # payload arguments with those bindings, then type the rewritten bodies.
99
+ if specialize_method_security_payloads(
100
+ ast, ctx.method_call_bindings, filename=filename):
101
+ del ctx
102
+ ast = bind_builtin_keywords(expand_finite_choice_extrema_lengths(ast))
103
+ check_ast_depth(ast, filename)
104
+ ctx = Analyzer(ast, filename=filename, budget=budget,
105
+ session_clones=clones).analyze()
86
106
  budget.check(phase=Phase.ANALYZER)
87
107
  # Attach after analysis: pragma expressions are not part of the
88
108
  # program body, so the analyzer never inspects them; the codegen
89
109
  # consumes them directly from the context to emit the on_bar tail
90
110
  # ``if (trace_enabled_) { trace(...); ... }`` block.
91
111
  ctx.pf_trace_pragmas = pragmas
92
- gen = CodeGen(ctx, budget=budget)
93
- cpp = gen.generate()
112
+ try:
113
+ gen = CodeGen(ctx, budget=budget)
114
+ cpp = gen.generate()
115
+ except CodegenInvariantError as error:
116
+ node_kind = error.node_kind
117
+ location = getattr(error.node, "loc", None)
118
+ if location is None:
119
+ raise RuntimeError(
120
+ f"Internal error: AST node '{node_kind}' has no source "
121
+ "location for its missing value lowering."
122
+ ) from error
123
+ raise CompileError([Diagnostic(
124
+ level=Level.ERROR, phase=Phase.CODEGEN, location=location,
125
+ message=f"Internal error: no value lowering for AST node '{node_kind}'.",
126
+ hint="Report this translator error to PineForge.",
127
+ )]) from error
94
128
  budget.check(phase=Phase.CODEGEN)
95
129
  apart = gen.block_locals_needing_names - renamed
96
130
  if apart:
@@ -99,6 +133,18 @@ def _generate(pine_source: str, check_support: bool, filename: str,
99
133
  continue
100
134
  needed = gen.session_functions_needing_clones
101
135
  if not needed:
136
+ findings = check_generated_cpp(cpp)
137
+ if findings:
138
+ raise CompileError([
139
+ Diagnostic(
140
+ level=Level.ERROR,
141
+ phase=Phase.CODEGEN,
142
+ location=SourceLocation(file=filename, line=1, col=1, end_col=1),
143
+ message=REASONS[finding.rule],
144
+ hint="Report this generated C++ allowlist failure to PineForge.",
145
+ )
146
+ for finding in findings[:20]
147
+ ])
102
148
  return gen, ctx, cpp, support_diagnostics, sites
103
149
  # Only uncloned functions ask, so the set grows each time and the
104
150
  # loop ends by the time every function that reads a flag at an