raz / commit 1328b817

commit
1328b81779afcb821adfc3be12e5a88d1eb240d7
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
88b18ba6
site: v0.18.1

The download, the report's and the library's PDFs and spec page with
Buf.cut, Out.lines, Thread.signal and Opt's four.

patch · log

9 files changed, +27 -20

site/public/_redirects (history) modified +1 -1

@@ -1 +1 @@
1-/download/latest /download/raz-0.18.0-linux-x86_64.tar.gz 302
1+/download/latest /download/raz-0.18.1-linux-x86_64.tar.gz 302

site/public/advanced/static.html (history) modified +2 -2

@@ -65,7 +65,7 @@
6565 <span class="cmd">$ ldd Bare</span>
6666 not a dynamic executable
6767 <span class="cmd">$ ls -l Bare | awk &#x27;{print $5, &quot;bytes&quot;}&#x27;</span>
68-26304 bytes</code></pre>
68+26296 bytes</code></pre>
6969 <p>It is statically linked: no interpreter, no shared libraries, no <code>libc</code>. <code>ldd</code> says so.</p>
7070 <h2>What it does when it runs</h2>
7171 <p><code>strace</code> lists every system call a program makes. This is the whole of it:</p>
@@ -134,7 +134,7 @@
134134 <pre class="output term"><code><span class="cmd">$ raz Lean.raz</span>
135135 <span class="cmd">$ raz Heavy.raz</span>
136136 <span class="cmd">$ ls -l Lean Heavy | awk &#x27;{print $9, $5}&#x27;</span>
137-Heavy 28480
137+Heavy 28472
138138 Lean 28464</code></pre>
139139 <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>
140140 <h2>Stripping</h2>

site/public/download/raz-0.18.1-linux-x86_64.tar.gz (history) added

Binary file; the patch has it.

site/public/download/raz-0.18.1-linux-x86_64.tar.gz.sha256 (history) added +1 -0

@@ -0,0 +1 @@
1+95184eacaa25bec1cdcd3e992c6ddc76c0a6fa95c5c5b50e48dc1b402ed65214 raz-0.18.1-linux-x86_64.tar.gz

site/public/index.html (history) modified +8 -8

@@ -113,24 +113,24 @@
113113 <a href="raz-lib.pdf">the library</a>.</p>
114114
115115 <h2 id="download">Download</h2>
116-<p>raz 0.18.0 is a tarball for x86-64 Linux with the compiler, <code>raz</code>,
116+<p>raz 0.18.1 is a tarball for x86-64 Linux with the compiler, <code>raz</code>,
117117 its library, <code>lib/</code>, which it finds beside itself, the formatter
118118 and the documentation tool as sources in <code>tools/</code>, and the manual
119119 pages. It needs nothing else installed.</p>
120120 <div class="cta">
121- <a class="btn primary" href="download/raz-0.18.0-linux-x86_64.tar.gz">Download raz 0.18.0</a>
122- <a class="btn" href="download/raz-0.18.0-linux-x86_64.tar.gz.sha256">SHA-256</a>
121+ <a class="btn primary" href="download/raz-0.18.1-linux-x86_64.tar.gz">Download raz 0.18.1</a>
122+ <a class="btn" href="download/raz-0.18.1-linux-x86_64.tar.gz.sha256">SHA-256</a>
123123 </div>
124-<pre class="code"><code>$ tar xzf raz-0.18.0-linux-x86_64.tar.gz
125-$ ln -s $PWD/raz-0.18.0-linux-x86_64/raz ~/.local/bin/raz
124+<pre class="code"><code>$ tar xzf raz-0.18.1-linux-x86_64.tar.gz
125+$ ln -s $PWD/raz-0.18.1-linux-x86_64/raz ~/.local/bin/raz
126126 $ raz run Hello.raz</code></pre>
127127 <p>The link works since raz finds <code>lib/</code> beside its real path. The
128128 manual pages are in <code>man/</code>: <code>man ./man/raz-tutorial.7</code>.
129129 The address <code>download/latest</code> always leads to the newest release,
130-and <code>download/raz-0.18.0-linux-x86_64.tar.gz</code> to this one, for
131-good. Earlier releases: <a href="download/raz-0.17.2-linux-x86_64.tar.gz">0.17.2</a>, <a href="download/raz-0.17.1-linux-x86_64.tar.gz">0.17.1</a>, <a href="download/raz-0.17.0-linux-x86_64.tar.gz">0.17.0</a>, <a href="download/raz-0.16.0-linux-x86_64.tar.gz">0.16.0</a>, <a href="download/raz-0.15.0-linux-x86_64.tar.gz">0.15.0</a>, <a href="download/raz-0.14.0-linux-x86_64.tar.gz">0.14.0</a>, <a href="download/raz-0.13.0-linux-x86_64.tar.gz">0.13.0</a>, <a href="download/raz-0.12.0-linux-x86_64.tar.gz">0.12.0</a>, <a href="download/raz-0.11.1-linux-x86_64.tar.gz">0.11.1</a>, <a href="download/raz-0.11.0-linux-x86_64.tar.gz">0.11.0</a>, <a href="download/raz-0.10.1-linux-x86_64.tar.gz">0.10.1</a>, <a href="download/raz-0.10.0-linux-x86_64.tar.gz">0.10.0</a>, <a href="download/raz-0.9.1-linux-x86_64.tar.gz">0.9.1</a>, <a href="download/raz-0.9.0-linux-x86_64.tar.gz">0.9.0</a>, <a href="download/raz-0.8.0-linux-x86_64.tar.gz">0.8.0</a>, <a href="download/raz-0.7.1-linux-x86_64.tar.gz">0.7.1</a>; each has its SHA-256 beside it, with
130+and <code>download/raz-0.18.1-linux-x86_64.tar.gz</code> to this one, for
131+good. Earlier releases: <a href="download/raz-0.18.0-linux-x86_64.tar.gz">0.18.0</a>, <a href="download/raz-0.17.2-linux-x86_64.tar.gz">0.17.2</a>, <a href="download/raz-0.17.1-linux-x86_64.tar.gz">0.17.1</a>, <a href="download/raz-0.17.0-linux-x86_64.tar.gz">0.17.0</a>, <a href="download/raz-0.16.0-linux-x86_64.tar.gz">0.16.0</a>, <a href="download/raz-0.15.0-linux-x86_64.tar.gz">0.15.0</a>, <a href="download/raz-0.14.0-linux-x86_64.tar.gz">0.14.0</a>, <a href="download/raz-0.13.0-linux-x86_64.tar.gz">0.13.0</a>, <a href="download/raz-0.12.0-linux-x86_64.tar.gz">0.12.0</a>, <a href="download/raz-0.11.1-linux-x86_64.tar.gz">0.11.1</a>, <a href="download/raz-0.11.0-linux-x86_64.tar.gz">0.11.0</a>, <a href="download/raz-0.10.1-linux-x86_64.tar.gz">0.10.1</a>, <a href="download/raz-0.10.0-linux-x86_64.tar.gz">0.10.0</a>, <a href="download/raz-0.9.1-linux-x86_64.tar.gz">0.9.1</a>, <a href="download/raz-0.9.0-linux-x86_64.tar.gz">0.9.0</a>, <a href="download/raz-0.8.0-linux-x86_64.tar.gz">0.8.0</a>, <a href="download/raz-0.7.1-linux-x86_64.tar.gz">0.7.1</a>; each has its SHA-256 beside it, with
132132 <code>.sha256</code> added to its name.</p>
133-<p class="sha">SHA-256 <code>d05f2adbfddd52eabbf10db275fa69390102f46e40825ae94adaeade219799aa</code></p>
133+<p class="sha">SHA-256 <code>95184eacaa25bec1cdcd3e992c6ddc76c0a6fa95c5c5b50e48dc1b402ed65214</code></p>
134134
135135 </main>
136136 <footer>raz is under the ISC license.</footer>

site/public/raz-lib.pdf (history) modified

Binary file; the patch has it.

site/public/raz.pdf (history) modified

Binary file; the patch has it.

site/public/spec.html (history) modified +14 -8

@@ -886,7 +886,7 @@
886886 </tr>
887887 <tr>
888888 <td><code>Thread</code></td>
889-<td>threads, <code>spawn</code> and <code>join</code>, and <code>Mutex</code>, in any program; in one that uses C, made by C’s <code>pthread_create</code></td>
889+<td>threads, <code>spawn</code>, <code>join</code> and <code>signal</code>, and <code>Mutex</code>, in any program; in one that uses C, made by C’s <code>pthread_create</code></td>
890890 </tr>
891891 <tr>
892892 <td><code>Mem</code></td>
@@ -995,17 +995,20 @@
995995 Mutex* = record ... end; (* zero is free *)
996996 proc spawn*(p: proc(arg: ^U8); arg: ^U8): (^Thread, ERROR); (* p(arg) in a new thread *)
997997 proc join*(t: ^Thread); (* waits for t to end, then frees its stack *)
998+proc signal*(t: ^Thread; sig: INT): INT; (* sig sent to t alone: 0, or minus an errno *)
998999 proc lock*(m: ^Mutex);
9991000 proc unlock*(m: ^Mutex);</code></pre>
10001001 <p>A <code>Lock</code> is for short sections: a thread that finds it taken tries again, giving up the processor now and then. A <code>Mutex</code> sleeps. Each of <code>Thread</code>’s threads runs on a stack of its own, with a page below it that can’t be touched, so that running off the stack stops the program with a message, as in the main thread. In a program that uses C, <code>Thread</code> makes its threads with C’s <code>pthread_create</code>, so that C’s library knows of them; in one that doesn’t, with the system’s own calls. The program is the same either way.</p>
1002+<p><code>Sys.kill</code> signals a program, and the system gives the signal to any of its threads; <code>signal</code> gives it to <code>t</code> alone, until <code>t</code> is joined, and is -3 (ESRCH) once <code>t</code> has ended. With <code>Sys.handle(sig)</code>, a call <code>t</code> waits in, a <code>read</code> or a <code>ready</code>, fails with -4, so that one thread can break into another’s wait, as <code>^C</code> breaks into the main thread’s. A signal sent before <code>t</code> begins its wait is only noted, so a program sends it again until <code>t</code> says it has stopped.</p>
10011003 <pre><code>module Out;
10021004 proc str*(s: []U8);
10031005 proc char*(c: U8);
10041006 proc ln*; (* a line feed *)
10051007 proc int*(n: I64); (* n in decimal *)
10061008 proc hex*(n: U64; digits: INT); (* n in hexadecimal, digits digits at least *)
1007-proc flush*;</code></pre>
1008-<p><strong>Out and C’s stdio.</strong> <code>Out</code> keeps a buffer of <code>Sys.outSize</code> bytes, 4 KB on Linux. It writes it out when it is full, at each line feed when standard output is a terminal, at <code>Out.flush</code>, and when the program ends by <code>Rt.exit</code>. A lock keeps what each call writes together when threads write at once. C’s <code>stdio</code> keeps a buffer of its own for the same standard output. A program that writes with both flushes one before writing with the other, or the text comes out of order:</p>
1009+proc flush*;
1010+proc lines*(on: BOOL); (* written at each line feed, or only when full *)</code></pre>
1011+<p><strong>Out and C’s stdio.</strong> <code>Out</code> keeps a buffer of <code>Sys.outSize</code> bytes, 4 KB on Linux. It writes it out when it is full, at each line feed when standard output is a terminal, at <code>Out.flush</code>, and when the program ends by <code>Rt.exit</code>. <code>lines(true)</code> has it written at each line feed whatever standard output is, as a filter of a stream that comes slowly wants through a pipe, as grep’s <code>--line-buffered</code>; <code>lines(false)</code>, only when full, at a terminal too. A lock keeps what each call writes together when threads write at once. C’s <code>stdio</code> keeps a buffer of its own for the same standard output. A program that writes with both flushes one before writing with the other, or the text comes out of order:</p>
10091012 <pre><code>module Both;
10101013 import Out, C; (* C: printf, fflush and C&#39;s FILE *stdout *)
10111014
@@ -1241,6 +1244,7 @@
12411244 proc str*(b: ^Buf; s: []U8);
12421245 proc spare*(b: ^Buf; n: INT): []U8; (* room for n more bytes, and those bytes, to fill *)
12431246 proc bytes*(b: ^Buf): []U8; (* what it holds, until it next grows *)
1247+proc cut*(b: ^Buf; n: INT); (* only the first n bytes kept, its memory kept *)
12441248 proc reset*(b: ^Buf); (* emptied, its memory kept *)
12451249 proc done*(b: ^Buf); (* its memory given back *)
12461250
@@ -1316,7 +1320,7 @@
13161320 proc fromBits*(u: U64): F64; (* the F64 whose bits are u *)
13171321 proc mul*(a, b: U64): (U64, U64); (* a times b: the low 64 bits of the product, and the high *)
13181322 proc toReal*(s: []U8): (F64, BOOL); (* s as a real, the F64 nearest it; false if it isn&#39;t one *)</code></pre>
1319-<p>A <code>Buf</code>, a <code>List</code>, a <code>Map</code> and a <code>Vec</code> take their memory from the allocator <code>init</code> gives them. <code>Buf.add</code>, <code>str</code> and <code>spare</code> stop the program, as a failed check does, if the allocator has no room; <code>room</code> asks first. A program reads into a <code>Buf</code> through <code>spare</code>, then adds what it read to <code>len</code>: <code>s := Buf.spare(b, 4096); n := Sys.read(fd, s); if n &gt; 0 then INC(b^.len, n); end;</code>. A <code>Vec</code> is <code>Buf</code> for any <code>T</code>: one block, which doubles when it is full, so <code>push</code> costs the same on average however long it grows. <code>all</code> gives the elements as a slice, indexed and checked as any is, and <code>v.len</code> is their number; the slice, and what <code>add</code> gives, are good until the array next grows. <code>pop</code> takes the last element off, keeping the memory. <code>push</code>, <code>add</code> and <code>resize</code> stop the program, as <code>Buf.add</code> does, if the allocator has no room; <code>room</code> asks first: <code>import Lines := Vec([]U8);</code>. <code>Fmt</code>’s format takes the next argument at each <code>{}</code>; <code>{{</code> and <code>}}</code> stand for <code>{</code> and <code>}</code>. A <code>Map</code> hashes and compares its keys with the procedures it is given: <code>import Count := Map([]U8, INT, Str.hash, Str.eq);</code>.</p>
1323+<p>A <code>Buf</code>, a <code>List</code>, a <code>Map</code> and a <code>Vec</code> take their memory from the allocator <code>init</code> gives them. <code>Buf.add</code>, <code>str</code> and <code>spare</code> stop the program, as a failed check does, if the allocator has no room; <code>room</code> asks first. A program reads into a <code>Buf</code> through <code>spare</code>, then adds what it read to <code>len</code>: <code>s := Buf.spare(b, 4096); n := Sys.read(fd, s); if n &gt; 0 then INC(b^.len, n); end;</code>. <code>cut</code> takes back what was added, to a length it had: <code>start := b^.len; ...; Buf.cut(b, start);</code>; a length past <code>len</code> stops the program, as an index past the end does. A <code>Vec</code> is <code>Buf</code> for any <code>T</code>: one block, which doubles when it is full, so <code>push</code> costs the same on average however long it grows. <code>all</code> gives the elements as a slice, indexed and checked as any is, and <code>v.len</code> is their number; the slice, and what <code>add</code> gives, are good until the array next grows. <code>pop</code> takes the last element off, keeping the memory. <code>push</code>, <code>add</code> and <code>resize</code> stop the program, as <code>Buf.add</code> does, if the allocator has no room; <code>room</code> asks first: <code>import Lines := Vec([]U8);</code>. <code>Fmt</code>’s format takes the next argument at each <code>{}</code>; <code>{{</code> and <code>}}</code> stand for <code>{</code> and <code>}</code>. A <code>Map</code> hashes and compares its keys with the procedures it is given: <code>import Count := Map([]U8, INT, Str.hash, Str.eq);</code>.</p>
13201324 <p><code>Str</code> reads and writes UTF-8. <code>encode</code> writes a character, of at most 10FFFFH, in one to four bytes; a number that isn’t one becomes FFFDH, the character that stands for a wrong one. <code>decode</code> reads the first character of <code>s</code>, and gives FFFDH and 1 for a byte that doesn’t start one rightly, and 0 and 0 for an empty <code>s</code>: a continuation, a byte followed by too few continuations, a surrogate, a character beyond 10FFFFH or one spelled in more bytes than it needs. <code>decodeLast</code> reads the last character in the same way, to walk a string backwards. <code>valid</code> says that <code>decode</code> finds no such byte in <code>s</code>, and <code>chars</code> counts the characters, each such byte one. <code>next</code> walks a string a character at a time, as <code>decode</code> reads them: from 0, it gives the character at <code>i</code> and where the one after it starts, and 0 and -1 when <code>i</code> is at the end, or past it:</p>
13211325 <pre><code>c, i := Str.next(s, 0);
13221326 while i &gt;= 0 do
@@ -1363,6 +1367,7 @@
13631367 letter*: U8; (* the option just read *)
13641368 value*: []U8; (* its value; &quot;&quot; for a flag *)
13651369 long*: BOOL; (* it was written by its long name *)
1370+ spelt*: []U8; (* as it was written, no dashes: &quot;b&quot; or &quot;bar&quot;; to read only *)
13661371 ...
13671372 end;
13681373 proc init*(p: ^Parser; name: []U8; table: []Row); (* the arguments from 1 on, by table *)
@@ -1371,9 +1376,10 @@
13711376 proc at*(p: ^Parser): INT; (* the argument operand would give next *)
13721377 proc scope*(p: ^Parser; name: []U8); (* subcommand name&#39;s options, from the word after it *)
13731378 proc number*(p: ^Parser; lo, hi: I64): I64; (* the value just read, a number from lo to hi *)
1379+proc refuse*(p: ^Parser; wants: []U8); (* the value just read refused, as number refuses one *)
13741380 proc fail*(p: ^Parser; text: []U8); (* the program&#39;s own mistake *)</code></pre>
13751381 <p><code>Opt</code> reads a command line by the rules of the C library’s <code>getopt</code>, with GNU’s long options, so that a program’s options behave as every other Unix program’s. The program describes itself once, in a table of <code>Row</code>s: its synopsis lines, its subcommands and its options. The help and the messages for mistakes are made from the table, so they can’t drift from it; the program’s test of <code>p.letter</code> is the only other place an option appears. The parser is a record the program owns, and the table a slice it keeps as long as the parser: a literal written in the call to <code>init</code> lives as long as the procedure that makes it.</p>
1376-<p>A row’s <code>scope</code> is <code>""</code> for the program itself, or a subcommand’s name: <code>"start"</code>, or <code>"remote.add"</code> for a subcommand of <code>remote</code>. An option has a <code>letter</code>, a <code>long</code> name, or both. One with a long name only has a key of its own below <code>'!'</code> for a letter, so that the program can tell it from the others. With a <code>value</code>, the name the help and the messages give it, the option takes a value; with <code>""</code> it is a flag.</p>
1382+<p>A row’s <code>scope</code> is <code>""</code> for the program itself, or a subcommand’s name: <code>"start"</code>, or <code>"remote.add"</code> for a subcommand of <code>remote</code>. An option has a <code>letter</code>, a <code>long</code> name, or both. One with a long name only has a key of its own below <code>'!'</code> for a letter, so that the program can tell it from the others. With a <code>value</code>, the name the help and the messages give it, the option takes a value; with <code>""</code> it is a flag. A value written in brackets, <code>"[when]"</code>, may be left out, and is <code>""</code> then: it is given only in the option’s own word, <code>--color=always</code> or <code>-calways</code>, never as the next, as <code>getopt</code>’s <code>::</code> has it, and the help shows it as <code>--color[=when]</code>.</p>
13771383 <pre><code>const wait = 1; (* the key of --wait, which has no letter *)
13781384 ...
13791385 Opt.init(ADR(p), &quot;keep&quot;, [
@@ -1410,12 +1416,12 @@
14101416
14111417 -b, --bar label show the job in the bar as label
14121418 -h, --help print this and exit</code></pre>
1413-<p>A scope with several synopsis lines has the others indented under the first; one with none, <code>usage:</code> and its words, as <code>usage: keep start</code>.</p>
1419+<p>A scope with several synopsis lines has the others indented under the first; one with none, <code>usage:</code> and its words, as <code>usage: keep start</code>. A scope may give <code>-h</code> to an option of its own, as grep’s “no file names”; help there is <code>--help</code> alone, and its row in the help has no letter.</p>
14141420 <p>A mistake on the command line is a sentence on standard error, the program’s name first, then the scope’s synopsis lines, as the help begins, and status 2:</p>
14151421 <pre><code>keep: unknown option -x
14161422 usage: keep start [-b label] name command [argument ...]</code></pre>
1417-<p>The sentences are <code>unknown option -x</code> (or <code>--name</code>, up to its <code>=</code>), <code>-b needs a label</code>, <code>--follow takes no value</code> and <code>--wait wants a number from 1 to 600, not '0'</code>. <code>fail</code> writes the program’s own mistakes the same way, but alone, so that the sentence can say where the help is: <code>keep: no command; see keep -h</code>.</p>
1418-<p>A mistake in the table is the program’s, not its user’s. <code>init</code> checks the table before it reads a word, and ends the program with status 1: <code>keep: option table, row 3: the option is in the scope already</code>. The others are an option with neither a letter nor a long name, a long name with <code>=</code> in it, a letter <code>-</code>, and <code>-h</code> or <code>--help</code> in the table, since they are <code>Opt</code>’s.</p>
1423+<p>The sentences are <code>unknown option -x</code> (or <code>--name</code>, up to its <code>=</code>), <code>-b needs a label</code>, <code>--follow takes no value</code> and <code>--wait wants a number from 1 to 600, not '0'</code>; for a number with no top, given the largest <code>I64</code> for <code>hi</code>, <code>--jobs wants a number from 1 up, not '0'</code>. <code>refuse</code> refuses a value the program reads itself, as <code>number</code> refuses one, naming the option as the user wrote it, <code>-b</code> or <code>--bar</code>: <code>Opt.refuse(ADR(p), "a label with no spaces")</code> writes <code>keep: -b wants a label with no spaces, not 'a b'</code>, and the synopsis lines. <code>p.spelt</code> is that spelling, for the program’s own sentences. <code>fail</code> writes the program’s own mistakes the same way, but alone, so that the sentence can say where the help is: <code>keep: no command; see keep -h</code>.</p>
1424+<p>A mistake in the table is the program’s, not its user’s. <code>init</code> checks the table before it reads a word, and ends the program with status 1: <code>keep: option table, row 3: the option is in the scope already</code>. The others are an option with neither a letter nor a long name, a long name with <code>=</code> in it, a letter <code>-</code>, a value with one bracket but not the other, and <code>--help</code> in the table, since it is <code>Opt</code>’s.</p>
14191425 <p><strong>Width</strong> says how many columns of a terminal text takes, for a program with a screen that wraps its lines and cuts them at the window’s edge.</p>
14201426 <pre><code>module Width;
14211427 proc width*(c: I32): INT; (* the columns the character c takes: 0, 1 or 2 *)

site/public/tour/hello.html (history) modified +1 -1

@@ -70,7 +70,7 @@
7070 <span class="cmd">$ raz run Quiet.raz</span>
7171 hello, again
7272 <span class="cmd">$ ls -l Quiet | awk &#x27;{print $5, &quot;bytes&quot;}&#x27;</span>
73-28480 bytes</code></pre>
73+28472 bytes</code></pre>
7474 <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>
7575 <h2>What <code>Out</code> can write</h2>
7676 <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>; or between backquotes, as a raw string with no escapes at all, which may run over lines (lesson 6).</p>