raz / commit 9ca6cfc3

commit
9ca6cfc37da65a90228eaf534dcd7ea179a8e56e
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
9dd75230
The blank, and a warning for a dropped result

Report 2026-10.14. _ is a symbol of its own, sBlank: _ := e loads a
single value, so a volatile one is read, and drops it; MultiAssign
skips the results a _ stands for. _ anywhere else says it isn't a
name. A call standing on its own that drops results is noted in drops
and warned of in order with the rest, with help writing _ := f(...).
The 117 drops in lib, examples, tools and the tests now say _ :=, their
comments kept in their columns. raz --version says 2026-10.14.
Tests: conform/run/Blank, conform/err/BlankName and BlankValue,
test/err/Dropped. 7,816 lines of code; bench 1.13M lines/s.

patch · log

35 files changed, +401 -155

CLAUDE.md modified +4 -2

@@ -86,8 +86,10 @@
8686 defect, and the library grows only by what breaks no program written
8787 for it. A wish for more, the owner's or yours, goes on the list in
8888 `PLAN.md`, for a later thaw; it isn't built. v0.6.0 was such a thaw,
89-by the owner's word: report 2026-10.12; the compiler follows 2026-10.13,
90-whose `Sys` writes without waiting, for rat's pastes. Its parser
89+by the owner's word: report 2026-10.12; the compiler follows 2026-10.14,
90+whose `Sys` writes without waiting, for rat's pastes (10.13), and
91+whose blank, `_ := f(x)`, drops a result that is otherwise warned of
92+(10.14), also by the owner's word. Its parser
9193 reaches the machine only through `gen.pas`; its steps 5 to 10 await
9294 the owner's review, and git has them. Keep
9395 `doc/compiler.md`'s table of lines and its routine names true when the

PLAN.md (history) modified +1 -5

@@ -17,8 +17,4 @@
1717 ## Wishes, for a later thaw
1818
1919 What the language or the library might have, met while writing raz;
20-none is built while the freeze holds.
21-
22-- A warning for a call whose result is dropped. Code drops results on
23- purpose (`SYSCALL`, `Sys.write`; about 40 places in `lib/`), so it
24- needs a way to say so first, such as `_ := f(x)`.
20+none is built while the freeze holds. None waits now.

conform/err/BlankName.raz (history) added +7 -0

@@ -0,0 +1,7 @@
1+module BlankName;
2+proc main*;
3+var _: I64; x: I64;
4+begin
5+ x := _;
6+end;
7+end BlankName.

conform/err/BlankValue.raz (history) added +9 -0

@@ -0,0 +1,9 @@
1+module BlankValue;
2+import Out;
3+proc main*;
4+var x: I64;
5+begin
6+ x := 1;
7+ Out.int(_);
8+end;
9+end BlankValue.

conform/run/AtExit.raz (history) modified +3 -3

@@ -26,9 +26,9 @@
2626 proc main*: INT;
2727 var i, full: I64;
2828 begin
29- Rt.atExit(first);
30- Rt.atExit(second);
31- Rt.atExit(third);
29+ _ := Rt.atExit(first);
30+ _ := Rt.atExit(second);
31+ _ := Rt.atExit(third);
3232 full := 0;
3333 for i := 1 to 40 do
3434 if Rt.atExit(nothing) = Rt.Full then INC(full); end;

conform/run/Blank.expect (history) added +1 -0

@@ -0,0 +1 @@
1+1 4 4

conform/run/Blank.raz (history) added +24 -0

@@ -0,0 +1,24 @@
1+module Blank;
2+import Out;
3+var calls: I64;
4+proc pair(a, b: I64): (I64, I64);
5+begin
6+ INC(calls);
7+ return a, b;
8+end;
9+proc count: I64;
10+begin
11+ INC(calls);
12+ return calls;
13+end;
14+proc main*;
15+var n, k: I64;
16+begin
17+ _ := count();
18+ n, _ := pair(1, 2);
19+ _, k := pair(3, 4);
20+ _, _ := pair(5, 6);
21+ _ := n + k;
22+ Out.int(n); Out.str(" "); Out.int(k); Out.str(" "); Out.int(calls); Out.ln;
23+end;
24+end Blank.

conform/run/FirstUse.raz (history) modified +2 -2

@@ -29,6 +29,6 @@
2929
3030 begin
3131 Table.init(ADR(names), Heap.heap);
32- Table.put(ADR(names), "rose", red);
33- Table.put(ADR(names), "sky", blue);
32+ _ := Table.put(ADR(names), "rose", red);
33+ _ := Table.put(ADR(names), "sky", blue);
3434 end FirstUse.

doc/book/PLAN.md added +106 -0

@@ -0,0 +1,106 @@
1+# Stage: the book "Compiling Raz"
2+
3+This is the owner's go-ahead for a new stage: a book, "Compiling Raz",
4+explaining how the raz compiler works. Follow CLAUDE.md's way of working:
5+one commit per step, push it, then stop for review. Don't change the
6+language or the compiler for the book's sake. If the book exposes a bug
7+or a clumsy spot, report it rather than fixing it.
8+
9+## Read first
10+- CLAUDE.md, doc/raz.md (the report), doc/compiler.md, README.md.
11+- src/*.pas, the whole compiler (about 5,000 lines), and enough of lib/
12+ (Rt, Heap, Mem, Thread, Sys) to explain the runtime.
13+- The tiza skill, for drawings.
14+
15+## The reader
16+A working programmer: not good at Pascal, little knowledge of compilers.
17+- Assume they roughly know registers, the stack and memory. Explain only
18+ what raz does with them (frames, calling convention, layout).
19+- Introduce compiler ideas (tokens, grammar, generating code while
20+ parsing, symbol tables) briefly and in friendly terms where they first
21+ appear.
22+- Teach just enough Pascal to read the compiler: one early chapter, then
23+ more as features come up. Teach enough raz the same way.
24+- Keep the two languages visibly apart: ```raz and ```pascal code blocks,
25+ and say which one is on screen.
26+- Don't explain formats that can be looked up. ELF gets a page on what
27+ raz writes and why, plus a pointer to the spec.
28+- Target 40-50k words.
29+
30+## Tone
31+Like Learn You a Haskell and Starting FORTH: tiny steps, talking straight
32+to the reader, every idea shown at once on a real example, drawings that
33+carry meaning. Warm, with an occasional dry aside. Never a joke per
34+paragraph; humor is seasoning. Plain, short sentences.
35+
36+## Mascot: Razmataz
37+A small, very serious creature with a flashy name, which suits a frugal
38+compiler (razzmatazz minus one z).
39+- Its motto, "once is enough", plays on "raz" meaning "one" or "once" in
40+ Polish and Russian. Check that the compiler really works in one pass
41+ before leaning on this; if it doesn't, find the honest version of the
42+ joke.
43+- Razmataz appears in tiza drawings: eating characters in the scanner,
44+ stacking boxes in frames, throwing unused code overboard in linking.
45+
46+## Structure
47+Build up gradually, not unit by unit:
48+1. Introduction and a whirlwind tour: compile `exit 42` (or the smallest
49+ real program) through every stage, shallowly.
50+2. Enough Pascal (and raz) to follow along.
51+3. One chapter per language feature, followed through scanner, parser,
52+ symbols, code generator and machine code: variables and expressions,
53+ control flow, procedures and frames, records and arrays, pointers and
54+ the heap, strings, modules, defer, C interop, threads.
55+4. Closing chapters: x64 encoding, link (tree shaking, layout), elf,
56+ speed (how it reaches 400k lines a second), and where to go next.
57+
58+Refine this order in the outline (step 1).
59+
60+## Format and tooling
61+- Markdown in doc/book/: NN-slug.md per chapter, plus metadata.yaml
62+ (title, author Luis, cover). It must read well as plain text.
63+- `make book` builds build/compiling-raz.epub with pandoc. If pandoc gets
64+ installed locally, update the desktop guide (see the global
65+ CLAUDE.md).
66+- Drawings: .tiza source and a rendered PNG, both committed (CI has no
67+ tiza). Every image has a caption that stands on its own in plain text.
68+ Use ASCII art in code blocks for diagrams that are really structure
69+ (frames, memory layout); those read the same in both formats.
70+- Disassembly is cleaned up: instructions only, the raz source line
71+ beside them as a comment, and bytes only where the bytes are the point.
72+ Show raw objdump output once, early, next to the cleaned version, and
73+ say how to get it.
74+- A checker, written in raz alongside tools/Doc.raz (reuse what exists),
75+ run by `make check`. It must:
76+ - compile and run every raz example marked as runnable and compare the
77+ expected output written in the book;
78+ - confirm every quoted Pascal excerpt still matches src/, quoted by
79+ unit and routine name, never by line number;
80+ - regenerate or verify the cleaned disassembly.
81+ The goal: when the compiler changes, `make check` fails rather than
82+ the book going quietly wrong.
83+- CI (.github/workflows/): on a push to main that touches doc/book/**,
84+ src/** or lib/**, build the epub and replace the file on a standing
85+ prerelease tagged `book` (gh release upload --clobber), so the owner
86+ has a fixed URL to open on an iPad. Tagged releases also attach that
87+ version's epub.
88+
89+## Steps (each one is a commit, then stop for review)
90+1. The outline: doc/book/OUTLINE.md, chapter by chapter, with what each
91+ one teaches, its running example, and the drawings planned.
92+2. The tooling: doc/book/ skeleton, `make book`, the checker in
93+ `make check`, the CI job. One placeholder chapter proves the pipeline
94+ end to end.
95+3. Razmataz's design sheet (tiza) and one sample chapter, the procedures
96+ and frames one, to set tone and depth.
97+4. Then one chapter per step, in order.
98+
99+doc/compiler.md stays as it is: the short guide for people changing the
100+compiler. The book can point to it but never replaces it.
101+
102+## Left to the tooling step
103+- How the checker marks runnable examples and quoted excerpts inside
104+ Markdown.
105+- Whether the cleaned disassembly comes from the compiler's own line
106+ information (`make gdb` suggests it has some) or from objdump.

doc/compiler.md (history) modified +14 -6

@@ -1,6 +1,6 @@
11 # Reading the raz compiler
22
3-The compiler is eleven files of Free Pascal, under 7,800 lines of code.
3+The compiler is eleven files of Free Pascal, under 7,900 lines of code.
44 This guide walks through them in the order they are best read: from the
55 characters of a source file to the bytes of an executable. It assumes
66 you know the language from `doc/raz.md`, and enough x86-64 to read a
@@ -9,13 +9,13 @@
99 | File | Lines | Code | What |
1010 |---|---|---|---|
1111 | `src/diag.pas` | 310 | 229 | Messages: positions, source excerpts, colour, counts |
12-| `src/scan.pas` | 884 | 745 | Symbols, literals, comments, positions |
12+| `src/scan.pas` | 886 | 747 | Symbols, literals, comments, positions |
1313 | `src/sym.pas` | 615 | 510 | Types, objects, scopes, layout |
1414 | `src/chunk.pas` | 276 | 217 | The compiled program: chunks, fixups, line notes |
1515 | `src/x64.pas` | 1,039 | 870 | The instruction encoder, jumps within a procedure, the assembler |
1616 | `src/gen.pas` | 1,332 | 1,039 | The stack machine, for x86-64: values, operations, checks, calls, frames |
1717 | `src/item.pas` | 1,342 | 1,118 | Items: types, constants, variables, operators, conversions, calls |
18-| `src/parse.pas` | 2,653 | 2,354 | Declarations, statements, expressions, built-ins, recovery, warnings |
18+| `src/parse.pas` | 2,712 | 2,407 | Declarations, statements, expressions, built-ins, recovery, warnings |
1919 | `src/link.pas` | 234 | 180 | Tree shaking, layout, patching, the places |
2020 | `src/elf.pas` | 435 | 352 | Static and dynamic ELF, symbol table, line numbers |
2121 | `src/raz.pas` | 197 | 147 | The command line |
@@ -418,7 +418,10 @@
418418 Then statements: `Statement` makes each one a recovery point (below)
419419 and `OneStatement` dispatches; `IfStatement`,
420420 `WhileStatement`, `ForStatement` and `MatchStatement` emit their jumps
421-with gen's labels. A `match` on an integer reads each arm's
421+with gen's labels. The blank is a symbol of its own, `sBlank`, so
422+no declaration or expression takes it: `_ := e` loads a single value
423+and drops it, and `MultiAssign` skips the results it stands for. A
424+`match` on an integer reads each arm's
422425 labels in `IntArm`, which refuses a value in two of them, and tests them
423426 one after another with `MatchRange`: compares and branches, no jump
424427 table. `Defer` is worth reading: a deferred statement
@@ -489,7 +492,10 @@
489492 reports what isn't exported, doesn't start with `_`, and was never
490493 used, or, for a variable, only assigned, and a procedure with results
491494 that may reach its end (`openEnd`, from `ends`, which each statement
492-sets). A generic module's instances
495+sets). The calls that drop results are a third list, `drops`, in
496+order: `CompileFile` notes where the module's own begin, since the
497+instances it makes along the way add theirs and take them back. A
498+generic module's instances
493499 share its text, so only the first is warned of.
494500
495501 The built-in procedures are in `Builtin` (and `New_`, `Atomic`): each
@@ -606,7 +612,9 @@
606612 it may reach its end without `return` (`ends`, `parse.pas`): each
607613 way through its statements must end in a `return`, an `if` with an
608614 `else`, a `match`, a `while true` or a `repeat ... until false`
609- with no `break`. `-Werror` makes each an error.
615+ with no `break`. So is a call standing on its own that drops a
616+ result (`drops`, kept by `OneStatement` and told by `Dropped`);
617+ `_ := f(x)` drops one on purpose. `-Werror` makes each an error.
610618 - **Several results** come back through a hidden pointer to the
611619 caller's slots; a code procedure returns two in rax and rdx.
612620 - **Reals.** A real constant is held as an F64. An `F32` in a register

examples/Printf.raz (history) modified +2 -2

@@ -9,8 +9,8 @@
99 for i := 1 to 3 do
1010 Out.str("raz says "); Out.int(i); Out.ln;
1111 Out.flush;
12- C.printf("C says %d, %s\n", I32(i * i), "squared");
13- C.fflush(C.stdout);
12+ _ := C.printf("C says %d, %s\n", I32(i * i), "squared");
13+ _ := C.fflush(C.stdout);
1414 end;
1515 end;
1616

examples/Pthreads.raz (history) modified +1 -1

@@ -42,7 +42,7 @@
4242 end;
4343 total := 0;
4444 for i := 0 to Workers - 1 do
45- C.pthread_join(t[i], nil);
45+ _ := C.pthread_join(t[i], nil);
4646 total := total + parts[i].sum;
4747 end;
4848 Out.str("total "); Out.int(total); Out.ln;

examples/Window.raz (history) modified +6 -6

@@ -52,18 +52,18 @@
5252 s := XDefaultScreen(d);
5353 w := XCreateSimpleWindow(d, XRootWindow(d, s), 0, 0, 320, 80, 1,
5454 XBlackPixel(d, s), XWhitePixel(d, s));
55- XStoreName(d, w, "raz");
56- XSelectInput(d, w, ExposureMask + KeyPressMask);
57- XMapWindow(d, w);
55+ _ := XStoreName(d, w, "raz");
56+ _ := XSelectInput(d, w, ExposureMask + KeyPressMask);
57+ _ := XMapWindow(d, w);
5858 repeat
59- XNextEvent(d, ^U8(ADR(ev)));
59+ _ := XNextEvent(d, ^U8(ADR(ev)));
6060 if I32(ev[0]) = Expose then
61- XDrawString(d, w, XDefaultGC(d, s), 20, 45, text, I32(LEN(text)));
61+ _ := XDrawString(d, w, XDefaultGC(d, s), 20, 45, text, I32(LEN(text)));
6262 end;
6363 until I32(ev[0]) = KeyPress;
6464 key := ^KeyEvent(ADR(ev));
6565 Out.str("key "); Out.int(INT(key^.keycode)); Out.ln;
66- XCloseDisplay(d);
66+ _ := XCloseDisplay(d);
6767 return 0;
6868 end;
6969

lib/Lock.raz (history) modified +1 -1

@@ -22,7 +22,7 @@
2222 (* Gives up l, which the caller holds. *)
2323 proc give*(l: ^Lock);
2424 begin
25- XCHG(ADR(l^.held), 0);
25+ _ := XCHG(ADR(l^.held), 0);
2626 end;
2727
2828 (* The module's test, in one thread: taken, given, taken again. *)

lib/Out.raz (history) modified +1 -1

@@ -101,5 +101,5 @@
101101
102102 begin
103103 tty := Sys.isTerminal(Sys.stdout);
104- Rt.atExit(flush);
104+ _ := Rt.atExit(flush);
105105 end Out.

lib/Rt.raz (history) modified +12 -12

@@ -107,8 +107,8 @@
107107 with status 2, as a failed check does. *)
108108 proc stop*(msg: []U8);
109109 begin
110- Sys.write(Sys.stderr, msg);
111- Sys.write(Sys.stderr, "\n");
110+ _ := Sys.write(Sys.stderr, msg);
111+ _ := Sys.write(Sys.stderr, "\n");
112112 exit(2);
113113 end;
114114
@@ -152,7 +152,7 @@
152152 proc say;
153153 begin
154154 line[lineLen] := '\n';
155- Sys.write(Sys.stderr, line[0..lineLen + 1]);
155+ _ := Sys.write(Sys.stderr, line[0..lineLen + 1]);
156156 lineLen := 0;
157157 end;
158158
@@ -330,7 +330,7 @@
330330 ip := q[1] - 1; (* the call, by its return address *)
331331 bp := q[0];
332332 end;
333- more(same);
333+ _ := more(same);
334334 end;
335335
336336 (* Says on standard error the calls under way, from the one that calls
@@ -365,8 +365,8 @@
365365 say;
366366 calls(at, callerFrame(), true);
367367 act := {}; (* the signal's default action *)
368- SYSCALL(13, sig, ADR(act), 0, 8); (* rt_sigaction *)
369- SYSCALL(62, SYSCALL(39), sig); (* kill(getpid(), sig) *)
368+ _ := SYSCALL(13, sig, ADR(act), 0, 8); (* rt_sigaction *)
369+ _ := SYSCALL(62, SYSCALL(39), sig); (* kill(getpid(), sig) *)
370370 end;
371371 if what = 0 then
372372 put("index ");
@@ -485,7 +485,7 @@
485485 var t: [4]INT; i, n, k: INT; p: ^Proc;
486486 begin
487487 t := [0, 0, 0, 0];
488- SYSCALL(38, 2, ADR(t), 0); (* setitimer(ITIMER_PROF): no more *)
488+ _ := SYSCALL(38, 2, ADR(t), 0); (* setitimer(ITIMER_PROF): no more *)
489489 profiling := false;
490490 n := numSamples;
491491 if n > MaxSamples then n := MaxSamples; end;
@@ -511,15 +511,15 @@
511511
512512 begin
513513 alt := {sp: ADR(altStack[0]), size: LEN(altStack)};
514- SYSCALL(131, ADR(alt), 0); (* sigaltstack *)
514+ _ := SYSCALL(131, ADR(alt), 0); (* sigaltstack *)
515515 act := {handler: onSignal, flags: Flags, restorer: sigReturn};
516- SYSCALL(13, SigSegv, ADR(act), 0, 8); (* rt_sigaction *)
517- SYSCALL(13, SigFpe, ADR(act), 0, 8);
516+ _ := SYSCALL(13, SigSegv, ADR(act), 0, 8); (* rt_sigaction *)
517+ _ := SYSCALL(13, SigFpe, ADR(act), 0, 8);
518518 if LEN(Sys.env("RAZ_PROFILE")) > 0 then
519519 act := {handler: onProf, flags: ProfFlags, restorer: sigReturn};
520- SYSCALL(13, SigProf, ADR(act), 0, 8);
520+ _ := SYSCALL(13, SigProf, ADR(act), 0, 8);
521521 timerv := [0, 1000, 0, 1000]; (* every millisecond, from one on *)
522- SYSCALL(38, 2, ADR(timerv), 0); (* setitimer(ITIMER_PROF) *)
522+ _ := SYSCALL(38, 2, ADR(timerv), 0); (* setitimer(ITIMER_PROF) *)
523523 profiling := true;
524524 end;
525525 end Rt.

lib/Sys.linux-x86_64.raz (history) modified +37 -37

@@ -156,7 +156,7 @@
156156 (* Closes the file descriptor fd. *)
157157 proc close*(fd: INT);
158158 begin
159- SYSCALL(3, fd);
159+ _ := SYSCALL(3, fd);
160160 end;
161161
162162 (* size bytes of fresh, zeroed memory from the system, a multiple of
@@ -172,7 +172,7 @@
172172 (* Gives back to the system the size bytes at p that mmap gave. *)
173173 proc munmap*(p: ^U8; size: INT);
174174 begin
175- SYSCALL(11, p, size);
175+ _ := SYSCALL(11, p, size);
176176 end;
177177
178178 (* Whether the file descriptor fd is a terminal: whether it has a
@@ -302,7 +302,7 @@
302302 (* Closes the directory d that openDir opened. *)
303303 proc closeDir*(d: ^Dir);
304304 begin
305- SYSCALL(3, d^.fd);
305+ _ := SYSCALL(3, d^.fd);
306306 end;
307307
308308 (* Puts the terminal on fd into raw mode: no echo, no lines, no signals,
@@ -325,7 +325,7 @@
325325 (* The terminal on fd as rawMode found it. *)
326326 proc restoreMode*(fd: INT);
327327 begin
328- SYSCALL(16, fd, 5402H, ADR(saved));
328+ _ := SYSCALL(16, fd, 5402H, ADR(saved));
329329 end;
330330
331331 (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't
@@ -353,7 +353,7 @@
353353 proc clock*: I64;
354354 var t: Timespec;
355355 begin
356- SYSCALL(228, 1, ADR(t)); (* clock_gettime: CLOCK_MONOTONIC *)
356+ _ := SYSCALL(228, 1, ADR(t)); (* clock_gettime: CLOCK_MONOTONIC *)
357357 return t.sec * 1000000000 + t.nsec;
358358 end;
359359
@@ -361,7 +361,7 @@
361361 proc now*: I64;
362362 var t: Timespec;
363363 begin
364- SYSCALL(228, 0, ADR(t)); (* clock_gettime: CLOCK_REALTIME *)
364+ _ := SYSCALL(228, 0, ADR(t)); (* clock_gettime: CLOCK_REALTIME *)
365365 return t.sec * 1000000000 + t.nsec;
366366 end;
367367
@@ -396,7 +396,7 @@
396396 if fd < 0 then return fd; end;
397397 if serving then
398398 one := 1; (* so that a server can start again at once *)
399- SYSCALL(54, fd, 1, 2, ADR(one), 4); (* setsockopt: SOL_SOCKET, SO_REUSEADDR *)
399+ _ := SYSCALL(54, fd, 1, 2, ADR(one), 4); (* setsockopt: SOL_SOCKET, SO_REUSEADDR *)
400400 r := SYSCALL(49, fd, a, size); (* bind *)
401401 if r = 0 then r := SYSCALL(50, fd, 4096); end; (* listen *)
402402 else
@@ -664,7 +664,7 @@
664664 proc openPty*: INT;
665665 var a: [4096]U8; fd, unlock: INT;
666666 begin
667- cstr("/dev/ptmx", a);
667+ _ := cstr("/dev/ptmx", a);
668668 fd := SYSCALL(2, ADR(a), 80102H); (* open: O_RDWR, O_NOCTTY, O_CLOEXEC *)
669669 if fd < 0 then return fd; end;
670670 unlock := 0;
@@ -803,38 +803,38 @@
803803 end;
804804 if argv = nil then return -12; end; (* ENOMEM *)
805805 all := 0FFFFFFFFFFFFFFFFH;
806- SYSCALL(14, 2, ADR(all), ADR(old), 8); (* rt_sigprocmask: SIG_SETMASK *)
806+ _ := SYSCALL(14, 2, ADR(all), ADR(old), 8); (* rt_sigprocmask: SIG_SETMASK *)
807807 pid := SYSCALL(57); (* fork *)
808808 if pid = 0 then
809809 if p.tty # 0 then
810- SYSCALL(112); (* setsid *)
810+ _ := SYSCALL(112); (* setsid *)
811811 fd := SYSCALL(2, ADR(name), 2); (* open, O_RDWR *)
812- if (fd < 0) or (SYSCALL(16, fd, 540EH, 0) # 0) then SYSCALL(231, 127); end; (* TIOCSCTTY; exit *)
813- for i := 0 to 2 do SYSCALL(33, fd, i); end; (* dup2 *)
812+ if (fd < 0) or (SYSCALL(16, fd, 540EH, 0) # 0) then _ := SYSCALL(231, 127); end; (* TIOCSCTTY; exit *)
813+ for i := 0 to 2 do _ := SYSCALL(33, fd, i); end; (* dup2 *)
814814 else
815- if p.group = -1 then SYSCALL(109, 0, 0); (* setpgid *)
816- elsif p.group # 0 then SYSCALL(109, 0, p.group);
815+ if p.group = -1 then _ := SYSCALL(109, 0, 0); (* setpgid *)
816+ elsif p.group # 0 then _ := SYSCALL(109, 0, p.group);
817817 end;
818- if p.foreground then foreground(0, SYSCALL(111)); end; (* getpgrp *)
818+ if p.foreground then _ := foreground(0, SYSCALL(111)); end; (* getpgrp *)
819819 for i := 0 to 2 do
820- if p.fds[i] # 0 then SYSCALL(33, p.fds[i], i); end; (* dup2 *)
820+ if p.fds[i] # 0 then _ := SYSCALL(33, p.fds[i], i); end; (* dup2 *)
821821 end;
822822 end;
823- if (LEN(p.dir) > 0) and (SYSCALL(80, ADR(dir)) # 0) then SYSCALL(231, 127); end; (* chdir *)
824- SYSCALL(436, 3, 0FFFFFFFFH, 0); (* close_range: every fd from 3 *)
825- for i := 1 to 64 do SYSCALL(13, i, ADR(dfl), 0, 8); end; (* rt_sigaction *)
826- SYSCALL(14, 2, ADR(empty), 0, 8); (* no signal blocked *)
827- SYSCALL(59, ADR(a), argv, argv + (LEN(p.args) + 1)); (* execve *)
828- SYSCALL(231, 127); (* exit *)
823+ if (LEN(p.dir) > 0) and (SYSCALL(80, ADR(dir)) # 0) then _ := SYSCALL(231, 127); end; (* chdir *)
824+ _ := SYSCALL(436, 3, 0FFFFFFFFH, 0); (* close_range: every fd from 3 *)
825+ for i := 1 to 64 do _ := SYSCALL(13, i, ADR(dfl), 0, 8); end; (* rt_sigaction *)
826+ _ := SYSCALL(14, 2, ADR(empty), 0, 8); (* no signal blocked *)
827+ _ := SYSCALL(59, ADR(a), argv, argv + (LEN(p.args) + 1)); (* execve *)
828+ _ := SYSCALL(231, 127); (* exit *)
829829 end;
830830 if (pid > 0) and (p.tty = 0) then
831831 (* as the program does, for whichever of the two runs first *)
832832 g := p.group;
833833 if g = -1 then g := pid; elsif g = 0 then g := SYSCALL(111); end;
834- if p.group # 0 then SYSCALL(109, pid, g); end;
835- if p.foreground then foreground(0, g); end;
834+ if p.group # 0 then _ := SYSCALL(109, pid, g); end;
835+ if p.foreground then _ := foreground(0, g); end;
836836 end;
837- SYSCALL(14, 2, ADR(old), 0, 8);
837+ _ := SYSCALL(14, 2, ADR(old), 0, 8);
838838 munmap(^U8(argv), size);
839839 return pid;
840840 end;
@@ -879,7 +879,7 @@
879879 end;
880880 fd := -1;
881881 if caughtSigs # 0 then fd := sigFd; end;
882- SYSCALL(14, 0, ADR(m), 0, 8); (* rt_sigprocmask: SIG_BLOCK *)
882+ _ := SYSCALL(14, 0, ADR(m), 0, 8); (* rt_sigprocmask: SIG_BLOCK *)
883883 fd := SYSCALL(289, fd, ADR(m), 8, 80800H); (* signalfd4: SFD_NONBLOCK, SFD_CLOEXEC *)
884884 if fd < 0 then return fd; end;
885885 caughtSigs := m;
@@ -907,13 +907,13 @@
907907 (* Gives the processor to another thread. *)
908908 proc yield*;
909909 begin
910- SYSCALL(24);
910+ _ := SYSCALL(24);
911911 end;
912912
913913 (* Ends the program, at once, with status. *)
914914 proc exit*(status: INT);
915915 begin
916- SYSCALL(231, status);
916+ _ := SYSCALL(231, status);
917917 end;
918918
919919 (* The test of programs: one on a pseudo-terminal of 100 by 30 prints
@@ -1063,9 +1063,9 @@
10631063 if (p = nil) or (p[99] # 0) then exit(2); end;
10641064 munmap(p, 100);
10651065 (* files and directories *)
1066- remove("/tmp/raz-sys-dir/f");
1067- remove("/tmp/raz-sys-dir/g");
1068- makeDir("/tmp/raz-sys-dir");
1066+ _ := remove("/tmp/raz-sys-dir/f");
1067+ _ := remove("/tmp/raz-sys-dir/g");
1068+ _ := makeDir("/tmp/raz-sys-dir");
10691069 fd := create("/tmp/raz-sys-dir/f");
10701070 if (fd < 0) or (write(fd, "abc") # 3) then exit(2); end;
10711071 close(fd);
@@ -1076,7 +1076,7 @@
10761076 if (err # 0) or not i.dir or i.file then exit(2); end;
10771077 i, err := info("/dev/null");
10781078 if (err # 0) or i.dir or i.file then exit(2); end;
1079- remove("/tmp/raz-sys-link");
1079+ _ := remove("/tmp/raz-sys-link");
10801080 if symlink("/tmp/raz-sys-dir", "/tmp/raz-sys-link") # 0 then exit(2); end;
10811081 i, err := info("/tmp/raz-sys-link");
10821082 if (err # 0) or not i.dir or not i.symlink then exit(2); end;
@@ -1084,9 +1084,9 @@
10841084 if (err # 0) or (name # "/tmp/raz-sys-dir") then exit(2); end;
10851085 name, err := readLink("/tmp/raz-sys-dir");
10861086 if err # -22 then exit(2); end; (* EINVAL: not a link *)
1087- remove("/tmp/raz-sys-link");
1087+ _ := remove("/tmp/raz-sys-link");
10881088 (* open as asked, seek, the mode and the time *)
1089- remove("/tmp/raz-sys-dir/h");
1089+ _ := remove("/tmp/raz-sys-dir/h");
10901090 fd := open("/tmp/raz-sys-dir/h", {writing, creating, exclusive});
10911091 if (fd < 0) or (write(fd, "abc") # 3) then exit(2); end;
10921092 close(fd);
@@ -1104,7 +1104,7 @@
11041104 if chmod("/tmp/raz-sys-dir/h", 1EDH) # 0 then exit(2); end;
11051105 i, err := info("/tmp/raz-sys-dir/h");
11061106 if i.mode # 1EDH then exit(2); end;
1107- remove("/tmp/raz-sys-dir/h");
1107+ _ := remove("/tmp/raz-sys-dir/h");
11081108 i, err := info("/no/such/file");
11091109 if err >= 0 then exit(2); end;
11101110 if openDir(ADR(d), "/tmp/raz-sys-dir") # 0 then exit(2); end;
@@ -1128,7 +1128,7 @@
11281128 (* a socket: nothing at a path, then a listener that a connection
11291129 makes ready, and a byte from it to the connection *)
11301130 if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *)
1131- remove("/tmp/raz-sys-socket");
1131+ _ := remove("/tmp/raz-sys-socket");
11321132 l := listen("/tmp/raz-sys-socket");
11331133 if (l < 0) or (listen("/tmp/raz-sys-socket") # -98) then exit(2); end; (* EADDRINUSE: there already *)
11341134 c := connect("/tmp/raz-sys-socket");
@@ -1143,7 +1143,7 @@
11431143 if send(c, "x") # -32 then exit(2); end; (* EPIPE, and no SIGPIPE *)
11441144 close(c);
11451145 close(l);
1146- remove("/tmp/raz-sys-socket");
1146+ _ := remove("/tmp/raz-sys-socket");
11471147 testPrograms;
11481148 testNet;
11491149 end;

lib/Sys.raz (history) modified +33 -33

@@ -189,7 +189,7 @@
189189 (* Closes the file descriptor fd. *)
190190 proc close*(fd: INT);
191191 begin
192- C.close(I32(fd));
192+ _ := C.close(I32(fd));
193193 end;
194194
195195 (* size bytes of fresh, zeroed memory from the system, a multiple of
@@ -205,7 +205,7 @@
205205 (* Gives back to the system the size bytes at p that mmap gave. *)
206206 proc munmap*(p: ^U8; size: INT);
207207 begin
208- C.munmap(p, UINT(size));
208+ _ := C.munmap(p, UINT(size));
209209 end;
210210
211211 (* Renames old to new, replacing what new names: 0, or minus an errno. *)
@@ -321,7 +321,7 @@
321321 (* Closes the directory d that openDir opened. *)
322322 proc closeDir*(d: ^Dir);
323323 begin
324- C.closedir(d^.d);
324+ _ := C.closedir(d^.d);
325325 end;
326326
327327 (* Puts the terminal on fd into raw mode, as cfmakeraw makes it: no
@@ -339,7 +339,7 @@
339339 (* The terminal on fd as rawMode found it. *)
340340 proc restoreMode*(fd: INT);
341341 begin
342- C.tcsetattr(I32(fd), 0, ADR(saved[0]));
342+ _ := C.tcsetattr(I32(fd), 0, ADR(saved[0]));
343343 end;
344344
345345 (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't
@@ -367,7 +367,7 @@
367367 proc time(clock: I32): I64;
368368 var t: Timespec;
369369 begin
370- C.clock_gettime(clock, ^U8(ADR(t)));
370+ _ := C.clock_gettime(clock, ^U8(ADR(t)));
371371 return t.sec * 1000000000 + t.nsec;
372372 end;
373373
@@ -415,7 +415,7 @@
415415 if fd < 0 then return failed(); end;
416416 if serving then
417417 one := 1; (* so that a server can start again at once *)
418- C.setsockopt(fd, 1, 2, ^U8(ADR(one)), 4); (* SOL_SOCKET, SO_REUSEADDR *)
418+ _ := C.setsockopt(fd, 1, 2, ^U8(ADR(one)), 4); (* SOL_SOCKET, SO_REUSEADDR *)
419419 r := C.bind(fd, a, U32(size));
420420 if r = 0 then r := C.listen(fd, 4096); end;
421421 else
@@ -423,7 +423,7 @@
423423 end;
424424 if r # 0 then
425425 err := failed(); (* before close can change errno *)
426- C.close(fd);
426+ _ := C.close(fd);
427427 return err;
428428 end;
429429 return INT(fd);
@@ -614,7 +614,7 @@
614614 if fd < 0 then return failed(); end;
615615 if (C.grantpt(fd) # 0) or (C.unlockpt(fd) # 0) then
616616 err := failed();
617- C.close(fd);
617+ _ := C.close(fd);
618618 return err;
619619 end;
620620 return INT(fd);
@@ -745,28 +745,28 @@
745745 end;
746746 if argv = nil then return -12; end; (* ENOMEM *)
747747 for i := 0 to LEN(all) - 1 do all[i] := 0FFFFFFFFFFFFFFFFH; end;
748- C.sigprocmask(2, ^U8(ADR(all)), ^U8(ADR(old))); (* SIG_SETMASK *)
748+ _ := C.sigprocmask(2, ^U8(ADR(all)), ^U8(ADR(old))); (* SIG_SETMASK *)
749749 pid := C.fork();
750750 if pid = 0 then
751751 if p.tty # 0 then
752- C.setsid();
752+ _ := C.setsid();
753753 fd := C.open(ADR(name[0]), 2); (* O_RDWR *)
754754 if (fd < 0) or (C.ioctl(fd, TIOCSCTTY, 0) # 0) then C._exit(127); end;
755- for i := 0 to 2 do C.dup2(fd, I32(i)); end;
755+ for i := 0 to 2 do _ := C.dup2(fd, I32(i)); end;
756756 else
757- if p.group = -1 then C.setpgid(0, 0);
758- elsif p.group # 0 then C.setpgid(0, I32(p.group));
757+ if p.group = -1 then _ := C.setpgid(0, 0);
758+ elsif p.group # 0 then _ := C.setpgid(0, I32(p.group));
759759 end;
760- if p.foreground then C.tcsetpgrp(0, C.getpgrp()); end;
760+ if p.foreground then _ := C.tcsetpgrp(0, C.getpgrp()); end;
761761 for i := 0 to 2 do
762- if p.fds[i] # 0 then C.dup2(I32(p.fds[i]), I32(i)); end;
762+ if p.fds[i] # 0 then _ := C.dup2(I32(p.fds[i]), I32(i)); end;
763763 end;
764764 end;
765765 if (LEN(p.dir) > 0) and (C.chdir(ADR(dir[0])) # 0) then C._exit(127); end;
766- C.close_range(3, 0FFFFFFFFH, 0); (* every fd from 3 *)
767- for i := 1 to 64 do C.sigaction(I32(i), ^U8(ADR(dfl)), nil); end;
768- C.sigprocmask(2, ^U8(ADR(empty)), nil);
769- C.execve(ADR(a[0]), argv, argv + (LEN(p.args) + 1));
766+ _ := C.close_range(3, 0FFFFFFFFH, 0); (* every fd from 3 *)
767+ for i := 1 to 64 do _ := C.sigaction(I32(i), ^U8(ADR(dfl)), nil); end;
768+ _ := C.sigprocmask(2, ^U8(ADR(empty)), nil);
769+ _ := C.execve(ADR(a[0]), argv, argv + (LEN(p.args) + 1));
770770 C._exit(127);
771771 end;
772772 err := failed();
@@ -774,10 +774,10 @@
774774 (* as the program does, for whichever of the two runs first *)
775775 g := p.group;
776776 if g = -1 then g := INT(pid); elsif g = 0 then g := INT(C.getpgrp()); end;
777- if p.group # 0 then C.setpgid(pid, I32(g)); end;
778- if p.foreground then C.tcsetpgrp(0, I32(g)); end;
777+ if p.group # 0 then _ := C.setpgid(pid, I32(g)); end;
778+ if p.foreground then _ := C.tcsetpgrp(0, I32(g)); end;
779779 end;
780- C.sigprocmask(2, ^U8(ADR(old)), nil);
780+ _ := C.sigprocmask(2, ^U8(ADR(old)), nil);
781781 munmap(^U8(argv), size);
782782 if pid < 0 then return err; end;
783783 return INT(pid);
@@ -818,7 +818,7 @@
818818 e := C.__errno_location();
819819 saved := e^; (* as the code it stopped left it *)
820820 b[0] := U8(sig);
821- C.write(sigWrite, ADR(b[0]), 1);
821+ _ := C.write(sigWrite, ADR(b[0]), 1);
822822 e^ := saved;
823823 end;
824824
@@ -873,7 +873,7 @@
873873 (* Gives the processor to another thread. *)
874874 proc yield*;
875875 begin
876- C.sched_yield();
876+ _ := C.sched_yield();
877877 end;
878878
879879 (* Ends the program, at once, with status. *)
@@ -1029,9 +1029,9 @@
10291029 if (p = nil) or (p[99] # 0) then exit(2); end;
10301030 munmap(p, 100);
10311031 (* files and directories *)
1032- remove("/tmp/raz-sys-dir/f");
1033- remove("/tmp/raz-sys-dir/g");
1034- makeDir("/tmp/raz-sys-dir");
1032+ _ := remove("/tmp/raz-sys-dir/f");
1033+ _ := remove("/tmp/raz-sys-dir/g");
1034+ _ := makeDir("/tmp/raz-sys-dir");
10351035 fd := create("/tmp/raz-sys-dir/f");
10361036 if (fd < 0) or (write(fd, "abc") # 3) then exit(2); end;
10371037 close(fd);
@@ -1042,7 +1042,7 @@
10421042 if (err # 0) or not i.dir or i.file then exit(2); end;
10431043 i, err := info("/dev/null");
10441044 if (err # 0) or i.dir or i.file then exit(2); end;
1045- remove("/tmp/raz-sys-link");
1045+ _ := remove("/tmp/raz-sys-link");
10461046 if symlink("/tmp/raz-sys-dir", "/tmp/raz-sys-link") # 0 then exit(2); end;
10471047 i, err := info("/tmp/raz-sys-link");
10481048 if (err # 0) or not i.dir or not i.symlink then exit(2); end;
@@ -1050,9 +1050,9 @@
10501050 if (err # 0) or (name # "/tmp/raz-sys-dir") then exit(2); end;
10511051 name, err := readLink("/tmp/raz-sys-dir");
10521052 if err # -22 then exit(2); end; (* EINVAL: not a link *)
1053- remove("/tmp/raz-sys-link");
1053+ _ := remove("/tmp/raz-sys-link");
10541054 (* open as asked, seek, the mode and the time *)
1055- remove("/tmp/raz-sys-dir/h");
1055+ _ := remove("/tmp/raz-sys-dir/h");
10561056 fd := open("/tmp/raz-sys-dir/h", {writing, creating, exclusive});
10571057 if (fd < 0) or (write(fd, "abc") # 3) then exit(2); end;
10581058 close(fd);
@@ -1070,7 +1070,7 @@
10701070 if chmod("/tmp/raz-sys-dir/h", 1EDH) # 0 then exit(2); end;
10711071 i, err := info("/tmp/raz-sys-dir/h");
10721072 if i.mode # 1EDH then exit(2); end;
1073- remove("/tmp/raz-sys-dir/h");
1073+ _ := remove("/tmp/raz-sys-dir/h");
10741074 i, err := info("/no/such/file");
10751075 if err >= 0 then exit(2); end;
10761076 if openDir(ADR(d), "/tmp/raz-sys-dir") # 0 then exit(2); end;
@@ -1094,7 +1094,7 @@
10941094 (* a socket: nothing at a path, then a listener that a connection
10951095 makes ready, and a byte from it to the connection *)
10961096 if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *)
1097- remove("/tmp/raz-sys-socket");
1097+ _ := remove("/tmp/raz-sys-socket");
10981098 l := listen("/tmp/raz-sys-socket");
10991099 if (l < 0) or (listen("/tmp/raz-sys-socket") # -98) then exit(2); end; (* EADDRINUSE: there already *)
11001100 c := connect("/tmp/raz-sys-socket");
@@ -1109,7 +1109,7 @@
11091109 if send(c, "x") # -32 then exit(2); end; (* EPIPE, and no SIGPIPE *)
11101110 close(c);
11111111 close(l);
1112- remove("/tmp/raz-sys-socket");
1112+ _ := remove("/tmp/raz-sys-socket");
11131113 testPrograms;
11141114 testNet;
11151115 end;

lib/Thread.linux-x86_64.raz (history) modified +5 -5

@@ -76,7 +76,7 @@
7676 begin
7777 t := ^Thread(arg);
7878 alt := {sp: ^U8(t) - Alt, size: Alt};
79- SYSCALL(131, ADR(alt), 0); (* sigaltstack *)
79+ _ := SYSCALL(131, ADR(alt), 0); (* sigaltstack *)
8080 t^.fn(t^.arg);
8181 end;
8282
@@ -114,7 +114,7 @@
114114 tid := ADR(t^.tid);
115115 v := tid^;
116116 while v # 0 do
117- futex(ADR(t^.tid), FutexWait, v);
117+ _ := futex(ADR(t^.tid), FutexWait, v);
118118 v := tid^;
119119 end;
120120 base := t^.base;
@@ -129,7 +129,7 @@
129129 if CAS(ADR(m^.state), 0, 1) then return; end;
130130 c := XCHG(ADR(m^.state), 2);
131131 while c # 0 do
132- futex(ADR(m^.state), FutexWait + Private, 2);
132+ _ := futex(ADR(m^.state), FutexWait + Private, 2);
133133 c := XCHG(ADR(m^.state), 2);
134134 end;
135135 end;
@@ -139,8 +139,8 @@
139139 proc unlock*(m: ^Mutex);
140140 begin
141141 if XADD(ADR(m^.state), -1) # 1 then
142- XCHG(ADR(m^.state), 0);
143- futex(ADR(m^.state), FutexWake + Private, 1);
142+ _ := XCHG(ADR(m^.state), 0);
143+ _ := futex(ADR(m^.state), FutexWake + Private, 1);
144144 end;
145145 end;
146146

src/parse.pas modified +79 -20

@@ -91,6 +91,12 @@
9191 stray: boolean; { an "end" in this procedure stood left of its statement's line }
9292 strayAt: TPos; { ... the first such statement }
9393 elseIf: boolean; { an "else if" in this procedure }
94+ drops: array[0..4095] of record
95+ at: TPos; { a call standing on its own that drops results }
96+ n: longint; { ... how many }
97+ end;
98+ numDrops: longint; { the module being compiled has those from its
99+ first one, saved by CompileFile, to here }
94100 ends: boolean; { the statements just read never go on past
95101 their end: each way through them returns }
96102 useAt: TPos; { ... which is here }
@@ -105,6 +111,7 @@
105111 { A missing symbol is reported just after the one before it. }
106112 procedure Expected(const what: shortstring);
107113 begin
114+ if tok = sBlank then Mark('_ isn''t a name: it is the blank, which stands only left of :=');
108115 MarkAt(MissingPos, 'expected ' + what + ', found ' + Found);
109116 end;
110117
@@ -1497,22 +1504,31 @@
14971504
14981505 { a, b := f(x): the variables first, left to right, then the call;
14991506 then each result to its variable, in order. }
1500-procedure MultiAssign(var x: TItem; first: longint);
1501-var d: array[0..15] of TItem; dn: array[0..15] of longint; y, z: TItem; n, i: longint; called: boolean; f: PObj;
1507+procedure MultiAssign(var x: TItem; first: longint; blank: boolean);
1508+var
1509+ d: array[0..15] of TItem; dn: array[0..15] of longint; blanks: array[0..15] of boolean;
1510+ y, z: TItem; n, i: longint; called: boolean; f: PObj;
15021511 begin
15031512 n := 0;
15041513 d[0] := x;
15051514 dn[0] := first;
1515+ blanks[0] := blank;
15061516 repeat
1507- NotReadOnly(d[n]);
1508- Assignable(d[n], dn[n]);
1509- Pin(d[n]);
1517+ if not blanks[n] then begin
1518+ NotReadOnly(d[n]);
1519+ Assignable(d[n], dn[n]);
1520+ Pin(d[n]);
1521+ end;
15101522 inc(n);
15111523 if tok <> sComma then break;
15121524 if n > High(d) then Mark('more than ' + IntStr(High(d) + 1) + ' variables in one assignment');
15131525 Next;
1514- dn[n] := id;
1515- LeftSide(d[n], called);
1526+ blanks[n] := tok = sBlank;
1527+ if blanks[n] then Next
1528+ else begin
1529+ dn[n] := id;
1530+ LeftSide(d[n], called);
1531+ end;
15161532 until false;
15171533 Expect(sBecomes);
15181534 Designator(y, called);
@@ -1520,10 +1536,12 @@
15201536 MarkAt(y.pos, 'expected a call with ' + IntStr(n) + ' results');
15211537 f := y.typ^.fields;
15221538 for i := 0 to n - 1 do begin
1523- z := y;
1524- Field(z, f);
1525- CoerceExact(z, d[i].typ, 'several results go to variables of just their types');
1526- Assign(d[i], z);
1539+ if not blanks[i] then begin
1540+ z := y;
1541+ Field(z, f);
1542+ CoerceExact(z, d[i].typ, 'several results go to variables of just their types');
1543+ Assign(d[i], z);
1544+ end;
15271545 f := f^.next;
15281546 end;
15291547 end;
@@ -1589,7 +1607,7 @@
15891607 Expression(y, x.typ);
15901608 Assign(x, y);
15911609 end else if tok = sComma then
1592- MultiAssign(x, first)
1610+ MultiAssign(x, first, false)
15931611 else if not called then begin
15941612 if (x.mode = mProc) or ((x.mode in [mVar, mStack]) and (x.typ^.form = fProc)) then begin
15951613 BeginCall(c, x);
@@ -1598,7 +1616,27 @@
15981616 end else if tok = sEql then
15991617 MarkHelp(x.pos, Subject(x, first) + ' isn''t a statement', 'assignment is written :=')
16001618 else MarkAt(x.pos, Subject(x, first) + ' isn''t a statement');
1601- end else Discard(x);
1619+ end else begin
1620+ if (x.mode <> mNone) and (numDrops <= High(drops)) then begin
1621+ drops[numDrops].at := x.pos;
1622+ if x.typ^.tuple then drops[numDrops].n := x.typ^.len else drops[numDrops].n := 1;
1623+ inc(numDrops);
1624+ end;
1625+ Discard(x);
1626+ end;
1627+ end;
1628+ sBlank: begin
1629+ Next;
1630+ if tok = sComma then MultiAssign(x, 0, true)
1631+ else begin
1632+ Expect(sBecomes);
1633+ Expression(x, nil);
1634+ { evaluated and dropped: a single value is loaded, so that a
1635+ volatile one is read }
1636+ if (x.mode in [mType, mBuiltin, mNone, mCase]) or (x.mode <> mStr) and not IsAggregate(x.typ) then
1637+ Value(x);
1638+ Discard(x);
1639+ end;
16021640 end;
16031641 sIf: IfStatement(start, Indent);
16041642 sWhile: WhileStatement(start, Indent);
@@ -2225,19 +2263,38 @@
22252263 Help('if it must be there, call it _' + NameOf(o^.name));
22262264 end;
22272265
2266+{ Warns of the call at p, which drops its n results }
2267+procedure Dropped(const p: TPos; n: longint);
2268+var s, blanks: shortstring; i: longint;
2269+begin
2270+ s := Source(p);
2271+ i := Pos('(', s);
2272+ if i > 0 then s := copy(s, 1, i - 1);
2273+ blanks := '_';
2274+ for i := 2 to n do blanks := blanks + ', _';
2275+ if n = 1 then Warning(p, 'the result of ' + s + ' is dropped')
2276+ else Warning(p, 'the results of ' + s + ' are dropped');
2277+ Help('if that is meant, write ' + blanks + ' := ' + s + '(...)');
2278+end;
2279+
22282280 { The warnings of module m, by where each declaration is: its own
2229- declarations and its procedures' are two lists, each in order. The
2281+ declarations and its procedures' are two lists, each in order, and
2282+ firstDrop on are the calls that drop results. The
22302283 instances of a generic module share its text, and so its warnings:
22312284 only the first is warned of. }
2232-procedure Warnings(m: PModule);
2233-var a, b: PObj; n: PModule;
2285+procedure Warnings(m: PModule; firstDrop: longint);
2286+var a, b: PObj; n: PModule; i: longint;
22342287 begin
22352288 n := firstModule;
22362289 while (n <> nil) and (n^.name <> m^.name) do n := n^.next;
22372290 if n <> nil then exit;
22382291 a := m^.first; b := m^.locals;
2239- while (a <> nil) or (b <> nil) do
2240- if (b = nil) or (a <> nil) and (a^.pos.a < b^.pos.a) then begin
2292+ i := firstDrop;
2293+ while (a <> nil) or (b <> nil) or (i < numDrops) do
2294+ if (i < numDrops) and ((a = nil) or (drops[i].at.a < a^.pos.a)) and ((b = nil) or (drops[i].at.a < b^.pos.a)) then begin
2295+ Dropped(drops[i].at, drops[i].n);
2296+ inc(i);
2297+ end else if (b = nil) or (a <> nil) and (a^.pos.a < b^.pos.a) then begin
22412298 Warn(a);
22422299 a := a^.link;
22432300 end else begin
@@ -2268,8 +2325,9 @@
22682325 st: TScanState; saved: array[0..MaxDepth - 1] of longint; d: longint;
22692326 oldMod: PModule; oldCheck, oldChecks: boolean; m: PModule;
22702327 lib: PLib; start: TPos; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs;
2271- generic: boolean; argsAt: TScanState; why: shortstring;
2328+ generic: boolean; argsAt: TScanState; why: shortstring; firstDrop: longint;
22722329 begin
2330+ firstDrop := numDrops;
22732331 SaveScan(st);
22742332 SaveScopes(d, saved);
22752333 oldMod := curModule; oldCheck := checkMode; oldPath := curFile; oldChecks := checks;
@@ -2394,7 +2452,8 @@
23942452 if (o^.cls = oProc) and o^.fwd then Error(TokPos, NameOf(o^.name) + ' is declared forward but never defined');
23952453 o := o^.link;
23962454 end;
2397- if (errors = 0) and not checkOnly then Warnings(m);
2455+ if (errors = 0) and not checkOnly then Warnings(m, firstDrop);
2456+ numDrops := firstDrop;
23982457 if errors > 0 then Finish; { a module with errors stops the compiler after it }
23992458 CloseScope;
24002459 m^.done := true;

src/raz.pas modified +1 -1

@@ -34,7 +34,7 @@
3434 { what git describe says, made by make: 0.3.0 at the tag v0.3.0,
3535 0.3.0-5-g38d29a8 five commits past it }
3636 Version = {$I version.inc};
37- Report = '2026-10.13'; { the version of doc/raz.md it follows }
37+ Report = '2026-10.14'; { the version of doc/raz.md it follows }
3838 MemfdCreate = 319; { the system call; FPC 3.2.2 has no name for it }
3939 MfdCloexec = 1; { an ELF still executes: the kernel opens it first }
4040

src/scan.pas modified +6 -4

@@ -24,6 +24,7 @@
2424 sPlus, sMinus, sTimes, sSlash, sEql, sNeq, sLss, sLeq, sGtr, sGeq,
2525 sBecomes, sColon, sSemicolon, sComma, sPeriod, sUpto, sEllipsis,
2626 sLparen, sRparen, sLbrak, sRbrak, sLbrace, sRbrace, sArrow, sAmp, sTilde, sBar,
27+ sBlank,
2728 { the reserved words, in the order of Words below }
2829 sAnd, sBegin, sBreak, sBy, sCode, sConst, sDefer, sDiv, sDo, sElse,
2930 sElsif, sEnd, sExtern, sFor, sForward, sIf, sImport, sIn, sLink,
@@ -106,10 +107,10 @@
106107 'in', 'link', 'match', 'mod', 'module', 'not', 'of', 'or', 'packed',
107108 'proc', 'record', 'repeat', 'return', 'set', 'shl', 'shr', 'then',
108109 'to', 'type', 'until', 'var', 'variant', 'VOLATILE', 'while', 'xor');
109- Ops: array[sPlus..sBar] of string[3] = (
110+ Ops: array[sPlus..sBlank] of string[3] = (
110111 '+', '-', '*', '/', '=', '#', '<', '<=', '>', '>=',
111112 ':=', ':', ';', ',', '.', '..', '...',
112- '(', ')', '[', ']', '{', '}', '^', '&', '~', '|');
113+ '(', ')', '[', ']', '{', '}', '^', '&', '~', '|', '_');
113114
114115 var
115116 cur: TScanState; { buf .. path; tok, ival, rval and id live above }
@@ -311,7 +312,7 @@
311312 { How an operator or reserved word is written, quoted, for messages. }
312313 function SymText(s: TSym): shortstring;
313314 begin
314- if s in [sPlus..sBar] then SymText := '"' + Ops[s] + '"'
315+ if s in [sPlus..sBlank] then SymText := '"' + Ops[s] + '"'
315316 else SymText := '"' + Words[ord(s) - ord(sAnd)] + '"';
316317 end;
317318
@@ -777,7 +778,8 @@
777778 until not (cur.buf[cur.pos] in ['A'..'Z', 'a'..'z', '0'..'9', '_']);
778779 if cur.pos - start > MaxIdent then LexError('a name has at most ' + IntStr(MaxIdent) + ' characters');
779780 h := Intern(@cur.buf[start], cur.pos - start);
780- if h < NumWords then tok := TSym(ord(sAnd) + h)
781+ if (cur.pos - start = 1) and (c = '_') then tok := sBlank
782+ else if h < NumWords then tok := TSym(ord(sAnd) + h)
781783 else begin tok := sIdent; id := h end;
782784 end;
783785 '0'..'9': Number;

test/err/Dropped.args (history) added +1 -0

@@ -0,0 +1 @@
1+-Werror

test/err/Dropped.err (history) added +9 -0

@@ -0,0 +1,9 @@
1+test/err/Dropped.raz:9:5: error: the result of Sys.write is dropped
2+ 9 | Sys.write(Sys.stdout, "a\n");
3+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+help: if that is meant, write _ := Sys.write(...)
5+test/err/Dropped.raz:10:5: error: the results of pair are dropped
6+ 10 | pair();
7+ | ^^^^^^
8+help: if that is meant, write _, _ := pair(...)
9+raz: 2 errors

test/err/Dropped.raz (history) added +14 -0

@@ -0,0 +1,14 @@
1+module Dropped;
2+import Sys;
3+proc pair: (I64, I64);
4+begin
5+ return 1, 2;
6+end;
7+proc main*;
8+begin
9+ Sys.write(Sys.stdout, "a\n");
10+ pair();
11+ _ := Sys.write(Sys.stdout, "b\n");
12+ _, _ := pair();
13+end;
14+end Dropped.

test/err/Static.raz (history) modified +1 -1

@@ -3,7 +3,7 @@
33
44 proc main*;
55 begin
6- C.printf("%d\n", Bare.f());
6+ _ := C.printf("%d\n", Bare.f());
77 end;
88
99 end Static.

test/msg/BlankName.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/BlankName.raz:3:5: error: _ isn't a name: it is the blank, which stands only left of :=
2+ 3 | var _: I64; x: I64;
3+ | ^
4+raz: 1 error

test/msg/BlankValue.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/BlankValue.raz:7:13: error: _ isn't a name: it is the blank, which stands only left of :=
2+ 7 | Out.int(_);
3+ | ^
4+raz: 1 error

test/run/Extern.raz (history) modified +3 -3

@@ -46,7 +46,7 @@
4646 1, 2, 3, 4, 5, 6, 7, "eight", 3.14159, 0.5);
4747 Out.str(buf[0..I64(n)]); Out.ln;
4848
49- setenv("RAZ_TEST", "yes", 1);
49+ _ := setenv("RAZ_TEST", "yes", 1);
5050 Out.int(I64(strlen(getenv("RAZ_TEST")))); Out.ln;
5151 e := environ;
5252 i := 0;
@@ -57,8 +57,8 @@
5757 Out.int(I64(optind)); Out.ln;
5858
5959 Out.flush;
60- C.printf("printf %d %s %.1f\n", -42, "too", 2.5);
61- C.fflush(C.stdout);
60+ _ := C.printf("printf %d %s %.1f\n", -42, "too", 2.5);
61+ _ := C.fflush(C.stdout);
6262 Out.str("done\n");
6363 end;
6464

test/run/Results.raz (history) modified +1 -1

@@ -69,7 +69,7 @@
6969 Out.int(a[1]); Out.str(" "); Out.int(g.b); Out.ln;
7070 q, r := minmax(9, 3);
7171 Out.int(q); Out.int(r); Out.ln;
72- divmod(1, 1);
72+ _, _ := divmod(1, 1);
7373 i, e := nothing();
7474 Out.int(i); if e = nil then Out.str(" zero"); end; Out.ln;
7575 i := 5;

test/run/Single.raz (history) modified +4 -4

@@ -35,8 +35,8 @@
3535 proc show(name: ^U8; x: F64);
3636 begin
3737 Out.flush;
38- C.printf("%s %.9g\n", name, x);
39- C.fflush(C.stdout);
38+ _ := C.printf("%s %.9g\n", name, x);
39+ _ := C.fflush(C.stdout);
4040 end;
4141
4242 proc main*;
@@ -77,8 +77,8 @@
7777 show("mix", mix(1.5, 2, 0.25, 0.125));
7878 for i := 0 to 3 do arr[i] := F32(i) * 0.5; end;
7979 show("arr", F64(arr[3]));
80- C.printf("%f %f\n", F64(arr[1]), 0.5);
81- C.fflush(C.stdout);
80+ _ := C.printf("%f %f\n", F64(arr[1]), 0.5);
81+ _ := C.fflush(C.stdout);
8282 end;
8383
8484 end Single.

test/run/Spawn.raz (history) modified +1 -1

@@ -21,7 +21,7 @@
2121 Thread.lock(ADR(m));
2222 INC(count);
2323 Thread.unlock(ADR(m));
24- XADD(ADR(atomic), 1);
24+ _ := XADD(ADR(atomic), 1);
2525 NEW(p, Heap.heap);
2626 p^.next := list;
2727 list := p;

test/run/ThreadOverflow.raz (history) modified +1 -1

@@ -12,7 +12,7 @@
1212
1313 proc work(_arg: ^U8);
1414 begin
15- down(0);
15+ _ := down(0);
1616 end;
1717
1818 proc main*;

tools/Doc.raz (history) modified +2 -2

@@ -178,7 +178,7 @@
178178 exp := name();
179179 stop := toSemicolon();
180180 next;
181- if is("forward") then toSemicolon();
181+ if is("forward") then _ := toSemicolon();
182182 else skipBody;
183183 end;
184184 declaration("", exp, start, ds, de, stop);
@@ -235,7 +235,7 @@
235235 if is("const") or is("type") or is("var") then section;
236236 elsif is("proc") then procedure;
237237 elsif is("extern") then external;
238- elsif is("import") or is("link") then toSemicolon(); next;
238+ elsif is("import") or is("link") then _ := toSemicolon(); next;
239239 else next;
240240 end;
241241 end;

tools/Mutate.raz (history) modified +1 -1

@@ -29,7 +29,7 @@
2929 state := 88172645463325252;
3030 for i := 0 to LEN(s) - 1 do state := state * 31 + U64(s[i]); end;
3131 if state = 0 then state := 1; end;
32- for i := 1 to 10 do random(2); end;
32+ for i := 1 to 10 do _ := random(2); end;
3333 end;
3434
3535 (* The symbols that aren't comments. *)