Repository navigation
Add pure-Silver formatting + print/abort ABI (Wave 1 unit 3) - #8
Merged
Merged
Conversation
New std/fmt.ag provides itoa/utoa/ftoa/btoa and buffered write helpers
over sys_write. std/io.ag print path uses the new formatters and exports
silver_rt_print_{i64,u64,bool,f64,cstr,bytes}, silver_rt_abort, and
silver_rt_abort_cstr matching silver_runtime/src/runtime/ffi.rs.
Co-Authored-By: Claude Fable 5 <[email protected]>
…entinel and update ffi.rs
CierCier
added a commit
that referenced
this pull request
Aug 1, 2026
Add pure-Silver formatting + print/abort ABI (Wave 1 unit 3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wave 1 unit 3 of
docs/runtime-migration.md.std/fmt.ag—itoa/utoa/ftoa/btoa, UTF-8 validation helpers, buffered stdout/stderr writes oversys_writestd/io.ag— print path rewritten onto fmt; exports frozensilver_rt_print_*/silver_rt_abort*ABItests/fmt_test.ag— 46 cases covering integer/float formatting edge cases and the print surfaceFile API still uses
FILE*temporarily (migrates in unit 9).Test plan
agc tests/fmt_test.ag→ 46/46 PASSGreptile Summary
This PR introduces
std/fmt.ag— a pure-Silver number-to-text formatting module implementing Grisu2 f64 conversion, integer/bool formatters, UTF-8 validation, and rawwrite(2)I/O helpers.std/io.ag'sprintln/eprintlnare rewritten onto these helpers (bypassing libc stdio), andffi.rsaligns the Rustsilver_rt_print_bytesnon-UTF-8 sentinel to include a newline, matching the Silver implementation.std/fmt.ag: Addsitoa/utoa/btoa/ftoa(all buffer-based, no allocation), a correct UTF-8 validator, and the frozensilver_rt_print_*/silver_rt_abort*ABI usingsys_writedirectly. The Grisu2 port faithfully replicates the rapidjson cached-power table and digit-generation loop, including manual unsigned arithmetic workarounds for the current codegen's signed-only lowering.std/io.ag:println/eprintlnnow callwrite_stdout/write_stderrfromstd.fmt, gaining null-pointer safety that the oldputs-based path lacked; the return semantics remain compatible (non-negative on success,EOFon error).tests/fmt_test.ag: 46 cases covering boundary values (i64 MIN/MAX, u64 MAX, 5e-324, f64 MAX, NaN, ±inf, -0), UTF-8 edge cases (surrogates, overlongs, truncated sequences), and the print surface as a smoke test.Confidence Score: 5/5
Safe to merge; no correctness issues found in the formatting, UTF-8 validation, ABI surface, or Grisu2 port.
The Grisu2 cached-power table and digit-generation loop are faithful to the rapidjson reference; integer/bool formatters and the two's-complement MIN handling are correct; UTF-8 validation correctly covers all lead-byte ranges, overlong sequences, surrogates, and truncated inputs. The ffi.rs change aligns the Rust sentinel with the Silver implementation. The one observation (zero-write short-circuit going undetected by the < 0 check in println) is a theoretical edge case that does not affect normal blocking stdout/stderr use.
No files require special attention.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Silver source calls print/format] --> B{Which path?} B -->|println / eprintln| C[std.io: null check] B -->|silver_rt_print_*| D[std.fmt: format into FmtPrintBuf] B -->|silver_rt_abort*| E[std.fmt: write_stderr + sys_kill SIGABRT] C --> F[std.fmt: cstr_len] F --> G[write_stdout / write_stderr] D --> H[itoa / utoa / btoa / ftoa] H --> I[append newline to buffer] I --> G G --> J[__fmt_write_fd: retry loop] J -->|r > 0| K[accumulate written bytes] K --> J J -->|written == len| L[sys_write fd 1 or 2] J -->|r == EINTR -4| J J -->|r < 0 non-EINTR| M[return error] subgraph ftoa Grisu2 H2[extract IEEE-754 fields] --> H3{special?} H3 -->|NaN| H4[write NaN] H3 -->|Inf| H5[write inf] H3 -->|zero| H6[write 0 or -0] H3 -->|normal/subnormal| H7[__fmt_grisu2] H7 --> H8[cached power lookup] H8 --> H9[__fmt_digit_gen + __fmt_grisu_round] H9 --> H10[place decimal point] end H --> H2%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD A[Silver source calls print/format] --> B{Which path?} B -->|println / eprintln| C[std.io: null check] B -->|silver_rt_print_*| D[std.fmt: format into FmtPrintBuf] B -->|silver_rt_abort*| E[std.fmt: write_stderr + sys_kill SIGABRT] C --> F[std.fmt: cstr_len] F --> G[write_stdout / write_stderr] D --> H[itoa / utoa / btoa / ftoa] H --> I[append newline to buffer] I --> G G --> J[__fmt_write_fd: retry loop] J -->|r > 0| K[accumulate written bytes] K --> J J -->|written == len| L[sys_write fd 1 or 2] J -->|r == EINTR -4| J J -->|r < 0 non-EINTR| M[return error] subgraph ftoa Grisu2 H2[extract IEEE-754 fields] --> H3{special?} H3 -->|NaN| H4[write NaN] H3 -->|Inf| H5[write inf] H3 -->|zero| H6[write 0 or -0] H3 -->|normal/subnormal| H7[__fmt_grisu2] H7 --> H8[cached power lookup] H8 --> H9[__fmt_digit_gen + __fmt_grisu_round] H9 --> H10[place decimal point] end H --> H2Reviews (3): Last reviewed commit: "Merge origin/main into std/fmt-pure-silv..." | Re-trigger Greptile
Context used: