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