man: rename nitg to nitc
[nit.git] / share / man / nit.md
1 % NIT(1)
2
3 # NAME
4
5 nit - interprets and debugs Nit programs.
6
7 # SYNOPSIS
8
9 nit [*options*] FILE [ARG]...
10
11 nit [*options*] -e COMMAND [ARG]...
12
13 # DESCRIPTION
14
15 `nit` is the current official interpreter.
16 It takes the main module of a program as the first argument then the options and commands of the program.
17
18     $ nit examples/hello_world.nit
19     hello world
20
21 The Nit interpreter is usable and valid as a *shebang* interpreted directive.
22 It is however recommended to use with `/usr/bin/env` because the location of the executable is not standardized.
23
24     #!/usr/bin/env nit
25     print "hello world"
26
27 The interpreter includes an interactive debugger, it supports basic commands used for debugging a program much like GDB or such.
28 See the `DEBUGGER` section for details.
29
30
31 The behavior of the interpreter may differs slightly from the compiler.
32
33 First, the interpreted is the reference implementation for the specification of the Nit language.
34 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.
35
36 Second, the FFI is not yet implemented in the interpreter.
37 Only a subset of the standard methods are implemented with some hard-coded behaviors.
38 While it is enough to use most of the standard library, a lot of additional libraries may not be usable by the interpreter.
39
40 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).
41 In practice, the slowness is not an issue for simple Nit scripts;
42 it is not a big deal if `nit` takes  millisecond to execute programs even if `nitc` only need microseconds.
43
44
45 # OPTIONS
46
47 Most options are the same than `nitc(1)`.
48 Here, only the specific one are indicated.
49
50 Note that, unlike in other Nit tools, the options *MUST* be indicated before the main module of a program.
51 Whatever follows it is used as arguments of the interpreted program.
52
53     $ nit -e 'print args.first' -v
54     -v
55
56 ## COMMAND
57
58 `-e`
59 :   Specifies the program from command-line.
60
61     The `-e` option runs a program written on the command line.
62     Like with ruby, perl, bash and other script language.
63
64         $ nit -e 'print 5+5'
65         10
66
67 `-n`
68 :   Repeatedly run the program for each line in file-name arguments.
69
70     If no arguments are given, then `nit` iterates over the lines of the standard input (stdin).
71
72         $ echo "hello world" | nit -n -e 'print sys.line.capitalized'
73         Hello World
74
75     If some arguments are given, then `nit` considers that each argument is a filepath then it iterates on their lines.
76
77 ## INTERPRETATION OPTIONS
78
79 `--discover-call-trace`
80 :   Trace calls of the first invocation of methods.
81
82     Each time a method is invoked for the first time, its information is printed on the standard output for error (`stderr`).
83
84     This option helps the user to have a simplified but humanly readable overview of the behavior of a particular program execution.
85
86 ## DEBUGGER OPTIONS
87
88 `-d`
89 :   Launches the target program with the debugger attached to it
90
91 `-c`
92 :   Launches the target program with the interpreter, such as when the program fails, the debugging prompt is summoned
93
94 `--socket`
95 :   Launches the target program with raw output on the network via sockets
96
97 `--websocket`
98 :   Launches the target program with output on the network via websockets
99
100 `--port`
101 :   Sets the debug port (Defaults to 22125) - Must be contained between 0 and 65535
102
103 ## OTHER OPTIONS
104
105 `-o`
106 :   Does nothing. Used for compatibility.
107
108
109 # DEBUGGER
110
111 To use use the debugger, launch your program using the nit interpreter `nit` with `-d` option.
112
113 It is also possible to execute the program normally until an error is encountered using the `-c` option.
114
115 A remote debugger is also available, it can be used with the client-side executable `nitdbg_client`.
116
117 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.
118
119 ## DEBUGGER FEATURES
120
121 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.
122
123 You can add/remove breakpoints on instructions, so that the execution will stop when the execution reaches the specified line of the specified file.
124
125 When an error is encountered, the debugger gives you the chance of inputting commands before exiting.
126
127 The debugger also gives the possibility of printing the values of the requested variables.
128
129 The modification of variables at runtime is possible too, but only if the variables are of primitive types (until it becomes possible).
130
131 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.
132
133 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.
134
135 ## DEBUGGER COMMANDS
136
137 `n`
138 :   Proceeds to the next instruction (step-over)
139
140 `s`
141 :   Steps in an instruction
142
143 `finish`
144 :   Steps out of an instruction
145
146 `c`
147 :   Continues the execution until a breakpoint is encountered or until an error/end of program
148
149 `b/break line_number`
150 :   Adds a breakpoint on line *line_number* for the current file
151
152 `b/break file line_number`
153 :   Adds a breakpoint on line *line_number* for the file *file* (Don't forget to add the .nit extension to the command)
154
155 `d/delete line_number`
156 :   Removes a breakpoint on line *line_number* for the current file
157
158 `d/delete file line_number`
159 :   Removes a breakpoint on line *line_number* for the file *file*
160
161 `kill`
162 :   Kills the current program (produces a stack trace)
163
164 `variable = value`
165 :   Sets the value of *variable* to *value* (Only supports primitive types for now : Bool, Char, Int, Float)
166
167 `p/print variable_name`
168 :   Prints the value of the variable *variable_name*
169
170 `p/print stack`
171 :   Prints a stack trace starting with the current frame
172
173 `p/print variable_name[index]`
174 :   Prints the value of the variable contained at the index *index* of variable *variable_name* (*variable_name* must be a subtype of SequenceRead)
175
176 `p/print variable_name[index_from..index_to]`
177 :   Prints the values of all the variables contained from index *index_from* up to *index_to* in the variable *variable_name*
178
179 All the print commands also work on any dimension SequenceRead collection.
180
181 `variable_name as alias`
182 :   Sets an alias *alias* for the variable *variable_name*
183
184 `trace variable_name [break/print]`
185 :   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)
186
187 `untrace variable_name`
188 :   Removes the trace on the variable you chose to trace earlier in the program
189
190
191 # SEE ALSO
192
193 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>