gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gm2] equality, inequality tests and structured types


From: Andreas Fischlin
Subject: Re: [Gm2] equality, inequality tests and structured types
Date: Sun, 18 Jan 2009 14:03:57 +0100
User-agent: Thunderbird 2.0.0.19 (Macintosh/20081209)

Hi Gaius,

Gaius Mulley wrote:

snip
fortunately in the M2 ISO standard on p263 the section "6.9.3.2
Variable Parameter Compatibility" states very nearly the same:

"The formal type of a variable parameter shall be compatible with the
type of an actual variable if any of the following statements is true:

a)  The formal type is the address type and the actual type is any
pointer type.

  
snip
although interestingly (unless opaque types are covered the statement
(a) - which I doubt) it disallows opaque and ADDRESS parameter
compatibility.  [This can be easily turned on/off via -fiso, -fpim2,
-fpim3 and -fpim4 options]
  

I'm no sure I quite get what you are saying here. I believe the statement a) is quite appropriate. Indeed, I would expect this compatibility to be given in any good Modula-2 implementation. However, I see no reference there to opaque types. Do yo then mean what would be needed is another statement in the ISO standard, one that would cover also compatibility questions of opaque types in the case of variable proc parameters?

I have a pragmatic view here: I believe it is best to expect from a Modula-2 implementation to use type SYSTEM.ADDRESS for implementing opaque types. Then a coercion of the following kind (emphasized in red) is possible for any opaque type:

In high-level (user visible module) definition module:

  TYPE
    Matrix;

   
In the implementation of the high-level (user visible module):

  PROCEDURE DeclMatrix( VAR m: Matrix;
                        nRows, nCols: INTEGER;
                        name : ARRAY OF CHAR   );
    VAR theMat: MLBase.Matrix;
  BEGIN
    theMat := MLBase.Matrix( m );
    MLBase.DeclMatrix( theMat, nRows, nCols, name );
    m := Matrix( theMat );
  END DeclMatrix;
 
 
In low-level (internal) definition module:       
     
  TYPE
    Matrix = POINTER TO MatrixData; (* implementation of Matrices.Matrix *)
    MatrixData = RECORD
      ...
     
  PROCEDURE DeclMatrix( VAR m: Matrix;
                        nRows, nCols: INTEGER;
                        name : ARRAY OF CHAR   );
  BEGIN                       
      ...
      Allocate( m, SIZE(MatrixData) );


BTW, we use above technique in RAMES quite lots and I argue such constructs should be possible in any powerful Modula-2 implementation.

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

             Make it as simple as possible, but distrust it!
________________________________________________________________________
 

Attachment: andreas_fischlin.vcf
Description: Vcard


reply via email to

[Prev in Thread] Current Thread [Next in Thread]