From 80585985d026050bd1278667aa5974ac59627686 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Thu, 15 Oct 2026 07:10:49 +0000 Subject: [PATCH] Report 2026-10.26: a thaw for INT and I64; Sys's position, truncate, sync and infoOf; Opt.at --- diff --git a/PROPOSALS.md b/PROPOSALS.md index bd067ad..78d2557 100644 --- a/PROPOSALS.md +++ b/PROPOSALS.md @@ -56,24 +56,6 @@ Met in tery's `aligned`, `(a + 7) & -8`. -## INT and I64 in one expression - -An `INT` goes silently into an `I64` where it is assigned, passed or -returned (5.10), but not in an expression: with `n: INT` and `a: I64`, -`a + n` is an error, and must be `a + I64(n)`. A program whose numbers -are `I64`s, a file's size and position, a time, a Forth's cells, and -whose lengths and indexes are `INT`s, writes `I64(...)` and `INT(...)` -on line after line. - -The proposal: where one operand of an arithmetic operator or a -relation is an `INT` and the other an `I64` (or `UINT` and `U64`), -the `INT` is widened, as it would be by an assignment, and the result -is an `I64`; which, as the assignment's widening, loses nothing on -any target. The other way, an `I64` into an `INT`, stays written. - -Met in tery throughout: its cells are `I64`, and every slice of its -memory, every stack depth and every length is an `INT`. - ## Dividing 128 bits by 64 `Math.mul` gives the 128-bit product of two `U64`s; there is nothing @@ -96,39 +78,6 @@ program, so it could come with any release, not only a thaw. Met in tery's `udivmod`, a loop of 64 rounds. - -## Sys: the position in a file, and its size - -`Sys.seek` moves to a position from a file's start or end, and says -the new one; nothing says where a file is without moving, nor makes a -file shorter. tery's `FILE-POSITION`, `FILE-SIZE` and `RESIZE-FILE` -make the system calls themselves, by their Linux numbers (`lseek`'s -`SEEK_CUR`, `ftruncate`), which is what `Sys` is there to keep out of -programs. - -The proposal, in `Sys`: - -``` -proc position*(fd: INT): I64; (* where the next read or write is, or minus an errno *) -proc truncate*(fd: INT; size: I64): INT; (* the file made size bytes long *) -proc sync*(fd: INT): INT; (* what was written to it on the disk *) -``` - -Each is a system call on Linux and a C call elsewhere, as the rest of -`Sys` is; they break no program. - -## Opt: where the operands are - -`Opt.operand` gives the operands one at a time, as slices; nothing -says where they are among the program's arguments. An interpreter -whose first operand is a script and the rest the script's own -arguments, as `tery file arg ...` or `sh script arg ...`, copies -each into an array of its own to hand them on. - -The proposal: `proc at*(p: ^Parser): INT;`, the number of the -argument `operand` would give next, after what options are left; so -that the arguments from there on are `Files.arg(i)` for `i` from -`at(p)` to `ARGC() - 1`, as they are. It breaks no program. ## Inlining a procedure that only returns diff --git a/doc/raz-lib.md b/doc/raz-lib.md index e30e1e1..df4e563 100644 --- a/doc/raz-lib.md +++ b/doc/raz-lib.md @@ -11,7 +11,7 @@ | Module | What | |---|---| | `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 | -| `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 | +| `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 | | `Out` | writing text and numbers to standard output, buffered; safe to call from several threads | | `C` | the parts of the C library the others use, and `printf`, `fflush`, `stdout`, `pthread_create`; a program that imports it uses C | | `Lock` | a lock for short sections, for C's threads and `Thread`'s alike | @@ -193,6 +193,9 @@ proc openRead*(path: []U8): INT; (* open(path, {reading}) *) proc create*(path: []U8): INT; (* open(path, {writing, creating, truncating}) *) proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64; (* the new position *) +proc position*(fd: INT): I64; (* where the next read or write is *) +proc truncate*(fd: INT; size: I64): INT; (* the file made size bytes long *) +proc sync*(fd: INT): INT; (* what was written to it, on the disk *) proc close*(fd: INT); proc isTerminal*(fd: INT): BOOL; proc mmap*(size: INT): ^U8; (* size bytes of zeroed memory, in whole pages; or nil *) @@ -208,6 +211,7 @@ proc symlink*(target, path: []U8): INT; (* path made a link to target *) proc readLink*(path: []U8): ([]U8, INT); (* what the link names, good until the next call *) proc info*(path: []U8): (Info, INT); (* following a symbolic link *) +proc infoOf*(fd: INT): (Info, INT); (* the open file's *) proc space*(path: []U8): (I64, I64, INT); (* the bytes free and in all on path's file system *) proc openDir*(d: ^Dir; path: []U8): INT; @@ -284,7 +288,12 @@ own; `truncating` it to nothing; `appending`, each write going to its end, however other programs write it too. `seek` moves to `pos` from the start of the file, or from its end if `fromEnd`, where a negative -`pos` reads back from the end. `Info.mtime` is what a program checks +`pos` reads back from the end; `position` says where the file is, +without moving. `truncate` makes the file `size` bytes long, cutting +it or adding zeros, and leaves the position where it was. `sync` +returns once what was written to the file is on the disk, as a +program needs before it says a file is saved. `infoOf` is `info` of +an open file: its size is what it holds now, however it was written. `Info.mtime` is what a program checks to see whether a file changed under it; `Info.mode` holds the nine bits of `rwxrwxrwx`, and `chmod` sets them, 1EDH (755) for a program, 1A4H (644) for data. @@ -625,6 +634,7 @@ proc init*(p: ^Parser; name: []U8; table: []Row); (* the arguments from 1 on, by table *) proc next*(p: ^Parser): BOOL; (* the next option; false when they end *) proc operand*(p: ^Parser): ([]U8, BOOL); (* the next operand; false when there are no more *) +proc at*(p: ^Parser): INT; (* the argument operand would give next *) proc scope*(p: ^Parser; name: []U8); (* subcommand name's options, from the word after it *) proc number*(p: ^Parser; lo, hi: I64): I64; (* the value just read, a number from lo to hi *) proc fail*(p: ^Parser; text: []U8); (* the program's own mistake *) @@ -688,7 +698,15 @@ - Each scope has its own options. An option given twice is read twice. `number` reads the value as `Str.toInt` does. `operand` reads what -options are left first, and the program doesn't see them. +options are left first, and the program doesn't see them. So does +`at`, which says where the operands are: the arguments from `operand`'s +next on are `Files.arg(i)` for `i` from `at(p)` to `ARGC() - 1`, so +that an interpreter hands a script its arguments as they are: + +``` +script, ok := Opt.operand(ADR(p)); (* tery file arg ... *) +first := Opt.at(ADR(p)); (* file's own arguments, from here on *) +``` `-h` or `--help` among a scope's options prints its help on standard output and ends the program with status 0. `init` and `scope` answer diff --git a/doc/raz.md b/doc/raz.md index 4f6e385..9892aaf 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -13,7 +13,7 @@ This report defines the language. It is short on purpose. Whatever it doesn't allow, raz doesn't have. -This is version 2026-10.25 of the report; section 11 says where each +This is version 2026-10.26 of the report; section 11 says where each version's changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler @@ -22,7 +22,9 @@ (section 7.8); it breaks a program that has a name `try`. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines and may be indented with the code around them (section 2), and -`match` on a string (section 7.4); it breaks no program. +`match` on a string (section 7.4); it breaks no program. 2026-10.26 +is a fifth: an `INT` widens to an `I64` wherever it goes to one, in +an expression too (sections 5.10 and 6.1); it breaks no program. The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program @@ -418,8 +420,8 @@ It is as big as an address, so it is the integer a pointer converts to (section 6.7), and a word the atomic built-ins work on (section 6.8). `INT` and `I64` are two types, even where they have the same -size: an `INT` goes silently into an `I64` (section 5.10), but the two -don't mix in an expression (section 6.1), and an `I64` becomes an +size: an `INT` goes silently into an `I64` wherever it meets one, in +an expression too (sections 5.10 and 6.1), and an `I64` becomes an `INT` only by `INT(x)`, which may drop bits on a smaller target. A type bigger than the largest `INT` in bytes is an error. @@ -615,11 +617,14 @@ Nothing else converts silently. In particular, there is no other conversion between integer types, between integers and reals, or between `F32` and `F64`, without a written conversion (section 6.7). -Results passed on whole need the same types exactly: in `a, b := -f(x)` and in `return f(x)`, an `INT` result doesn't pass up as an -`I64`. Elsewhere, `return n, n` included, an `INT` widens as above; the -bounds of a `for` and the step of `INC` and `DEC` take the type of the -variable they work on, and an `INT` is not widened to it. +An `INT` widens to `I64`, and a `UINT` to `U64`, wherever its value +goes where an `I64` is wanted: in `a, b := f(x)` and `return f(x)` as +in any other assignment, to the bounds of a `for` and the step of +`INC` and `DEC` whose variable is an `I64`, and in an expression, where +it meets an `I64` (section 6.1). The types themselves stay two: a +`^INT` isn't a `^I64`, an `INT` variable isn't passed to a `var` +parameter of type `I64`, and a procedure returning an `INT` isn't of a +procedure type returning an `I64`. ## 6. Expressions @@ -662,12 +667,15 @@ Both operands of `+ - * div mod & | xor`, and of a relation, have the same integer type, or one is an untyped constant that takes the -other's type, which it must fit. So do `v` and `k` in `INC(v, k)` and -`DEC(v, k)`. The result has that type and wraps around at its width: +other's type, which it must fit, or one is an `INT` and the other an +`I64` (a `UINT` and a `U64`), and the `INT` widens to `I64` (section +5.10). So do `v` and `k` in `INC(v, k)` and +`DEC(v, k)`, where only `k` widens: an `I64` `k` isn't added to an +`INT` `v`. The result has that type and wraps around at its width: in `U8`, `200 + 100` is `44`. A unary minus wraps too: for `x` of an -unsigned type, `-x` is `0 - x`. Two integer types are never mixed, -whatever their sizes: with `i: I64`, `i < LEN(s)` is an error, and -`i` should be an `INT`. +unsigned type, `-x` is `0 - x`. Other integer types are never mixed, +whatever their sizes: with `i: I32`, `i < LEN(s)` is an error, and +`i` should be an `INT`. With `pos: I64`, `pos + LEN(s)` is an `I64`. Where the report asks for an integer and names no type, as an index, a slice's bound, a shift's count, a pointer's offset `i` in `p + i`, or @@ -908,8 +916,9 @@ integer or enumeration type, named by its name alone; `a` and then `b` are evaluated once, before the first round; `s` is a constant other than zero, and 1 if left out. `a` and `b` have `i`'s type, or are -untyped constants that take it, as with `+` (section 6.1): so in -`for i := 0 to LEN(s) - 1`, `i` must be an `INT`. +untyped constants that take it, or are `INT`s that widen to an `I64` +`i`, as with `+` (section 6.1): so in `for i := 0 to LEN(s) - 1`, `i` +is an `INT` or an `I64`. The loop never steps past `b`, so `i` can't wrap: afterwards `i` holds the last value it took, or `a` if the body never ran. The body diff --git a/doc/report-history.md b/doc/report-history.md index ea80cec..7d3432f 100644 --- a/doc/report-history.md +++ b/doc/report-history.md @@ -142,3 +142,10 @@ `field`, `lower`, `upper`, `join`, `replace`, `decodeLast`, `next`, `valid`, `chars`, `toHex` and `fromInt`; `Math` gains `toReal` (volume 2). +- **2026-10.26.** A thaw, for `INT` and `I64`. An `INT` widens to an + `I64`, and a `UINT` to a `U64`, wherever its value goes to one: in an + expression, where it meets one, and in `a, b := f(x)`, `return + f(x)`, a `for`'s bounds and the step of `INC` and `DEC` (sections + 5.10, 6.1 and 7.2). It breaks no program. `Sys` gains `position`, + `truncate`, `sync` and `infoOf`; `Opt` gains `at`, where the + operands are (volume 2).