[M3devel] Oops, forgot to ask

Rodney M. Bates rodney_bates at lcwb.coop
Thu Dec 17 16:08:41 CET 2009



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
.

Gives these errors:

rodney at allegheny:~/proj/m3/exp/card/src$ cm3
--- building in ../AMD64_LINUX ---

new source -> compiling Card.m3
"../src/Card.m3", line 20: incompatible types (CPF)
"../src/Card.m3", line 21: incompatible types (DPF)
2 errors encountered
compilation failed => not building program "prog"
Fatal Error: package build failed









More information about the M3devel mailing list