Skip to main content

Module process

Module process 

Source
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_args stored, or else the OS’s.
nova_rt_process_arg
process_arg(i: Int) -> String: argument i, or the empty string for an index out of range. std/process’s args() 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 with code. std::process::exit runs std’s cleanup, which flushes stdout, and does not join running tasks. The OS truncates code: Unix keeps its low 8 bits.
set_args
Fixes the program’s arguments to args. Returns true if this call set them, and false, changing nothing, if they were already fixed by an earlier call or an earlier read.