[M3devel] Oops, forgot to ask

Tony Hosking hosking at cs.purdue.edu
Thu Dec 17 17:12:26 CET 2009


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20091217/e9ca9ccb/attachment-0002.html>


More information about the M3devel mailing list