@pineforge/codegen-pyodide 0.8.0 → 0.9.0

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.
@@ -206,8 +206,39 @@ class InputHelper:
206
206
  default = self._get_input_default(node)
207
207
  default_cpp = self._visit_expr(default) if default is not None else "0"
208
208
  getter = self._input_type_to_getter(func_name, namespace)
209
+ # The generic ``input(...)`` overload is typed by its defval in Pine
210
+ # v6 (an int default yields an int input). The static getter table
211
+ # cannot see the default, so infer the getter from the default's
212
+ # literal type here. This matters for TA lengths: ``input(15)`` must
213
+ # route to ``get_input_int`` so the RMA/EMA ctor receives an int.
214
+ if func_name == "input" and namespace is None:
215
+ if isinstance(default, BoolLiteral):
216
+ getter = "get_input_bool"
217
+ elif isinstance(default, NumberLiteral):
218
+ if isinstance(default.value, bool):
219
+ getter = "get_input_bool"
220
+ elif isinstance(default.value, int):
221
+ getter = "get_input_int"
222
+ else:
223
+ getter = "get_input_double"
224
+ elif isinstance(default, StringLiteral):
225
+ getter = "get_input_string"
226
+ default_cpp = self._coerce_string_input_default(getter, default_cpp)
209
227
  return f'{getter}("{title}", {default_cpp})'
210
228
 
229
+ def _coerce_string_input_default(self, getter: str, default_cpp: str) -> str:
230
+ """String getters take a ``std::string`` default. An unresolved default
231
+ (e.g. ``input.string(size.tiny, ...)`` where ``size.tiny`` lowers to
232
+ ``0``) would pass a null char* and crash ``strlen`` inside the getter,
233
+ so coerce any non-string default to a safe empty string. (Label size is
234
+ a visual no-op in the backtest, so the exact default does not affect
235
+ trading logic.)"""
236
+ if getter == "get_input_string":
237
+ stripped = default_cpp.strip()
238
+ if not stripped.startswith("std::string(") and not stripped.startswith('"'):
239
+ return 'std::string("")'
240
+ return default_cpp
241
+
211
242
  def _enforce_enum_declared_before_input_enum(self, node: FuncCall) -> None:
212
243
  """Mirror the analyzer: ``input.enum(Enum.member)`` requires Enum to be defined above the call.
213
244