From 9ca6cfc37da65a90228eaf534dcd7ea179a8e56e Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Mon, 12 Oct 2026 11:48:13 +0100 Subject: [PATCH] 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. --- diff --git a/CLAUDE.md b/CLAUDE.md index 84ad956..d2acdc0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -86,8 +86,10 @@ defect, and the library grows only by what breaks no program written for it. A wish for more, the owner's or yours, goes on the list in `PLAN.md`, for a later thaw; it isn't built. v0.6.0 was such a thaw, -by the owner's word: report 2026-10.12; the compiler follows 2026-10.13, -whose `Sys` writes without waiting, for rat's pastes. Its parser +by the owner's word: report 2026-10.12; the compiler follows 2026-10.14, +whose `Sys` writes without waiting, for rat's pastes (10.13), and +whose blank, `_ := f(x)`, drops a result that is otherwise warned of +(10.14), also by the owner's word. Its parser reaches the machine only through `gen.pas`; its steps 5 to 10 await the owner's review, and git has them. Keep `doc/compiler.md`'s table of lines and its routine names true when the diff --git a/PLAN.md b/PLAN.md index bf0e5c5..2b610ca 100644 --- a/PLAN.md +++ b/PLAN.md @@ -17,8 +17,4 @@ ## Wishes, for a later thaw What the language or the library might have, met while writing raz; -none is built while the freeze holds. - -- A warning for a call whose result is dropped. Code drops results on - purpose (`SYSCALL`, `Sys.write`; about 40 places in `lib/`), so it - needs a way to say so first, such as `_ := f(x)`. +none is built while the freeze holds. None waits now. diff --git a/conform/err/BlankName.raz b/conform/err/BlankName.raz new file mode 100644 index 0000000..8a098d3 --- /dev/null +++ b/conform/err/BlankName.raz @@ -0,0 +1,7 @@ +module BlankName; +proc main*; +var _: I64; x: I64; +begin + x := _; +end; +end BlankName. diff --git a/conform/err/BlankValue.raz b/conform/err/BlankValue.raz new file mode 100644 index 0000000..8090b6d --- /dev/null +++ b/conform/err/BlankValue.raz @@ -0,0 +1,9 @@ +module BlankValue; +import Out; +proc main*; +var x: I64; +begin + x := 1; + Out.int(_); +end; +end BlankValue. diff --git a/conform/run/AtExit.raz b/conform/run/AtExit.raz index e4618f5..0ab4ba1 100644 --- a/conform/run/AtExit.raz +++ b/conform/run/AtExit.raz @@ -26,9 +26,9 @@ proc main*: INT; var i, full: I64; begin - Rt.atExit(first); - Rt.atExit(second); - Rt.atExit(third); + _ := Rt.atExit(first); + _ := Rt.atExit(second); + _ := Rt.atExit(third); full := 0; for i := 1 to 40 do if Rt.atExit(nothing) = Rt.Full then INC(full); end; diff --git a/conform/run/Blank.expect b/conform/run/Blank.expect new file mode 100644 index 0000000..97fb4a0 --- /dev/null +++ b/conform/run/Blank.expect @@ -0,0 +1 @@ +1 4 4 diff --git a/conform/run/Blank.raz b/conform/run/Blank.raz new file mode 100644 index 0000000..c8e818d --- /dev/null +++ b/conform/run/Blank.raz @@ -0,0 +1,24 @@ +module Blank; +import Out; +var calls: I64; +proc pair(a, b: I64): (I64, I64); +begin + INC(calls); + return a, b; +end; +proc count: I64; +begin + INC(calls); + return calls; +end; +proc main*; +var n, k: I64; +begin + _ := count(); + n, _ := pair(1, 2); + _, k := pair(3, 4); + _, _ := pair(5, 6); + _ := n + k; + Out.int(n); Out.str(" "); Out.int(k); Out.str(" "); Out.int(calls); Out.ln; +end; +end Blank. diff --git a/conform/run/FirstUse.raz b/conform/run/FirstUse.raz index 03163b0..1044a97 100644 --- a/conform/run/FirstUse.raz +++ b/conform/run/FirstUse.raz @@ -29,6 +29,6 @@ begin Table.init(ADR(names), Heap.heap); - Table.put(ADR(names), "rose", red); - Table.put(ADR(names), "sky", blue); + _ := Table.put(ADR(names), "rose", red); + _ := Table.put(ADR(names), "sky", blue); end FirstUse. diff --git a/doc/book/PLAN.md b/doc/book/PLAN.md new file mode 100644 index 0000000..ea6c683 --- /dev/null +++ b/doc/book/PLAN.md @@ -0,0 +1,106 @@ +# Stage: the book "Compiling Raz" + +This is the owner's go-ahead for a new stage: a book, "Compiling Raz", +explaining how the raz compiler works. Follow CLAUDE.md's way of working: +one commit per step, push it, then stop for review. Don't change the +language or the compiler for the book's sake. If the book exposes a bug +or a clumsy spot, report it rather than fixing it. + +## Read first +- CLAUDE.md, doc/raz.md (the report), doc/compiler.md, README.md. +- src/*.pas, the whole compiler (about 5,000 lines), and enough of lib/ + (Rt, Heap, Mem, Thread, Sys) to explain the runtime. +- The tiza skill, for drawings. + +## The reader +A working programmer: not good at Pascal, little knowledge of compilers. +- Assume they roughly know registers, the stack and memory. Explain only + what raz does with them (frames, calling convention, layout). +- Introduce compiler ideas (tokens, grammar, generating code while + parsing, symbol tables) briefly and in friendly terms where they first + appear. +- Teach just enough Pascal to read the compiler: one early chapter, then + more as features come up. Teach enough raz the same way. +- Keep the two languages visibly apart: ```raz and ```pascal code blocks, + and say which one is on screen. +- Don't explain formats that can be looked up. ELF gets a page on what + raz writes and why, plus a pointer to the spec. +- Target 40-50k words. + +## Tone +Like Learn You a Haskell and Starting FORTH: tiny steps, talking straight +to the reader, every idea shown at once on a real example, drawings that +carry meaning. Warm, with an occasional dry aside. Never a joke per +paragraph; humor is seasoning. Plain, short sentences. + +## Mascot: Razmataz +A small, very serious creature with a flashy name, which suits a frugal +compiler (razzmatazz minus one z). +- Its motto, "once is enough", plays on "raz" meaning "one" or "once" in + Polish and Russian. Check that the compiler really works in one pass + before leaning on this; if it doesn't, find the honest version of the + joke. +- Razmataz appears in tiza drawings: eating characters in the scanner, + stacking boxes in frames, throwing unused code overboard in linking. + +## Structure +Build up gradually, not unit by unit: +1. Introduction and a whirlwind tour: compile `exit 42` (or the smallest + real program) through every stage, shallowly. +2. Enough Pascal (and raz) to follow along. +3. One chapter per language feature, followed through scanner, parser, + symbols, code generator and machine code: variables and expressions, + control flow, procedures and frames, records and arrays, pointers and + the heap, strings, modules, defer, C interop, threads. +4. Closing chapters: x64 encoding, link (tree shaking, layout), elf, + speed (how it reaches 400k lines a second), and where to go next. + +Refine this order in the outline (step 1). + +## Format and tooling +- Markdown in doc/book/: NN-slug.md per chapter, plus metadata.yaml + (title, author Luis, cover). It must read well as plain text. +- `make book` builds build/compiling-raz.epub with pandoc. If pandoc gets + installed locally, update the desktop guide (see the global + CLAUDE.md). +- Drawings: .tiza source and a rendered PNG, both committed (CI has no + tiza). Every image has a caption that stands on its own in plain text. + Use ASCII art in code blocks for diagrams that are really structure + (frames, memory layout); those read the same in both formats. +- Disassembly is cleaned up: instructions only, the raz source line + beside them as a comment, and bytes only where the bytes are the point. + Show raw objdump output once, early, next to the cleaned version, and + say how to get it. +- A checker, written in raz alongside tools/Doc.raz (reuse what exists), + run by `make check`. It must: + - compile and run every raz example marked as runnable and compare the + expected output written in the book; + - confirm every quoted Pascal excerpt still matches src/, quoted by + unit and routine name, never by line number; + - regenerate or verify the cleaned disassembly. + The goal: when the compiler changes, `make check` fails rather than + the book going quietly wrong. +- CI (.github/workflows/): on a push to main that touches doc/book/**, + src/** or lib/**, build the epub and replace the file on a standing + prerelease tagged `book` (gh release upload --clobber), so the owner + has a fixed URL to open on an iPad. Tagged releases also attach that + version's epub. + +## Steps (each one is a commit, then stop for review) +1. The outline: doc/book/OUTLINE.md, chapter by chapter, with what each + one teaches, its running example, and the drawings planned. +2. The tooling: doc/book/ skeleton, `make book`, the checker in + `make check`, the CI job. One placeholder chapter proves the pipeline + end to end. +3. Razmataz's design sheet (tiza) and one sample chapter, the procedures + and frames one, to set tone and depth. +4. Then one chapter per step, in order. + +doc/compiler.md stays as it is: the short guide for people changing the +compiler. The book can point to it but never replaces it. + +## Left to the tooling step +- How the checker marks runnable examples and quoted excerpts inside + Markdown. +- Whether the cleaned disassembly comes from the compiler's own line + information (`make gdb` suggests it has some) or from objdump. diff --git a/doc/compiler.md b/doc/compiler.md index 8637ff3..2fcbe2d 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -1,6 +1,6 @@ # Reading the raz compiler -The compiler is eleven files of Free Pascal, under 7,800 lines of code. +The compiler is eleven files of Free Pascal, under 7,900 lines of code. This guide walks through them in the order they are best read: from the characters of a source file to the bytes of an executable. It assumes you know the language from `doc/raz.md`, and enough x86-64 to read a @@ -9,13 +9,13 @@ | File | Lines | Code | What | |---|---|---|---| | `src/diag.pas` | 310 | 229 | Messages: positions, source excerpts, colour, counts | -| `src/scan.pas` | 884 | 745 | Symbols, literals, comments, positions | +| `src/scan.pas` | 886 | 747 | Symbols, literals, comments, positions | | `src/sym.pas` | 615 | 510 | Types, objects, scopes, layout | | `src/chunk.pas` | 276 | 217 | The compiled program: chunks, fixups, line notes | | `src/x64.pas` | 1,039 | 870 | The instruction encoder, jumps within a procedure, the assembler | | `src/gen.pas` | 1,332 | 1,039 | The stack machine, for x86-64: values, operations, checks, calls, frames | | `src/item.pas` | 1,342 | 1,118 | Items: types, constants, variables, operators, conversions, calls | -| `src/parse.pas` | 2,653 | 2,354 | Declarations, statements, expressions, built-ins, recovery, warnings | +| `src/parse.pas` | 2,712 | 2,407 | Declarations, statements, expressions, built-ins, recovery, warnings | | `src/link.pas` | 234 | 180 | Tree shaking, layout, patching, the places | | `src/elf.pas` | 435 | 352 | Static and dynamic ELF, symbol table, line numbers | | `src/raz.pas` | 197 | 147 | The command line | @@ -418,7 +418,10 @@ Then statements: `Statement` makes each one a recovery point (below) and `OneStatement` dispatches; `IfStatement`, `WhileStatement`, `ForStatement` and `MatchStatement` emit their jumps -with gen's labels. A `match` on an integer reads each arm's +with gen's labels. The blank is a symbol of its own, `sBlank`, so +no declaration or expression takes it: `_ := e` loads a single value +and drops it, and `MultiAssign` skips the results it stands for. A +`match` on an integer reads each arm's labels in `IntArm`, which refuses a value in two of them, and tests them one after another with `MatchRange`: compares and branches, no jump table. `Defer` is worth reading: a deferred statement @@ -489,7 +492,10 @@ reports what isn't exported, doesn't start with `_`, and was never used, or, for a variable, only assigned, and a procedure with results that may reach its end (`openEnd`, from `ends`, which each statement -sets). A generic module's instances +sets). The calls that drop results are a third list, `drops`, in +order: `CompileFile` notes where the module's own begin, since the +instances it makes along the way add theirs and take them back. A +generic module's instances share its text, so only the first is warned of. The built-in procedures are in `Builtin` (and `New_`, `Atomic`): each @@ -606,7 +612,9 @@ it may reach its end without `return` (`ends`, `parse.pas`): each way through its statements must end in a `return`, an `if` with an `else`, a `match`, a `while true` or a `repeat ... until false` - with no `break`. `-Werror` makes each an error. + with no `break`. So is a call standing on its own that drops a + result (`drops`, kept by `OneStatement` and told by `Dropped`); + `_ := f(x)` drops one on purpose. `-Werror` makes each an error. - **Several results** come back through a hidden pointer to the caller's slots; a code procedure returns two in rax and rdx. - **Reals.** A real constant is held as an F64. An `F32` in a register diff --git a/examples/Printf.raz b/examples/Printf.raz index 1ff611e..fb34caf 100644 --- a/examples/Printf.raz +++ b/examples/Printf.raz @@ -9,8 +9,8 @@ for i := 1 to 3 do Out.str("raz says "); Out.int(i); Out.ln; Out.flush; - C.printf("C says %d, %s\n", I32(i * i), "squared"); - C.fflush(C.stdout); + _ := C.printf("C says %d, %s\n", I32(i * i), "squared"); + _ := C.fflush(C.stdout); end; end; diff --git a/examples/Pthreads.raz b/examples/Pthreads.raz index 268dcf2..095f889 100644 --- a/examples/Pthreads.raz +++ b/examples/Pthreads.raz @@ -42,7 +42,7 @@ end; total := 0; for i := 0 to Workers - 1 do - C.pthread_join(t[i], nil); + _ := C.pthread_join(t[i], nil); total := total + parts[i].sum; end; Out.str("total "); Out.int(total); Out.ln; diff --git a/examples/Window.raz b/examples/Window.raz index bf6cf35..10f4b43 100644 --- a/examples/Window.raz +++ b/examples/Window.raz @@ -52,18 +52,18 @@ s := XDefaultScreen(d); w := XCreateSimpleWindow(d, XRootWindow(d, s), 0, 0, 320, 80, 1, XBlackPixel(d, s), XWhitePixel(d, s)); - XStoreName(d, w, "raz"); - XSelectInput(d, w, ExposureMask + KeyPressMask); - XMapWindow(d, w); + _ := XStoreName(d, w, "raz"); + _ := XSelectInput(d, w, ExposureMask + KeyPressMask); + _ := XMapWindow(d, w); repeat - XNextEvent(d, ^U8(ADR(ev))); + _ := XNextEvent(d, ^U8(ADR(ev))); if I32(ev[0]) = Expose then - XDrawString(d, w, XDefaultGC(d, s), 20, 45, text, I32(LEN(text))); + _ := XDrawString(d, w, XDefaultGC(d, s), 20, 45, text, I32(LEN(text))); end; until I32(ev[0]) = KeyPress; key := ^KeyEvent(ADR(ev)); Out.str("key "); Out.int(INT(key^.keycode)); Out.ln; - XCloseDisplay(d); + _ := XCloseDisplay(d); return 0; end; diff --git a/lib/Lock.raz b/lib/Lock.raz index 2c85f42..ce69f9d 100644 --- a/lib/Lock.raz +++ b/lib/Lock.raz @@ -22,7 +22,7 @@ (* Gives up l, which the caller holds. *) proc give*(l: ^Lock); begin - XCHG(ADR(l^.held), 0); + _ := XCHG(ADR(l^.held), 0); end; (* The module's test, in one thread: taken, given, taken again. *) diff --git a/lib/Out.raz b/lib/Out.raz index e3119d2..b2b3a3f 100644 --- a/lib/Out.raz +++ b/lib/Out.raz @@ -101,5 +101,5 @@ begin tty := Sys.isTerminal(Sys.stdout); - Rt.atExit(flush); + _ := Rt.atExit(flush); end Out. diff --git a/lib/Rt.raz b/lib/Rt.raz index a240ad1..8072da1 100644 --- a/lib/Rt.raz +++ b/lib/Rt.raz @@ -107,8 +107,8 @@ with status 2, as a failed check does. *) proc stop*(msg: []U8); begin - Sys.write(Sys.stderr, msg); - Sys.write(Sys.stderr, "\n"); + _ := Sys.write(Sys.stderr, msg); + _ := Sys.write(Sys.stderr, "\n"); exit(2); end; @@ -152,7 +152,7 @@ proc say; begin line[lineLen] := '\n'; - Sys.write(Sys.stderr, line[0..lineLen + 1]); + _ := Sys.write(Sys.stderr, line[0..lineLen + 1]); lineLen := 0; end; @@ -330,7 +330,7 @@ ip := q[1] - 1; (* the call, by its return address *) bp := q[0]; end; - more(same); + _ := more(same); end; (* Says on standard error the calls under way, from the one that calls @@ -365,8 +365,8 @@ say; calls(at, callerFrame(), true); act := {}; (* the signal's default action *) - SYSCALL(13, sig, ADR(act), 0, 8); (* rt_sigaction *) - SYSCALL(62, SYSCALL(39), sig); (* kill(getpid(), sig) *) + _ := SYSCALL(13, sig, ADR(act), 0, 8); (* rt_sigaction *) + _ := SYSCALL(62, SYSCALL(39), sig); (* kill(getpid(), sig) *) end; if what = 0 then put("index "); @@ -485,7 +485,7 @@ var t: [4]INT; i, n, k: INT; p: ^Proc; begin t := [0, 0, 0, 0]; - SYSCALL(38, 2, ADR(t), 0); (* setitimer(ITIMER_PROF): no more *) + _ := SYSCALL(38, 2, ADR(t), 0); (* setitimer(ITIMER_PROF): no more *) profiling := false; n := numSamples; if n > MaxSamples then n := MaxSamples; end; @@ -511,15 +511,15 @@ begin alt := {sp: ADR(altStack[0]), size: LEN(altStack)}; - SYSCALL(131, ADR(alt), 0); (* sigaltstack *) + _ := SYSCALL(131, ADR(alt), 0); (* sigaltstack *) act := {handler: onSignal, flags: Flags, restorer: sigReturn}; - SYSCALL(13, SigSegv, ADR(act), 0, 8); (* rt_sigaction *) - SYSCALL(13, SigFpe, ADR(act), 0, 8); + _ := SYSCALL(13, SigSegv, ADR(act), 0, 8); (* rt_sigaction *) + _ := SYSCALL(13, SigFpe, ADR(act), 0, 8); if LEN(Sys.env("RAZ_PROFILE")) > 0 then act := {handler: onProf, flags: ProfFlags, restorer: sigReturn}; - SYSCALL(13, SigProf, ADR(act), 0, 8); + _ := SYSCALL(13, SigProf, ADR(act), 0, 8); timerv := [0, 1000, 0, 1000]; (* every millisecond, from one on *) - SYSCALL(38, 2, ADR(timerv), 0); (* setitimer(ITIMER_PROF) *) + _ := SYSCALL(38, 2, ADR(timerv), 0); (* setitimer(ITIMER_PROF) *) profiling := true; end; end Rt. diff --git a/lib/Sys.linux-x86_64.raz b/lib/Sys.linux-x86_64.raz index 772cc44..07c2865 100644 --- a/lib/Sys.linux-x86_64.raz +++ b/lib/Sys.linux-x86_64.raz @@ -156,7 +156,7 @@ (* Closes the file descriptor fd. *) proc close*(fd: INT); begin - SYSCALL(3, fd); + _ := SYSCALL(3, fd); end; (* size bytes of fresh, zeroed memory from the system, a multiple of @@ -172,7 +172,7 @@ (* Gives back to the system the size bytes at p that mmap gave. *) proc munmap*(p: ^U8; size: INT); begin - SYSCALL(11, p, size); + _ := SYSCALL(11, p, size); end; (* Whether the file descriptor fd is a terminal: whether it has a @@ -302,7 +302,7 @@ (* Closes the directory d that openDir opened. *) proc closeDir*(d: ^Dir); begin - SYSCALL(3, d^.fd); + _ := SYSCALL(3, d^.fd); end; (* Puts the terminal on fd into raw mode: no echo, no lines, no signals, @@ -325,7 +325,7 @@ (* The terminal on fd as rawMode found it. *) proc restoreMode*(fd: INT); begin - SYSCALL(16, fd, 5402H, ADR(saved)); + _ := SYSCALL(16, fd, 5402H, ADR(saved)); end; (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't @@ -353,7 +353,7 @@ proc clock*: I64; var t: Timespec; begin - SYSCALL(228, 1, ADR(t)); (* clock_gettime: CLOCK_MONOTONIC *) + _ := SYSCALL(228, 1, ADR(t)); (* clock_gettime: CLOCK_MONOTONIC *) return t.sec * 1000000000 + t.nsec; end; @@ -361,7 +361,7 @@ proc now*: I64; var t: Timespec; begin - SYSCALL(228, 0, ADR(t)); (* clock_gettime: CLOCK_REALTIME *) + _ := SYSCALL(228, 0, ADR(t)); (* clock_gettime: CLOCK_REALTIME *) return t.sec * 1000000000 + t.nsec; end; @@ -396,7 +396,7 @@ if fd < 0 then return fd; end; if serving then one := 1; (* so that a server can start again at once *) - SYSCALL(54, fd, 1, 2, ADR(one), 4); (* setsockopt: SOL_SOCKET, SO_REUSEADDR *) + _ := SYSCALL(54, fd, 1, 2, ADR(one), 4); (* setsockopt: SOL_SOCKET, SO_REUSEADDR *) r := SYSCALL(49, fd, a, size); (* bind *) if r = 0 then r := SYSCALL(50, fd, 4096); end; (* listen *) else @@ -664,7 +664,7 @@ proc openPty*: INT; var a: [4096]U8; fd, unlock: INT; begin - cstr("/dev/ptmx", a); + _ := cstr("/dev/ptmx", a); fd := SYSCALL(2, ADR(a), 80102H); (* open: O_RDWR, O_NOCTTY, O_CLOEXEC *) if fd < 0 then return fd; end; unlock := 0; @@ -803,38 +803,38 @@ end; if argv = nil then return -12; end; (* ENOMEM *) all := 0FFFFFFFFFFFFFFFFH; - SYSCALL(14, 2, ADR(all), ADR(old), 8); (* rt_sigprocmask: SIG_SETMASK *) + _ := SYSCALL(14, 2, ADR(all), ADR(old), 8); (* rt_sigprocmask: SIG_SETMASK *) pid := SYSCALL(57); (* fork *) if pid = 0 then if p.tty # 0 then - SYSCALL(112); (* setsid *) + _ := SYSCALL(112); (* setsid *) fd := SYSCALL(2, ADR(name), 2); (* open, O_RDWR *) - if (fd < 0) or (SYSCALL(16, fd, 540EH, 0) # 0) then SYSCALL(231, 127); end; (* TIOCSCTTY; exit *) - for i := 0 to 2 do SYSCALL(33, fd, i); end; (* dup2 *) + if (fd < 0) or (SYSCALL(16, fd, 540EH, 0) # 0) then _ := SYSCALL(231, 127); end; (* TIOCSCTTY; exit *) + for i := 0 to 2 do _ := SYSCALL(33, fd, i); end; (* dup2 *) else - if p.group = -1 then SYSCALL(109, 0, 0); (* setpgid *) - elsif p.group # 0 then SYSCALL(109, 0, p.group); + if p.group = -1 then _ := SYSCALL(109, 0, 0); (* setpgid *) + elsif p.group # 0 then _ := SYSCALL(109, 0, p.group); end; - if p.foreground then foreground(0, SYSCALL(111)); end; (* getpgrp *) + if p.foreground then _ := foreground(0, SYSCALL(111)); end; (* getpgrp *) for i := 0 to 2 do - if p.fds[i] # 0 then SYSCALL(33, p.fds[i], i); end; (* dup2 *) + if p.fds[i] # 0 then _ := SYSCALL(33, p.fds[i], i); end; (* dup2 *) end; end; - if (LEN(p.dir) > 0) and (SYSCALL(80, ADR(dir)) # 0) then SYSCALL(231, 127); end; (* chdir *) - SYSCALL(436, 3, 0FFFFFFFFH, 0); (* close_range: every fd from 3 *) - for i := 1 to 64 do SYSCALL(13, i, ADR(dfl), 0, 8); end; (* rt_sigaction *) - SYSCALL(14, 2, ADR(empty), 0, 8); (* no signal blocked *) - SYSCALL(59, ADR(a), argv, argv + (LEN(p.args) + 1)); (* execve *) - SYSCALL(231, 127); (* exit *) + if (LEN(p.dir) > 0) and (SYSCALL(80, ADR(dir)) # 0) then _ := SYSCALL(231, 127); end; (* chdir *) + _ := SYSCALL(436, 3, 0FFFFFFFFH, 0); (* close_range: every fd from 3 *) + for i := 1 to 64 do _ := SYSCALL(13, i, ADR(dfl), 0, 8); end; (* rt_sigaction *) + _ := SYSCALL(14, 2, ADR(empty), 0, 8); (* no signal blocked *) + _ := SYSCALL(59, ADR(a), argv, argv + (LEN(p.args) + 1)); (* execve *) + _ := SYSCALL(231, 127); (* exit *) end; if (pid > 0) and (p.tty = 0) then (* as the program does, for whichever of the two runs first *) g := p.group; if g = -1 then g := pid; elsif g = 0 then g := SYSCALL(111); end; - if p.group # 0 then SYSCALL(109, pid, g); end; - if p.foreground then foreground(0, g); end; + if p.group # 0 then _ := SYSCALL(109, pid, g); end; + if p.foreground then _ := foreground(0, g); end; end; - SYSCALL(14, 2, ADR(old), 0, 8); + _ := SYSCALL(14, 2, ADR(old), 0, 8); munmap(^U8(argv), size); return pid; end; @@ -879,7 +879,7 @@ end; fd := -1; if caughtSigs # 0 then fd := sigFd; end; - SYSCALL(14, 0, ADR(m), 0, 8); (* rt_sigprocmask: SIG_BLOCK *) + _ := SYSCALL(14, 0, ADR(m), 0, 8); (* rt_sigprocmask: SIG_BLOCK *) fd := SYSCALL(289, fd, ADR(m), 8, 80800H); (* signalfd4: SFD_NONBLOCK, SFD_CLOEXEC *) if fd < 0 then return fd; end; caughtSigs := m; @@ -907,13 +907,13 @@ (* Gives the processor to another thread. *) proc yield*; begin - SYSCALL(24); + _ := SYSCALL(24); end; (* Ends the program, at once, with status. *) proc exit*(status: INT); begin - SYSCALL(231, status); + _ := SYSCALL(231, status); end; (* The test of programs: one on a pseudo-terminal of 100 by 30 prints @@ -1063,9 +1063,9 @@ if (p = nil) or (p[99] # 0) then exit(2); end; munmap(p, 100); (* files and directories *) - remove("/tmp/raz-sys-dir/f"); - remove("/tmp/raz-sys-dir/g"); - makeDir("/tmp/raz-sys-dir"); + _ := remove("/tmp/raz-sys-dir/f"); + _ := remove("/tmp/raz-sys-dir/g"); + _ := makeDir("/tmp/raz-sys-dir"); fd := create("/tmp/raz-sys-dir/f"); if (fd < 0) or (write(fd, "abc") # 3) then exit(2); end; close(fd); @@ -1076,7 +1076,7 @@ if (err # 0) or not i.dir or i.file then exit(2); end; i, err := info("/dev/null"); if (err # 0) or i.dir or i.file then exit(2); end; - remove("/tmp/raz-sys-link"); + _ := remove("/tmp/raz-sys-link"); if symlink("/tmp/raz-sys-dir", "/tmp/raz-sys-link") # 0 then exit(2); end; i, err := info("/tmp/raz-sys-link"); if (err # 0) or not i.dir or not i.symlink then exit(2); end; @@ -1084,9 +1084,9 @@ if (err # 0) or (name # "/tmp/raz-sys-dir") then exit(2); end; name, err := readLink("/tmp/raz-sys-dir"); if err # -22 then exit(2); end; (* EINVAL: not a link *) - remove("/tmp/raz-sys-link"); + _ := remove("/tmp/raz-sys-link"); (* open as asked, seek, the mode and the time *) - remove("/tmp/raz-sys-dir/h"); + _ := remove("/tmp/raz-sys-dir/h"); fd := open("/tmp/raz-sys-dir/h", {writing, creating, exclusive}); if (fd < 0) or (write(fd, "abc") # 3) then exit(2); end; close(fd); @@ -1104,7 +1104,7 @@ if chmod("/tmp/raz-sys-dir/h", 1EDH) # 0 then exit(2); end; i, err := info("/tmp/raz-sys-dir/h"); if i.mode # 1EDH then exit(2); end; - remove("/tmp/raz-sys-dir/h"); + _ := remove("/tmp/raz-sys-dir/h"); i, err := info("/no/such/file"); if err >= 0 then exit(2); end; if openDir(ADR(d), "/tmp/raz-sys-dir") # 0 then exit(2); end; @@ -1128,7 +1128,7 @@ (* a socket: nothing at a path, then a listener that a connection makes ready, and a byte from it to the connection *) if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *) - remove("/tmp/raz-sys-socket"); + _ := remove("/tmp/raz-sys-socket"); l := listen("/tmp/raz-sys-socket"); if (l < 0) or (listen("/tmp/raz-sys-socket") # -98) then exit(2); end; (* EADDRINUSE: there already *) c := connect("/tmp/raz-sys-socket"); @@ -1143,7 +1143,7 @@ if send(c, "x") # -32 then exit(2); end; (* EPIPE, and no SIGPIPE *) close(c); close(l); - remove("/tmp/raz-sys-socket"); + _ := remove("/tmp/raz-sys-socket"); testPrograms; testNet; end; diff --git a/lib/Sys.raz b/lib/Sys.raz index 349653a..f1366be 100644 --- a/lib/Sys.raz +++ b/lib/Sys.raz @@ -189,7 +189,7 @@ (* Closes the file descriptor fd. *) proc close*(fd: INT); begin - C.close(I32(fd)); + _ := C.close(I32(fd)); end; (* size bytes of fresh, zeroed memory from the system, a multiple of @@ -205,7 +205,7 @@ (* Gives back to the system the size bytes at p that mmap gave. *) proc munmap*(p: ^U8; size: INT); begin - C.munmap(p, UINT(size)); + _ := C.munmap(p, UINT(size)); end; (* Renames old to new, replacing what new names: 0, or minus an errno. *) @@ -321,7 +321,7 @@ (* Closes the directory d that openDir opened. *) proc closeDir*(d: ^Dir); begin - C.closedir(d^.d); + _ := C.closedir(d^.d); end; (* Puts the terminal on fd into raw mode, as cfmakeraw makes it: no @@ -339,7 +339,7 @@ (* The terminal on fd as rawMode found it. *) proc restoreMode*(fd: INT); begin - C.tcsetattr(I32(fd), 0, ADR(saved[0])); + _ := C.tcsetattr(I32(fd), 0, ADR(saved[0])); end; (* The columns and rows of the terminal on fd; 80 by 24 if it doesn't @@ -367,7 +367,7 @@ proc time(clock: I32): I64; var t: Timespec; begin - C.clock_gettime(clock, ^U8(ADR(t))); + _ := C.clock_gettime(clock, ^U8(ADR(t))); return t.sec * 1000000000 + t.nsec; end; @@ -415,7 +415,7 @@ if fd < 0 then return failed(); end; if serving then one := 1; (* so that a server can start again at once *) - C.setsockopt(fd, 1, 2, ^U8(ADR(one)), 4); (* SOL_SOCKET, SO_REUSEADDR *) + _ := C.setsockopt(fd, 1, 2, ^U8(ADR(one)), 4); (* SOL_SOCKET, SO_REUSEADDR *) r := C.bind(fd, a, U32(size)); if r = 0 then r := C.listen(fd, 4096); end; else @@ -423,7 +423,7 @@ end; if r # 0 then err := failed(); (* before close can change errno *) - C.close(fd); + _ := C.close(fd); return err; end; return INT(fd); @@ -614,7 +614,7 @@ if fd < 0 then return failed(); end; if (C.grantpt(fd) # 0) or (C.unlockpt(fd) # 0) then err := failed(); - C.close(fd); + _ := C.close(fd); return err; end; return INT(fd); @@ -745,28 +745,28 @@ end; if argv = nil then return -12; end; (* ENOMEM *) for i := 0 to LEN(all) - 1 do all[i] := 0FFFFFFFFFFFFFFFFH; end; - C.sigprocmask(2, ^U8(ADR(all)), ^U8(ADR(old))); (* SIG_SETMASK *) + _ := C.sigprocmask(2, ^U8(ADR(all)), ^U8(ADR(old))); (* SIG_SETMASK *) pid := C.fork(); if pid = 0 then if p.tty # 0 then - C.setsid(); + _ := C.setsid(); fd := C.open(ADR(name[0]), 2); (* O_RDWR *) if (fd < 0) or (C.ioctl(fd, TIOCSCTTY, 0) # 0) then C._exit(127); end; - for i := 0 to 2 do C.dup2(fd, I32(i)); end; + for i := 0 to 2 do _ := C.dup2(fd, I32(i)); end; else - if p.group = -1 then C.setpgid(0, 0); - elsif p.group # 0 then C.setpgid(0, I32(p.group)); + if p.group = -1 then _ := C.setpgid(0, 0); + elsif p.group # 0 then _ := C.setpgid(0, I32(p.group)); end; - if p.foreground then C.tcsetpgrp(0, C.getpgrp()); end; + if p.foreground then _ := C.tcsetpgrp(0, C.getpgrp()); end; for i := 0 to 2 do - if p.fds[i] # 0 then C.dup2(I32(p.fds[i]), I32(i)); end; + if p.fds[i] # 0 then _ := C.dup2(I32(p.fds[i]), I32(i)); end; end; end; if (LEN(p.dir) > 0) and (C.chdir(ADR(dir[0])) # 0) then C._exit(127); end; - C.close_range(3, 0FFFFFFFFH, 0); (* every fd from 3 *) - for i := 1 to 64 do C.sigaction(I32(i), ^U8(ADR(dfl)), nil); end; - C.sigprocmask(2, ^U8(ADR(empty)), nil); - C.execve(ADR(a[0]), argv, argv + (LEN(p.args) + 1)); + _ := C.close_range(3, 0FFFFFFFFH, 0); (* every fd from 3 *) + for i := 1 to 64 do _ := C.sigaction(I32(i), ^U8(ADR(dfl)), nil); end; + _ := C.sigprocmask(2, ^U8(ADR(empty)), nil); + _ := C.execve(ADR(a[0]), argv, argv + (LEN(p.args) + 1)); C._exit(127); end; err := failed(); @@ -774,10 +774,10 @@ (* as the program does, for whichever of the two runs first *) g := p.group; if g = -1 then g := INT(pid); elsif g = 0 then g := INT(C.getpgrp()); end; - if p.group # 0 then C.setpgid(pid, I32(g)); end; - if p.foreground then C.tcsetpgrp(0, I32(g)); end; + if p.group # 0 then _ := C.setpgid(pid, I32(g)); end; + if p.foreground then _ := C.tcsetpgrp(0, I32(g)); end; end; - C.sigprocmask(2, ^U8(ADR(old)), nil); + _ := C.sigprocmask(2, ^U8(ADR(old)), nil); munmap(^U8(argv), size); if pid < 0 then return err; end; return INT(pid); @@ -818,7 +818,7 @@ e := C.__errno_location(); saved := e^; (* as the code it stopped left it *) b[0] := U8(sig); - C.write(sigWrite, ADR(b[0]), 1); + _ := C.write(sigWrite, ADR(b[0]), 1); e^ := saved; end; @@ -873,7 +873,7 @@ (* Gives the processor to another thread. *) proc yield*; begin - C.sched_yield(); + _ := C.sched_yield(); end; (* Ends the program, at once, with status. *) @@ -1029,9 +1029,9 @@ if (p = nil) or (p[99] # 0) then exit(2); end; munmap(p, 100); (* files and directories *) - remove("/tmp/raz-sys-dir/f"); - remove("/tmp/raz-sys-dir/g"); - makeDir("/tmp/raz-sys-dir"); + _ := remove("/tmp/raz-sys-dir/f"); + _ := remove("/tmp/raz-sys-dir/g"); + _ := makeDir("/tmp/raz-sys-dir"); fd := create("/tmp/raz-sys-dir/f"); if (fd < 0) or (write(fd, "abc") # 3) then exit(2); end; close(fd); @@ -1042,7 +1042,7 @@ if (err # 0) or not i.dir or i.file then exit(2); end; i, err := info("/dev/null"); if (err # 0) or i.dir or i.file then exit(2); end; - remove("/tmp/raz-sys-link"); + _ := remove("/tmp/raz-sys-link"); if symlink("/tmp/raz-sys-dir", "/tmp/raz-sys-link") # 0 then exit(2); end; i, err := info("/tmp/raz-sys-link"); if (err # 0) or not i.dir or not i.symlink then exit(2); end; @@ -1050,9 +1050,9 @@ if (err # 0) or (name # "/tmp/raz-sys-dir") then exit(2); end; name, err := readLink("/tmp/raz-sys-dir"); if err # -22 then exit(2); end; (* EINVAL: not a link *) - remove("/tmp/raz-sys-link"); + _ := remove("/tmp/raz-sys-link"); (* open as asked, seek, the mode and the time *) - remove("/tmp/raz-sys-dir/h"); + _ := remove("/tmp/raz-sys-dir/h"); fd := open("/tmp/raz-sys-dir/h", {writing, creating, exclusive}); if (fd < 0) or (write(fd, "abc") # 3) then exit(2); end; close(fd); @@ -1070,7 +1070,7 @@ if chmod("/tmp/raz-sys-dir/h", 1EDH) # 0 then exit(2); end; i, err := info("/tmp/raz-sys-dir/h"); if i.mode # 1EDH then exit(2); end; - remove("/tmp/raz-sys-dir/h"); + _ := remove("/tmp/raz-sys-dir/h"); i, err := info("/no/such/file"); if err >= 0 then exit(2); end; if openDir(ADR(d), "/tmp/raz-sys-dir") # 0 then exit(2); end; @@ -1094,7 +1094,7 @@ (* a socket: nothing at a path, then a listener that a connection makes ready, and a byte from it to the connection *) if connect("/tmp/raz-no-such-socket") # -2 then exit(2); end; (* ENOENT *) - remove("/tmp/raz-sys-socket"); + _ := remove("/tmp/raz-sys-socket"); l := listen("/tmp/raz-sys-socket"); if (l < 0) or (listen("/tmp/raz-sys-socket") # -98) then exit(2); end; (* EADDRINUSE: there already *) c := connect("/tmp/raz-sys-socket"); @@ -1109,7 +1109,7 @@ if send(c, "x") # -32 then exit(2); end; (* EPIPE, and no SIGPIPE *) close(c); close(l); - remove("/tmp/raz-sys-socket"); + _ := remove("/tmp/raz-sys-socket"); testPrograms; testNet; end; diff --git a/lib/Thread.linux-x86_64.raz b/lib/Thread.linux-x86_64.raz index e2e3020..08ee50e 100644 --- a/lib/Thread.linux-x86_64.raz +++ b/lib/Thread.linux-x86_64.raz @@ -76,7 +76,7 @@ begin t := ^Thread(arg); alt := {sp: ^U8(t) - Alt, size: Alt}; - SYSCALL(131, ADR(alt), 0); (* sigaltstack *) + _ := SYSCALL(131, ADR(alt), 0); (* sigaltstack *) t^.fn(t^.arg); end; @@ -114,7 +114,7 @@ tid := ADR(t^.tid); v := tid^; while v # 0 do - futex(ADR(t^.tid), FutexWait, v); + _ := futex(ADR(t^.tid), FutexWait, v); v := tid^; end; base := t^.base; @@ -129,7 +129,7 @@ if CAS(ADR(m^.state), 0, 1) then return; end; c := XCHG(ADR(m^.state), 2); while c # 0 do - futex(ADR(m^.state), FutexWait + Private, 2); + _ := futex(ADR(m^.state), FutexWait + Private, 2); c := XCHG(ADR(m^.state), 2); end; end; @@ -139,8 +139,8 @@ proc unlock*(m: ^Mutex); begin if XADD(ADR(m^.state), -1) # 1 then - XCHG(ADR(m^.state), 0); - futex(ADR(m^.state), FutexWake + Private, 1); + _ := XCHG(ADR(m^.state), 0); + _ := futex(ADR(m^.state), FutexWake + Private, 1); end; end; diff --git a/src/parse.pas b/src/parse.pas index 113c4aa..4c40d0e 100644 --- a/src/parse.pas +++ b/src/parse.pas @@ -91,6 +91,12 @@ stray: boolean; { an "end" in this procedure stood left of its statement's line } strayAt: TPos; { ... the first such statement } elseIf: boolean; { an "else if" in this procedure } + drops: array[0..4095] of record + at: TPos; { a call standing on its own that drops results } + n: longint; { ... how many } + end; + numDrops: longint; { the module being compiled has those from its + first one, saved by CompileFile, to here } ends: boolean; { the statements just read never go on past their end: each way through them returns } useAt: TPos; { ... which is here } @@ -105,6 +111,7 @@ { A missing symbol is reported just after the one before it. } procedure Expected(const what: shortstring); begin + if tok = sBlank then Mark('_ isn''t a name: it is the blank, which stands only left of :='); MarkAt(MissingPos, 'expected ' + what + ', found ' + Found); end; @@ -1497,22 +1504,31 @@ { a, b := f(x): the variables first, left to right, then the call; then each result to its variable, in order. } -procedure MultiAssign(var x: TItem; first: longint); -var d: array[0..15] of TItem; dn: array[0..15] of longint; y, z: TItem; n, i: longint; called: boolean; f: PObj; +procedure MultiAssign(var x: TItem; first: longint; blank: boolean); +var + d: array[0..15] of TItem; dn: array[0..15] of longint; blanks: array[0..15] of boolean; + y, z: TItem; n, i: longint; called: boolean; f: PObj; begin n := 0; d[0] := x; dn[0] := first; + blanks[0] := blank; repeat - NotReadOnly(d[n]); - Assignable(d[n], dn[n]); - Pin(d[n]); + if not blanks[n] then begin + NotReadOnly(d[n]); + Assignable(d[n], dn[n]); + Pin(d[n]); + end; inc(n); if tok <> sComma then break; if n > High(d) then Mark('more than ' + IntStr(High(d) + 1) + ' variables in one assignment'); Next; - dn[n] := id; - LeftSide(d[n], called); + blanks[n] := tok = sBlank; + if blanks[n] then Next + else begin + dn[n] := id; + LeftSide(d[n], called); + end; until false; Expect(sBecomes); Designator(y, called); @@ -1520,10 +1536,12 @@ MarkAt(y.pos, 'expected a call with ' + IntStr(n) + ' results'); f := y.typ^.fields; for i := 0 to n - 1 do begin - z := y; - Field(z, f); - CoerceExact(z, d[i].typ, 'several results go to variables of just their types'); - Assign(d[i], z); + if not blanks[i] then begin + z := y; + Field(z, f); + CoerceExact(z, d[i].typ, 'several results go to variables of just their types'); + Assign(d[i], z); + end; f := f^.next; end; end; @@ -1589,7 +1607,7 @@ Expression(y, x.typ); Assign(x, y); end else if tok = sComma then - MultiAssign(x, first) + MultiAssign(x, first, false) else if not called then begin if (x.mode = mProc) or ((x.mode in [mVar, mStack]) and (x.typ^.form = fProc)) then begin BeginCall(c, x); @@ -1598,7 +1616,27 @@ end else if tok = sEql then MarkHelp(x.pos, Subject(x, first) + ' isn''t a statement', 'assignment is written :=') else MarkAt(x.pos, Subject(x, first) + ' isn''t a statement'); - end else Discard(x); + end else begin + if (x.mode <> mNone) and (numDrops <= High(drops)) then begin + drops[numDrops].at := x.pos; + if x.typ^.tuple then drops[numDrops].n := x.typ^.len else drops[numDrops].n := 1; + inc(numDrops); + end; + Discard(x); + end; + end; + sBlank: begin + Next; + if tok = sComma then MultiAssign(x, 0, true) + else begin + Expect(sBecomes); + Expression(x, nil); + { evaluated and dropped: a single value is loaded, so that a + volatile one is read } + if (x.mode in [mType, mBuiltin, mNone, mCase]) or (x.mode <> mStr) and not IsAggregate(x.typ) then + Value(x); + Discard(x); + end; end; sIf: IfStatement(start, Indent); sWhile: WhileStatement(start, Indent); @@ -2225,19 +2263,38 @@ Help('if it must be there, call it _' + NameOf(o^.name)); end; +{ Warns of the call at p, which drops its n results } +procedure Dropped(const p: TPos; n: longint); +var s, blanks: shortstring; i: longint; +begin + s := Source(p); + i := Pos('(', s); + if i > 0 then s := copy(s, 1, i - 1); + blanks := '_'; + for i := 2 to n do blanks := blanks + ', _'; + if n = 1 then Warning(p, 'the result of ' + s + ' is dropped') + else Warning(p, 'the results of ' + s + ' are dropped'); + Help('if that is meant, write ' + blanks + ' := ' + s + '(...)'); +end; + { The warnings of module m, by where each declaration is: its own - declarations and its procedures' are two lists, each in order. The + declarations and its procedures' are two lists, each in order, and + firstDrop on are the calls that drop results. The instances of a generic module share its text, and so its warnings: only the first is warned of. } -procedure Warnings(m: PModule); -var a, b: PObj; n: PModule; +procedure Warnings(m: PModule; firstDrop: longint); +var a, b: PObj; n: PModule; i: longint; begin n := firstModule; while (n <> nil) and (n^.name <> m^.name) do n := n^.next; if n <> nil then exit; a := m^.first; b := m^.locals; - while (a <> nil) or (b <> nil) do - if (b = nil) or (a <> nil) and (a^.pos.a < b^.pos.a) then begin + i := firstDrop; + while (a <> nil) or (b <> nil) or (i < numDrops) do + 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 + Dropped(drops[i].at, drops[i].n); + inc(i); + end else if (b = nil) or (a <> nil) and (a^.pos.a < b^.pos.a) then begin Warn(a); a := a^.link; end else begin @@ -2268,8 +2325,9 @@ st: TScanState; saved: array[0..MaxDepth - 1] of longint; d: longint; oldMod: PModule; oldCheck, oldChecks: boolean; m: PModule; lib: PLib; start: TPos; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs; - generic: boolean; argsAt: TScanState; why: shortstring; + generic: boolean; argsAt: TScanState; why: shortstring; firstDrop: longint; begin + firstDrop := numDrops; SaveScan(st); SaveScopes(d, saved); oldMod := curModule; oldCheck := checkMode; oldPath := curFile; oldChecks := checks; @@ -2394,7 +2452,8 @@ if (o^.cls = oProc) and o^.fwd then Error(TokPos, NameOf(o^.name) + ' is declared forward but never defined'); o := o^.link; end; - if (errors = 0) and not checkOnly then Warnings(m); + if (errors = 0) and not checkOnly then Warnings(m, firstDrop); + numDrops := firstDrop; if errors > 0 then Finish; { a module with errors stops the compiler after it } CloseScope; m^.done := true; diff --git a/src/raz.pas b/src/raz.pas index 25d3b9e..d89610d 100644 --- a/src/raz.pas +++ b/src/raz.pas @@ -34,7 +34,7 @@ { what git describe says, made by make: 0.3.0 at the tag v0.3.0, 0.3.0-5-g38d29a8 five commits past it } Version = {$I version.inc}; - Report = '2026-10.13'; { the version of doc/raz.md it follows } + Report = '2026-10.14'; { the version of doc/raz.md it follows } MemfdCreate = 319; { the system call; FPC 3.2.2 has no name for it } MfdCloexec = 1; { an ELF still executes: the kernel opens it first } diff --git a/src/scan.pas b/src/scan.pas index 98e6964..f21408b 100644 --- a/src/scan.pas +++ b/src/scan.pas @@ -24,6 +24,7 @@ sPlus, sMinus, sTimes, sSlash, sEql, sNeq, sLss, sLeq, sGtr, sGeq, sBecomes, sColon, sSemicolon, sComma, sPeriod, sUpto, sEllipsis, sLparen, sRparen, sLbrak, sRbrak, sLbrace, sRbrace, sArrow, sAmp, sTilde, sBar, + sBlank, { the reserved words, in the order of Words below } sAnd, sBegin, sBreak, sBy, sCode, sConst, sDefer, sDiv, sDo, sElse, sElsif, sEnd, sExtern, sFor, sForward, sIf, sImport, sIn, sLink, @@ -106,10 +107,10 @@ 'in', 'link', 'match', 'mod', 'module', 'not', 'of', 'or', 'packed', 'proc', 'record', 'repeat', 'return', 'set', 'shl', 'shr', 'then', 'to', 'type', 'until', 'var', 'variant', 'VOLATILE', 'while', 'xor'); - Ops: array[sPlus..sBar] of string[3] = ( + Ops: array[sPlus..sBlank] of string[3] = ( '+', '-', '*', '/', '=', '#', '<', '<=', '>', '>=', ':=', ':', ';', ',', '.', '..', '...', - '(', ')', '[', ']', '{', '}', '^', '&', '~', '|'); + '(', ')', '[', ']', '{', '}', '^', '&', '~', '|', '_'); var cur: TScanState; { buf .. path; tok, ival, rval and id live above } @@ -311,7 +312,7 @@ { How an operator or reserved word is written, quoted, for messages. } function SymText(s: TSym): shortstring; begin - if s in [sPlus..sBar] then SymText := '"' + Ops[s] + '"' + if s in [sPlus..sBlank] then SymText := '"' + Ops[s] + '"' else SymText := '"' + Words[ord(s) - ord(sAnd)] + '"'; end; @@ -777,7 +778,8 @@ until not (cur.buf[cur.pos] in ['A'..'Z', 'a'..'z', '0'..'9', '_']); if cur.pos - start > MaxIdent then LexError('a name has at most ' + IntStr(MaxIdent) + ' characters'); h := Intern(@cur.buf[start], cur.pos - start); - if h < NumWords then tok := TSym(ord(sAnd) + h) + if (cur.pos - start = 1) and (c = '_') then tok := sBlank + else if h < NumWords then tok := TSym(ord(sAnd) + h) else begin tok := sIdent; id := h end; end; '0'..'9': Number; diff --git a/test/err/Dropped.args b/test/err/Dropped.args new file mode 100644 index 0000000..2f41be6 --- /dev/null +++ b/test/err/Dropped.args @@ -0,0 +1 @@ +-Werror diff --git a/test/err/Dropped.err b/test/err/Dropped.err new file mode 100644 index 0000000..4ac0a3d --- /dev/null +++ b/test/err/Dropped.err @@ -0,0 +1,9 @@ +test/err/Dropped.raz:9:5: error: the result of Sys.write is dropped + 9 | Sys.write(Sys.stdout, "a\n"); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: if that is meant, write _ := Sys.write(...) +test/err/Dropped.raz:10:5: error: the results of pair are dropped + 10 | pair(); + | ^^^^^^ +help: if that is meant, write _, _ := pair(...) +raz: 2 errors diff --git a/test/err/Dropped.raz b/test/err/Dropped.raz new file mode 100644 index 0000000..85a708a --- /dev/null +++ b/test/err/Dropped.raz @@ -0,0 +1,14 @@ +module Dropped; +import Sys; +proc pair: (I64, I64); +begin + return 1, 2; +end; +proc main*; +begin + Sys.write(Sys.stdout, "a\n"); + pair(); + _ := Sys.write(Sys.stdout, "b\n"); + _, _ := pair(); +end; +end Dropped. diff --git a/test/err/Static.raz b/test/err/Static.raz index 7d4272b..c034a29 100644 --- a/test/err/Static.raz +++ b/test/err/Static.raz @@ -3,7 +3,7 @@ proc main*; begin - C.printf("%d\n", Bare.f()); + _ := C.printf("%d\n", Bare.f()); end; end Static. diff --git a/test/msg/BlankName.err b/test/msg/BlankName.err new file mode 100644 index 0000000..4bbb239 --- /dev/null +++ b/test/msg/BlankName.err @@ -0,0 +1,4 @@ +conform/err/BlankName.raz:3:5: error: _ isn't a name: it is the blank, which stands only left of := + 3 | var _: I64; x: I64; + | ^ +raz: 1 error diff --git a/test/msg/BlankValue.err b/test/msg/BlankValue.err new file mode 100644 index 0000000..09b00ee --- /dev/null +++ b/test/msg/BlankValue.err @@ -0,0 +1,4 @@ +conform/err/BlankValue.raz:7:13: error: _ isn't a name: it is the blank, which stands only left of := + 7 | Out.int(_); + | ^ +raz: 1 error diff --git a/test/run/Extern.raz b/test/run/Extern.raz index cb47289..568ccee 100644 --- a/test/run/Extern.raz +++ b/test/run/Extern.raz @@ -46,7 +46,7 @@ 1, 2, 3, 4, 5, 6, 7, "eight", 3.14159, 0.5); Out.str(buf[0..I64(n)]); Out.ln; - setenv("RAZ_TEST", "yes", 1); + _ := setenv("RAZ_TEST", "yes", 1); Out.int(I64(strlen(getenv("RAZ_TEST")))); Out.ln; e := environ; i := 0; @@ -57,8 +57,8 @@ Out.int(I64(optind)); Out.ln; Out.flush; - C.printf("printf %d %s %.1f\n", -42, "too", 2.5); - C.fflush(C.stdout); + _ := C.printf("printf %d %s %.1f\n", -42, "too", 2.5); + _ := C.fflush(C.stdout); Out.str("done\n"); end; diff --git a/test/run/Results.raz b/test/run/Results.raz index f588c01..8cd791f 100644 --- a/test/run/Results.raz +++ b/test/run/Results.raz @@ -69,7 +69,7 @@ Out.int(a[1]); Out.str(" "); Out.int(g.b); Out.ln; q, r := minmax(9, 3); Out.int(q); Out.int(r); Out.ln; - divmod(1, 1); + _, _ := divmod(1, 1); i, e := nothing(); Out.int(i); if e = nil then Out.str(" zero"); end; Out.ln; i := 5; diff --git a/test/run/Single.raz b/test/run/Single.raz index 34349aa..57acc76 100644 --- a/test/run/Single.raz +++ b/test/run/Single.raz @@ -35,8 +35,8 @@ proc show(name: ^U8; x: F64); begin Out.flush; - C.printf("%s %.9g\n", name, x); - C.fflush(C.stdout); + _ := C.printf("%s %.9g\n", name, x); + _ := C.fflush(C.stdout); end; proc main*; @@ -77,8 +77,8 @@ show("mix", mix(1.5, 2, 0.25, 0.125)); for i := 0 to 3 do arr[i] := F32(i) * 0.5; end; show("arr", F64(arr[3])); - C.printf("%f %f\n", F64(arr[1]), 0.5); - C.fflush(C.stdout); + _ := C.printf("%f %f\n", F64(arr[1]), 0.5); + _ := C.fflush(C.stdout); end; end Single. diff --git a/test/run/Spawn.raz b/test/run/Spawn.raz index baba4b1..3d273fd 100644 --- a/test/run/Spawn.raz +++ b/test/run/Spawn.raz @@ -21,7 +21,7 @@ Thread.lock(ADR(m)); INC(count); Thread.unlock(ADR(m)); - XADD(ADR(atomic), 1); + _ := XADD(ADR(atomic), 1); NEW(p, Heap.heap); p^.next := list; list := p; diff --git a/test/run/ThreadOverflow.raz b/test/run/ThreadOverflow.raz index e2c345c..a499b0f 100644 --- a/test/run/ThreadOverflow.raz +++ b/test/run/ThreadOverflow.raz @@ -12,7 +12,7 @@ proc work(_arg: ^U8); begin - down(0); + _ := down(0); end; proc main*; diff --git a/tools/Doc.raz b/tools/Doc.raz index 1af4f69..5b8d89c 100644 --- a/tools/Doc.raz +++ b/tools/Doc.raz @@ -178,7 +178,7 @@ exp := name(); stop := toSemicolon(); next; - if is("forward") then toSemicolon(); + if is("forward") then _ := toSemicolon(); else skipBody; end; declaration("", exp, start, ds, de, stop); @@ -235,7 +235,7 @@ if is("const") or is("type") or is("var") then section; elsif is("proc") then procedure; elsif is("extern") then external; - elsif is("import") or is("link") then toSemicolon(); next; + elsif is("import") or is("link") then _ := toSemicolon(); next; else next; end; end; diff --git a/tools/Mutate.raz b/tools/Mutate.raz index 8d5b176..c6bcaa4 100644 --- a/tools/Mutate.raz +++ b/tools/Mutate.raz @@ -29,7 +29,7 @@ state := 88172645463325252; for i := 0 to LEN(s) - 1 do state := state * 31 + U64(s[i]); end; if state = 0 then state := 1; end; - for i := 1 to 10 do random(2); end; + for i := 1 to 10 do _ := random(2); end; end; (* The symbols that aren't comments. *)