[M3devel] Compiling Modula-3 to C

Mika Nystrom mika at async.async.caltech.edu
Sun Apr 25 06:52:02 CEST 2010


Jay K writes:
>
>Agitation not necessarly inferred. :)
>
>
>Mika=2C the thing is.. consider "safety".
>I can argue..as a C programmer..I know what is safe=2C I don't
>need the language protection.
>Practise proves this is somewhat true=2C somewhat false.
>=A0=A0=20
>=A0
>Similar to your argument:
>=A0I know what is opaque=2C I don't need the language protection.
>
>=A0
>I don't think a comment declaring opacity is strong enough.

A little different.

C never lets you have safety.

Modula-3 gives you opacity.  You just can't have it at the same
time as stack allocation.  Same thing with anything else that
you only get with OBJECTs for that matter (e.g., dynamic method
dispatch).  You can't break through the opacity with a cast, either.

...
>
>I understand that C++ is a little bit complicated=2C with public/private/pr=
>otected=2C and friends.
>And C# has more options (visible to the assembly/.dll).
>I think at least one bit is worthwhile though.
>public or private.
>Public to all or nobody.
>I doubt new syntax would even be needed.
>Just like:
>
>foo.i3:
>TYPE Foo=3B
>or TYPE FooPublic =3D RECORD END=3B TYPE <: FooPublic=3B
>
>foo.m3
>=A0REVEAL Foo =3D RECORD ... END=3B
>

I think you'd just want fully opaque types.  Mixing in <: here seems
inappropriate.  <: has meaning for the abstract types (up till now),
whereas I can't figure out what it means for RECORDs.  If you want to
reveal fields you can always do it through a PROCEDURE that converts from
the opaque type to a visible type.

TYPE T = OPAQUE RECORD;

TYPE Visible = RECORD  ... END;

PROCEDURE MakeVisible(READONLY t : T) : Visible;

Then in the implementation all you have is

REVEAL T = RECORD ... END;

     Mika



More information about the M3devel mailing list