raz / doc / raz.1

397 lines · 10.1 KiB · raw · history · last change dafe42af

1.\" raz(1) - the raz compiler
2.Dd October 19, 2026
3.Dt RAZ 1
4.Os
5.Sh NAME
6.Nm raz
7.Nd compile a raz program to a Linux executable
8.Sh SYNOPSIS
9.Nm
10.Op Ar option ...
11.Ar Main.raz
12.Nm
13.Cm run
14.Op Ar option ...
15.Ar Main.raz
16.Op Ar arg ...
17.Nm
18.Fl q Cm check
19.Op Ar option ...
20.Ar Main.raz
21.Nm
22.Fl q Cm words
23.Op Ar option ...
24.Ar Main.raz : Ns Ar LINE : Ns Ar COL
25.Nm
26.Fl q Cm def
27.Op Ar option ...
28.Ar Main.raz : Ns Ar LINE : Ns Ar COL
29.Sh DESCRIPTION
30.Nm
31compiles the module in
32.Ar Main.raz ,
33and every module it imports, to an executable for x86-64 Linux, with
34no assembler, linker or C library in between.
35A program that names a C library in a
36.Ic link
37line, or declares an
38.Ic extern
39procedure, is linked against C dynamically; any other is static.
40.Pp
41A module
42.Ar Name
43is found as
44.Ar Name Ns .linux-x86_64.raz
45or
46.Ar Name Ns .raz
47in the directory of
48.Ar Main.raz ,
49then in each
50.Fl I
51directory in turn, then in the user library directories (see
52.Sx ENVIRONMENT ) ,
53then in the library,
54.Pa lib/
55beside the
56.Nm
57executable (or the one
58.Fl lib
59names), whose modules
60.Xr raz-lib 3
61says.
62A program has one module of each name: a module found in two of these
63places is an error, unless one of the files is a symbolic link to the
64other, which chooses it.
65.Pp
66.Nm
67.Cm run
68compiles the same way, then runs the program with the
69.Ar arg Ns s ,
70writing no file: its output and exit status are those of the command.
71.Pp
72Every array index and slice is checked, unless the module says
73.Ic check off ;
74a failed check, a nil pointer, a division by zero or a stack overflow
75ends the program with status 2, and says on standard error where it
76was, the calls under way, and their variables:
77.Bd -literal -offset indent
78Bad.raz:6:7: index 5 is out of range for a length of 3
79 in Bad.main at Bad.raz:6:7: i = 5
80.Ed
81.Pp
82The executable has a symbol table and line numbers for
83.Xr gdb 1 ,
84.Xr nm 1
85and
86.Xr perf 1 ,
87unless built with
88.Fl s .
89.Sh OPTIONS
90.Bl -tag -width "-noprofile"
91.It Fl o Ar file
92Write the executable to
93.Ar file .
94Left out, it is
95.Ar Main.raz
96without
97.Pa .raz .
98.Cm run
99takes no
100.Fl o .
101.It Fl I Ar dir
102Look for imported modules in
103.Ar dir
104too, after the main module's own directory and before the library.
105It may be given up to 16 times.
106An error in a module found in such a directory, or in one of
107.Ev RAZ_PATH ,
108names that directory in its path; and if the directory holds a file
109.Pa RAZ-VERSION ,
110of one line such as
111.Ql 0.21 ,
112a second line says the raz the library was written for and this one:
113.Ql (a library written for raz 0.18; this is raz 0.21) .
114The compiler only reads the file; it never refuses to build for it.
115.It Fl lib Ar dir
116The standard library is
117.Ar dir ,
118not the
119.Pa lib/
120beside the
121.Nm
122executable.
123It is searched last, after the main module's directory, the
124.Fl I
125directories and the user library directories, as the default library is;
126the duplicate-module rule and its symbolic-link exception apply to it
127unchanged.
128It is an error if
129.Ar dir
130cannot be reached.
131A kernel's library holds its own
132.Pa Rt.raz
133and
134.Pa Sys.raz ,
135with symbolic links to the modules of raz's own library that it takes.
136.It Fl Werror
137A warning counts as an error.
138.It Fl S
139List the main module's machine code, each instruction under the line
140of source it was made for, on standard output, and write no
141executable.
142.It Fl s
143Strip the program of what is there for finding faults: its symbol
144table, its line numbers, the places a failure is told by, and the
145profiler.
146A failure then says only its address, and the program is much
147smaller: hello, world is 7 KB, against 28 KB.
148.It Fl base Ar addr
149Load the program at
150.Ar addr ,
151not 400000H, as a kernel may want: a multiple of 4096, written as raz
152writes a number, as
153.Cm 0FFFFFFFF80000000H .
154The program must lie wholly in the low or the top 2 GB of the address
155space, which a 32-bit address reaches.
156.It Fl bare
157Make a program for the bare machine, a kernel, with no Linux under it.
158Its entry point reads no arguments, so
159.Fn ARGC
160is 0, and runs no body of
161.Cm Rt ,
162whose system calls set the handlers of signals: a nil pointer or a
163division fault is not told.
164A failed check is still told, by a system call the kernel must catch.
165Its stack must be 16-byte aligned, as Linux leaves it, and its bss
166zeroed.
167A program that uses C is refused.
168.It Fl noprofile
169Leave out the profiler, which
170.Ev RAZ_PROFILE
171turns on, but keep the rest.
172.It Fl libc Ar name
173Link a program that uses C against
174.Ar name ,
175.Cm glibc
176or
177.Cm musl .
178Left out, it is glibc, or musl on a machine that has musl's loader,
179.Pa /lib/ld-musl-x86_64.so.1 ,
180and not glibc's, as Alpine has.
181A program without C needs no C library, and runs on either.
182.It Fl q Cm check
183For an editor: check
184.Ar Main.raz ,
185reading its text from standard input, as the editor holds it, and
186write no program.
187Each message is a row on standard output; see
188.Sx FOR AN EDITOR .
189.It Fl q Cm words
190For an editor: with
191.Ar Main.raz : Ns Ar LINE : Ns Ar COL
192in place of
193.Ar Main.raz ,
194write the names that can be typed at that cursor, a row each, and
195nothing else.
196.It Fl q Cm def
197For an editor: with
198.Ar Main.raz : Ns Ar LINE : Ns Ar COL
199in place of
200.Ar Main.raz ,
201write where the name at that cursor is declared, and what it is.
202.It Fl h , Fl \-help
203Say the options.
204.It Fl \-version
205Say the version of
206.Nm ,
207and the version of the report it follows.
208.El
209.Sh ENVIRONMENT
210.Bl -tag -width "RAZ_PROFILE"
211.It Ev RAZ_PATH
212Colon-separated directories of installed raz source modules, searched
213after the
214.Fl I
215directories and before the standard library.
216When unset, the user library directory is
217.Pa $HOME/.raz/lib ;
218with no nonempty
219.Ev HOME ,
220there is no default.
221An explicitly empty
222.Ev RAZ_PATH
223disables user library directories; it does not disable the standard
224library. Empty entries are ignored, not taken as the working directory.
225Relative paths are relative to the compiler's working directory.
226The compiler does not expand a tilde or variables within paths.
227Directories are not searched recursively: install a library's source
228modules directly in one of them, with their target-specific siblings.
229The duplicate-module error and symbolic-link exception apply across
230all search directories;
231.Fl I
232does not override an installed module.
233.It Ev RAZ_PROFILE
234Set to anything, in the environment of a program built without
235.Fl s
236or
237.Fl noprofile ,
238it has the program sample itself every millisecond of its time, and
239say at its end, on standard error, which procedures took the most of
240it, each with its share in its own code and its share in all, with the
241procedures it called, and which places in the source:
242.Bd -literal -offset indent
243profile: 521 samples of a millisecond; each procedure's own, then with its calls'
244 16% 27% Screen.put
245 9% 93% Parser.feed
246by place:
247 8% src/Screen.raz:275:5
248.Ed
249.El
250.Sh EXIT STATUS
251.Nm
252exits 0 if it wrote the program, and 1 if it found an error, which it
253says on standard error, with the line of source and a mark under the
254place.
255.Nm
256.Cm run
257exits as the program does.
258.Sh FOR AN EDITOR
259.Fl q
260is for an editor's language server, which asks of the text it holds,
261saved or not.
262The text of the main module comes from standard input; the modules it
263imports are read from their files, found as for a compile.
264Every row is fields split by tabs.
265.Pp
266.Fl q Cm check
267gives a row for each error, warning and note:
268.Bd -literal -offset indent
269FILE LINE COL ENDLINE ENDCOL KIND MESSAGE
270.Ed
271.Pp
272where the place runs from
273.Ar LINE
274and
275.Ar COL
276up to, not including,
277.Ar ENDLINE
278and
279.Ar ENDCOL ,
280lines and bytes in a line counted from 1, and
281.Ar KIND
282is
283.Cm error ,
284.Cm warning
285or
286.Cm note .
287.Ar FILE
288may be another module's, as for a note.
289An error about no place in a file, as a module not found, has an empty
290.Ar FILE
291and zeros.
292It exits 1 if there was an error, else 0.
293.Pp
294.Fl q Cm words
295reads the module up to the cursor, past any errors, and gives a row for
296each name that can be typed there and starts with what is typed of the
297name the cursor is in or just after:
298.Bd -literal -offset indent
299KIND NAME TYPE
300.Ed
301.Pp
302where
303.Ar KIND
304is
305.Cm const ,
306.Cm type ,
307.Cm var ,
308.Cm proc ,
309.Cm module ,
310.Cm field
311or
312.Cm builtin .
313After a module's name and a dot, the names are those the module
314exports; elsewhere, every name in scope there, a local hiding a global
315of its name.
316The rows come in no order.
317Inside a comment or a string, after a record's dot, or where a name is
318declared, there are none.
319It exits 0.
320.Pp
321.Fl q Cm def
322reads the module up to the cursor as
323.Cm words
324does, and gives one row for the name the cursor is in, or just after:
325.Bd -literal -offset indent
326FILE LINE COL ENDLINE ENDCOL KIND NAME TYPE
327.Ed
328.Pp
329where the place is that of the name in its declaration, as
330.Cm check
331gives places, and
332.Ar KIND
333and
334.Ar TYPE
335are as
336.Cm words
337gives them.
338A module's place is its name in its own
339.Li module
340line, on an import's name too; a name of the language's own, as
341.Cm INT
342or
343.Cm LEN ,
344has no file, and zeros.
345Where
346.Cm words
347would give no names, it gives no row.
348It exits 0.
349.Sh LISTING
350The listing of
351.Fl S
352is in lines of three kinds, which a tool may read:
353.Bl -bullet -offset indent
354.It
355a blank line, then a procedure's name as
356.Ql Module.name: ;
357.It
358a source line: its number, right-aligned in 6 columns, two spaces, and
359the line's text as it is in the file;
360.It
361an instruction: its offset in the procedure, right-aligned in 14
362columns, two spaces, and the instruction as an assembler would read it;
363a jump within the procedure gives its target as an offset in the same
364way, and a call of a procedure names it.
365.El
366.Pp
367The listing is of the main module's live procedures, those the program
368uses, in the order their code was made.
369Nothing is disassembled: each instruction is the one the compiler meant
370to write.
371A source line comes before the first instruction made for it, and is
372not repeated until the line changes.
373.Sh EXAMPLES
374Compile and run hello, world:
375.Bd -literal -offset indent
376raz Hello.raz && ./Hello
377raz run Hello.raz
378.Ed
379.Pp
380Build a small program for shipping, then see where its time goes:
381.Bd -literal -offset indent
382raz -s -o hello Hello.raz
383raz -o prog Prog.raz && RAZ_PROFILE=1 ./prog
384.Ed
385.Sh SEE ALSO
386.Xr raz-lib 3 ,
387the library;
388.Xr raz-tutorial 7 ,
389a tour of the language;
390.Xr raz 7 ,
391the language at a glance;
392.Xr gdb 1 .
393The report,
394.Pa doc/raz.md ,
395defines the language, and the guide to the compiler,
396.Pa doc/compiler.md ,
397walks through its sources.