ww: import toolchain — C bootstrap + ww-side self-host (phases 0-10)
C bootstrap (phases 0-9):
cmd/wwc, cmd/6c, cmd/6a, cmd/6l, cmd/ww, rt, lib/*.
ww-side self-host (phase 10):
selfhost/cmd/wwc — ww-cgen frontend; bootstrap fixed point.
selfhost/cmd/6a — assembler; byte-identical to C 6a (test 991).
selfhost/cmd/6l — linker w/ archive (.a) support; byte-identical
to C 6l (test 992).
selfhost/cmd/ww — driver (build/run/version); byte-identical to
C ww (test 993).
make test: 15/15. make bootstrap: ww2.s == ww3.s, ww2.o == ww3.o,
ww2 == ww3 byte-identical, with the full ww-tooled chain.
This commit is contained in:
67
lib/fmt/fmt.ww
Normal file
67
lib/fmt/fmt.ww
Normal file
@@ -0,0 +1,67 @@
|
||||
// fmt — minimal formatting writers. All output goes through os.write
|
||||
// to fd 1 (stdout). No printf-family yet — we don't have varargs in
|
||||
// the language proper — but the typed entry points cover the common
|
||||
// cases.
|
||||
|
||||
use os;
|
||||
use strconv;
|
||||
|
||||
export fn print(s: str) i64 = {
|
||||
return os.write(1, s.ptr, s.len: u64);
|
||||
};
|
||||
|
||||
export fn println(s: str) void = {
|
||||
os.write(1, s.ptr, s.len: u64);
|
||||
os.write(1, "\n".ptr, 1u64);
|
||||
};
|
||||
|
||||
export fn printint(v: i64) void = {
|
||||
let buf: [32]u8;
|
||||
let n: i32 = strconv.i64toa(buf[0:32], v);
|
||||
os.write(1, buf.ptr, n: u64);
|
||||
};
|
||||
|
||||
export fn printlnint(v: i64) void = {
|
||||
printint(v);
|
||||
os.write(1, "\n".ptr, 1u64);
|
||||
};
|
||||
|
||||
// errln — write a message to stderr with a trailing newline.
|
||||
export fn errln(s: str) void = {
|
||||
os.write(2, s.ptr, s.len: u64);
|
||||
os.write(2, "\n".ptr, 1u64);
|
||||
};
|
||||
|
||||
// fprint / fprintln — same as print/println but on an arbitrary fd.
|
||||
// Used by the compiler to write to its -o output file.
|
||||
export fn fprint(fd: i32, s: str) i64 = {
|
||||
return os.write(fd, s.ptr, s.len: u64);
|
||||
};
|
||||
|
||||
export fn fprintln(fd: i32, s: str) void = {
|
||||
os.write(fd, s.ptr, s.len: u64);
|
||||
os.write(fd, "\n".ptr, 1u64);
|
||||
};
|
||||
|
||||
export fn fprintint(fd: i32, v: i64) void = {
|
||||
let buf: [32]u8;
|
||||
let n: i32 = strconv.i64toa(buf[0:32], v);
|
||||
os.write(fd, buf.ptr, n: u64);
|
||||
};
|
||||
|
||||
// errpos — write "<file>:<line>:<col>: <msg>\n" to fd 2. The shape
|
||||
// every compiler diagnostic uses; centralised so the format stays
|
||||
// consistent across phases.
|
||||
export fn errpos(file: str, line: i32, col: i32, msg: str) void = {
|
||||
os.write(2, file.ptr, file.len: u64);
|
||||
os.write(2, ":".ptr, 1u64);
|
||||
let buf: [32]u8;
|
||||
let n: i32 = strconv.i64toa(buf[0:32], line: i64);
|
||||
os.write(2, buf.ptr, n: u64);
|
||||
os.write(2, ":".ptr, 1u64);
|
||||
n = strconv.i64toa(buf[0:32], col: i64);
|
||||
os.write(2, buf.ptr, n: u64);
|
||||
os.write(2, ": ".ptr, 2u64);
|
||||
os.write(2, msg.ptr, msg.len: u64);
|
||||
os.write(2, "\n".ptr, 1u64);
|
||||
};
|
||||
Reference in New Issue
Block a user