Expand description
The program’s arguments and exit, behind std/process (see its module
doc and docs/adr/0023-program-arguments.md). pub so the driver’s JIT
path can set the list, and so tests/process_args_*.rs can drive it.
The running program’s arguments, and a way to end it with a status:
the runtime half of std/process’s args() and exit().
One process-wide list, set at most once. nova run runs a program
inside nova.exe, whose own argv is nova’s, so the driver calls
set_args with [FILE, ARGS...] before main
(CompiledProgram::run_with_args). If nothing set it, the first read takes
the OS’s argv through std::env::args_os(). A built executable takes that
path: its generated C main drops argc and argv, but std’s argv does
not depend on them. glibc passes them to std’s .init_array function,
macOS answers _NSGetArgc/_NSGetArgv, and Windows parses the UTF-16
GetCommandLineW, which keeps non-ASCII arguments a C main’s ANSI
argv would garble. nova test’s binary takes it too, and gets no
arguments. docs/adr/0023-program-arguments.md records the decision.
An argument that is not valid Unicode is converted with
to_string_lossy: U+FFFD stands in for its bad bytes, and nothing panics.
pub, so crates/nova-runtime/tests/process_args_*.rs can drive it, and
so nova-codegen-cranelift can call set_args.
Functions§
- args
- The program’s arguments: the list
set_argsstored, or else the OS’s. - nova_
rt_ process_ arg process_arg(i: Int) -> String: argumenti, or the empty string for an index out of range.std/process’sargs()never asks for one.- nova_
rt_ process_ arg_ count process_arg_count() -> Int: how many arguments the program has, counting the program itself at index 0.- nova_
rt_ process_ exit process_exit(code: Int): ends the process withcode.std::process::exitruns std’s cleanup, which flushes stdout, and does not join running tasks. The OS truncatescode: Unix keeps its low 8 bits.- set_
args - Fixes the program’s arguments to
args. Returnstrueif this call set them, andfalse, changing nothing, if they were already fixed by an earlier call or an earlier read.