Settle three readings of the report A named and an anonymous type built alike are the same, and a type declared as just a name is another name for it. A hex number above high(I64) is a U64, so -1 no longer fits a U64. A pointer to an array isn't indexed with p[i]; its elements are p^[i].
| @@ -54,6 +54,11 @@ | ||
| 54 | 54 | digit and ends in `H`. `1.5` and `2.0E-3` are reals; a real always has |
| 55 | 55 | a digit on both sides of its point. |
| 56 | 56 | |
| 57 | +An integer is an untyped constant, which takes the type it is used as, | |
| 58 | +up to the largest `I64`. A hexadecimal number above that, such as | |
| 59 | +`0FFFFFFFFFFFFFFFFH`, has type `U64`: so `-1` never fits a `U64`, and | |
| 60 | +the big number goes nowhere else without a conversion. | |
| 61 | + | |
| 57 | 62 | **Characters.** `'a'` is the code point of one character, an integer: |
| 58 | 63 | `'a'` is 97 and `'é'` is 233. |
| 59 | 64 | |
| @@ -342,7 +347,12 @@ | ||
| 342 | 347 | |
| 343 | 348 | Two named types are the same only if they are the same declaration. |
| 344 | 349 | Two anonymous types are the same if they are built alike: `^I64` is |
| 345 | -`^I64` wherever it is written. | |
| 350 | +`^I64` wherever it is written. A named and an anonymous type are the | |
| 351 | +same if the named one is built like the anonymous one, so that | |
| 352 | +`p := ADR(n)` works for `p: NodePtr` with `type NodePtr = ^Node`. | |
| 353 | + | |
| 354 | +A type declared with only a name on the right, `type Count = I64;`, is | |
| 355 | +another name for that type, not a new one. | |
| 346 | 356 | |
| 347 | 357 | A value of type `A` can be assigned to a variable of type `B` (and |
| 348 | 358 | passed to a parameter of type `B`, and returned as a `B`) if they are |
| @@ -422,7 +432,9 @@ | ||
| 422 | 432 | - `p - q`, with both of the same pointer type, is the number of |
| 423 | 433 | elements between them, an `I64`. |
| 424 | 434 | - `p[i]` is `(p + i)^`. `p[lo..hi]` is the slice of the `hi - lo` |
| 425 | - elements from `p + lo`. Neither is checked. | |
| 435 | + elements from `p + lo`. Neither is checked. A pointer to an array | |
| 436 | + isn't indexed this way, since a step would be a whole array: its | |
| 437 | + elements are `p^[i]`. | |
| 426 | 438 | - Pointers compare with `= # < <= > >=` as unsigned addresses. |
| 427 | 439 | Procedure values compare with `=` and `#` only. |
| 428 | 440 |
| @@ -463,6 +463,8 @@ | ||
| 463 | 463 | |
| 464 | 464 | procedure IndexPrep(var x: TItem); |
| 465 | 465 | begin |
| 466 | + if (x.typ^.form = fPtr) and (x.typ^.base^.form = fArray) then | |
| 467 | + Mark('a pointer to an array is indexed as p^[i]'); | |
| 466 | 468 | if x.typ^.form = fPtr then begin |
| 467 | 469 | Value(x); PushRax; x.mode := mStack |
| 468 | 470 | end else if (x.mode = mVar) and (x.typ^.form in [fArray, fSlice]) then |
| @@ -590,7 +590,11 @@ | ||
| 590 | 590 | var called, vol: boolean; t: PType; |
| 591 | 591 | begin |
| 592 | 592 | case tok of |
| 593 | - sInt, sChar: begin MakeConst(x, tConst, ival); Next end; | |
| 593 | + sInt, sChar: begin | |
| 594 | + { only a hex number can be above high(I64), and it is a U64 } | |
| 595 | + if ival < 0 then MakeConst(x, tU64, ival) else MakeConst(x, tConst, ival); | |
| 596 | + Next; | |
| 597 | + end; | |
| 594 | 598 | sReal: begin MakeReal(x, rval); Next end; |
| 595 | 599 | sString: begin MakeStr(x); Next end; |
| 596 | 600 | sIdent: begin |
| @@ -296,10 +296,7 @@ | ||
| 296 | 296 | else Fits := (v >= 0) and (v <= 65535); |
| 297 | 297 | 4: if t^.signed then Fits := (v >= -2147483648) and (v <= 2147483647) |
| 298 | 298 | else Fits := (v >= 0) and (v <= 4294967295); |
| 299 | - else | |
| 300 | - { an untyped constant is 64 bits; one with the top bit set came from | |
| 301 | - a hex literal, and stands for a U64 above high(I64) } | |
| 302 | - Fits := true; | |
| 299 | + else Fits := t^.signed or (v >= 0); | |
| 303 | 300 | end; |
| 304 | 301 | end; |
| 305 | 302 |
| @@ -0,0 +1 @@ | ||
| 1 | +can't use U64 as I64 |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module BigI64; | |
| 2 | +proc main*; | |
| 3 | +var i: I64; | |
| 4 | +begin | |
| 5 | + i := 0FFFFFFFFFFFFFFFFH; | |
| 6 | +end; | |
| 7 | +end BigI64. |
| @@ -0,0 +1 @@ | ||
| 1 | +constant doesn't fit U64 |
| @@ -0,0 +1,7 @@ | ||
| 1 | +module NegU64; | |
| 2 | +proc main*; | |
| 3 | +var u: U64; | |
| 4 | +begin | |
| 5 | + u := -1; | |
| 6 | +end; | |
| 7 | +end NegU64. |
| @@ -0,0 +1 @@ | ||
| 1 | +a pointer to an array is indexed as p^[i] |
| @@ -0,0 +1,8 @@ | ||
| 1 | +module PtrArray; | |
| 2 | +proc main*; | |
| 3 | +var a: [4]I64; p: ^[4]I64; | |
| 4 | +begin | |
| 5 | + p := ADR(a); | |
| 6 | + p[1] := 0; | |
| 7 | +end; | |
| 8 | +end PtrArray. |