pineforge-codegen 1.8.0__py3-none-any.whl → 1.9.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.
@@ -34,13 +34,17 @@ HOST_MEMBER_NAMES = frozenset({
34
34
  "closed_trade_direction",
35
35
  "closed_trade_entry_bar_index",
36
36
  "closed_trade_entry_comment",
37
+ "closed_trade_entry_comment_equals",
37
38
  "closed_trade_entry_id",
39
+ "closed_trade_entry_id_equals",
38
40
  "closed_trade_entry_price",
39
41
  "closed_trade_entry_time",
40
42
  "closed_trade_equity",
41
43
  "closed_trade_exit_bar_index",
42
44
  "closed_trade_exit_comment",
45
+ "closed_trade_exit_comment_equals",
43
46
  "closed_trade_exit_id",
47
+ "closed_trade_exit_id_equals",
44
48
  "closed_trade_exit_price",
45
49
  "closed_trade_exit_time",
46
50
  "closed_trade_max_drawdown",
@@ -7572,7 +7572,10 @@ class SecurityEmitter:
7572
7572
  # (current value not yet pushed — push happens after this assign).
7573
7573
  return f"{hist}[{idx_lit - 1}]"
7574
7574
 
7575
- if isinstance(expr_node, BinOp):
7575
+ # A literal comparison uses the expression visitor's shared lowering
7576
+ # below, with the same fallback frame and index bindings as a getter.
7577
+ if (isinstance(expr_node, BinOp)
7578
+ and self._closed_trade_text_equality_operands(expr_node) is None):
7576
7579
  left = self._build_security_expr(
7577
7580
  sec_id, expr_node.left, ta_range, ta_results, resolving, security_mutable_names, helper_binding_stack, emitted_lines
7578
7581
  )
@@ -3597,14 +3597,7 @@ class CallVisitor:
3597
3597
  if isinstance(node.callee, MemberAccess):
3598
3598
  inner = node.callee.object
3599
3599
  if isinstance(inner, MemberAccess) and inner.member in ("closedtrades", "opentrades"):
3600
- # The engine's accessors take an ``int`` trade index; a
3601
- # double-valued Pine expression narrows into it.
3602
- idx = (
3603
- self._coerce_int_slot(
3604
- self._visit_expr(node.args[0]), node.args[0], "int",
3605
- )
3606
- if node.args else "0"
3607
- )
3600
+ idx = self._trade_index_cpp(node)
3608
3601
  is_open = inner.member == "opentrades"
3609
3602
  if not is_open:
3610
3603
  # Closed-trade accessors require the resident trade rows;
@@ -3658,6 +3651,17 @@ class CallVisitor:
3658
3651
  f"have rejected. Add a handler above or extend STRATEGY_FUNCTIONS."
3659
3652
  )
3660
3653
 
3654
+ def _trade_index_cpp(self, node: FuncCall) -> str:
3655
+ """The shared index slot of owning getters and in-place comparisons."""
3656
+ # The engine's accessors take an int; preserve na when narrowing a
3657
+ # double-valued Pine expression, and evaluate the expression once.
3658
+ return (
3659
+ self._coerce_int_slot(
3660
+ self._visit_expr(node.args[0]), node.args[0], "int",
3661
+ )
3662
+ if node.args else "0"
3663
+ )
3664
+
3661
3665
  # TradingView's parameter order of color.from_gradient.
3662
3666
  _FROM_GRADIENT_PARAMS = (
3663
3667
  "value", "bottom_value", "top_value", "bottom_color", "top_color",
@@ -216,6 +216,13 @@ _DRAWING_EFFECT_NAMESPACES = frozenset({
216
216
  })
217
217
  _DRAWING_EFFECT_METHODS = frozenset({"delete", "cell", "merge_cells"})
218
218
 
219
+ _CLOSED_TRADE_TEXT_EQUALS = {
220
+ "entry_id": "closed_trade_entry_id_equals",
221
+ "exit_id": "closed_trade_exit_id_equals",
222
+ "entry_comment": "closed_trade_entry_comment_equals",
223
+ "exit_comment": "closed_trade_exit_comment_equals",
224
+ }
225
+
219
226
 
220
227
  def _ast_children(node):
221
228
  """The AST nodes directly under ``node``: its fields, lists, tuples (a
@@ -1413,7 +1420,53 @@ class ExprVisitor:
1413
1420
  node, left, right,
1414
1421
  lambda left, right: f"(({left}).id {node.op} ({right}).id)")
1415
1422
 
1423
+ @staticmethod
1424
+ def _closed_trade_text_equality_operands(
1425
+ node: BinOp,
1426
+ ) -> tuple[FuncCall, StringLiteral] | None:
1427
+ """A direct closed-trade text read compared with a NUL-free literal."""
1428
+ if node.op not in ("==", "!="):
1429
+ return None
1430
+ call, literal = node.left, node.right
1431
+ if isinstance(call, StringLiteral):
1432
+ call, literal = literal, call
1433
+ if (not isinstance(call, FuncCall)
1434
+ or not isinstance(literal, StringLiteral)
1435
+ or "\0" in literal.value):
1436
+ return None
1437
+ callee = call.callee
1438
+ if (not isinstance(callee, MemberAccess)
1439
+ or callee.member not in _CLOSED_TRADE_TEXT_EQUALS):
1440
+ return None
1441
+ owner = callee.object
1442
+ if (not isinstance(owner, MemberAccess)
1443
+ or owner.member != "closedtrades"
1444
+ or not isinstance(owner.object, Identifier)
1445
+ or owner.object.name != "strategy"):
1446
+ return None
1447
+ return call, literal
1448
+
1449
+ def _closed_trade_text_equals_cpp(self, node: BinOp) -> str | None:
1450
+ operands = self._closed_trade_text_equality_operands(node)
1451
+ if operands is None:
1452
+ return None
1453
+ call, literal = operands
1454
+ index = self._trade_index_cpp(call)
1455
+ self._reads_trade_history = True
1456
+ escaped = f'"{self._cpp_string_escape(literal.value)}"'
1457
+ helper = _CLOSED_TRADE_TEXT_EQUALS[call.callee.member]
1458
+ # sizeof counts the emitted bytes, including UTF-8 and escaped bytes.
1459
+ # A NUL literal keeps std::string(const char*)'s existing truncation.
1460
+ comparison = (
1461
+ f"{helper}({index}, std::string_view({escaped}, "
1462
+ f"sizeof({escaped}) - 1))"
1463
+ )
1464
+ return f"!({comparison})" if node.op == "!=" else comparison
1465
+
1416
1466
  def _visit_binop(self, node: BinOp) -> str:
1467
+ text_equals = self._closed_trade_text_equals_cpp(node)
1468
+ if text_equals is not None:
1469
+ return text_equals
1417
1470
  if node.op in ("==", "!="):
1418
1471
  identity = self._reference_equality_cpp(node)
1419
1472
  if identity is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pineforge-codegen
3
- Version: 1.8.0
3
+ Version: 1.9.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
@@ -49,22 +49,22 @@ pineforge_codegen/codegen/graph_journal.py,sha256=BpofbOUP1frO816AVzYLJUCkx7xKeo
49
49
  pineforge_codegen/codegen/helpers.py,sha256=yZUzc94bg5V1uBe2Nrw6SqytFq3gGjM7Y4VRhTmlOAs,33339
50
50
  pineforge_codegen/codegen/helpers_syminfo.py,sha256=GFrx9i2HXSCmGIpIds0cFrtJ6IQiznfXxH8aI8h3DQ4,4878
51
51
  pineforge_codegen/codegen/history_sharing.py,sha256=mlU5eriAIf7IMUuw6xyBMmGXKqutan5xN2mVYaLVp48,9214
52
- pineforge_codegen/codegen/host_members.py,sha256=EmHaeD17CiDVR4YDiU-egS1F0FOYKSnYFQA7lOkcHGo,4635
52
+ pineforge_codegen/codegen/host_members.py,sha256=PFz2JTOAvmq4RdGlQI6Nl9r1Yir7p0yta4ycUXvXKG8,4787
53
53
  pineforge_codegen/codegen/id_sites.py,sha256=__kzaNci4KEQimheKXgEypXDU8Mj0YGkXo24AlZWo3k,10990
54
54
  pineforge_codegen/codegen/input.py,sha256=Jclpl_2T18RvwGmzcd78GzXzOTzoRKydANlTfh8-K84,33519
55
55
  pineforge_codegen/codegen/order_shapes.py,sha256=H20ElOyewRdXXY7e8LMdkdj7pxf36H0Q5Jsg3yVPPRY,14848
56
56
  pineforge_codegen/codegen/run_stops.py,sha256=4gkHBySR_sd5AgXXv3R-7Z83zGmoCWLXZFcPxKPngY8,3541
57
- pineforge_codegen/codegen/security.py,sha256=XFDSLMPfnVxOOTX4JUiDY9HuxGAApXMYqRfkQW6VzxU,419515
57
+ pineforge_codegen/codegen/security.py,sha256=fUtDsmJ1eYgG7MCEH2iE4cOW7JL8yPv1Je62YrpZiZA,419753
58
58
  pineforge_codegen/codegen/session_market.py,sha256=-urGaWozZ0k4uNzZ5lPB2fqftpJrftcZiw4eWWMnJKM,3438
59
59
  pineforge_codegen/codegen/ta.py,sha256=w9nvIqbbLCOL8jLnW7z9vMlu8RqYyF8nTtrQoRKnwcA,106771
60
60
  pineforge_codegen/codegen/tables.py,sha256=TN12BFSRFixlLlsHSYdEnzx6epKpyEkbPYqZDcOZ1C8,71490
61
61
  pineforge_codegen/codegen/tv_number_format.py,sha256=SZ70zOmMD9vC1ko0WQnt6X0q7PJ_-jT93N7ZtquwPLE,11637
62
62
  pineforge_codegen/codegen/types.py,sha256=efJgP5E0tbJRlpNIijRXQUYZXDumT4S-gD4Lqn0NfiI,213505
63
- pineforge_codegen/codegen/visit_call.py,sha256=KNF0A24_CUqBHf866u87yGQwsNs3u4sV2AI4zhR4Pk8,200097
64
- pineforge_codegen/codegen/visit_expr.py,sha256=Rw5cZgg65hKHBJTDOS6ScD70VtrdkVXoLpDD-xGkxc0,114099
63
+ pineforge_codegen/codegen/visit_call.py,sha256=eOa6QhpA-0oguvjNFz_mRHA-FqH5UvpBxGAV5gRyT48,200249
64
+ pineforge_codegen/codegen/visit_expr.py,sha256=rT2YzUZsbU9Qm09c3pGVmcMewNdpKRISOB1F1t8cDBs,116309
65
65
  pineforge_codegen/codegen/visit_stmt.py,sha256=BSBhjbrkav0V55VflboQzJ7H3Ky7A1P5WwwNvLXHeQA,118944
66
- pineforge_codegen-1.8.0.dist-info/METADATA,sha256=cDoPOsPxgYPjRRhdpenDS21f_ceKuqaGfO2xJExt2Dk,54924
67
- pineforge_codegen-1.8.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
68
- pineforge_codegen-1.8.0.dist-info/entry_points.txt,sha256=dSUCCmwV4UpL1PyC6THPdQ-l3ddue7ZH1RgRHpASvhY,74
69
- pineforge_codegen-1.8.0.dist-info/licenses/LICENSE,sha256=X0M0ankijg7iZuoI78biEG1kr6klX8NgzDKZAyaPcg4,11161
70
- pineforge_codegen-1.8.0.dist-info/RECORD,,
66
+ pineforge_codegen-1.9.0.dist-info/METADATA,sha256=2cp7DPV9hKCenhn15EUAHnWvwb0X-ovYkWH_Fn6g4gQ,54924
67
+ pineforge_codegen-1.9.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
68
+ pineforge_codegen-1.9.0.dist-info/entry_points.txt,sha256=dSUCCmwV4UpL1PyC6THPdQ-l3ddue7ZH1RgRHpASvhY,74
69
+ pineforge_codegen-1.9.0.dist-info/licenses/LICENSE,sha256=X0M0ankijg7iZuoI78biEG1kr6klX8NgzDKZAyaPcg4,11161
70
+ pineforge_codegen-1.9.0.dist-info/RECORD,,