| | @@ -1509,3 +1509,52 @@ |
| 1509 | 1509 | so a printed value can't be pasted into code (rayo). Writing `E` would |
| 1510 | 1510 | change output a test may compare; reading `e` too would change the |
| 1511 | 1511 | report. |
| 1512 | + |
| 1513 | +## Selectors after a `^T(e)` conversion |
| 1514 | + |
| 1515 | +A conversion through a pointer type's name is a designator, so |
| 1516 | +selectors follow it: with `PR = ^R` and `PU = ^U8`, `PR(ADR(r))^.b` |
| 1517 | +and `PU(ADR(r))[0..4]` compile today. The same conversion written out |
| 1518 | +is the grammar's own factor, `"^" ["VOLATILE"] Type "(" Expr ")"`, and |
| 1519 | +takes none: `^R(ADR(r))^.b` is "a conversion can't be dereferenced", |
| 1520 | +and `^U8(ADR(r))[0..4]` is "can't use ^U8 as []U8", the slice read as |
| 1521 | +part of the operand. So a program declares a pointer type, or a |
| 1522 | +variable, for one read through a C struct or one slice of raw memory. |
| 1523 | + |
| 1524 | +The proposal: that factor takes selectors, as a named conversion does. |
| 1525 | + |
| 1526 | + Factor = ... | "^" ["VOLATILE"] Type "(" Expr ")" { Selector } | ... |
| 1527 | + |
| 1528 | +`^U8(p)[0..n]` is a slice of `n` bytes from `p`; `^XMapEvent(ADR(ev))^.window` |
| 1529 | +is one field of an event. Nothing new is checked or left unchecked: the |
| 1530 | +selectors are a pointer's, as they are after `PU(p)`. A statement still |
| 1531 | +starts with a name or `try`, so `^T(x)^ := v` stays out (the report |
| 1532 | +says so already, and a view, `mem[a].(I64) := v`, writes it). What is |
| 1533 | +text with an error today gets a meaning, and nothing else changes. |
| 1534 | + |
| 1535 | +Met in znaczy, raudio, rcrypto and linia (the slice) and rx11 (the |
| 1536 | +dereference). |
| 1537 | + |
| 1538 | +## The limits of an integer type: `MIN(T)` and `MAX(T)` |
| 1539 | + |
| 1540 | +Programs write `7FFFFFFFFFFFFFFFH` for the largest `I64` and `-10^12` |
| 1541 | +for "below anything real", and nothing ties either to its type: change |
| 1542 | +a field from `I64` to `I32` and the constant still compiles, wrong. |
| 1543 | +Oberon has `MIN` and `MAX` of a basic type for this. |
| 1544 | + |
| 1545 | +The proposal: two built-in procedures, for an integer type `T` only: |
| 1546 | + |
| 1547 | +| Call | Result | |
| 1548 | +|---|---| |
| 1549 | +| `MIN(T)` | the smallest value of `T`, an untyped constant | |
| 1550 | +| `MAX(T)` | the largest value of `T`, an untyped constant | |
| 1551 | + |
| 1552 | +`MIN(U64)` is 0, `MAX(U64)` is 18446744073709551615, `MIN(I64)` is |
| 1553 | +-9223372036854775808, so the constants need the compiler's |
| 1554 | +`U64`-and-`I64` range, which constant folding already has. A name for |
| 1555 | +another type, an enumeration, a set or a real, is an error: an |
| 1556 | +enumeration has `LEN`-like answers of its own, and a real's limits |
| 1557 | +(an infinity, the largest finite) are a separate question. Two words |
| 1558 | +taken among the built-ins, which a program can't declare anyway. |
| 1559 | + |
| 1560 | +Met in mosaico, rfuzz and raudio. |