lib/fmt+lib/log: drop rt_syscall stubs; use os
After #9 (f1440bf) fn labels mangle by module, so lib/fmt and lib/log
can use os; without colliding with lib/io on the read/write/close
leaves at link.
Drop the @symbol("rt_syscall") rtsyscall3/rtsyscall1 + rawwrite/
rawexit wrappers in both files; route the 7 fmt + 3 log call sites
through os.write / os.exit. Trim the workaround-rationale comments.
Mechanical rename; underlying syscall numbers and args unchanged.
This commit is contained in:
@@ -39,13 +39,8 @@
|
||||
//
|
||||
// Sink today is [[io.stream]] only — lib/io has no fd-backed stream
|
||||
// yet (Hare's `io::handle = file | int` collapses to one variant).
|
||||
// The default logger writes to stderr via a private io.stream that
|
||||
// dispatches through an rt_syscall write callback; mirrors lib/fmt's
|
||||
// defensive `rawwrite` / `rawexit` shape for the same C-symbol
|
||||
// collision reason (lib/os and lib/io both export `write`/`read`/
|
||||
// `close`, and `use os;` from log would re-trip #17). Both fmt and
|
||||
// log drop their rt_syscall stubs in one cleanup commit once #17
|
||||
// (cgen module-mangling of fn labels) lands.
|
||||
// The default logger writes to stderr via a private io.stream whose
|
||||
// write callback forwards to [[os.write]] on fd 2.
|
||||
//
|
||||
// Compiler note: wwstage cgen's variadic dispatch is name-based
|
||||
// (`fnparamslookup(callee.str)`), which would conflate the
|
||||
@@ -74,25 +69,7 @@
|
||||
|
||||
use fmt;
|
||||
use io;
|
||||
|
||||
// Direct rt_syscall bindings rather than `use os;` — os exports
|
||||
// read/write/close, which collide with io.read/write/close under the
|
||||
// driver's flat-scope concat. Mirrors lib/fmt and lib/memio. Removed
|
||||
// once #17 (cgen mod-mangle for fn labels) lands.
|
||||
@symbol("rt_syscall") fn rtsyscall3(num: i64, a: i64, b: i64, c: i64) i64;
|
||||
@symbol("rt_syscall") fn rtsyscall1(num: i64, a: i64) i64;
|
||||
|
||||
// rawwrite — Linux write(2) syscall (nr=1). Private stderr sink uses
|
||||
// this so log's exported surface stays clear of the os.write symbol.
|
||||
fn rawwrite(fd: i32, p: *u8, n: u64) i64 = {
|
||||
return rtsyscall3(1i64, fd: i64, p: i64, n: i64);
|
||||
};
|
||||
|
||||
// rawexit — Linux exit(2) syscall (nr=60). Used by [[fatal]] and
|
||||
// [[lfatal]] for the process-terminating arm.
|
||||
fn rawexit(code: i32) void = {
|
||||
rtsyscall1(60i64, code: i64);
|
||||
};
|
||||
use os;
|
||||
|
||||
// logger — interface for log dispatch. v1 carries a single vtable
|
||||
// slot. Hare layers a `printfln` slot for format-string callbacks;
|
||||
@@ -115,10 +92,10 @@ export type stdlogger = struct {
|
||||
sink: *io.stream,
|
||||
};
|
||||
|
||||
// stderrsink — private io.stream wired through the raw stderr fd (2)
|
||||
// via [[rawwrite]]. Used as [[default]]'s sink. Independent of lib/io's
|
||||
// future fd-backed stream — when that lands, this collapses to a
|
||||
// thin wrapper and graduates in one go.
|
||||
// stderrsink — private io.stream wired through fd 2 via [[os.write]].
|
||||
// Used as [[default]]'s sink. Independent of lib/io's future fd-backed
|
||||
// stream — when that lands, this collapses to a thin wrapper and
|
||||
// graduates in one go.
|
||||
let stderrsink: io.stream;
|
||||
|
||||
// _silent — backing storage for the [[silent]] global.
|
||||
@@ -167,7 +144,7 @@ fn stderrread(s: *io.stream, buf: []u8) (i32 | io.eof | io.closed) = {
|
||||
};
|
||||
|
||||
fn stderrwrite(s: *io.stream, buf: []u8) (i32 | io.closed) = {
|
||||
let r: i64 = rawwrite(2, buf.ptr, buf.len: u64);
|
||||
let r: i64 = os.write(2, buf.ptr, buf.len: u64);
|
||||
if (r < 0) {
|
||||
let e: io.closed;
|
||||
return e;
|
||||
@@ -218,14 +195,14 @@ export fn println(args: fmt.formattable...) void = {
|
||||
// Hare's lib/log/funcs.ha counterpart at line 28.
|
||||
export fn lfatal(log: *logger, args: fmt.formattable...) never = {
|
||||
lprintln(log, args...);
|
||||
rawexit(255);
|
||||
os.exit(255);
|
||||
};
|
||||
|
||||
// fatal — lprintln to [[global]] then exit(255). Hare's lib/log/
|
||||
// funcs.ha counterpart at line 45.
|
||||
export fn fatal(args: fmt.formattable...) never = {
|
||||
println(args...);
|
||||
rawexit(255);
|
||||
os.exit(255);
|
||||
};
|
||||
|
||||
// setlogger — install `log` as the [[global]] logger. Hare's
|
||||
|
||||
Reference in New Issue
Block a user