[core] Specialize TemplatableValue for non-string types as function pointer

Specialize TemplatableValue so non-string types use function-pointer-only
storage (4 bytes on 32-bit) instead of the tagged union with std::function
support (8 bytes). The std::string specialization retains full support for
VALUE, STATIC_STRING, FLASH_STRING, and stateful lambdas.

Codegen now wraps non-string constants in stateless lambdas automatically,
so the generated C++ always assigns a function pointer.
This commit is contained in:
J. Nick Koston
2026-04-07 13:16:14 -10:00
parent aad898503d
commit 9bf0133525
8 changed files with 161 additions and 192 deletions
+2 -3
View File
@@ -669,11 +669,10 @@ async def test_templatable__int_with_std_string() -> None:
@pytest.mark.asyncio
async def test_templatable__string_with_non_string_output_type() -> None:
"""Static string with non-std::string output_type returns raw string."""
"""Static string with non-std::string output_type returns stateless lambda."""
result = await cg.templatable("hello", [], ct.bool_)
assert isinstance(result, str)
assert result == "hello"
assert isinstance(result, cg.LambdaExpression)
@pytest.mark.asyncio