[M3devel] Oops, forgot to ask

Rodney M. Bates rodney_bates at lcwb.coop
Thu Dec 17 22:29:00 CET 2009


The only one I know of is if you want to a pickle or network object
with a long field that is nonnegative, but you want its size to be converted
between different native word sizes when reading the pickles.

Tony Hosking wrote:
> Aha!  Thanks Rodney.  Do we have any use-cases for LONGCARD?
> 
> On 17 Dec 2009, at 10:08, Rodney M. Bates wrote:
> 
>>
>>
>> Tony Hosking wrote:
>>> This does not make sense:
>>> Here is the compiler's definition of the builtin CARDINAL type:
>>> MODULE Card;
>>> IMPORT SubrangeType, Target, TInt, Tipe, Int;
>>> PROCEDURE Initialize () =
>>>  BEGIN
>>>    T := SubrangeType.New (TInt.Zero, Target.Integer.max, Int.T, TRUE);
>>
>> CARDINAL is builtin -----------------------------------------------^
>>
>>>    Tipe.Define ("CARDINAL", T, TRUE);
>>>  END Initialize;
>>> BEGIN
>>> END Card.
>>> Notice that it is a subrange type [0..LAST(INTEGER)].
>>> Antony Hosking | Associate Professor | Computer Science | Purdue 
>>> University
>>> 305 N. University Street | West Lafayette | IN 47907 | USA
>>> Office +1 765 494 6001 | Mobile +1 765 427 5484
>>
>> And from MODULE SubrangeType:
>>
>> ....
>>
>> PROCEDURE EqualChk (a: P;  t: Type.T;  x: Type.Assumption): BOOLEAN =
>>  VAR b: P := t;
>>  BEGIN
>>    Seal (a);  Seal (b);
>>    RETURN (a.builtin = b.builtin)
>>
>>            ^ --- builtin property must be the same for type equality
>>
>>       AND TInt.EQ (a.min, b.min)
>>       AND TInt.EQ (a.max, b.max)
>>       AND Type.IsEqual (a.baseType, b.baseType, x);
>>  END EqualChk;
>>
>> ...
>>
>> PROCEDURE Parse (): Type.T =
>>  TYPE TK = Token.T;
>>  VAR p: P := New (TInt.Zero, TInt.MOne, NIL, FALSE);
>>
>> Programmer-defined subrange is not builtin -- ^
>>
>>  BEGIN
>>    Match (TK.tLBRACKET);
>>    p.minE := Expr.Parse ();
>>    Match (TK.tDOTDOT);
>>    p.maxE := Expr.Parse ();
>>    Match (TK.tRBRACKET);
>>    RETURN p;
>>  END Parse;
>>
>> This program:
>>
>> MODULE Card EXPORTS Main
>>
>> ; TYPE C = CARDINAL
>> ; TYPE D = [ 0 .. LAST ( INTEGER ) ]
>>
>> ; PROCEDURE DP ( VAR DPF : D )
>>  = BEGIN
>>      DPF := 0
>>    END DP
>> ; PROCEDURE CP ( VAR CPF : C )
>>  = BEGIN
>>      CPF := 0
>>    END CP
>>
>> ; PROCEDURE Try ( )
>>  = VAR CV : C
>>  ; VAR DV : D
>>  ; BEGIN
>>      CP ( CV )
>>    ; CP ( DV )            <--- line 20
>>    ; DP ( CV )
>>    ; DP ( DV )
>>    END Try
>>
>> ; BEGIN
>>    Try ( )
>>  END Card
> 



More information about the M3devel mailing list