Skip to content

Stdlib: printf() — VM + AOT formatted stdout write (#3681) - #3902

Merged
PurHur merged 1 commit into
masterfrom
agent/stdlib-printf-3681
May 31, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/stdlib-printf-3681

Conversation

@PurHur

@PurHur PurHur commented May 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add printf() VM builtin (ext/standard/printf_.php) delegating format to VmSprintf, output via OutputBuffer, return byte length (php-src formatted_print.c).
  • Add AOT/JIT lowering via __compiler_printf runtime (lib/AOT/runtime/superglobals_refresh.c) and JitPrintf; register in SelfHostBuiltinPolicy bundle allowlist.
  • Compliance + AOT PHPT + PrintfBuiltinTest (VM return length + AOT stdout smoke).

php-src reference

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter PrintfBuiltinTest'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter "VMTest.*printf"'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter "AotTest.*printf"'
Check Result
PrintfBuiltinTest (VM + AOT) OK (3 tests)
VMTest.*printf OK (3 tests)
AotTest.*printf OK (3 tests)

Closes #3681

Made with Cursor

Implement printf() using the existing VmSprintf/__compiler_sprintf subset,
writing through OutputBuffer (VM) or __compiler_printf + ob echo (AOT).
Register in SelfHostBuiltinPolicy so native binaries lower the builtin.

php-src: ext/standard/formatted_print.c
Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 4682bf9 into master May 31, 2026
@PurHur
PurHur deleted the agent/stdlib-printf-3681 branch May 31, 2026 09:50
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.

Stdlib: printf() — formatted output to stdout (ext/standard/formatted_print.c parity)

1 participant