[M3devel] [modula3/cm3] Packed set literal generation issue (#21)

JC Chu jcchu at acm.org
Sun Sep 24 14:04:28 CEST 2017


> Are you aware that the BITS 32 here has no effect on the size of the global variable?

Yes.  I was looking for a bit set type that’s guaranteed to have the same representation as some integer type, such as BITS BITSIZE(INTEGER) FOR [0..-1 + BITSIZE(INTEGER)] for INTEGER.  But that guarantee doesn’t seem to exist, according to the language definition.  Seems like the correct way is to use Word interface (but then Long (the corresponding interface for LONGINT) doesn’t seem to be usable).

— JC

From: Rodney M. Bates [mailto:notifications at github.com]
Sent: Wednesday, September 20, 2017 5:35
To: modula3/cm3 <cm3 at noreply.github.com>
Cc: jcchu <jcchu at acm.org>; Author <author at noreply.github.com>
Subject: Re: [modula3/cm3] Packed set literal generation issue (#21)

Fixed on github, commit 12f50b4cde746056b943bd8aaa105c3fcb46b1a8

Deleted the assertion, which is neither true nor needed.

But see below:

On 09/16/2017 11:54 PM, jcchu wrote:
> See the fragment below.
>
> VAR r := SET OF [0..31] { 0 }; (* OK *)
> s := BITS 32 FOR SET OF [0..31] { 0 }; (* -- assertion failure in “SetExpr.m3” *)

Are you aware that the BITS 32 here has no effect on the size of the global variable?

Quoting from 2.2.5, Packed types:

TYPE T = BITS n FOR Base

where Base is a type and n is an integer-valued constant expression.
The values of type T are the same as the values of type Base, but variables of type T
that occur in records, objects, or arrays
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
will occupy exactly n bits and be packed adjacent to the preceding field or element.

s is not inside a record, object, or array, so the BITS specification has no effect on
the memory allocated by the compiler.

There are, however some more obscure differences:

1) Although T and BITS n FOR T are are assignable to each other,
BITS n FOR T and BITS m FOR T, (n#m) have no subtype or assignability
relationship, so to assign one to the other would require two assignment
steps, with a T as the intermediate type.

2) Anywhere type equality, as opposed to assignability, is required, T and
BITS n FOR T will not match. For example, you cannot pass one of these to
the other as a VAR parameter.





>
>> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub <https://github.com/modula3/cm3/issues/21>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AGVctFuGQY2yHbHNLupX6pnu4MVJDlXgks5sjKYMgaJpZM4PaCl5>.
>


—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<https://github.com/modula3/cm3/issues/21#issuecomment-330680504>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AK3PNMFBPWWpfK3zQpmt8ebPZbPlaBQ6ks5skDOIgaJpZM4PaCl5>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20170924/e44e91a6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 332 bytes
Desc: image001.jpg
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20170924/e44e91a6/attachment.jpg>


More information about the M3devel mailing list