Skip to content

Command line Arguments

Nick Barnes edited this page May 2, 2013 · 3 revisions

There is some twisty treatment of command-line arguments in the runtime. Here are some brief notes.

Process Start

main.c::main() calls threads.c::run_scheduler(), which starts the thread system and runs mlw_start::start_mlworks() in the first active thread (the zeroth thread is the scheduler itself). argv and argc are passed through into start_mlworks().

On Windows, there is a "DLLized" version of the runtime. In that case, mlw_dll::mlw_main() collects the command line args by calling OS/Win32/os.c::parse_command_line(), and then calls run_scheduler() in the same way. There is another function called mlw_dll::trampoline(), which isn't apparently called from anywhere in the runtime, but which essentially does the same thing. If you figure out how the DLLized runtime is supposed to work, please document it.

Parsing in the Runtime

Runtime arguments are delimited by -MLWpass <x> ... <x>. For instance -MLWpass foo -load batch.img foo. This is apparently the only way to pass runtime options. The allowed options are defined in mlw_start.c (search for option_load and usage_message). Option parsing itself is done in options.c. Everything after the closing delimiter of the -MLWpass option, or the whole argument list if that is not passed, is put into the global variables mlw_start.c::module_argv and mlw_start.c::module_argc.

Passing to ML

MLWorks.arguments() : unit -> string list calls system.c::arguments() which turns module_argv into ML strings and returns the resulting list. For an example of this being called, see main/__batch.sml.

Parsing in ML

main/_batch.sml has an example of command-line parsing in ML.

Previous behaviour

Until 1998-09 (or thereabouts), the command-line was treated differently. Specifically, all options were treated as runtime options except those contained in a -pass <x> ... <x> section, which were passed on to ML. For instance, this is the behaviour of the runtime shipped with MLWorks 2.0 (which we may use for bootstrapping purposes).

Clone this wiki locally