[M3devel] computing a typeid in backend for a pointer to a declared type??
Hendrik Boom
hendrik at topoi.pooq.com
Sun Apr 7 20:37:46 CEST 2013
On Sun, Apr 07, 2013 at 11:02:51AM -0500, Rodney M. Bates wrote:
>
>
> On 04/07/2013 12:56 AM, Jay K wrote:
> >In the C backend, I would like to share code for records and objects.
> >
> >
> >As I understand, objects are always pointers.
>
> Yes.
>
> >
> >
> >In my framework, I map typeids to type information.
> >
> >
> >For this to work, given an object, I need to declare both a record
> >and a pointer to it. I need two typeids for that.
> >
> >
> >I'm in the position where I need to compute a typeid.
> >Is that feasible?
> >
> >
> >
> >I have two choices if I can't do that:
> >
> >
> > 1) map from strings instead, where the strings tend to be
> > a string form of a typeid, but where I can make up other forms;
> > quite an inefficiency
> >
> >
> > 1b) have two maps maybe
> >
> >
> >
> > 2) build a flag into my record data that indicates "record or object"
>
> FWIW, I believe it is true that every way of using an object type in Modula-3
> implicitly and uniquely identifies whether it works on the pointer or the
> heap object. For example, := and = mean the pointer, while any use of . implies
> dereferencing. There is no whole-object assignment or whole-object comparison,
> as there are for REF RECORD (which has two types).
>
> Maybe this distinction is lost in the lowering that happens by the time M3C gets it,
> or later.
I this matter Modula 3 is very different from C++, which idenntifies
classes wiith structure types. It even treats struct and class as
equivalent keywords. That was a big mistake in C++, and
results in pathological behavior when assigning class
values instead of class pointers.
-- hendrik
k
More information about the M3devel
mailing list