Files
sx/examples/1030-errors-log-and-comptime.sx
agra 59f0aa7716 std: restructure — std/ modules, namespace tail, std/xml.sx
allocators/fs/process/socket/log/trace/test move under modules/std/
(allocators.sx becomes std/mem.sx; the Allocator protocol moves into
the std.sx prelude, impls stay in mem.sx). New std/xml.sx holds
xml_escape as xml.escape. std.sx gains the carried namespace tail —
flat-importing std.sx now also provides mem./xml./log. — with the
remaining modules (fs/process/socket/json/cli/hash/test) deferred from
the tail until the global last-wins maps are fully own-wins (pulling
them into every closure collides bare names corpus-wide; they stay
direct imports: modules/std/fs.sx etc.). log.sx's internal emit
renamed log_emit (it clobbered consumer fns named emit program-wide).
bundle.sx uses xml.escape via the carried alias. Consumer import paths
swept mechanically; .ir snapshots recaptured for the larger std
closure. m3te + game build unchanged.
2026-06-11 06:10:59 +03:00

32 lines
1.2 KiB
Plaintext

// `log.sx` leveled logging + the `is_comptime()` builtin (ERR step E4.1,
// slice 1). `log.{warn,info,err,debug}` interpolate like `print` and write
// `LEVEL: <msg>` to stderr. `is_comptime()` is `true` under `#run` (the
// comptime interpreter) and folds to `false` in compiled code, so a gated
// branch dead-codes out of the runtime binary.
//
// (`log.error` is spelled `log.err` — `error` is a reserved keyword. The
// `process.exit` / `assert` part of E4.1 is blocked on `noreturn` codegen,
// issue 0058.)
//
// The test runner merges stderr+stdout; the log lines (stderr) precede the
// single stdout line. Expected exit code: 0.
#import "modules/std.sx";
log :: #import "modules/std/log.sx";
probe :: () -> s32 {
if is_comptime() { return 1; } // comptime interpreter path
return 2; // compiled-code path
}
CT :: #run probe(); // folds to 1 (run in the interpreter)
main :: () -> s32 {
log.warn("disk {}% full", 91);
log.info("user {} connected", "alice");
log.err("bad fd {}", 7);
log.debug("trace x={}", 42);
print("[stdout] is_comptime runtime={} comptime={}\n", probe(), CT);
return 0;
}