[Oberon] PO2013 compiler and SET operations

Michael Schierl schierlm at gmx.de
Wed Jul 29 17:08:14 CEST 2020


Hello,


Today I stumbled over some oddity when trying to mask bits out of
INTEGERs via SET operations.

Consider this short example module:

MODULE X;

  IMPORT SYSTEM;

  PROCEDURE SetDiff(a, b:SET): SET;
  BEGIN
  RETURN a - b
  END SetDiff;

  PROCEDURE Mask1(a, b: INTEGER): INTEGER;
  BEGIN
  RETURN SYSTEM.VAL(INTEGER, SetDiff(SYSTEM.VAL(SET, a), {b .. b + 7}))
  END Mask1;

  PROCEDURE Mask2(a, b: INTEGER): INTEGER;
  BEGIN
  RETURN SYSTEM.VAL(INTEGER, SYSTEM.VAL(SET, a) - {b .. b + 7})
  END Mask2;


  PROCEDURE Test1*;
  BEGIN
  ASSERT(Mask1(12345678H, 8) = 12340078H);
  END Test1;

  PROCEDURE Test2*;
  BEGIN
  ASSERT(Mask2(12345678H, 8) = 12340078H);
  END Test2;
END X.


My expectation would be that both Mask1 and Mask2 perform the same
operation, and therefore both ASSERTs hold. Yet Mask2 returns 0 instead
of 12340078H.

Tested with both the original PO2013 compiler and Andreas' Extended
Oberon compiler.


Any explanation?


Regards,


Michael


More information about the Oberon mailing list