nit: Added link to `CONTRIBUTING.md` from the README
[nit.git] / share / man / nit.md
1 # NAME
2
3 nit - interprets and debugs Nit programs.
4
5 # SYNOPSIS
6
7 nit [*options*] FILE [ARG]...
8
9 nit [*options*] -e COMMAND [ARG]...
10
11 # DESCRIPTION
12
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.
15
16     $ nit examples/hello_world.nit
17     hello world
18
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.
21
22     #!/usr/bin/env nit
23     print "hello world"
24
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.
27
28
29 The behavior of the interpreter may differs slightly from the compiler.
30
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.
33
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.
37
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.
41
42
43 # OPTIONS
44
45 Most options are the same than `nitc(1)`.
46 Here, only the specific one are indicated.
47
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.
50
51     $ nit -e 'print args.first' -v
52     -v
53
54 ## COMMAND
55
56 ### `-e`
57 Specifies the program from command-line.
58
59 The `-e` option runs a program written on the command line.
60 Like with ruby, perl, bash and other script language.
61
62     $ nit -e 'print 5+5'
63     10
64
65 ### `-n`
66 Repeatedly run the program for each line in file-name arguments.
67
68 If no arguments are given, then `nit` iterates over the lines of the standard input (stdin).
69
70     $ echo "hello world" | nit -n -e 'print sys.line.capitalized'
71     Hello World
72
73 If some arguments are given, then `nit` considers that each argument is a filepath then it iterates on their lines.
74
75 ## INTERPRETATION OPTIONS
76
77 ### `--discover-call-trace`
78 Trace calls of the first invocation of methods.
79
80 Each time a method is invoked for the first time, its information is printed on the standard output for error (`stderr`).
81
82 This option helps the user to have a simplified but humanly readable overview of the behavior of a particular program execution.
83
84 ## DEBUGGER OPTIONS
85
86 ### `-d`
87 Launches the target program with the debugger attached to it.
88
89 ### `-c`
90 Launches the target program with the interpreter, such as when the program fails, the debugging prompt is summoned.
91
92 ### `--socket`
93 Launches the target program with raw output on the network via sockets.
94
95 ### `--websocket`
96 Launches the target program with output on the network via websockets.
97
98 ### `--port`
99 Sets the debug port (Defaults to 22125) - Must be contained between 0 and 65535.
100
101 ## OTHER OPTIONS
102
103 ### `--vm`
104 Run the virtual machine instead of the naive interpreter (experimental).
105
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.
107
108 ### `-o`
109 Does nothing. Used for compatibility.
110
111
112 # DEBUGGER
113
114 To use use the debugger, launch your program using the nit interpreter `nit` with `-d` option.
115
116 It is also possible to execute the program normally until an error is encountered using the `-c` option.
117
118 A remote debugger is also available, it can be used with the client-side executable `nitdbg_client`.
119
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.
121
122 ## DEBUGGER FEATURES
123
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.
125
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.
127
128 When an error is encountered, the debugger gives you the chance of inputting commands before exiting.
129
130 The debugger also gives the possibility of printing the values of the requested variables.
131
132 The modification of variables at runtime is possible too, but only if the variables are of primitive types (until it becomes possible).
133
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.
135
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.
137
138 ## DEBUGGER COMMANDS
139
140 ### `n`
141 Proceeds to the next instruction (step-over)
142
143 ### `s`
144 Steps in an instruction
145
146 ### `finish`
147 Steps out of an instruction
148
149 ### `c`
150 Continues the execution until a breakpoint is encountered or until an error/end of program
151
152 ### `b/break line_number`
153 Adds a breakpoint on line *line_number* for the current file
154
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)
157
158 ### `d/delete line_number`
159 Removes a breakpoint on line *line_number* for the current file
160
161 ### `d/delete file line_number`
162 Removes a breakpoint on line *line_number* for the file *file*
163
164 ### `kill`
165 Kills the current program (produces a stack trace)
166
167 ### `variable = value`
168 Sets the value of *variable* to *value* (Only supports primitive types for now : Bool, Char, Int, Float)
169
170 ### `p/print variable_name`
171 Prints the value of the variable *variable_name*
172
173 ### `p/print stack`
174 Prints a stack trace starting with the current frame
175
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)
178
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*
181
182 All the print commands also work on any dimension SequenceRead collection.
183
184 ### `variable_name as alias`
185 Sets an alias *alias* for the variable *variable_name*
186
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)
189
190 ### `untrace variable_name`
191 Removes the trace on the variable you chose to trace earlier in the program
192
193
194 # SEE ALSO
195
196 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>