[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophi
From: |
Fischlin Andreas |
Subject: |
Re: [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference) |
Date: |
Sun, 13 Nov 2011 23:24:01 +0000 |
Dear Gaius,
> Hi Andreas,
>
> overlapping variant tag values, for example:
>
> TYPE
> mytag = [0..4] ;
>
> foo = RECORD
> CASE :mytag OF
>
> 0..2: x: INTEGER |
> 1..4: y: CARDINAL
>
> END
> END ;
>
> should gm2 complain that the two tag ranges overlap? [*]
for all what I know above is illegal, a plain syntax error (multiple defined
cases). Perhaps what is intended should be defined similar to this
MODULE TstCase;
TYPE
Mystruct = RECORD
CASE c:CARDINAL OF
0,2: x: INTEGER; |
1,3..4: y: CARDINAL; |
END;
END(*RECORD*);
VAR
x: Mystruct;
TYPE
Myenum = (a, b, c, d);
Mystruct2 = RECORD
CASE e:Myenum OF
a..b: x: INTEGER; |
c..d: y: CARDINAL; |
END;
END(*RECORD*);
VAR
y: Mystruct2;
BEGIN
x.c := 4; x.x := 77;
y.e := b; y.y := 88;
END TstCase.
Regards,
Andreas
ETH Zurich
Prof. Dr. Andreas Fischlin
Systems Ecology - Institute of Integrative Biology
CHN E 21.1
Universitaetstrasse 16
8092 Zurich
SWITZERLAND
address@hidden
www.sysecol.ethz.ch
+41 44 633-6090 phone
+41 44 633-1136 fax
+41 79 221-4657 mobile
Make it as simple as possible, but distrust it!
________________________________________________________________________
On 13/11/2011, at 15:47 , Gaius Mulley wrote:
> "Fischlin Andreas" <address@hidden> writes:
>
>> Dear Gaius,
>>
>> What exactly do you mean by overlap? You mean memory allocation
>
>
> Hi Andreas,
>
> overlapping variant tag values, for example:
>
> TYPE
> mytag = [0..4] ;
>
> foo = RECORD
> CASE :mytag OF
>
> 0..2: x: INTEGER |
> 1..4: y: CARDINAL
>
> END
> END ;
>
> should gm2 complain that the two tag ranges overlap? [*]
>
>
>> including alignment in memory or ambiguous case selection? The latter
>
> yes I was referring to ambiguous case selection - ok yes it will be
> flagged as such! [*]
>
>> is clearly an error, the first should be possible or you defy lots of
>> legacy code, especially PIM code (and I know thousands and thousands
>> lines of such code ;-) ). For PIM code the assumption is that the
>
> indeed alignment overlap is very necessary for many applications.
>
>> compiler allocates memory for the largest variant (unless requested
>> otherwise with a construct such as TSIZE(T(t1)) used as parameter with
>> ALLOCATE (not NEW)). Alignment in memory is done without gaps,
>> assuming a byte addressing machine, meaning that the shortest variant
>> of the record wastes the most memory. Today such memory waste is not
>> very costly and if a user is concerned about this, he/she could
>> program different records from the very beginning, instead of a case
>> variant (or use ALLOCATE(p, TSIZE(T(tmin))) and make sure she never
>> changes the case during use of a given memory block). So the
>> programmer has full control over this anyway.
>>
>> BTW, to illustrate this, some code excerpt of a little routine that
>> depends heavily on coercion made possible through case variant records
>> and that support greatly portable programing among platforms. We use
>> this to determine big vs. little endianess and consequently all REAL
>> to string conversions in an endianess independent manner.
>>
>> PROCEDURE MachineIsBigEndian(): BOOLEAN;
>> TYPE
>> LongIntVar = RECORD
>> CASE :BOOLEAN OF
>> TRUE : c : LONGCARD;
>> | FALSE: b : ARRAY [1..4] OF CHAR; (* assumes TSIZE(CHAR) =
>> TSIZE(BYTE) *)
>> END;
>> END;
>> VAR int : LongIntVar; one: CHAR;
>> BEGIN (* MachineIsBigEndian *)
>> int.c := 1; one := 01C;
>> IF (int.b[4] = one) THEN
>> (* test whether really big endian *)
>> IF (int.b[1] <> 0C) OR (int.b[2] <> 0C) OR (int.b[3] <> 0C) THEN
>> (* middle endian, should not occur *)
>> HALTOnMachineDependency("Portab","MachineIsBigEndian","Unsupported
>> architecture encountered (middle endian?)");
>> END(*IF*);
>> ELSE
>> (* test whether really little endian *)
>> IF (int.b[2] <> 0C) OR (int.b[3] <> 0C) OR (int.b[4] <> 0C) THEN
>> (* middle endian, should not occur *)
>> HALTOnMachineDependency("Portab","MachineIsBigEndian","Unsupported
>> architecture encountered (middle endian?)");
>> END(*IF*);
>> END(*IF*);
>> RETURN (int.b[4] = one)
>> END MachineIsBigEndian;
>>
>> If in memory int.c would not overlap with int.b the entire algorithm
>> would completely fail. BTW, I believe a Modula-2 compiler not
>> supporting such an overlap would be pretty much useless and AFAIK to
>> loads of legacy Modula-2 code (and ISO too).
>
> yes I totally agree - network protocol implementation is also made
> slightly cleaner with this feature.
>
> regards,
> Gaius
>
>>
>> Regards,
>> Andreas
- [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), Fischlin Andreas, 2011/11/11
- Re: [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), john o goyo, 2011/11/11
- Re: [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), Gary E Rudy, 2011/11/12
- Re: [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), Gaius Mulley, 2011/11/13
- Re: [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), john o goyo, 2011/11/13
- Re: [Gm2] CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), Manfred Hollstein, 2011/11/13
- Re: [Gm2] CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), john o goyo, 2011/11/13
- Re: [Gm2] CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), Gaius Mulley, 2011/11/13
- Re: [Gm2] CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference) (CVS fixes), Gaius Mulley, 2011/11/16
- Message not available
- Message not available
- Re: [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference),
Fischlin Andreas <=
- Re: [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), Gaius Mulley, 2011/11/16
- Re: [Gm2] Fwd: CASE: gm2-4.1.2 of 2011-11-08 bug (or possibly philosophical difference), Fischlin Andreas, 2011/11/16