3 nit - interprets and debugs Nit programs.
7 nit [*options*] FILE [ARG]...
9 nit [*options*] -e COMMAND [ARG]...
13 `nit` is the current official interpreter.
14 It takes the main module of a program as the first argument then the options and commands of the program.
16 $ nit examples/hello_world.nit
19 The Nit interpreter is usable and valid as a *shebang* interpreted directive.
20 It is however recommended to use with `/usr/bin/env` because the location of the executable is not standardized.
25 The interpreter includes an interactive debugger, it supports basic commands used for debugging a program much like GDB or such.
26 See the `DEBUGGER` section for details.
29 The behavior of the interpreter may differs slightly from the compiler.
31 First, the interpreted is the reference implementation for the specification of the Nit language.
32 That means if `nitc` and `nit` have a different behavior on a same program, it is likely that `nit` is right and `nitc` is wrong.
34 Second, the FFI is not yet implemented in the interpreter.
35 Only a subset of the standard methods are implemented with some hard-coded behaviors.
36 While it is enough to use most of the standard library, a lot of additional libraries may not be usable by the interpreter.
38 Last, `nit` is the *Naive Interpretation Tool*, it means that it is slow and may take an average of 50.000% in overhead comparatively to `nitc`(it also means that `nitc` is fast).
39 In practice, the slowness is not an issue for simple Nit scripts;
40 it is not a big deal if `nit` takes millisecond to execute programs even if `nitc` only need microseconds.
45 Most options are the same than `nitc(1)`.
46 Here, only the specific one are indicated.
48 Note that, unlike in other Nit tools, the options *MUST* be indicated before the main module of a program.
49 Whatever follows it is used as arguments of the interpreted program.
51 $ nit -e 'print args.first' -v
57 Specifies the program from command-line.
59 The `-e` option runs a program written on the command line.
60 Like with ruby, perl, bash and other script language.
66 Repeatedly run the program for each line in file-name arguments.
68 If no arguments are given, then `nit` iterates over the lines of the standard input (stdin).
70 $ echo "hello world" | nit -n -e 'print sys.line.capitalized'
73 If some arguments are given, then `nit` considers that each argument is a filepath then it iterates on their lines.
75 ## INTERPRETATION OPTIONS
77 ### `--discover-call-trace`
78 Trace calls of the first invocation of methods.
80 Each time a method is invoked for the first time, its information is printed on the standard output for error (`stderr`).
82 This option helps the user to have a simplified but humanly readable overview of the behavior of a particular program execution.
87 Launches the target program with the debugger attached to it.
90 Launches the target program with the interpreter, such as when the program fails, the debugging prompt is summoned.
93 Launches the target program with raw output on the network via sockets.
96 Launches the target program with output on the network via websockets.
99 Sets the debug port (Defaults to 22125) - Must be contained between 0 and 65535.
104 Run the virtual machine instead of the naive interpreter (experimental).
106 The virtual machine is currently under heavy development and, unless you are developing the vm, there is no reason to use this option yet.
109 Does nothing. Used for compatibility.
114 To use use the debugger, launch your program using the nit interpreter `nit` with `-d` option.
116 It is also possible to execute the program normally until an error is encountered using the `-c` option.
118 A remote debugger is also available, it can be used with the client-side executable `nitdbg_client`.
120 On the client side, the debugger works like the previous one, input some commands when debugging a program, except you have to launch the server before trying to debug.
124 When using a debugger, a must-have is the possibility to control execution of your program by stepping over, in and out of a line/snippet of code. The nit debugger allows you to do that.
126 You can add/remove breakpoints on instructions, so that the execution will stop when the execution reaches the specified line of the specified file.
128 When an error is encountered, the debugger gives you the chance of inputting commands before exiting.
130 The debugger also gives the possibility of printing the values of the requested variables.
132 The modification of variables at runtime is possible too, but only if the variables are of primitive types (until it becomes possible).
134 Also, you probably won't want to type a long variable name every time you wish to print its value, the debugger has the possibility of setting aliases to replace the awfully long and cryptic name of that variable you try to access by a beautiful alias.
136 If you want to trace the modifications or uses of a variable of your choice, the trace command will be perfect for you as it will print or break when encountering the variable of your choice.
141 Proceeds to the next instruction (step-over)
144 Steps in an instruction
147 Steps out of an instruction
150 Continues the execution until a breakpoint is encountered or until an error/end of program
152 ### `b/break line_number`
153 Adds a breakpoint on line *line_number* for the current file
155 ### `b/break file line_number`
156 Adds a breakpoint on line *line_number* for the file *file* (Don't forget to add the .nit extension to the command)
158 ### `d/delete line_number`
159 Removes a breakpoint on line *line_number* for the current file
161 ### `d/delete file line_number`
162 Removes a breakpoint on line *line_number* for the file *file*
165 Kills the current program (produces a stack trace)
167 ### `variable = value`
168 Sets the value of *variable* to *value* (Only supports primitive types for now : Bool, Char, Int, Float)
170 ### `p/print variable_name`
171 Prints the value of the variable *variable_name*
174 Prints a stack trace starting with the current frame
176 ### `p/print variable_name[index]`
177 Prints the value of the variable contained at the index *index* of variable *variable_name* (*variable_name* must be a subtype of SequenceRead)
179 ### `p/print variable_name[index_from..index_to]`
180 Prints the values of all the variables contained from index *index_from* up to *index_to* in the variable *variable_name*
182 All the print commands also work on any dimension SequenceRead collection.
184 ### `variable_name as alias`
185 Sets an alias *alias* for the variable *variable_name*
187 ### `trace variable_name [break/print]`
188 Traces the uses of the variable you chose to trace by printing the statement it appears in or by breaking on each use. (The [break/print] part is not mandatory, by default, the print option will be used)
190 ### `untrace variable_name`
191 Removes the trace on the variable you chose to trace earlier in the program
196 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>