Files
sx/examples/0602-comptime-interp-cast-ptr-cmp.sx
agra 65ac370683 P5.4: migrate all callers to on_build; delete set_post_link_callback
on_build is now the sole post-build callback mechanism. Migrated the 9 callers
(0602/0603/1611/1614/1615/1616 + the platform bundle_main) from
opts.set_post_link_callback(cb) to on_build(cb), giving each callback the
(opt: BuildOptions) param. Deleted set_post_link_callback from build.sx,
compiler_lib (bound_fns + handleSetPostLinkCallback), and the VM arm.

Reworked the P5 smoke tests for the new semantics: an on_build override REPLACES
the build (must emit+link or delegate), unlike the old post-link callback which
ran after the auto-link. 1662 (queries) + 1664 (override+List-grow) now delegate
to default_pipeline for the real build; deleted 1661/1663 (the primitives are now
exercised by every AOT build). bundle_main invoked with pass_options=true.

Benign 37-.ir churn (build.sx shrank). 703/0 both gates.
2026-06-19 09:37:05 +03:00

36 lines
1.0 KiB
Plaintext

// `cast(T) val` inside a conditional, evaluated by the IR interpreter
// during a post-link callback. The `cast` syntax lowers the type arg
// (`i64`) as a `placeholder` IR op; the interpreter treats placeholders
// as undef so the comparison runs through unchanged.
#import "modules/std.sx";
#import "modules/build.sx";
libc :: #library "c";
popen :: (cmd: [:0]u8, mode: [:0]u8) -> *void extern libc;
puts :: (s: [:0]u8) -> i32 extern libc;
R :: struct { x: i32; }
bug :: (cmd: [:0]u8) -> ?R {
f := popen(cmd, "r");
if cast(i64) f == 0 { return null; }
R.{ x = 1 }
}
post_link :: (opt: BuildOptions) -> bool abi(.compiler) {
if r := bug("echo hi") { puts("ok"); } else { puts("null"); }
true
}
// The registrar is itself compiler-domain (`abi(.compiler)`): it runs in the
// comptime evaluator (never the binary), so its `build_options()` /
// `set_post_link_callback()` compiler-API calls are permitted.
configure :: () abi(.compiler) {
opts := build_options();
on_build(post_link);
}
#run configure();
main :: () { print("rt\n"); }