raz / commit f4ab7cf6

commit
f4ab7cf63f45cd7de908d62e337340b7a1e08302
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
53eb79f6
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].

patch · log

10 files changed, +47 -7

doc/jed.md modified +14 -2

@@ -54,6 +54,11 @@
5454 digit and ends in `H`. `1.5` and `2.0E-3` are reals; a real always has
5555 a digit on both sides of its point.
5656
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+
5762 **Characters.** `'a'` is the code point of one character, an integer:
5863 `'a'` is 97 and `'é'` is 233.
5964
@@ -342,7 +347,12 @@
342347
343348 Two named types are the same only if they are the same declaration.
344349 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.
346356
347357 A value of type `A` can be assigned to a variable of type `B` (and
348358 passed to a parameter of type `B`, and returned as a `B`) if they are
@@ -422,7 +432,9 @@
422432 - `p - q`, with both of the same pointer type, is the number of
423433 elements between them, an `I64`.
424434 - `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]`.
426438 - Pointers compare with `= # < <= > >=` as unsigned addresses.
427439 Procedure values compare with `=` and `#` only.
428440

src/gen.pas modified +2 -0

@@ -463,6 +463,8 @@
463463
464464 procedure IndexPrep(var x: TItem);
465465 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]');
466468 if x.typ^.form = fPtr then begin
467469 Value(x); PushRax; x.mode := mStack
468470 end else if (x.mode = mVar) and (x.typ^.form in [fArray, fSlice]) then

src/parse.pas modified +5 -1

@@ -590,7 +590,11 @@
590590 var called, vol: boolean; t: PType;
591591 begin
592592 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;
594598 sReal: begin MakeReal(x, rval); Next end;
595599 sString: begin MakeStr(x); Next end;
596600 sIdent: begin

src/sym.pas modified +1 -4

@@ -296,10 +296,7 @@
296296 else Fits := (v >= 0) and (v <= 65535);
297297 4: if t^.signed then Fits := (v >= -2147483648) and (v <= 2147483647)
298298 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);
303300 end;
304301 end;
305302

test/err/BigI64.err added +1 -0

@@ -0,0 +1 @@
1+can't use U64 as I64

test/err/BigI64.jed added +7 -0

@@ -0,0 +1,7 @@
1+module BigI64;
2+proc main*;
3+var i: I64;
4+begin
5+ i := 0FFFFFFFFFFFFFFFFH;
6+end;
7+end BigI64.

test/err/NegU64.err added +1 -0

@@ -0,0 +1 @@
1+constant doesn't fit U64

test/err/NegU64.jed added +7 -0

@@ -0,0 +1,7 @@
1+module NegU64;
2+proc main*;
3+var u: U64;
4+begin
5+ u := -1;
6+end;
7+end NegU64.

test/err/PtrArray.err added +1 -0

@@ -0,0 +1 @@
1+a pointer to an array is indexed as p^[i]

test/err/PtrArray.jed added +8 -0

@@ -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.