Skip to content

refactor(core): improve string support#342

Open
Guikingone wants to merge 1 commit into
illegalstudio:mainfrom
Guikingone:fix/string-builtin-correctness
Open

refactor(core): improve string support#342
Guikingone wants to merge 1 commit into
illegalstudio:mainfrom
Guikingone:fix/string-builtin-correctness

Conversation

@Guikingone
Copy link
Copy Markdown
Contributor

No description provided.

…rg unboxing

Three related string-builtin fixes.

wordwrap: rewrite __rt_wordwrap on ARM64 and x86_64 to PHP's word-aware
algorithm (break at the last space at/after the width; an over-long word stays
intact unless cut_long_words is set; existing newlines reset the line length)
and plumb the cut_long_words flag through codegen (x6 ARM64 / r9 x86_64). It was
previously a fixed-width char-wrapper with the cut flag never passed to the
runtime.

sprintf/printf: __rt_sprintf dispatches on the conversion specifier character
(f/e/g→float, s→string, else→int), not on the pushed record tag, so a Mixed or
cross-type argument was misread (Mixed→0, int under %s→empty, string under
%d→pointer). Add a shared format_args::emit_format_and_call (used by both
sprintf and printf) that parses the literal format and coerces each argument to
its specifier's type before pushing a matching record. A string under an integer
specifier is cast with __rt_str_to_int locally in this path rather than widening
the shared coerce_result_to_type (other call sites gate coercion on it).

string builtins: unbox Mixed/Union arguments to the single- and multi-argument
string builtins through the shared super::args::emit_string_arg helper, so a
Mixed operand is cast via __rt_mixed_cast_string instead of leaving a boxed cell
with stale string registers.

Adds regression tests across formatting/encoding/transform; output matches PHP.
@Guikingone Guikingone force-pushed the fix/string-builtin-correctness branch from 0f7d057 to 9ba48a2 Compare June 5, 2026 11:22
@Guikingone Guikingone marked this pull request as ready for review June 5, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant