From f4ab7cf63f45cd7de908d62e337340b7a1e08302 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sat, 10 Oct 2026 08:13:07 +0000 Subject: [PATCH] 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]. --- diff --git a/doc/jed.md b/doc/jed.md index c68b0d9..247375a 100644 --- a/doc/jed.md +++ b/doc/jed.md @@ -54,6 +54,11 @@ digit and ends in `H`. `1.5` and `2.0E-3` are reals; a real always has a digit on both sides of its point. +An integer is an untyped constant, which takes the type it is used as, +up to the largest `I64`. A hexadecimal number above that, such as +`0FFFFFFFFFFFFFFFFH`, has type `U64`: so `-1` never fits a `U64`, and +the big number goes nowhere else without a conversion. + **Characters.** `'a'` is the code point of one character, an integer: `'a'` is 97 and `'é'` is 233. @@ -342,7 +347,12 @@ Two named types are the same only if they are the same declaration. Two anonymous types are the same if they are built alike: `^I64` is -`^I64` wherever it is written. +`^I64` wherever it is written. A named and an anonymous type are the +same if the named one is built like the anonymous one, so that +`p := ADR(n)` works for `p: NodePtr` with `type NodePtr = ^Node`. + +A type declared with only a name on the right, `type Count = I64;`, is +another name for that type, not a new one. A value of type `A` can be assigned to a variable of type `B` (and passed to a parameter of type `B`, and returned as a `B`) if they are @@ -422,7 +432,9 @@ - `p - q`, with both of the same pointer type, is the number of elements between them, an `I64`. - `p[i]` is `(p + i)^`. `p[lo..hi]` is the slice of the `hi - lo` - elements from `p + lo`. Neither is checked. + elements from `p + lo`. Neither is checked. A pointer to an array + isn't indexed this way, since a step would be a whole array: its + elements are `p^[i]`. - Pointers compare with `= # < <= > >=` as unsigned addresses. Procedure values compare with `=` and `#` only. diff --git a/src/gen.pas b/src/gen.pas index be5f78d..1e59770 100644 --- a/src/gen.pas +++ b/src/gen.pas @@ -463,6 +463,8 @@ procedure IndexPrep(var x: TItem); begin + if (x.typ^.form = fPtr) and (x.typ^.base^.form = fArray) then + Mark('a pointer to an array is indexed as p^[i]'); if x.typ^.form = fPtr then begin Value(x); PushRax; x.mode := mStack end else if (x.mode = mVar) and (x.typ^.form in [fArray, fSlice]) then diff --git a/src/parse.pas b/src/parse.pas index 20ff6ae..d452264 100644 --- a/src/parse.pas +++ b/src/parse.pas @@ -590,7 +590,11 @@ var called, vol: boolean; t: PType; begin case tok of - sInt, sChar: begin MakeConst(x, tConst, ival); Next end; + sInt, sChar: begin + { only a hex number can be above high(I64), and it is a U64 } + if ival < 0 then MakeConst(x, tU64, ival) else MakeConst(x, tConst, ival); + Next; + end; sReal: begin MakeReal(x, rval); Next end; sString: begin MakeStr(x); Next end; sIdent: begin diff --git a/src/sym.pas b/src/sym.pas index 44b5799..e7d044c 100644 --- a/src/sym.pas +++ b/src/sym.pas @@ -296,10 +296,7 @@ else Fits := (v >= 0) and (v <= 65535); 4: if t^.signed then Fits := (v >= -2147483648) and (v <= 2147483647) else Fits := (v >= 0) and (v <= 4294967295); - else - { an untyped constant is 64 bits; one with the top bit set came from - a hex literal, and stands for a U64 above high(I64) } - Fits := true; + else Fits := t^.signed or (v >= 0); end; end; diff --git a/test/err/BigI64.err b/test/err/BigI64.err new file mode 100644 index 0000000..ae5d055 --- /dev/null +++ b/test/err/BigI64.err @@ -0,0 +1 @@ +can't use U64 as I64 diff --git a/test/err/BigI64.jed b/test/err/BigI64.jed new file mode 100644 index 0000000..19aacef --- /dev/null +++ b/test/err/BigI64.jed @@ -0,0 +1,7 @@ +module BigI64; +proc main*; +var i: I64; +begin + i := 0FFFFFFFFFFFFFFFFH; +end; +end BigI64. diff --git a/test/err/NegU64.err b/test/err/NegU64.err new file mode 100644 index 0000000..53be09c --- /dev/null +++ b/test/err/NegU64.err @@ -0,0 +1 @@ +constant doesn't fit U64 diff --git a/test/err/NegU64.jed b/test/err/NegU64.jed new file mode 100644 index 0000000..867c83b --- /dev/null +++ b/test/err/NegU64.jed @@ -0,0 +1,7 @@ +module NegU64; +proc main*; +var u: U64; +begin + u := -1; +end; +end NegU64. diff --git a/test/err/PtrArray.err b/test/err/PtrArray.err new file mode 100644 index 0000000..80ec6ba --- /dev/null +++ b/test/err/PtrArray.err @@ -0,0 +1 @@ +a pointer to an array is indexed as p^[i] diff --git a/test/err/PtrArray.jed b/test/err/PtrArray.jed new file mode 100644 index 0000000..17a91e7 --- /dev/null +++ b/test/err/PtrArray.jed @@ -0,0 +1,8 @@ +module PtrArray; +proc main*; +var a: [4]I64; p: ^[4]I64; +begin + p := ADR(a); + p[1] := 0; +end; +end PtrArray.