raz / commit b97dee13

commit
b97dee13083782009a20e18f532371bc135cc8ee
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
8f8b29d4
site: v0.17.1

The download, the report and the library's PDFs, and the tour's Words,
which finds from a place and tells a digit.

patch · log

11 files changed, +50 -33

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

@@ -1 +1 @@
1-/download/latest /download/raz-0.17.0-linux-x86_64.tar.gz 302
1+/download/latest /download/raz-0.17.1-linux-x86_64.tar.gz 302

site/public/advanced/listing.html (history) modified +12 -12

@@ -258,18 +258,18 @@
258258 <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>
259259 <pre class="output term"><code><span class="cmd">$ raz -o Dot Dot.raz</span>
260260 <span class="cmd">$ objdump -d -M intel --no-show-raw-insn Dot | sed -n &#x27;/&lt;Dot.dot&gt;:/,/ret/p&#x27; | head -12</span>
261-0000000000403ae0 &lt;Dot.dot&gt;:
262- 403ae0: push rbp
263- 403ae1: mov rbp,rsp
264- 403ae4: sub rsp,0x40
265- 403aeb: mov QWORD PTR [rbp-0x38],rbx
266- 403aef: xor ebx,ebx
267- 403af1: mov QWORD PTR [rbp-0x30],r12
268- 403af5: xor r12d,r12d
269- 403af8: mov QWORD PTR [rbp-0x28],r13
270- 403afc: xor r13d,r13d
271- 403aff: mov QWORD PTR [rbp-0x20],rdx
272- 403b03: mov QWORD PTR [rbp-0x18],rcx</code></pre>
261+0000000000403bc0 &lt;Dot.dot&gt;:
262+ 403bc0: push rbp
263+ 403bc1: mov rbp,rsp
264+ 403bc4: sub rsp,0x40
265+ 403bcb: mov QWORD PTR [rbp-0x38],rbx
266+ 403bcf: xor ebx,ebx
267+ 403bd1: mov QWORD PTR [rbp-0x30],r12
268+ 403bd5: xor r12d,r12d
269+ 403bd8: mov QWORD PTR [rbp-0x28],r13
270+ 403bdc: xor r13d,r13d
271+ 403bdf: mov QWORD PTR [rbp-0x20],rdx
272+ 403be3: mov QWORD PTR [rbp-0x18],rcx</code></pre>
273273 <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&rsquo;s name and run it with <code>raz run Name.raz</code>.</p><div class="pager"><a href="syscalls.html">&larr; System calls</a><a href="index.html">Contents</a><a class="next" href="volatile.html">Volatile &rarr;</a></div></article></div>
274274 </main>
275275 <footer>raz is under the ISC license.</footer>

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

@@ -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-26224 bytes</code></pre>
68+26728 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,14 +134,14 @@
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 28408
138-Lean 28392</code></pre>
137+Heavy 28904
138+Lean 28896</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>
141141 <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>
142142 <pre class="output term"><code><span class="cmd">$ raz -s -o Lean-stripped Lean.raz</span>
143143 <span class="cmd">$ ls -l Lean Lean-stripped | awk &#x27;{print $9, $5}&#x27;</span>
144-Lean 28392
144+Lean 28896
145145 Lean-stripped 6856
146146 <span class="cmd">$ ./Lean-stripped</span>
147147 same program</code></pre>

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

Binary file; the patch has it.

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

@@ -0,0 +1 @@
1+49fb424ac3b7ee9ed29c87cd9fcb89ed314d2c17ca449077154aa293f2b9ff1c raz-0.17.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.17.0 is a tarball for x86-64 Linux with the compiler, <code>raz</code>,
116+<p>raz 0.17.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.17.0-linux-x86_64.tar.gz">Download raz 0.17.0</a>
122- <a class="btn" href="download/raz-0.17.0-linux-x86_64.tar.gz.sha256">SHA-256</a>
121+ <a class="btn primary" href="download/raz-0.17.1-linux-x86_64.tar.gz">Download raz 0.17.1</a>
122+ <a class="btn" href="download/raz-0.17.1-linux-x86_64.tar.gz.sha256">SHA-256</a>
123123 </div>
124-<pre class="code"><code>$ tar xzf raz-0.17.0-linux-x86_64.tar.gz
125-$ ln -s $PWD/raz-0.17.0-linux-x86_64/raz ~/.local/bin/raz
124+<pre class="code"><code>$ tar xzf raz-0.17.1-linux-x86_64.tar.gz
125+$ ln -s $PWD/raz-0.17.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.17.0-linux-x86_64.tar.gz</code> to this one, for
131-good. Earlier releases: <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.17.1-linux-x86_64.tar.gz</code> to this one, for
131+good. Earlier releases: <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>2425d173fb00eb6352a3a1c089469d038e00abae870816fd90d7a6fb707ae370</code></p>
133+<p class="sha">SHA-256 <code>49fb424ac3b7ee9ed29c87cd9fcb89ed314d2c17ca449077154aa293f2b9ff1c</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 +18 -6

@@ -78,7 +78,7 @@
7878 <p>writes <code>"usage: tool [-v] file ...\n -v say what is done\n"</code>. Each line of an indented raw string must start with the closing line’s blanks, the same spaces and tabs in the same order, or it is an error; a line holding only blanks is an empty line of the text. A raw string that isn’t indented is the text between its backquotes as it stands.</p>
7979 <p>A raw string can’t hold a backquote; a text that needs one joins it with <code>+</code>, as <code>"`"</code>. Everywhere else a raw string is a string, as one in double quotes is.</p>
8080 <p>Messages give the line and the column, counted in characters (section 10).</p>
81-<p><strong>Comments</strong> are <code>(*</code> … <code>*)</code> and nest. By convention, the comment just before an exported declaration is its documentation, and the one before <code>module</code> is the module’s.</p>
81+<p><strong>Comments</strong> are <code>(*</code> … <code>*)</code> and nest. A comment ends at the <code>*)</code> that closes it, wherever that stands, so one that quotes <code>*)</code>, as in <code>x*)</code> of a pattern, writes it apart: <code>x* )</code>. By convention, the comment just before an exported declaration is its documentation, and the one before <code>module</code> is the module’s.</p>
8282 <p><strong>Operators and delimiters:</strong></p>
8383 <pre><code>+ - * / &amp; | ~ = # &lt; &lt;= &gt; &gt;= := : ; , . .. ... ( ) [ ] { } ^</code></pre>
8484 <p><code>|</code> is also what starts an arm of <code>match</code> (section 7.4); an arm comes where a statement could, never after an operand, so the two don’t mix.</p>
@@ -869,7 +869,7 @@
869869 </tr>
870870 <tr>
871871 <td><code>Sys</code></td>
872-<td>system calls: <code>open</code>, <code>openMode</code>, <code>openRead</code>, <code>create</code>, <code>read</code>, <code>write</code>, <code>seek</code>, <code>position</code>, <code>truncate</code>, <code>sync</code>, <code>syncAll</code>, <code>lock</code>, <code>close</code>, <code>dup</code>, <code>dupTo</code>, <code>dupAbove</code>, <code>keepOnExec</code>, <code>mmap</code>, <code>munmap</code>, <code>isTerminal</code>, <code>yield</code>, <code>exit</code>; files and directories, <code>rename</code>, <code>remove</code>, <code>removeDir</code>, <code>makeDir</code>, <code>chmod</code>, <code>access</code>, <code>umask</code>, <code>symlink</code>, <code>readLink</code>, <code>info</code>, <code>linkInfo</code>, <code>infoOf</code>, <code>openDir</code>, <code>nextEntry</code>, <code>entryKind</code>, <code>closeDir</code>; the terminal, <code>rawMode</code>, <code>restoreMode</code>, <code>getMode</code>, <code>setMode</code>, <code>termSize</code>, <code>ready</code>; the environment, <code>env</code>, <code>envAt</code>, <code>workDir</code>, <code>setWorkDir</code>; programs, <code>spawn</code> and <code>exec</code>, pipes and signals; the user, the machine, time used and limits; time, <code>clock</code>, <code>now</code>, <code>sleep</code>; <code>random</code>; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and <code>Sys.raz</code> over the C library for the others</td>
872+<td>system calls: <code>open</code>, <code>openMode</code>, <code>openRead</code>, <code>create</code>, <code>read</code>, <code>write</code>, <code>seek</code>, <code>position</code>, <code>truncate</code>, <code>sync</code>, <code>syncAll</code>, <code>lock</code>, <code>close</code>, <code>dup</code>, <code>dupTo</code>, <code>dupAbove</code>, <code>keepOnExec</code>, <code>mmap</code>, <code>munmap</code>, <code>isTerminal</code>, <code>yield</code>, <code>exit</code>; files and directories, <code>rename</code>, <code>remove</code>, <code>removeDir</code>, <code>makeDir</code>, <code>chmod</code>, <code>access</code>, <code>umask</code>, <code>symlink</code>, <code>readLink</code>, <code>info</code>, <code>linkInfo</code>, <code>infoOf</code>, <code>openDir</code>, <code>nextEntry</code>, <code>entryKind</code>, <code>closeDir</code>; the terminal, <code>rawMode</code>, <code>restoreMode</code>, <code>getMode</code>, <code>setMode</code>, <code>termSize</code>, <code>ready</code>; the environment, <code>env</code>, <code>envAt</code>, <code>setEnv</code>, <code>workDir</code>, <code>setWorkDir</code>; programs, <code>spawn</code> and <code>exec</code>, pipes and signals; the user, the machine, time used and limits; time, <code>clock</code>, <code>now</code>, <code>sleep</code>; <code>random</code>; what an errno means, <code>errorText</code>; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and <code>Sys.raz</code> over the C library for the others</td>
873873 </tr>
874874 <tr>
875875 <td><code>Out</code></td>
@@ -913,7 +913,7 @@
913913 </tr>
914914 <tr>
915915 <td><code>Fmt</code></td>
916-<td>formatted output: <code>Fmt.print("{} of {}\n", [Fmt.int(n), Fmt.real(x, 2)])</code>, or into a <code>Buf</code> with <code>Fmt.write</code></td>
916+<td>formatted output: <code>Fmt.print("{} of {}\n", [Fmt.int(n), Fmt.real(x, 2)])</code>, into a <code>Buf</code> with <code>Fmt.write</code>, or to standard error with <code>Fmt.eprint</code></td>
917917 </tr>
918918 <tr>
919919 <td><code>List</code></td>
@@ -1115,8 +1115,11 @@
11151115 proc readyFor*(reads, writes: []INT; ms: INT): INT; (* readyOf, and the first of writes with room to write *)
11161116 proc setBlocking*(fd: INT; yes: BOOL): INT; (* if not yes, a read or write that would wait is -11 at once *)
11171117
1118+proc errorText*(err: INT): []U8; (* what errno err, or minus it, means, as C&#39;s strerror says *)
1119+
11181120 proc env*(name: []U8): []U8; (* the environment variable&#39;s value; &quot;&quot; if unset *)
11191121 proc envAt*(i: INT): ([]U8, BOOL); (* the environment&#39;s ith NAME=value, from 0; false past the last *)
1122+proc setEnv*(name, value: []U8): INT; (* name set to value, for env and the programs started *)
11201123 proc workDir*: ([]U8, INT); (* the working directory, good until the next call *)
11211124 proc setWorkDir*(path: []U8): INT;
11221125
@@ -1175,7 +1178,7 @@
11751178 <p><code>spawn</code> starts the program at <code>p.path</code>, with <code>p.args</code> as its arguments, the first being its name. A <code>p.path</code> without a <code>/</code> is looked for as a shell looks for a command, and as C’s <code>execvp</code> does: in each directory of this program’s <code>PATH</code> in turn, an empty one being the working directory, or of <code>/bin:/usr/bin</code> if <code>PATH</code> is unset or empty; the first that runs is the program. Its environment is this program’s with each <code>NAME=value</code> of <code>p.env</code> added or put in place of the old value, or, if <code>p.onlyEnv</code>, <code>p.env</code> alone. It starts in <code>p.dir</code>. Its standard input, output and error are <code>p.fds</code>; a 0 gives it this program’s own, so <code>{path: "ls", args: ["ls"]}</code> runs <code>ls</code> as a shell runs it, with every other field zero. It gets no other open file but those of <code>p.more</code>, each at its own number, as a shell passes <code>3&lt;file</code> on, every signal does what it does at first, and none is blocked. If <code>p.tty</code> is a pseudo-terminal’s fd, the program starts a session on that terminal: it is its controlling terminal, and its standard input, output and error, and <code>p.fds</code> and <code>p.group</code> are not used.</p>
11761179 <p><code>p.group</code> puts the program in a process group, the programs that a shell’s job is made of: -1 makes it the first of a new group, whose number is its process id, and the other programs of the job join that number. The terminal gives its keys, and the signals of Ctrl-C and Ctrl-Z, to one group, the one in its foreground: <code>p.foreground</code> puts the program’s group there before it starts, and <code>foreground</code> puts any group there, as a shell does to take the terminal back. <code>setGroup</code> moves a program to a group, as the shell does for each program it starts, for whichever of the two runs first; a shell runs in a group of its own, <code>setGroup(0, 0)</code>.</p>
11771180 <p><code>exec</code> runs the program <code>p</code> describes in this program’s place, as a shell’s <code>exec cmd</code> does, found and started as <code>spawn</code> would start it, <code>p.tty</code>, <code>p.group</code>, <code>p.foreground</code>, <code>p.fds</code> and <code>p.dir</code> included, except that it keeps this program’s other open files: each stays open in the program unless <code>keepOnExec(fd, false)</code> was said of it, as it is of <code>pipe</code>’s, and those of <code>p.more</code> are kept. It returns only if the program can’t run: -2 (ENOENT) or -13 (EACCES) if there is none to run, with nothing done; or, if the program is found but won’t start, minus the errno, with what <code>p</code> asks of the terminal, the group, the files and the directory done, and this program’s signals as they were.</p>
1178-<p>A shell moves its own files with <code>dup</code> and <code>dupTo</code>, for <code>2&gt;&amp;1</code> and <code>exec &gt;log</code> and around a builtin: <code>dupTo(fd, into)</code> makes <code>into</code> the same open file as <code>fd</code>, closing what <code>into</code> was, and <code>dup</code> gives a new fd for it, the lowest free, as a shell saves a file to give it back. <code>dupAbove(fd, 10)</code> gives one at 10 or above, closed on exec, out of the way of the fds a script names (<code>3&gt;log</code>), as a shell keeps its own. <code>fork</code> copies this program, which goes on from there in both: it is 0 in the copy and the copy’s process id in this one, as a shell runs a builtin or a procedure as a stage of a pipe. Only the thread that calls it is copied, so a program with threads mustn’t; and what <code>Out</code> keeps is copied too, to be written twice, so <code>Out.flush</code> comes first. <code>group</code> is the process group this program is in: a shell starting on a terminal waits until it is <code>foregroundOf(0)</code> before it takes it. <code>access</code> says whether this user, by its real ids, may read, write or execute a file, as <code>test -r</code>, <code>-w</code> and <code>-x</code> ask, which <code>Info.mode</code> alone can’t say; an empty <code>how</code> asks only whether it is there. <code>open</code> refuses <code>executing</code>, with -22 (EINVAL). <code>umask</code> sets the bits taken away from the mode of every file this program, and those it starts, make, and says what they were. <code>envAt</code> gives the environment one variable at a time, from 0, for a shell to list it and to pass it on whole with <code>onlyEnv</code>. <code>getMode</code> reads a terminal’s modes, and <code>setMode</code> sets them again once what was written is sent, so that a shell keeps them for each job: a program stopped by Ctrl-Z with its terminal raw gets it back raw, and the shell its own between. <code>cpuTime</code> says how long the processor ran this program, in its own code and in the system for it, or, if <code>children</code>, the programs it started and has waited for, as <code>time</code> and <code>times</code> say. <code>limit</code> gives a limit, <code>limitFiles</code> say, soft and hard, and <code>setLimit</code> sets them, as <code>ulimit</code> does: a program may raise its soft limit up to the hard one, and lower either. <code>uid</code> is the user this program runs as, <code>euid</code> the one whose rights it has, 0 for root, as a prompt shows <code>#</code>; <code>hostName</code> is the machine’s name.</p>
1181+<p>A shell moves its own files with <code>dup</code> and <code>dupTo</code>, for <code>2&gt;&amp;1</code> and <code>exec &gt;log</code> and around a builtin: <code>dupTo(fd, into)</code> makes <code>into</code> the same open file as <code>fd</code>, closing what <code>into</code> was, and <code>dup</code> gives a new fd for it, the lowest free, as a shell saves a file to give it back. <code>dupAbove(fd, 10)</code> gives one at 10 or above, closed on exec, out of the way of the fds a script names (<code>3&gt;log</code>), as a shell keeps its own. <code>fork</code> copies this program, which goes on from there in both: it is 0 in the copy and the copy’s process id in this one, as a shell runs a builtin or a procedure as a stage of a pipe. Only the thread that calls it is copied, so a program with threads mustn’t; and what <code>Out</code> keeps is copied too, to be written twice, so <code>Out.flush</code> comes first. <code>group</code> is the process group this program is in: a shell starting on a terminal waits until it is <code>foregroundOf(0)</code> before it takes it. <code>access</code> says whether this user, by its real ids, may read, write or execute a file, as <code>test -r</code>, <code>-w</code> and <code>-x</code> ask, which <code>Info.mode</code> alone can’t say; an empty <code>how</code> asks only whether it is there. <code>open</code> refuses <code>executing</code>, with -22 (EINVAL). <code>umask</code> sets the bits taken away from the mode of every file this program, and those it starts, make, and says what they were. <code>envAt</code> gives the environment one variable at a time, from 0, for a shell to list it and to pass it on whole with <code>onlyEnv</code>. <code>setEnv</code> refuses a name that is empty or holds an <code>=</code>, and a 0 in either, with -22; as C’s <code>setenv</code>, it isn’t safe while another thread reads the environment, and what <code>env</code> gave for a variable may be gone once it sets that variable again. <code>getMode</code> reads a terminal’s modes, and <code>setMode</code> sets them again once what was written is sent, so that a shell keeps them for each job: a program stopped by Ctrl-Z with its terminal raw gets it back raw, and the shell its own between. <code>cpuTime</code> says how long the processor ran this program, in its own code and in the system for it, or, if <code>children</code>, the programs it started and has waited for, as <code>time</code> and <code>times</code> say. <code>limit</code> gives a limit, <code>limitFiles</code> say, soft and hard, and <code>setLimit</code> sets them, as <code>ulimit</code> does: a program may raise its soft limit up to the hard one, and lower either. <code>uid</code> is the user this program runs as, <code>euid</code> the one whose rights it has, 0 for root, as a prompt shows <code>#</code>; <code>hostName</code> is the machine’s name.</p>
11791182 <p><code>wait</code> waits for the program <code>pid</code> to change, for any of this program’s if <code>pid</code> is -1, or for any of the group <code>g</code> if <code>pid</code> is <code>-g</code>, as a shell waits for a job’s programs, and says which one, and how: <code>exited</code>, with its exit status; <code>killed</code>, with the number of the signal that ended it; or <code>stopped</code>, by Ctrl-Z or a signal, with the signal’s number. Without <code>block</code> it doesn’t wait, and is 0 and <code>running</code> if no program changed. A program that has nothing to wait for is -10 (ECHILD). <code>kill</code> sends a program a signal, <code>sigTerm</code> to end it; to a group, if <code>pid</code> is minus its number.</p>
11801183 <p><strong>Signals.</strong> <code>catch</code> takes the signals <code>sigs</code> away from what they would do, ending the program most of them, and gives an fd that is ready to read when one comes, so that a program waits for signals with <code>ready</code> and <code>readyOf</code> as it waits for keys or a server. <code>caught</code> gives each signal that came, in turn. A later <code>catch</code> adds to the signals caught and gives the same fd. Catching <code>sigKill</code> or <code>sigStop</code>, or the signals <code>Rt</code> reports, SIGSEGV and SIGFPE, is -22 (EINVAL). <code>ignore</code> makes a signal do nothing, as a shell ignores <code>sigTtou</code> so that it can take its terminal back, and <code>ignore(sig, false)</code> gives it back what it does at first. A program that <code>spawn</code> starts begins with neither.</p>
11811184 <p><code>handle</code> is for a program that must see a signal while it waits in a system call, as a shell waiting for its foreground program, or for a key, sees Ctrl-C: the signal is noted, and the call it comes during, <code>wait</code>, <code>read</code>, <code>ready</code> and the rest, fails with -4 (EINTR) rather than going on; <code>sleep</code> sleeps its time all the same. <code>came(sig)</code> says whether it came since the last time it was asked. Nothing else runs when the signal comes, so the program does what it does after it, in its own time; <code>Out</code> and <code>Files</code> try again after -4. <code>ignore(sig, false)</code> gives the signal back what it does at first, and the signals <code>catch</code> refuses, <code>handle</code> refuses too.</p>
@@ -1194,6 +1197,7 @@
11941197 proc free*(a: ^Mem.Allocator; s: []U8); (* what copy gave from a, given back; &quot;&quot; is none *)
11951198 proc hash*(s: []U8): U64; (* FNV-1a, 64 bits *)
11961199 proc find*(s, sub: []U8): INT; (* where sub first starts in s, or -1 *)
1200+proc findFrom*(s, sub: []U8; from: INT): INT; (* where sub first starts in s at or after from, or -1 *)
11971201 proc findLast*(s, sub: []U8): INT; (* where sub last starts in s, or -1 *)
11981202 proc hasPrefix*(s, p: []U8): BOOL;
11991203 proc hasSuffix*(s, x: []U8): BOOL;
@@ -1202,6 +1206,11 @@
12021206 proc trimRight*(s: []U8): []U8; (* s without the spaces at its end *)
12031207 proc cut*(s, sep: []U8): ([]U8, []U8, BOOL); (* what comes before the first sep, and after it *)
12041208 proc field*(s: []U8): ([]U8, []U8); (* the first run of bytes in s that aren&#39;t spaces, and what follows it *)
1209+proc isDigit*(c: U8): BOOL; (* 0 to 9 *)
1210+proc isLetter*(c: U8): BOOL; (* A to Z, a to z *)
1211+proc isSpace*(c: U8): BOOL; (* a space, as trim takes it *)
1212+proc isPunct*(c: U8): BOOL; (* printable, and neither a letter, a digit nor the blank *)
1213+proc hexVal*(c: U8): INT; (* c&#39;s value as a hexadecimal digit, or -1 *)
12051214 proc lower*(s: []U8); (* s&#39;s ASCII capitals made small, in place *)
12061215 proc upper*(s: []U8); (* s&#39;s ASCII small letters made capitals, in place *)
12071216 proc join*(b: ^Buf.Buf; parts: [][]U8; sep: []U8); (* the parts added to b, sep between each two *)
@@ -1242,6 +1251,7 @@
12421251 real(r: F64; places: INT);
12431252 end;
12441253 proc print*(f: []U8; args: []Arg); (* to standard output *)
1254+proc eprint*(f: []U8; args: []Arg); (* to standard error, once Out is flushed *)
12451255 proc write*(b: ^Buf.Buf; f: []U8; args: []Arg); (* added to b *)
12461256
12471257 module List(T);
@@ -1269,6 +1279,8 @@
12691279 proc room*(v: ^Vec; n: INT): BOOL; (* room for n more; false if the allocator has none *)
12701280 proc push*(v: ^Vec; x: T); (* x added at the end *)
12711281 proc add*(v: ^Vec): ^T; (* a new element at the end, zero, to fill in place *)
1282+proc tryPush*(v: ^Vec; x: T): BOOL; (* push; false, and v as it was, if there is no room *)
1283+proc tryAdd*(v: ^Vec): (^T, BOOL); (* add; nil and false, and v as it was, if there is no room *)
12721284 proc resize*(v: ^Vec; n: INT); (* n elements: cut short, or the new ones zero *)
12731285 proc all*(v: ^Vec): []T; (* the elements, until it next grows *)
12741286 proc reset*(v: ^Vec); (* emptied, its memory kept *)
@@ -1306,8 +1318,8 @@
13061318 ... (* c is a character of s *)
13071319 c, i := Str.next(s, i);
13081320 end;</code></pre>
1309-<p>A string is bytes, and <code>Str</code> takes no more of Unicode than UTF-8: <code>lower</code>, <code>upper</code> and <code>eqFold</code> change and match ASCII letters alone, and nothing says how wide a character is on a terminal, nor which spellings of a text are the same.</p>
1310-<p>A space, to <code>trim</code>, <code>trimLeft</code>, <code>trimRight</code> and <code>field</code>, is a blank, a tab, a line feed, a carriage return, a vertical tab or a form feed. <code>cut</code> gives what comes before the first <code>sep</code> in <code>s</code>, what comes after it, and <code>true</code>; or <code>s</code>, an empty string and <code>false</code> if <code>s</code> has no <code>sep</code>. <code>field</code> passes the spaces at the start of <code>s</code> and gives the bytes up to the next space or the end, and the rest of <code>s</code> from there; two empty strings if <code>s</code> holds only spaces. They take a string apart without memory of their own, each part a slice of <code>s</code>:</p>
1321+<p>A string is bytes, and <code>Str</code> takes no more of Unicode than UTF-8: <code>lower</code>, <code>upper</code> and <code>eqFold</code> change and match ASCII letters alone, the character tests know ASCII alone, and nothing says how wide a character is on a terminal, nor which spellings of a text are the same.</p>
1322+<p>A space, to <code>isSpace</code>, <code>trim</code>, <code>trimLeft</code>, <code>trimRight</code> and <code>field</code>, is a blank, a tab, a line feed, a carriage return, a vertical tab or a form feed. <code>cut</code> gives what comes before the first <code>sep</code> in <code>s</code>, what comes after it, and <code>true</code>; or <code>s</code>, an empty string and <code>false</code> if <code>s</code> has no <code>sep</code>. <code>field</code> passes the spaces at the start of <code>s</code> and gives the bytes up to the next space or the end, and the rest of <code>s</code> from there; two empty strings if <code>s</code> holds only spaces. They take a string apart without memory of their own, each part a slice of <code>s</code>:</p>
13111323 <pre><code>line, rest, more := Str.cut(text, &quot;\n&quot;); (* the first line, and the others *)
13121324 key, val, ok := Str.cut(line, &quot;=&quot;);
13131325 w, rest := Str.field(line); (* the words of a line *)

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-28400 bytes</code></pre>
73+28904 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>

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

@@ -162,7 +162,7 @@
162162 <pre class="output"><code>1 1 2 3 4 5
163163 </code></pre>
164164 <h2>Strings</h2>
165-<p>A string is a slice of bytes, <code>[]U8</code>, in UTF-8, and a string constant's bytes are constant. A <code>[8]U8</code> made from one is a copy you can change. Arrays and slices of integers compare with <code>=</code> and <code>#</code>, so strings do too. <code>Str</code> has the rest: ordering, finding, hashing, prefixes and suffixes, trimming, taking apart, ASCII case, UTF-8, and numbers to and from text.</p>
165+<p>A string is a slice of bytes, <code>[]U8</code>, in UTF-8, and a string constant's bytes are constant. A <code>[8]U8</code> made from one is a copy you can change. Arrays and slices of integers compare with <code>=</code> and <code>#</code>, so strings do too. <code>Str</code> has the rest: ordering, finding, hashing, prefixes and suffixes, trimming, taking apart, ASCII case and kinds of character, UTF-8, and numbers to and from text.</p>
166166 <div class="file"><span>Words.raz</span></div><pre class="code"><code><span class="kw">module</span> Words;
167167 <span class="kw">import</span> Out, Str;
168168
@@ -175,6 +175,8 @@
175175 Out.int(Str.find(s, <span class="string">&quot;world&quot;</span>)); Out.ln; <span class="comment">(* 7 *)</span>
176176 Out.int(Str.find(s, <span class="string">&quot;xyz&quot;</span>)); Out.ln; <span class="comment">(* -1 *)</span>
177177 Out.int(Str.findLast(<span class="string">&quot;abcabc&quot;</span>, <span class="string">&quot;bc&quot;</span>)); Out.ln; <span class="comment">(* 4 *)</span>
178+ Out.int(Str.findFrom(s, <span class="string">&quot;o&quot;</span>, <span class="number">5</span>)); Out.ln; <span class="comment">(* 8: the first o from 5 on *)</span>
179+ <span class="kw">if</span> Str.isDigit(<span class="string">&#x27;7&#x27;</span>) <span class="kw">and</span> <span class="kw">not</span> Str.isLetter(<span class="string">&#x27;7&#x27;</span>) <span class="kw">then</span> Out.str(<span class="string">&quot;a digit\n&quot;</span>); <span class="kw">end</span>;
178180 <span class="kw">if</span> Str.hasPrefix(s, <span class="string">&quot;hell&quot;</span>) <span class="kw">then</span> Out.str(<span class="string">&quot;prefix\n&quot;</span>); <span class="kw">end</span>;
179181 <span class="kw">if</span> Str.hasSuffix(s, <span class="string">&quot;world&quot;</span>) <span class="kw">then</span> Out.str(<span class="string">&quot;suffix\n&quot;</span>); <span class="kw">end</span>;
180182 Out.int(Str.cmp(<span class="string">&quot;apple&quot;</span>, <span class="string">&quot;banana&quot;</span>)); Out.ln; <span class="comment">(* -1 *)</span>
@@ -199,6 +201,8 @@
199201 7
200202 -1
201203 4
204+8
205+a digit
202206 prefix
203207 suffix
204208 -1