[M3devel] layout of objects?

Tony Hosking hosking at cs.purdue.edu
Fri Mar 22 06:50:23 CET 2013


header
methods pointer
fields

If I recall correctly.

Sent from my iPad

On Mar 22, 2013, at 12:55 AM, Jay K <jay.krell at cornell.edu> wrote:

> layout of objects?
> 
> 
> 
> How are Modula-3 objects layed out?
> i.e. "OBJECT"/"METHODS"/"OVERRIDES"
> I skimmed m3front and it wasn't obvious.
> 
> 
> 
> A common way for C++ "objects" to be layed out,
> in the face of no RTTI and only single inheritance,
> and virtual functions, is that a pointer to a record
> of function pointers is first in the record.
> 
> 
> Like this:
> 
> 
> class Type
> {
> virtual void F1();
> virtual void F2();
> int data1;
> int data2;
> };
> 
> 
> ends up lik more this:
> 
> 
> struct TypeFunctions
> {
>  void (*F1)(Type*);
>  void (*F2)(Type*);
> };
> 
> 
> struct Type
> {
> TypeFunctions* Functions; /* always first,
> or at least a fixed offset, and located independent
> of the size of the data; could also be at "-1" or such */.
> int data1;
> int data2;
> };
> 
> 
> Type* x;
> x->F1();
> 
> 
> =>
> x->Functions->F1(x);
> 
> 
> Functions added in more derived types go at the end.
> Ditto for data.
> In the absence of multiple-inheritance and RTTI, it is simple and predictable.
> (RTTI makes only small modifications.)
> 
> 
> Looking through m3front, it wasn't at all obvious if it works this way.
> 
> 
> I would like to declare something in C (or possibly C++, but not likely),
> such that I might actually recognize the various low level operations
> and "uncompile" it back to a typeful/typesafe form, like the above C++
> to C transform.
> 
> 
> 
> I can't likely uncompile to C++ with virtual functions,
> because the actual layout in C++ is not guaranteed.
> 
> 
> 
> Granted, I am being lazy.
> I should/could compile some small samples.
> But I might not get the entire story that way.
> 
> 
> 
> Thanks,
> - Jay
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20130322/5f8a41ee/attachment-0002.html>


More information about the M3devel mailing list