vishapoberon / compiler

vishap oberon compiler
http://oberon.vishap.am
GNU General Public License v3.0
186 stars 25 forks source link

Files.WriteSet wrong type in SYSTEM.VAL #96

Closed kekcleader closed 2 years ago

kekcleader commented 3 years ago

Since SET is now 32-bit with -OC, this expression in FIles.Mod is no longer correct: SYSTEM.VAL(LONGINT, x), where x is of type SET. A compiler warning is generated during VOC runtime compilation process for -OC:

SYSTEM.VAL result includes memory past end of source variable; use SYSTEM.GET

The full procedure code:

PROCEDURE WriteSet* (VAR R: Rider; x: SET);
  VAR b: ARRAY 4 OF CHAR; i: LONGINT;
BEGIN i := SYSTEM.VAL(LONGINT, x); 
  b[0] := CHR(i); b[1] := CHR(i DIV 100H); b[2] := CHR(i DIV 10000H); b[3] := CHR(i DIV 1000000H);
  WriteBytes(R, b, 4); 
END WriteSet;
kekcleader commented 3 years ago

Suggested solution:

IF SIZE(SET) = SIZE(INTEGER) THEN i := SYSTEM.VAL(INTEGER, x)
ELSE i := SYSTEM.VAL(LONGINT, x)
END;
kekcleader commented 3 years ago

However, the previous suggested solution still produces a warning message.

This works with no warning messages:

PROCEDURE WriteSet* (VAR R: Rider; x: SET);
  VAR b: ARRAY 4 OF CHAR; i: LONGINT;
    y: SYSTEM.SET64;
BEGIN
  IF SIZE(SET) = SIZE(INTEGER) THEN i := SYSTEM.VAL(INTEGER, x)
  ELSE y := x; i := SYSTEM.VAL(LONGINT, y)
  END;
  b[0] := CHR(i); b[1] := CHR(i DIV 100H); b[2] := CHR(i DIV 10000H); b[3] := CHR(i DIV 1000000H);
  WriteBytes(R, b, 4)
END WriteSet;
norayr commented 2 years ago

thank you for reporting. this looks reasonable. never used -OC, Dave implemented it.

i already committed this.