F3.1: std.cli os_args — real OS argv accessor via #foreign _NSGetArgv (examples/0716)

Add library/modules/std/cli.sx: a pure-sx command-line argument accessor
backed by the macOS C runtime (_NSGetArgv/_NSGetArgc), no compiler change.

  os_argc() -> s64
  os_args(buf: []string) -> []string

Zero heap, zero per-arg allocation: os_args fills a caller-provided buffer
(stack array) with string VIEWS over the process's own argv block, which
lives for the whole process. The returned slice header is a by-value stack
return; nothing touches context.allocator.

Documents the `sx run` reality: under `sx run <prog.sx> ...` the process
argv is the interpreter's argv (sx, run, prog.sx, ...), not a program's
logical args. This accessor reports the real process argv truthfully;
mapping to logical args is a later consumer concern (distribution P3.1).

Non-macOS platforms bail loudly (message + _exit) rather than returning a
silent empty.

examples/0716-modules-cli-argv.sx asserts only deterministic structural
invariants (argc >= 1, argv[0] non-empty, os_argc() == filled length).
This commit is contained in:
agra
2026-06-04 03:21:41 +03:00
parent 090bdd7cfa
commit e7f5bd7aaa
5 changed files with 130 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
argc>=1: ok
arg0-nonempty: ok
argc-consistent: ok