code wiki / (root) / nx_io.nx

nx_io.nx

buildroot/runtime/nx_io.nx

5107 B172 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic io
docsdependenciesstructsconstsfunctions

about

nx_io.nx -- buffered fd I/O (line-buffered stdout, full-buffered file). Today every nx_*.nx tool uses raw `sys_write(fd, buf, n)`. For per-character or per-token output (disassembler, hex dumps, log formatters) that's a syscall per byte -- thousands of context switches for one tool invocation. This module wraps each fd in a 4 KiB buffer: io = nx_io_open_fd(fd, mode) nx_io_write(io, "hello", 5) nx_io_putc(io, 0x21) nx_io_flush(io) nx_io_close(io) modes: NX_IO_LINEBUF : flush on '\n' (good for stderr / interactive) NX_IO_FULLBUF : flush only when buffer full or explicit flush Pairs with nx_strfmt (formatter takes an fd today, can take an nx_io once we wire it through) + nx_log + nx_dbg.

dependencies 1 imports · 0 importers

syscalls.nx nx_io.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_io_open_fd nx_io_putc nx_io_flush nx_io_flush ↻ nx_io_write nx_io_flush ↻ nx_io_puts nx_io_write ↻

structs

34struct NxIoFd

consts

30const NX_IO_BUFSZ: i64 = 4096
31const NX_IO_LINEBUF: i64 = 1
32const NX_IO_FULLBUF: i64 = 2
42const NX_IO_FD_BYTES: i64 = 40

functions

44func nx_io_open_fd(fd: i64, mode: i64) -> *NxIoFd
called by 1: main
57func nx_io_flush(io: *NxIoFd) -> i64
66func nx_io_putc(io: *NxIoFd, c: i64) -> i64
called by 1: main calls 1: nx_io_flush
81func nx_io_write(io: *NxIoFd, src: *u8, n: i64) -> i64
called by 2: nx_io_putsmain calls 1: nx_io_flush
119func nx_io_puts(io: *NxIoFd, s: *u8) -> i64
called by 1: main calls 1: nx_io_write
127func nx_io_close(io: *NxIoFd) -> i64
calls 1: nx_io_flush
133func main() -> i64