site: the compiler is in raz, builds itself; report 2026-10.21 Home page: ~10,500 lines, ~500K lines/s (self-built); public/ rebuilt.
| @@ -15,13 +15,13 @@ | ||
| 15 | 15 | system calls and call C libraries. It has no garbage collector and no hidden |
| 16 | 16 | run time: what the program does is what its text says.</p> |
| 17 | 17 | |
| 18 | -<p>The compiler is one Free Pascal program of about 9,100 lines. It makes | |
| 18 | +<p>The compiler is written in raz, about 10,500 lines, and builds itself. It makes | |
| 19 | 19 | x86-64 machine code and the ELF file itself, with no assembler or linker, in |
| 20 | -one pass, at about 900,000 lines a second.</p> | |
| 20 | +one pass, at about 500,000 lines a second.</p> | |
| 21 | 21 | |
| 22 | 22 | <div class="facts"> |
| 23 | - <span><b>~9,100</b> lines of compiler</span> | |
| 24 | - <span><b>~900K</b> lines compiled a second</span> | |
| 23 | + <span><b>~10,500</b> lines of compiler</span> | |
| 24 | + <span><b>~500K</b> lines compiled a second</span> | |
| 25 | 25 | <span><b>static</b> executables, no run time to install</span> |
| 26 | 26 | <span><b>1</b> report, about <b>30</b> pages</span> |
| 27 | 27 | </div> |
| @@ -246,18 +246,18 @@ | ||
| 246 | 246 | <ul><li><code>gdb</code> finds procedures by name and lines by number, since the executable carries them: <code>break Dot.dot</code> and <code>list</code> work, and so does stepping a line at a time.</li><li><code>RAZ_PROFILE=1</code> samples the program every millisecond and says which procedures and lines took the time.</li><li><code>objdump -d</code> disassembles what is really in the file, if you want to see the bytes behind a listing.</li></ul> |
| 247 | 247 | <pre class="output term"><code><span class="cmd">$ raz -o Dot Dot.raz</span> |
| 248 | 248 | <span class="cmd">$ objdump -d -M intel --no-show-raw-insn Dot | sed -n '/<Dot.dot>:/,/ret/p' | head -12</span> |
| 249 | -0000000000403ac0 <Dot.dot>: | |
| 250 | - 403ac0: push rbp | |
| 251 | - 403ac1: mov rbp,rsp | |
| 252 | - 403ac4: sub rsp,0x40 | |
| 253 | - 403acb: mov QWORD PTR [rbp-0x30],rbx | |
| 254 | - 403acf: xor ebx,ebx | |
| 255 | - 403ad1: mov QWORD PTR [rbp-0x28],r12 | |
| 256 | - 403ad5: xor r12d,r12d | |
| 257 | - 403ad8: mov QWORD PTR [rbp-0x20],rdx | |
| 258 | - 403adc: mov QWORD PTR [rbp-0x18],rcx | |
| 259 | - 403ae0: xor ebx,ebx | |
| 260 | - 403ae2: mov r8,rsi</code></pre> | |
| 249 | +0000000000403b40 <Dot.dot>: | |
| 250 | + 403b40: push rbp | |
| 251 | + 403b41: mov rbp,rsp | |
| 252 | + 403b44: sub rsp,0x40 | |
| 253 | + 403b4b: mov QWORD PTR [rbp-0x30],rbx | |
| 254 | + 403b4f: xor ebx,ebx | |
| 255 | + 403b51: mov QWORD PTR [rbp-0x28],r12 | |
| 256 | + 403b55: xor r12d,r12d | |
| 257 | + 403b58: mov QWORD PTR [rbp-0x20],rdx | |
| 258 | + 403b5c: mov QWORD PTR [rbp-0x18],rcx | |
| 259 | + 403b60: xor ebx,ebx | |
| 260 | + 403b62: mov r8,rsi</code></pre> | |
| 261 | 261 | <p>The listing is what the encoder meant; <code>objdump</code> is what the processor will read. They tell the same story.</p><p class="tryit">Save a program under its module’s name and run it with <code>raz run Name.raz</code>.</p><div class="pager"><a href="syscalls.html">← System calls</a><a href="index.html">Contents</a><a class="next" href="volatile.html">Volatile →</a></div></article></div> |
| 262 | 262 | </main> |
| 263 | 263 | <footer>raz is under the ISC license.</footer> |
| @@ -65,7 +65,7 @@ | ||
| 65 | 65 | <span class="cmd">$ ldd Bare</span> |
| 66 | 66 | not a dynamic executable |
| 67 | 67 | <span class="cmd">$ ls -l Bare | awk '{print $5, "bytes"}'</span> |
| 68 | -26184 bytes</code></pre> | |
| 68 | +26280 bytes</code></pre> | |
| 69 | 69 | <p>It is statically linked: no interpreter, no shared libraries, no <code>libc</code>. <code>ldd</code> says so.</p> |
| 70 | 70 | <h2>What it does when it runs</h2> |
| 71 | 71 | <p><code>strace</code> lists every system call a program makes. This is the whole of it:</p> |
| @@ -134,15 +134,15 @@ | ||
| 134 | 134 | <pre class="output term"><code><span class="cmd">$ raz Lean.raz</span> |
| 135 | 135 | <span class="cmd">$ raz Heavy.raz</span> |
| 136 | 136 | <span class="cmd">$ ls -l Lean Heavy | awk '{print $9, $5}'</span> |
| 137 | -Heavy 28392 | |
| 138 | -Lean 28384</code></pre> | |
| 137 | +Heavy 28496 | |
| 138 | +Lean 28480</code></pre> | |
| 139 | 139 | <p>The sizes differ by a few bytes, not by the hundreds of kilobytes that the table and the procedure would take: they are not in the executable at all. You can link in a library module without worrying what else it offers.</p> |
| 140 | 140 | <h2>Stripping</h2> |
| 141 | 141 | <p><code>-s</code> leaves out what is there for finding faults: the symbols and line numbers, the places a failure is told by, and the profiler. It is for the final build of a size-conscious program; the default keeps them so that gdb and failure messages work.</p> |
| 142 | 142 | <pre class="output term"><code><span class="cmd">$ raz -s -o Lean-stripped Lean.raz</span> |
| 143 | 143 | <span class="cmd">$ ls -l Lean Lean-stripped | awk '{print $9, $5}'</span> |
| 144 | -Lean 28384 | |
| 145 | -Lean-stripped 6720 | |
| 144 | +Lean 28480 | |
| 145 | +Lean-stripped 6848 | |
| 146 | 146 | <span class="cmd">$ ./Lean-stripped</span> |
| 147 | 147 | same program</code></pre> |
| 148 | 148 | <p><code>raz -S Lean.raz</code> is the other direction: it prints the machine code the compiler made, one source line at a time. The next two parts of the tour use it.</p><p class="tryit">Save a program under its module’s name and run it with <code>raz run Name.raz</code>.</p><div class="pager"><a href="allocators.html">← Writing an allocator</a><a href="index.html">Contents</a><a class="next" href="linkstatic.html">Threads without C, and keeping the two apart →</a></div></article></div> |
| @@ -35,13 +35,13 @@ | ||
| 35 | 35 | system calls and call C libraries. It has no garbage collector and no hidden |
| 36 | 36 | run time: what the program does is what its text says.</p> |
| 37 | 37 | |
| 38 | -<p>The compiler is one Free Pascal program of about 9,100 lines. It makes | |
| 38 | +<p>The compiler is written in raz, about 10,500 lines, and builds itself. It makes | |
| 39 | 39 | x86-64 machine code and the ELF file itself, with no assembler or linker, in |
| 40 | -one pass, at about 900,000 lines a second.</p> | |
| 40 | +one pass, at about 500,000 lines a second.</p> | |
| 41 | 41 | |
| 42 | 42 | <div class="facts"> |
| 43 | - <span><b>~9,100</b> lines of compiler</span> | |
| 44 | - <span><b>~900K</b> lines compiled a second</span> | |
| 43 | + <span><b>~10,500</b> lines of compiler</span> | |
| 44 | + <span><b>~500K</b> lines compiled a second</span> | |
| 45 | 45 | <span><b>static</b> executables, no run time to install</span> |
| 46 | 46 | <span><b>1</b> report, about <b>30</b> pages</span> |
| 47 | 47 | </div> |
| @@ -36,7 +36,7 @@ | ||
| 36 | 36 | </ul> |
| 37 | 37 | <p>raz is a small systems language, first made for x86-64 Linux. A raz program can lay a record over a device’s registers, read and write a device’s memory exactly as written, take part in lock-free algorithms, make system calls and call C libraries. It has no garbage collector and no hidden run time: what the program does is what its text says.</p> |
| 38 | 38 | <p>This report defines the language. It is short on purpose. Whatever it doesn’t allow, raz doesn’t have.</p> |
| 39 | -<p>This is version 2026-10.20 of the report; section 12 says what each version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for <code>try</code> (section 7.8); it breaks a program that has a name <code>try</code>.</p> | |
| 39 | +<p>This is version 2026-10.21 of the report; section 12 says what each version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for <code>try</code> (section 7.8); it breaks a program that has a name <code>try</code>.</p> | |
| 40 | 40 | <p>The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program written for it. What anyone wishes it had waits on a list, for a later thaw.</p> |
| 41 | 41 | <h1 id="a-first-look">1. A first look</h1> |
| 42 | 42 | <pre><code>module Hello; |
| @@ -494,7 +494,13 @@ | ||
| 494 | 494 | | dot: area := 0.0; |
| 495 | 495 | end;</code></pre> |
| 496 | 496 | <p><code>match</code> runs the arm of the case <code>s</code> holds. An arm may name the case’s fields, in order, all of them; the names stand for those fields of <code>s</code> itself, so assigning to one changes <code>s</code>; if <code>s</code> isn’t a variable, they stand for the fields of a copy. An arm may also leave the fields unnamed. Every case must have an arm, and only one, unless there is an <code>| else:</code> arm, which must come last.</p> |
| 497 | -<p><code>match</code> on an enumeration works the same way: each arm names one of the enumeration’s names.</p> | |
| 497 | +<p><code>match</code> on an enumeration works the same way: each arm names one of the enumeration’s names, or several, separated by commas, for the arm to run when the value is any of them:</p> | |
| 498 | +<pre><code>match op of | |
| 499 | +| sPlus, sMinus: kind := additive; | |
| 500 | +| sTimes: kind := multiplicative; | |
| 501 | +| else: | |
| 502 | +end;</code></pre> | |
| 503 | +<p>Every name must have an arm, and only one, unless there is an <code>| else:</code> arm. A variant’s arm names one case: the fields it may name belong to that case alone.</p> | |
| 498 | 504 | <p><code>match</code> on an integer runs the arm whose labels hold its value:</p> |
| 499 | 505 | <pre><code>match ch of |
| 500 | 506 | | ' ', '\t': skip := true; |
| @@ -1096,6 +1102,7 @@ | ||
| 1096 | 1102 | <li><strong>2026-10.18.</strong> A code procedure takes and returns slices (section 8).</li> |
| 1097 | 1103 | <li><strong>2026-10.19.</strong> The library gains <code>Bytes</code> (section 11).</li> |
| 1098 | 1104 | <li><strong>2026-10.20.</strong> <code>try</code>: a call of a procedure whose last result is an <code>ERROR</code>, which makes the procedure it stands in return that error when it isn’t <code>nil</code> (sections 2, 5.8, 6, 7.8 and appendix B). <code>try</code> becomes a reserved word, which breaks a program with a name <code>try</code>.</li> |
| 1105 | +<li><strong>2026-10.21.</strong> An arm of a <code>match</code> on an enumeration may name several of its names (section 7.4).</li> | |
| 1099 | 1106 | </ul> |
| 1100 | 1107 | <h1 id="appendix-a.-what-an-implementation-chooses">Appendix A. What an implementation chooses</h1> |
| 1101 | 1108 | <p>Everything in this report binds every implementation of raz, except what follows, which each chooses for itself and documents. This compiler’s choices are in <code>doc/compiler.md</code>, under “This compiler’s choices”. The programs in <code>conform/</code> are how an implementation shows that it follows this report: it passes them all, its reals aside where its target has none; <code>conform/check.sh</code> runs them.</p> |
| @@ -70,7 +70,7 @@ | ||
| 70 | 70 | <span class="cmd">$ raz run Quiet.raz</span> |
| 71 | 71 | hello, again |
| 72 | 72 | <span class="cmd">$ ls -l Quiet | awk '{print $5, "bytes"}'</span> |
| 73 | -28392 bytes</code></pre> | |
| 73 | +28488 bytes</code></pre> | |
| 74 | 74 | <p>The program is a static executable with no run time besides the code it uses, so it is a few kilobytes, and runs without any library installed.</p> |
| 75 | 75 | <h2>What <code>Out</code> can write</h2> |
| 76 | 76 | <p><code>Out</code> is the library's buffered output. It writes strings, single characters, numbers in decimal or hexadecimal, and a line feed. A string is written as it is, with <code>\n</code> for a line feed, <code>\t</code> for a tab, <code>\"</code> and <code>\\</code>.</p> |