nx_io.nx
buildroot/runtime/nx_io.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 34 | struct NxIoFd |
consts
| 30 | const NX_IO_BUFSZ: i64 = 4096 |
| 31 | const NX_IO_LINEBUF: i64 = 1 |
| 32 | const NX_IO_FULLBUF: i64 = 2 |
| 42 | const NX_IO_FD_BYTES: i64 = 40 |
functions
| 44 | func nx_io_open_fd(fd: i64, mode: i64) -> *NxIoFd called by 1: main |
| 57 | func nx_io_flush(io: *NxIoFd) -> i64 |
| 66 | func nx_io_putc(io: *NxIoFd, c: i64) -> i64 |
| 81 | func nx_io_write(io: *NxIoFd, src: *u8, n: i64) -> i64 |
| 119 | func nx_io_puts(io: *NxIoFd, s: *u8) -> i64 |
| 127 | func nx_io_close(io: *NxIoFd) -> i64 calls 1: nx_io_flush |
| 133 | func main() -> i64 |