| 1 | .\" raz(7) - the raz language at a glance |
| 2 | .Dd October 15, 2026 |
| 3 | .Dt RAZ 7 |
| 4 | .Os |
| 5 | .Sh NAME |
| 6 | .Nm raz |
| 7 | .Nd the raz programming language at a glance |
| 8 | .Sh DESCRIPTION |
| 9 | raz is a small systems language for x86-64 Linux, with no garbage |
| 10 | collector and no hidden run time. |
| 11 | This page is what a programmer looks up; the report, |
| 12 | .Pa doc/raz.md |
| 13 | in raz's sources, is the definition, and the numbers in brackets, |
| 14 | such as [6.8], are its sections. |
| 15 | .Xr raz-tutorial 7 |
| 16 | is a tour, |
| 17 | .Xr raz-lib 3 |
| 18 | the library and |
| 19 | .Xr raz 1 |
| 20 | the compiler. |
| 21 | .Sh WORDS AND SYMBOLS |
| 22 | [2] A program is UTF-8; everything outside strings, characters and |
| 23 | comments is ASCII. |
| 24 | .Bl -tag -width "Identifiers" |
| 25 | .It Identifiers |
| 26 | A letter or |
| 27 | .Cm _ , |
| 28 | then letters, digits and |
| 29 | .Cm _ , |
| 30 | up to 63 characters; case matters. |
| 31 | .Cm _ |
| 32 | alone is the blank. |
| 33 | .It Numbers |
| 34 | .Cm 123 ; |
| 35 | .Cm 0FFH , |
| 36 | hexadecimal, in capitals; |
| 37 | .Cm 1.5 |
| 38 | and |
| 39 | .Cm 2.0E-3 , |
| 40 | reals, with a digit on both sides of the point. |
| 41 | A number is untyped until it meets a type. |
| 42 | .It Characters |
| 43 | .Cm 'a' , |
| 44 | the code point, an integer. |
| 45 | .It Strings |
| 46 | .Cm \(dqhello\en\(dq , |
| 47 | its UTF-8 bytes, ending on its line. |
| 48 | .It Raw strings |
| 49 | .Cm \(gaC:\etmp\(ga , |
| 50 | the text between backquotes as it stands, no escapes, over lines; if |
| 51 | the opening backquote ends its line and the closing one has only |
| 52 | blanks before it, those blanks come off every line. |
| 53 | .It Escapes |
| 54 | .Cm \en \et \er \e0 \e\e \e' \e\(dq \eu{E9} , |
| 55 | and in strings |
| 56 | .Cm \exHH , |
| 57 | any byte. |
| 58 | .It Comments |
| 59 | .Cm "(* ... *)" , |
| 60 | nesting. |
| 61 | The comment just before a declaration, or before |
| 62 | .Cm module , |
| 63 | is its documentation. |
| 64 | .El |
| 65 | .Pp |
| 66 | The reserved words, all lowercase but |
| 67 | .Cm VOLATILE : |
| 68 | .Bd -literal -offset indent |
| 69 | and begin break by code const continue defer div do else elsif |
| 70 | end extern for forward if import in link match mod module not |
| 71 | of or packed proc record repeat return set shl shr then to try |
| 72 | type until var variant VOLATILE while xor |
| 73 | .Ed |
| 74 | .Pp |
| 75 | The basic types, |
| 76 | .Cm ERROR , true , false , nil |
| 77 | and the built-in procedures are predeclared, in a scope around every |
| 78 | module, and may be declared again. |
| 79 | .Sh THE GRAMMAR IN BRIEF |
| 80 | [appendix B] |
| 81 | .Cm "{ x }" |
| 82 | is any number of |
| 83 | .Cm x , |
| 84 | .Cm "[ x ]" |
| 85 | is one or none. |
| 86 | .Bd -literal -offset indent |
| 87 | Module = "module" Name [ "(" Params ")" ] ";" { Import } |
| 88 | { "link" ( String | "static" ) ";" } |
| 89 | [ "check" "off" ";" ] |
| 90 | { Decl } [ "begin" Stmts ] "end" Name "." . |
| 91 | Import = "import" Item { "," Item } ";" . |
| 92 | Item = Name [ ":=" Name [ "(" Type { "," Type } ")" ] ] . |
| 93 | Decl = "const" { Name ["*"] [ ":" Type ] "=" Expr ";" } |
| 94 | | "type" { Name ["*"] "=" Type ";" } |
| 95 | | "var" { Names ":" Type ";" } |
| 96 | | "proc" Name ["*"] Signature ";" Body ";" |
| 97 | | "extern" ( "proc" Name ["*"] Signature |
| 98 | | "var" Name ["*"] ":" Type ) ";" . |
| 99 | Body = "forward" | { Local } "begin" Stmts "end" [ Name ] |
| 100 | | "code" { [ Label ":" ] [ Instr ] ";" } "end" [ Name ] . |
| 101 | Signature = [ "(" Params ")" ] [ ":" ( Type | "(" Types ")" ) ] . |
| 102 | Type = Name | Module "." Name | "[" Expr "]" Type | "[" "]" Type |
| 103 | | "^" [ "VOLATILE" ] Type |
| 104 | | [ "packed" ] "record" Fields "end" |
| 105 | | "variant" { Case ";" } "end" | "(" Names ")" |
| 106 | | "set" "of" Type | "proc" Signature . |
| 107 | Stmt = Designator [ ":=" Expr ] | "_" ":=" Expr |
| 108 | | Target "," Target { "," Target } ":=" Expr |
| 109 | | "if" Expr "then" Stmts { "elsif" Expr "then" Stmts } |
| 110 | [ "else" Stmts ] "end" |
| 111 | | "while" Expr "do" Stmts "end" |
| 112 | | "repeat" Stmts "until" Expr |
| 113 | | "for" Name ":=" Expr "to" Expr [ "by" Expr ] |
| 114 | "do" Stmts "end" |
| 115 | | "match" Expr "of" { "|" Arm } "end" |
| 116 | | "return" [ Exprs ] | "break" | "continue" | "defer" Stmt . |
| 117 | Arm = ( Case [ "(" Names ")" ] | Label { "," Label } | "else" ) |
| 118 | ":" Stmts . |
| 119 | Stmts = { Stmt ";" } . |
| 120 | .Ed |
| 121 | .Pp |
| 122 | Every statement ends in |
| 123 | .Cm \&; , |
| 124 | even one that ends in |
| 125 | .Cm end |
| 126 | or |
| 127 | .Cm until . |
| 128 | A procedure without parameters leaves out the parentheses where it is |
| 129 | declared and where it is called. |
| 130 | A name is declared before it is used, but for a pointer's type, which |
| 131 | may come later in the same |
| 132 | .Cm type |
| 133 | section, and a |
| 134 | .Cm forward |
| 135 | procedure. |
| 136 | Procedures don't nest. |
| 137 | .Sh MODULES |
| 138 | [3] Module |
| 139 | .Cm M |
| 140 | lives in |
| 141 | .Pa M.raz , |
| 142 | or |
| 143 | .Pa M.linux-x86_64.raz |
| 144 | for one target's own; it is found beside the main module, then in each |
| 145 | .Fl I |
| 146 | directory, then in the library. |
| 147 | A program has one module of each name, and the library's names are |
| 148 | kept for it. |
| 149 | .Bl -bullet |
| 150 | .It |
| 151 | A name declared with |
| 152 | .Cm * |
| 153 | is exported, and used as |
| 154 | .Cm M.name . |
| 155 | An exported variable is read-only outside its module. |
| 156 | .It |
| 157 | .Cm "import O := Out;" |
| 158 | renames; |
| 159 | .Cm "import Ints := List(INT);" |
| 160 | makes an instance of a generic module, one for each distinct list of |
| 161 | arguments, its procedure arguments named after its types: |
| 162 | .Cm "Map([]const U8, INT, Str.hash, Str.eq)" . |
| 163 | .It |
| 164 | A module's body runs once, after those of the modules it imports, and |
| 165 | before the main module's |
| 166 | .Cm main . |
| 167 | .It |
| 168 | .Cm "link \(dqlibX.so.1\(dq;" |
| 169 | loads a C library (it needs |
| 170 | .Cm "import SYSTEM" ); |
| 171 | .Cm "link static;" |
| 172 | says the program must not use C. |
| 173 | .Cm "check off;" |
| 174 | leaves the module's index and slice checks out (it too needs |
| 175 | .Cm "import SYSTEM" ). |
| 176 | .It |
| 177 | .Cm "import SYSTEM;" |
| 178 | is no file but the language's module of what reaches memory by other |
| 179 | roads than variables. |
| 180 | A module needs it for |
| 181 | .Cm SYSTEM.ADR , |
| 182 | .Cm SYSTEM.PTR , |
| 183 | .Cm SYSTEM.SYSCALL |
| 184 | and |
| 185 | .Cm SYSTEM.ARGV ; |
| 186 | pointer arithmetic, indexing and slicing; |
| 187 | conversions to and from pointers; |
| 188 | .Cm extern , |
| 189 | .Cm link , |
| 190 | code procedures and |
| 191 | .Cm "check off;" . |
| 192 | It can't be renamed; a module that imports one that says it needn't. |
| 193 | .El |
| 194 | .Sh TYPES |
| 195 | [5] Sizes are x86-64's. |
| 196 | .Bl -column "U8 U16 U32 U64" "n * SIZE(T)" "an enumeration, 256 names at most" |
| 197 | .It Sy Type Ta Sy Size Ta Sy Values |
| 198 | .It "I8 I16 I32 I64" Ta "1, 2, 4, 8" Ta "signed, two's complement" |
| 199 | .It "U8 U16 U32 U64" Ta "1, 2, 4, 8" Ta "unsigned" |
| 200 | .It "INT, UINT" Ta "8" Ta "as big as an address, 16 bits at least" |
| 201 | .It "BOOL" Ta "1" Ta "false, true" |
| 202 | .It "F32, F64" Ta "4, 8" Ta "IEEE 754" |
| 203 | .It "ERROR" Ta "8" Ta "nil, or a constant's error" |
| 204 | .It "^T, proc ..." Ta "8" Ta "an address, or nil" |
| 205 | .It "[]T" Ta "16" Ta "a pointer and a length" |
| 206 | .It "[]const T" Ta "16" Ta "a slice, its elements only read" |
| 207 | .It "[n]T" Ta "n * SIZE(T)" Ta "n elements, copied whole" |
| 208 | .It "(a, b, c)" Ta "1" Ta "an enumeration, 256 names at most" |
| 209 | .It "set of E" Ta "1, 2, 4, 8" Ta "bit i for E's name i, 64 at most" |
| 210 | .El |
| 211 | .Pp |
| 212 | An enumeration's name may be written with its type, |
| 213 | .Cm Color.red , |
| 214 | and must be where another declaration of its scope has the name too |
| 215 | [5.7]. |
| 216 | .Bl -bullet |
| 217 | .It |
| 218 | A |
| 219 | .Cm record |
| 220 | is laid out as C's struct; a |
| 221 | .Cm "packed record" |
| 222 | has no padding, and its misaligned fields no address. |
| 223 | .It |
| 224 | A |
| 225 | .Cm variant |
| 226 | is an |
| 227 | .Cm INT |
| 228 | tag and the room of its largest case: |
| 229 | .Cm "variant circle(r: F64); dot; end" . |
| 230 | A case is built as |
| 231 | .Cm circle(1.0) |
| 232 | or |
| 233 | .Cm dot , |
| 234 | and read only by |
| 235 | .Cm match . |
| 236 | A typed constant may hold variants: |
| 237 | .Cm "const Shapes: []Shape = [circle(1.0), dot];" |
| 238 | .It |
| 239 | .Cm "^VOLATILE T" |
| 240 | points at what something else may change: each access is one access, |
| 241 | of its size, in order [7.6]. |
| 242 | .It |
| 243 | .Cm "const NotFound*: ERROR = \(dqnot found\(dq;" |
| 244 | makes an error unlike every other, compared by |
| 245 | .Cm = |
| 246 | and |
| 247 | .Cm # ; |
| 248 | .Cm MSG(e) |
| 249 | is its message. |
| 250 | .It |
| 251 | Every variable starts at zero: 0, false, nil, the empty slice, a |
| 252 | variant's first case. |
| 253 | .It |
| 254 | Named record, variant and enumeration types are each a type of their |
| 255 | own; other types built alike are the same. |
| 256 | .Cm "type A = B;" |
| 257 | is another name for |
| 258 | .Cm B . |
| 259 | .El |
| 260 | .Pp |
| 261 | A value goes where another type is wanted only as an integer constant |
| 262 | that fits it, |
| 263 | .Cm nil |
| 264 | into a pointer, procedure or |
| 265 | .Cm ERROR , |
| 266 | .Cm ^T |
| 267 | into |
| 268 | .Cm "^VOLATILE T" , |
| 269 | .Cm [n]T |
| 270 | into |
| 271 | .Cm []T |
| 272 | or |
| 273 | .Cm []const T , |
| 274 | a |
| 275 | .Cm []T |
| 276 | into |
| 277 | .Cm []const T , |
| 278 | a string into |
| 279 | .Cm "[]const U8" , []U8 , ^U8 |
| 280 | (with a zero byte after it) or |
| 281 | .Cm [n]U8 , |
| 282 | a procedure into its type, |
| 283 | .Cm INT |
| 284 | into |
| 285 | .Cm I64 , |
| 286 | .Cm UINT |
| 287 | into |
| 288 | .Cm U64 , |
| 289 | wherever it goes, results passed on whole and a |
| 290 | .Cm for Ns 's |
| 291 | bounds too, and |
| 292 | .Cm U8 , I8 |
| 293 | and |
| 294 | .Cm I16 |
| 295 | into |
| 296 | .Cm INT , |
| 297 | .Cm U8 |
| 298 | and |
| 299 | .Cm U16 |
| 300 | into |
| 301 | .Cm UINT , |
| 302 | in the same places but for results passed on whole, unless an |
| 303 | operator made them: with |
| 304 | .Cm "a, b: U8" , |
| 305 | .Cm "n := a + b" |
| 306 | is an error, and |
| 307 | .Cm "n := INT(a) + b" |
| 308 | is the sum |
| 309 | [5.10]. |
| 310 | Anything else is converted by name. |
| 311 | .Sh OPERATORS |
| 312 | [6] From the tightest: |
| 313 | .Bl -column "* / div mod & shl shr" "and, or, not: BOOL; & | xor ~: bits" |
| 314 | .It Sy Operators Ta Sy Notes |
| 315 | .It "not ~" Ta "not of a BOOL; ~ of an integer's bits" |
| 316 | .It "* / div mod & shl shr" Ta "/ for reals; shifts count modulo the width" |
| 317 | .It "+ - | xor" Ta "a unary minus takes the first term" |
| 318 | .It "= # < <= > >= in" Ta "# is different; in, for a set" |
| 319 | .It "and" Ta "evaluates its right side only if needed" |
| 320 | .It "or" Ta "the same" |
| 321 | .El |
| 322 | .Bl -bullet |
| 323 | .It |
| 324 | Both operands have one type, or one is an untyped constant that fits |
| 325 | the other's, or one is an |
| 326 | .Cm INT |
| 327 | and the other an |
| 328 | .Cm I64 |
| 329 | .Pq Cm UINT , U64 , |
| 330 | and the result is an |
| 331 | .Cm I64 : |
| 332 | with |
| 333 | .Cm "i: I32" , |
| 334 | .Cm "i < LEN(s)" |
| 335 | is an error. |
| 336 | Integers wrap at their width. |
| 337 | .Cm div |
| 338 | rounds toward zero, and |
| 339 | .Cm mod |
| 340 | takes the dividend's sign; dividing by zero stops the program. |
| 341 | .It |
| 342 | Pointers: |
| 343 | .Cm p^ , |
| 344 | .Cm "p + i" |
| 345 | and |
| 346 | .Cm "p - i" |
| 347 | in elements, |
| 348 | .Cm "p - q" , |
| 349 | .Cm p[i] , |
| 350 | and |
| 351 | .Cm p[lo..hi] , |
| 352 | a slice; a record's fields through it are |
| 353 | .Cm p^.f . |
| 354 | Arithmetic, indexing and slicing need |
| 355 | .Cm "import SYSTEM" . |
| 356 | .It |
| 357 | Arrays and slices: |
| 358 | .Cm a[i] , |
| 359 | and |
| 360 | .Cm a[lo..hi] |
| 361 | from |
| 362 | .Cm lo |
| 363 | up to but not including |
| 364 | .Cm hi . |
| 365 | Two of integers, BOOLs, enumerations, sets or pointers compare with |
| 366 | .Cm = |
| 367 | and |
| 368 | .Cm # . |
| 369 | .It |
| 370 | Sets: |
| 371 | .Cm + |
| 372 | union, |
| 373 | .Cm * |
| 374 | intersection, |
| 375 | .Cm - |
| 376 | difference, |
| 377 | .Cm <= |
| 378 | and |
| 379 | .Cm >= |
| 380 | subset and superset. |
| 381 | .It |
| 382 | Literals: |
| 383 | .Cm "[1, 2, 3]" , |
| 384 | an array, and |
| 385 | .Cm "{x: 1, y: 2}" , |
| 386 | a record with its other fields zero, where the type is known; |
| 387 | .Cm "{red, blue}" , |
| 388 | a set. |
| 389 | .Cm "const Weekend: []Day = [sat, sun];" |
| 390 | takes its length from its literal [4]. |
| 391 | .El |
| 392 | .Sh CONVERSIONS |
| 393 | [6.7] A type's name converts: |
| 394 | .Cm I32(x) , F64(n) , ^Cell(adr) , "^VOLATILE U32(0FEE00000H)" . |
| 395 | .Bl -column "pointer, procedure" "pointer, procedure" "rounded toward zero" |
| 396 | .It Sy From Ta Sy To Ta Sy Result |
| 397 | .It "integer" Ta "integer" Ta "cut, or extended" |
| 398 | .It "integer" Ta "F32, F64" Ta "the nearest" |
| 399 | .It "F32, F64" Ta "integer" Ta "rounded toward zero" |
| 400 | .It "F32 / F64" Ta "F64 / F32" Ta "the same, or the nearest" |
| 401 | .It "enumeration, set" Ta "integer" Ta "its position, its bits" |
| 402 | .It "integer" Ta "enumeration, set" Ta "checked; its low bits" |
| 403 | .It "INT, UINT" Ta "pointer, procedure" Ta "the address" |
| 404 | .It "pointer, procedure" Ta "INT, UINT, pointer" Ta "the address" |
| 405 | .El |
| 406 | .Pp |
| 407 | The last two rows need |
| 408 | .Cm "import SYSTEM" . |
| 409 | There is no other: none between |
| 410 | .Cm BOOL |
| 411 | and integers, and none to records, arrays, slices, variants or |
| 412 | .Cm ERROR . |
| 413 | .Sh VIEWS |
| 414 | [6.9] |
| 415 | .Cm v.(T) |
| 416 | is the |
| 417 | .Cm T |
| 418 | whose bytes start where the variable |
| 419 | .Cm v |
| 420 | does: a variable, not a copy, read and written. |
| 421 | .Bd -literal -offset indent |
| 422 | mem[16].(I64) := -1; (* mem[16] to mem[23] *) |
| 423 | k := buf[0].(Header).count; |
| 424 | bits := x.(U64); (* an F64's bits; I64(x) is its number *) |
| 425 | .Ed |
| 426 | .Pp |
| 427 | .Cm T |
| 428 | is an integer, a real or a pointer, or a record or array of them. |
| 429 | .Cm "a[i].(T)" |
| 430 | lies from |
| 431 | .Cm a[i] |
| 432 | to the end of |
| 433 | .Cm a , |
| 434 | which is checked as an index is; any other |
| 435 | .Cm v.(T) |
| 436 | lies within |
| 437 | .Cm v . |
| 438 | A view may be misaligned, so it has no address, and a volatile |
| 439 | variable can't be viewed. |
| 440 | .Sh BUILT-IN PROCEDURES |
| 441 | [6.8] |
| 442 | .Bl -tag -width "SYSTEM.SYSCALL(n, x1, ...)" |
| 443 | .It Fn SIZE T |
| 444 | The size of type |
| 445 | .Ar T , |
| 446 | an untyped constant. |
| 447 | .It Fn SIZE T.f |
| 448 | The size of field |
| 449 | .Ar f |
| 450 | of the record type |
| 451 | .Ar T , |
| 452 | an untyped constant. |
| 453 | .It Fn OFFSET T f |
| 454 | The byte offset of field |
| 455 | .Ar f |
| 456 | in the record type |
| 457 | .Ar T , |
| 458 | an untyped constant. |
| 459 | .It Fn SYSTEM.ADR x |
| 460 | The address of the variable |
| 461 | .Ar x . |
| 462 | .It Fn LEN a |
| 463 | The length of an array, a string constant or a slice. |
| 464 | .It Fn SYSTEM.PTR s |
| 465 | The address the slice |
| 466 | .Ar s |
| 467 | starts at, a |
| 468 | .Li ^T |
| 469 | for a |
| 470 | .Li []T , |
| 471 | unchecked: for an empty slice what it holds, |
| 472 | .Dv nil |
| 473 | for one never set. |
| 474 | Of an array, the address of its first element. |
| 475 | .It Fn NEW p a |
| 476 | .Ar p |
| 477 | set to a fresh, zeroed |
| 478 | .Ar T |
| 479 | from the allocator |
| 480 | .Ar a , |
| 481 | a |
| 482 | .Cm ^Mem.Allocator , |
| 483 | or to nil. |
| 484 | .It Fn BYTES x |
| 485 | The bytes of the variable |
| 486 | .Ar x |
| 487 | as a |
| 488 | .Li []U8 : |
| 489 | for a |
| 490 | .Li []T |
| 491 | its |
| 492 | .Li LEN(s) * SIZE(T) |
| 493 | bytes; of a type a view may take. |
| 494 | .It Fn MSG e |
| 495 | The message of an |
| 496 | .Cm ERROR . |
| 497 | .It Fn COPY d s |
| 498 | The elements of |
| 499 | .Ar s |
| 500 | copied to the start of |
| 501 | .Ar d , |
| 502 | as one block, even if they overlap; past |
| 503 | .Fn LEN d , |
| 504 | a failed check. |
| 505 | .It Fn FILL d x |
| 506 | Every element of the array or slice |
| 507 | .Ar d |
| 508 | set to |
| 509 | .Ar x , |
| 510 | a value of its type. |
| 511 | .It Fn INC v k , Fn DEC v k |
| 512 | .Ar v |
| 513 | plus or minus |
| 514 | .Ar k , |
| 515 | or 1; it wraps. |
| 516 | .It Fn CAS v old new |
| 517 | If the variable |
| 518 | .Ar v |
| 519 | is |
| 520 | .Ar old , |
| 521 | set it to |
| 522 | .Ar new |
| 523 | and return true; atomically. |
| 524 | .It Fn XCHG v x , Fn XADD v x |
| 525 | Set, or add to, the variable |
| 526 | .Ar v , |
| 527 | returning the value before; atomically. |
| 528 | .It Fn ABS x |
| 529 | .Ar x |
| 530 | without its sign, of its type: an integer or a real. |
| 531 | .It Fn ROL x n , Fn ROR x n |
| 532 | .Ar x , |
| 533 | of an unsigned integer type, rotated left or right by |
| 534 | .Ar n |
| 535 | bits modulo its width. |
| 536 | .It Fn CLZ x , Fn CTZ x |
| 537 | The zero bits above the highest one, or below the lowest one, in |
| 538 | .Ar x , |
| 539 | of an unsigned integer type; its width if |
| 540 | .Ar x |
| 541 | is 0. |
| 542 | .It Fn POPCOUNT x |
| 543 | The one bits in |
| 544 | .Ar x , |
| 545 | of an unsigned integer type, or the members of a set. |
| 546 | .It Fn MIN T , Fn MAX T |
| 547 | The smallest, or the largest, value of the integer type |
| 548 | .Ar T . |
| 549 | .It Cm FENCE |
| 550 | A full memory barrier. |
| 551 | .It Fn SYSTEM.SYSCALL n x1 ... |
| 552 | Linux system call |
| 553 | .Ar n , |
| 554 | with up to six arguments; minus an errno on failure. |
| 555 | .It Fn ARGC , Fn SYSTEM.ARGV |
| 556 | The command line: its count, and its C strings. |
| 557 | .El |
| 558 | .Sh STATEMENTS |
| 559 | [7] |
| 560 | .Bl -tag -width "repeat ... until" |
| 561 | .It Cm "x := e" |
| 562 | Copies; arrays, records and slices whole. |
| 563 | .Cm "a, b := f(x)" |
| 564 | takes several results apart, and |
| 565 | .Cm "_ := f(x)" |
| 566 | drops one on purpose. |
| 567 | .It Cm "f(x)" |
| 568 | A call; a result it drops is warned of. |
| 569 | .It Cm if , while , repeat |
| 570 | On a |
| 571 | .Cm BOOL . |
| 572 | .Cm repeat |
| 573 | runs its body once at least. |
| 574 | .It Cm for |
| 575 | .Cm "for i := a to b by s do ... end" : |
| 576 | .Cm a |
| 577 | and |
| 578 | .Cm b |
| 579 | evaluated once, |
| 580 | .Cm s |
| 581 | a constant, 1 if left out; never steps past |
| 582 | .Cm b , |
| 583 | and leaves |
| 584 | .Cm i |
| 585 | at the last value it took. |
| 586 | .It Cm match |
| 587 | On a variant, an arm for each case, naming its fields; on an |
| 588 | enumeration, an arm for each name; on an integer, arms of constants |
| 589 | and ranges, |
| 590 | .Cm "| '0' .. '9':" , |
| 591 | and an |
| 592 | .Cm "| else:" ; |
| 593 | on a string, arms of string constants, |
| 594 | .Cm "| \(dqadd\(dq, \(dqplus\(dq:" , |
| 595 | and an |
| 596 | .Cm "| else:" , |
| 597 | which any |
| 598 | .Cm match |
| 599 | may end with. |
| 600 | An imported case may be written qualified, |
| 601 | .Cm "| Xml.done:" . |
| 602 | .It Cm return |
| 603 | With the results, several separated by commas, or |
| 604 | .Cm "return f(x)" , |
| 605 | passing on |
| 606 | .Cm f Ns 's; |
| 607 | off the end, a procedure returns zeros. |
| 608 | .It Cm break |
| 609 | Out of the innermost |
| 610 | .Cm while , repeat |
| 611 | or |
| 612 | .Cm for . |
| 613 | .It Cm continue |
| 614 | To the end of the innermost loop's round: a |
| 615 | .Cm while |
| 616 | or a |
| 617 | .Cm repeat |
| 618 | tests again, a |
| 619 | .Cm for |
| 620 | steps; so a |
| 621 | .Cm while Ns 's |
| 622 | step comes before it. |
| 623 | There is no |
| 624 | .Cm goto . |
| 625 | .It Cm defer |
| 626 | Runs its statement when the statements it stands in end, by their end, |
| 627 | a |
| 628 | .Cm return , |
| 629 | a |
| 630 | .Cm break |
| 631 | or a |
| 632 | .Cm continue ; |
| 633 | the last first. |
| 634 | .El |
| 635 | .Pp |
| 636 | Operands, arguments and an assignment's designators are evaluated left |
| 637 | to right, the designators first [7.5]. |
| 638 | .Sh PROCEDURES |
| 639 | [8] |
| 640 | .Bl -bullet |
| 641 | .It |
| 642 | A parameter is a copy; a |
| 643 | .Cm var |
| 644 | one is the caller's variable, of the parameter's type exactly; a |
| 645 | .Cm const |
| 646 | one is the caller's variable too, read in place and never changed, and |
| 647 | takes any expression of its type. |
| 648 | A procedure takes what it reads as a value when it is a single value |
| 649 | or a slice, as |
| 650 | .Cm const |
| 651 | when it is a record or an array; what it changes as |
| 652 | .Cm var ; |
| 653 | and a pointer only for what it keeps. |
| 654 | .It |
| 655 | .Cm "proc f(x: INT): (INT, ERROR);" |
| 656 | returns several results. |
| 657 | Returning a slice of a local array, of a value parameter, or of an |
| 658 | array literal is an error: the frame it points into is gone [7.3]. |
| 659 | An array a call returns lives to the end of the procedure the call |
| 660 | is in [8]. |
| 661 | A procedure is a value of its type, |
| 662 | .Cm "proc(a, b: INT): BOOL" , |
| 663 | or nil. |
| 664 | .It |
| 665 | A |
| 666 | .Cm code |
| 667 | procedure is machine code, in Intel's syntax, called by the System V |
| 668 | convention: |
| 669 | .Cm "rdtsc; shl rdx, 32; or rax, rdx; ret;" . |
| 670 | .It |
| 671 | .Cm "extern proc printf(f: ^U8; ...): I32;" |
| 672 | (in a module that imports SYSTEM) is C's [9]: its parameters integers, reals, pointers and procedures. |
| 673 | .Cm "extern var environ: ^^U8;" |
| 674 | is C's variable. |
| 675 | A raz procedure of those types is a C callback. |
| 676 | .It |
| 677 | .Cm "proc main*;" |
| 678 | or |
| 679 | .Cm "proc main*: INT;" |
| 680 | of the main module runs after every body; its result is the exit |
| 681 | status. |
| 682 | .Cm Rt.exit |
| 683 | ends the program after the procedures given to |
| 684 | .Cm Rt.atExit |
| 685 | [10]. |
| 686 | .El |
| 687 | .Sh WHAT IS CHECKED |
| 688 | [6.5, 10] Each of these stops the program with status 2, or its |
| 689 | signal's, saying on standard error where, why, and the calls under way |
| 690 | with their variables: |
| 691 | .Bl -bullet -compact |
| 692 | .It |
| 693 | an index past the length, and a slice out of |
| 694 | .Cm "0 <= lo <= hi <= length" , |
| 695 | unless the module has checks off; |
| 696 | .It |
| 697 | a view that runs past the end of what it is made of, with the same |
| 698 | proviso; |
| 699 | .It |
| 700 | a slice of a pointer that runs backwards, and a number that is no |
| 701 | position of the enumeration it converts to; |
| 702 | .It |
| 703 | a |
| 704 | .Cm nil |
| 705 | pointer, a |
| 706 | .Cm nil |
| 707 | procedure, and a stack overflow; |
| 708 | .It |
| 709 | a division by zero, and the smallest value of a signed type divided by |
| 710 | -1. |
| 711 | .El |
| 712 | .Pp |
| 713 | Integers wrap and reals never stop the program. |
| 714 | The compiler warns of what is declared and not used, of a variable |
| 715 | only assigned, and of a dropped result; |
| 716 | .Fl Werror |
| 717 | makes them errors. |
| 718 | What isn't checked is memory reached around the checks: a stale or |
| 719 | made-up pointer, indexing through a pointer, C, and code procedures. |
| 720 | .Sh LIMITS |
| 721 | This compiler's, beyond the report's 63 characters to a name, 256 |
| 722 | names to an enumeration and 64 to a set: |
| 723 | .Bl -column "deferred statements in a procedure" "integers and reals." |
| 724 | .It "a string literal" Ta "65,535 bytes" |
| 725 | .It "a number, as written" Ta "255 characters" |
| 726 | .It "elements of a literal" Ta "1,024" |
| 727 | .It "names in one declaration" Ta "64" |
| 728 | .It "variables in one assignment" Ta "16" |
| 729 | .It "deferred statements in a procedure" Ta "64" |
| 730 | .It "labels in one match" Ta "64" |
| 731 | .It "arguments of a call" Ta "63" |
| 732 | .It "type arguments of a generic module" Ta "8" |
| 733 | .It "scopes nested" Ta "64" |
| 734 | .It "parameters of a code procedure" Ta "6 integers, 8 reals" |
| 735 | .It "procedures given to Rt.atExit" Ta "32" |
| 736 | .It "-I directories" Ta "16" |
| 737 | .It "errors told in one run" Ta "20" |
| 738 | .El |
| 739 | .Sh SEE ALSO |
| 740 | .Xr raz 1 , |
| 741 | .Xr raz-lib 3 , |
| 742 | .Xr raz-tutorial 7 ; |
| 743 | the report, |
| 744 | .Pa doc/raz.md , |
| 745 | and the guide to the compiler, |
| 746 | .Pa doc/compiler.md , |
| 747 | in raz's sources. |