raz / commit 80585985

commit
80585985d026050bd1278667aa5974ac59627686
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
668e440b
Report 2026-10.26: a thaw for INT and I64; Sys's position, truncate, sync and infoOf; Opt.at

patch · log

4 files changed, +53 -70

PROPOSALS.md modified +0 -51

@@ -56,24 +56,6 @@
5656
5757 Met in tery's `aligned`, `(a + 7) & -8`.
5858
59-## INT and I64 in one expression
60-
61-An `INT` goes silently into an `I64` where it is assigned, passed or
62-returned (5.10), but not in an expression: with `n: INT` and `a: I64`,
63-`a + n` is an error, and must be `a + I64(n)`. A program whose numbers
64-are `I64`s, a file's size and position, a time, a Forth's cells, and
65-whose lengths and indexes are `INT`s, writes `I64(...)` and `INT(...)`
66-on line after line.
67-
68-The proposal: where one operand of an arithmetic operator or a
69-relation is an `INT` and the other an `I64` (or `UINT` and `U64`),
70-the `INT` is widened, as it would be by an assignment, and the result
71-is an `I64`; which, as the assignment's widening, loses nothing on
72-any target. The other way, an `I64` into an `INT`, stays written.
73-
74-Met in tery throughout: its cells are `I64`, and every slice of its
75-memory, every stack depth and every length is an `INT`.
76-
7759 ## Dividing 128 bits by 64
7860
7961 `Math.mul` gives the 128-bit product of two `U64`s; there is nothing
@@ -96,39 +78,6 @@
9678 program, so it could come with any release, not only a thaw.
9779
9880 Met in tery's `udivmod`, a loop of 64 rounds.
99-
100-## Sys: the position in a file, and its size
101-
102-`Sys.seek` moves to a position from a file's start or end, and says
103-the new one; nothing says where a file is without moving, nor makes a
104-file shorter. tery's `FILE-POSITION`, `FILE-SIZE` and `RESIZE-FILE`
105-make the system calls themselves, by their Linux numbers (`lseek`'s
106-`SEEK_CUR`, `ftruncate`), which is what `Sys` is there to keep out of
107-programs.
108-
109-The proposal, in `Sys`:
110-
111-```
112-proc position*(fd: INT): I64; (* where the next read or write is, or minus an errno *)
113-proc truncate*(fd: INT; size: I64): INT; (* the file made size bytes long *)
114-proc sync*(fd: INT): INT; (* what was written to it on the disk *)
115-```
116-
117-Each is a system call on Linux and a C call elsewhere, as the rest of
118-`Sys` is; they break no program.
119-
120-## Opt: where the operands are
121-
122-`Opt.operand` gives the operands one at a time, as slices; nothing
123-says where they are among the program's arguments. An interpreter
124-whose first operand is a script and the rest the script's own
125-arguments, as `tery file arg ...` or `sh script arg ...`, copies
126-each into an array of its own to hand them on.
127-
128-The proposal: `proc at*(p: ^Parser): INT;`, the number of the
129-argument `operand` would give next, after what options are left; so
130-that the arguments from there on are `Files.arg(i)` for `i` from
131-`at(p)` to `ARGC() - 1`, as they are. It breaks no program.
13281
13382 ## Inlining a procedure that only returns
13483

doc/raz-lib.md (history) modified +21 -3

@@ -11,7 +11,7 @@
1111 | Module | What |
1212 |---|---|
1313 | `Rt` | ending the program, `exit` and `atExit`; `stop`, which ends it with a message; `trace`, the calls under way; what the compiler's checks call when they fail |
14-| `Sys` | system calls: `open`, `openRead`, `create`, `read`, `write`, `seek`, `close`, `mmap`, `munmap`, `isTerminal`, `yield`, `exit`; files and directories, `rename`, `remove`, `removeDir`, `makeDir`, `chmod`, `symlink`, `readLink`, `info`, `openDir`, `nextEntry`, `closeDir`; the terminal, `rawMode`, `restoreMode`, `termSize`, `ready`; the environment, `env`, `workDir`, `setWorkDir`; programs, pipes and signals; time, `clock`, `now`, `sleep`; `random`; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and `Sys.raz` over the C library for the others |
14+| `Sys` | system calls: `open`, `openRead`, `create`, `read`, `write`, `seek`, `position`, `truncate`, `sync`, `close`, `mmap`, `munmap`, `isTerminal`, `yield`, `exit`; files and directories, `rename`, `remove`, `removeDir`, `makeDir`, `chmod`, `symlink`, `readLink`, `info`, `infoOf`, `openDir`, `nextEntry`, `closeDir`; the terminal, `rawMode`, `restoreMode`, `termSize`, `ready`; the environment, `env`, `workDir`, `setWorkDir`; programs, pipes and signals; time, `clock`, `now`, `sleep`; `random`; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and `Sys.raz` over the C library for the others |
1515 | `Out` | writing text and numbers to standard output, buffered; safe to call from several threads |
1616 | `C` | the parts of the C library the others use, and `printf`, `fflush`, `stdout`, `pthread_create`; a program that imports it uses C |
1717 | `Lock` | a lock for short sections, for C's threads and `Thread`'s alike |
@@ -193,6 +193,9 @@
193193 proc openRead*(path: []U8): INT; (* open(path, {reading}) *)
194194 proc create*(path: []U8): INT; (* open(path, {writing, creating, truncating}) *)
195195 proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64; (* the new position *)
196+proc position*(fd: INT): I64; (* where the next read or write is *)
197+proc truncate*(fd: INT; size: I64): INT; (* the file made size bytes long *)
198+proc sync*(fd: INT): INT; (* what was written to it, on the disk *)
196199 proc close*(fd: INT);
197200 proc isTerminal*(fd: INT): BOOL;
198201 proc mmap*(size: INT): ^U8; (* size bytes of zeroed memory, in whole pages; or nil *)
@@ -208,6 +211,7 @@
208211 proc symlink*(target, path: []U8): INT; (* path made a link to target *)
209212 proc readLink*(path: []U8): ([]U8, INT); (* what the link names, good until the next call *)
210213 proc info*(path: []U8): (Info, INT); (* following a symbolic link *)
214+proc infoOf*(fd: INT): (Info, INT); (* the open file's *)
211215 proc space*(path: []U8): (I64, I64, INT); (* the bytes free and in all on path's file system *)
212216
213217 proc openDir*(d: ^Dir; path: []U8): INT;
@@ -284,7 +288,12 @@
284288 own; `truncating` it to nothing; `appending`, each write going to its
285289 end, however other programs write it too. `seek` moves to `pos` from
286290 the start of the file, or from its end if `fromEnd`, where a negative
287-`pos` reads back from the end. `Info.mtime` is what a program checks
291+`pos` reads back from the end; `position` says where the file is,
292+without moving. `truncate` makes the file `size` bytes long, cutting
293+it or adding zeros, and leaves the position where it was. `sync`
294+returns once what was written to the file is on the disk, as a
295+program needs before it says a file is saved. `infoOf` is `info` of
296+an open file: its size is what it holds now, however it was written. `Info.mtime` is what a program checks
288297 to see whether a file changed under it; `Info.mode` holds the nine
289298 bits of `rwxrwxrwx`, and `chmod` sets them, 1EDH (755) for a program,
290299 1A4H (644) for data.
@@ -625,6 +634,7 @@
625634 proc init*(p: ^Parser; name: []U8; table: []Row); (* the arguments from 1 on, by table *)
626635 proc next*(p: ^Parser): BOOL; (* the next option; false when they end *)
627636 proc operand*(p: ^Parser): ([]U8, BOOL); (* the next operand; false when there are no more *)
637+proc at*(p: ^Parser): INT; (* the argument operand would give next *)
628638 proc scope*(p: ^Parser; name: []U8); (* subcommand name's options, from the word after it *)
629639 proc number*(p: ^Parser; lo, hi: I64): I64; (* the value just read, a number from lo to hi *)
630640 proc fail*(p: ^Parser; text: []U8); (* the program's own mistake *)
@@ -688,7 +698,15 @@
688698 - Each scope has its own options. An option given twice is read twice.
689699
690700 `number` reads the value as `Str.toInt` does. `operand` reads what
691-options are left first, and the program doesn't see them.
701+options are left first, and the program doesn't see them. So does
702+`at`, which says where the operands are: the arguments from `operand`'s
703+next on are `Files.arg(i)` for `i` from `at(p)` to `ARGC() - 1`, so
704+that an interpreter hands a script its arguments as they are:
705+
706+```
707+script, ok := Opt.operand(ADR(p)); (* tery file arg ... *)
708+first := Opt.at(ADR(p)); (* file's own arguments, from here on *)
709+```
692710
693711 `-h` or `--help` among a scope's options prints its help on standard
694712 output and ends the program with status 0. `init` and `scope` answer

doc/raz.md (history) modified +25 -16

@@ -13,7 +13,7 @@
1313 This report defines the language. It is short on purpose. Whatever it
1414 doesn't allow, raz doesn't have.
1515
16-This is version 2026-10.25 of the report; section 11 says where each
16+This is version 2026-10.26 of the report; section 11 says where each
1717 version's changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose,
1818 for a language anyone can build again. They break programs written
1919 for 2026-10.10 and before: for 2026-10.9, say, the report of compiler
@@ -22,7 +22,9 @@
2222 (section 7.8); it breaks a program that has a name `try`. 2026-10.25
2323 is a fourth, for strings: raw strings, which may run over lines
2424 and may be indented with the code around them (section 2), and
25-`match` on a string (section 7.4); it breaks no program.
25+`match` on a string (section 7.4); it breaks no program. 2026-10.26
26+is a fifth: an `INT` widens to an `I64` wherever it goes to one, in
27+an expression too (sections 5.10 and 6.1); it breaks no program.
2628
2729 The language is frozen, softly, from this version on: it changes only
2830 to mend a defect, and its library grows only by what breaks no program
@@ -418,8 +420,8 @@
418420 It is as big as an address, so it is the integer a pointer converts
419421 to (section 6.7), and a word the atomic built-ins work on (section
420422 6.8). `INT` and `I64` are two types, even where they have the same
421-size: an `INT` goes silently into an `I64` (section 5.10), but the two
422-don't mix in an expression (section 6.1), and an `I64` becomes an
423+size: an `INT` goes silently into an `I64` wherever it meets one, in
424+an expression too (sections 5.10 and 6.1), and an `I64` becomes an
423425 `INT` only by `INT(x)`, which may drop bits on a smaller target. A
424426 type bigger than the largest `INT` in bytes is an error.
425427
@@ -615,11 +617,14 @@
615617 Nothing else converts silently. In particular, there is no other
616618 conversion between integer types, between integers and reals, or
617619 between `F32` and `F64`, without a written conversion (section 6.7).
618-Results passed on whole need the same types exactly: in `a, b :=
619-f(x)` and in `return f(x)`, an `INT` result doesn't pass up as an
620-`I64`. Elsewhere, `return n, n` included, an `INT` widens as above; the
621-bounds of a `for` and the step of `INC` and `DEC` take the type of the
622-variable they work on, and an `INT` is not widened to it.
620+An `INT` widens to `I64`, and a `UINT` to `U64`, wherever its value
621+goes where an `I64` is wanted: in `a, b := f(x)` and `return f(x)` as
622+in any other assignment, to the bounds of a `for` and the step of
623+`INC` and `DEC` whose variable is an `I64`, and in an expression, where
624+it meets an `I64` (section 6.1). The types themselves stay two: a
625+`^INT` isn't a `^I64`, an `INT` variable isn't passed to a `var`
626+parameter of type `I64`, and a procedure returning an `INT` isn't of a
627+procedure type returning an `I64`.
623628
624629 ## 6. Expressions
625630
@@ -662,12 +667,15 @@
662667
663668 Both operands of `+ - * div mod & | xor`, and of a relation, have the
664669 same integer type, or one is an untyped constant that takes the
665-other's type, which it must fit. So do `v` and `k` in `INC(v, k)` and
666-`DEC(v, k)`. The result has that type and wraps around at its width:
670+other's type, which it must fit, or one is an `INT` and the other an
671+`I64` (a `UINT` and a `U64`), and the `INT` widens to `I64` (section
672+5.10). So do `v` and `k` in `INC(v, k)` and
673+`DEC(v, k)`, where only `k` widens: an `I64` `k` isn't added to an
674+`INT` `v`. The result has that type and wraps around at its width:
667675 in `U8`, `200 + 100` is `44`. A unary minus wraps too: for `x` of an
668-unsigned type, `-x` is `0 - x`. Two integer types are never mixed,
669-whatever their sizes: with `i: I64`, `i < LEN(s)` is an error, and
670-`i` should be an `INT`.
676+unsigned type, `-x` is `0 - x`. Other integer types are never mixed,
677+whatever their sizes: with `i: I32`, `i < LEN(s)` is an error, and
678+`i` should be an `INT`. With `pos: I64`, `pos + LEN(s)` is an `I64`.
671679
672680 Where the report asks for an integer and names no type, as an index, a
673681 slice's bound, a shift's count, a pointer's offset `i` in `p + i`, or
@@ -908,8 +916,9 @@
908916 integer or enumeration type, named by its name alone; `a` and then `b`
909917 are evaluated once, before the first round; `s` is a constant other
910918 than zero, and 1 if left out. `a` and `b` have `i`'s type, or are
911-untyped constants that take it, as with `+` (section 6.1): so in
912-`for i := 0 to LEN(s) - 1`, `i` must be an `INT`.
919+untyped constants that take it, or are `INT`s that widen to an `I64`
920+`i`, as with `+` (section 6.1): so in `for i := 0 to LEN(s) - 1`, `i`
921+is an `INT` or an `I64`.
913922
914923 The loop never steps past `b`, so `i` can't wrap: afterwards `i`
915924 holds the last value it took, or `a` if the body never ran. The body

doc/report-history.md (history) modified +7 -0

@@ -142,3 +142,10 @@
142142 `field`, `lower`, `upper`, `join`, `replace`, `decodeLast`,
143143 `next`, `valid`, `chars`, `toHex` and `fromInt`; `Math` gains
144144 `toReal` (volume 2).
145+- **2026-10.26.** A thaw, for `INT` and `I64`. An `INT` widens to an
146+ `I64`, and a `UINT` to a `U64`, wherever its value goes to one: in an
147+ expression, where it meets one, and in `a, b := f(x)`, `return
148+ f(x)`, a `for`'s bounds and the step of `INC` and `DEC` (sections
149+ 5.10, 6.1 and 7.2). It breaks no program. `Sys` gains `position`,
150+ `truncate`, `sync` and `infoOf`; `Opt` gains `at`, where the
151+ operands are (volume 2).