Module modf_arity

Module modf_arity 

Source
Expand description

Pass: lower HLSL two-arg modf(x, &out) to WGSL’s one-arg struct form.

HLSL spec: modf(x, &out) returns the fractional part of x and writes the integer part (truncated toward zero) into out.

WGSL spec: modf(x) returns __modf_result_f32 { fract: f32, whole: f32 }. The two-arg HLSL form is rejected at parse with too many arguments passed to 'modf'.

Corpus shape (5 / 2 000 warp presets, all in the same PutDist helper inherited from the whoah / martin / amandio packs):

float fg, fb;
fg = modf((1-x)*255.0, fb);

Rewrite injects a unique temp at the call site so the input is only evaluated once, then replaces the original assign with the two component reads:

let _md2_modf_K = modf((1-x)*255.0);
fb = _md2_modf_K.whole;
fg = _md2_modf_K.fract;

Only fires on Stmt::Assign(target, =, Call("modf", [arg, out_ident])) where out_ident is a bare Expr::Ident. Compound assigns (+= etc.) and out-arg shapes the user wrote as modf(x, &out) (with HLSL’s & prefix) are out-of-scope — neither appears in the corpus.

Statics§

MODF_TEMP_COUNTER 🔒

Functions§

rewrite_modf_arity 🔒
slice 🔒
span_includes_semi 🔒
try_emit_modf_in_init 🔒
try_emit_modf_rewrite 🔒
unique_temp 🔒
walk_block 🔒
walk_stmt 🔒