[M3devel] LOOPHOLE and open array types

Rodney M. Bates rodney_bates at lcwb.coop
Fri Jun 25 00:03:55 CEST 2010


The language definition says:
-------------------------------------------------------------------
An unchecked type transfer operation has the form:

     LOOPHOLE(e, T)

where e is an expression whose type is not an open array type and
T is a type.  It denotes e's bit pattern interpreted as a
variable or value of type T.  It is a designator if e is, and is
writable if e is.  An unchecked runtime error can occur if e's
bit pattern is not a legal T, or if e is a designator and some
legal bit pattern for T is not legal for e.

If T is not an open array type, BITSIZE(e) must equal
BITSIZE(T).  If T is an open array type, its element type must
not be an open array type, and e's bit pattern is interpreted as an
array whose length is BITSIZE(e) divided by BITSIZE(the element
type of T).  The division must come out even.
-------------------------------------------------------------------

Is there any reason not to allow e to have an open array type
*if* T is an open array type?  Element size of T would have to
evenly divide element size of e, to avoid runtime checks.

Other rules being the same, this would allow, e.g.:

PROCEDURE FromCtypes_chars (F: ARRAY OF Ctypes.char): TEXT

= BEGIN
     RETURN Text.FromChars(LOOPHOLE(F, ARRAY OF CHAR))
   END FromCtypes_chars

It would take a bit more implementation to handle the RT size of
e, but there is already the capability to produce a result value
of open array type.  The only difference would be the element
count would be element count of e times a constant instead of
just a constant.



More information about the M3devel mailing list