<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Are opaque types always revealed eventually? Or only sometimes?<br>I'd like to generate structs and member references and not be adding offsets to pointers.<br>For method calls and record field references.<br>And, ugh, the GC data needs to be generated using "offsetof". But probably all we get is a bunch<br>of integers and no indication where the frontend got them from.. :(<br><br><br>Thanks,<br> - Jay<br><br><br><div><div id="SkyDrivePlaceholder"></div><hr id="stopSpelling">From: hosking@cs.purdue.edu<br>Date: Fri, 22 Mar 2013 03:08:04 -0500<br>To: jay.krell@cornell.edu<br>CC: m3devel@elegosoft.com<br>Subject: Re: [M3devel] layout of objects?<br><br><div><div>x>=0 means a known constant method offset at compile time.</div><div><div>Otherwise, offset must be loaded at run time.  This is needed for opaque types, where the offset cannot be computed at run time.  Given TYPE T <: U we can't know at compile time how many methods are defined between U and T so the offset cannot be a compile time constant.</div></div><div><br></div><div>On Mar 22, 2013, at 2:01 AM, Jay K <<a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a>> wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div class="ecxhmmessage" style="font-size:12pt;font-family:Calibri;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;"><div dir="ltr">Do you understand hereabouts m3front/src/exprs/MethodExpr.m3?<br><br><br>PROCEDURE Compile (p: P) =<br>  VAR<br>    x := ObjectType.MethodOffset (p.holder);<br>    method: Method.Info;<br>  BEGIN<br>    Type.Compile (p.object);<br>    Method.SplitX (p.method, method);<br><br>    Type.LoadInfo (p.object, M3RT.OTC_defaultMethods, addr := TRUE);<br>    IF (x >= 0) THEN<br>      INC (method.offset, x);<br>    ELSE (* runtime offset to methods *)<br>      Type.LoadInfo (p.holder, M3RT.OTC_methodOffset);<br>      CG.Index_bytes (Target.Byte);<br>    END;<br>    CG.Boost_alignment (Target.Address.align);<br>    CG.Load_indirect (CG.Type.Addr, method.offset, Target.Address.size);<br>    CG.Boost_alignment (Target.Address.align);<br>  END Compile;<br><br><br>"runtime offset to methods"?<br></div></div></blockquote><div><br></div><blockquote><div class="ecxhmmessage" style="font-size:12pt;font-family:Calibri;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;"><div dir="ltr">ObjectType.MethodOffset:<br><br>PROCEDURE MethodOffset (t: Type.T): INTEGER =<br>  VAR p := Confirm (t);<br>  BEGIN<br>    IF (p = NIL) THEN RETURN Unknown_w_magic END;<br>    GetOffsets (p, use_magic := TRUE);<br>    RETURN p.methodOffset;<br>  END MethodOffset;<br><br><br>PROCEDURE Confirm (t: Type.T): P =<br>  VAR info: Type.Info;<br>  BEGIN<br>    LOOP<br>      t := Type.CheckInfo (t, info);<br>      IF (info.class = Type.Class.Object) THEN<br>        RETURN t;<br>      ELSIF (info.class = Type.Class.Opaque) THEN<br>        t := Revelation.LookUp (t);<br>      ELSE<br>        RETURN NIL;<br>      END;<br>    END;<br>  END Confirm;<br><br><br>...<br><br><br><br> - Jay<br><br><br><br><br><br><div><div id="ecxSkyDrivePlaceholder"></div><hr id="ecxstopSpelling">Subject: Re: [M3devel] layout of objects?<br>From: <a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>Date: Fri, 22 Mar 2013 01:44:37 -0500<br>CC: <a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a>; <a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a><br>To: <a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a><br><br>Not quite.  I just checked RTAllocator.m3 and it is pointer to methods at offset 0, followed by fields.<div>Heap header is at -ADRSIZE(Header).</div><div>The type information in RT0 is used to initialize the object instances.<br><div><br><div><div>On Mar 22, 2013, at 1:34 AM, Dragiša Durić <<a href="mailto:dragisha@m3w.org">dragisha@m3w.org</a>> wrote:</div><br class="ecxApple-interchange-newline"><blockquote><div style="word-wrap:break-word;">It's not m3front, it's RT0.<div><br></div><div>First data field is at offset 0, and pointer to type information is at -BYTESIZE(POINTER). Type information records are specified in RT0.</div><div><br><div><div>On Mar 22, 2013, at 5:56 AM, Jay K wrote:</div><br class="ecxApple-interchange-newline"><blockquote><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;font-size:medium;"><div class="ecxhmmessage" style="font-size:12pt;font-family:Calibri;"><div dir="ltr">layout of objects?<br><br><br><br>How are Modula-3 objects layed out?<br>i.e. "OBJECT"/"METHODS"/"OVERRIDES"<br>I skimmed m3front and it wasn't obvious.<br><br><br><br>A common way for C++ "objects" to be layed out,<br>in the face of no RTTI and only single inheritance,<br>and virtual functions, is that a pointer to a record<br>of function pointers is first in the record.<br><br><br>Like this:<br><br><br>class Type<br>{<br>virtual void F1();<br>virtual void F2();<br>int data1;<br>int data2;<br>};<br><br><br>ends up lik more this:<br><br><br>struct TypeFunctions<br>{<br> void (*F1)(Type*);<br> void (*F2)(Type*);<br>};<br><br><br>struct Type<br>{<br>TypeFunctions* Functions; /* always first,<br>or at least a fixed offset, and located independent<br>of the size of the data; could also be at "-1" or such */.<br>int data1;<br>int data2;<br>};<br><br><br>Type* x;<br>x->F1();<br><br><br>=><br>x->Functions->F1(x);<br><br><br>Functions added in more derived types go at the end.<br>Ditto for data.<br>In the absence of multiple-inheritance and RTTI, it is simple and predictable.<br>(RTTI makes only small modifications.)<br><br><br>Looking through m3front, it wasn't at all obvious if it works this way.<br><br><br>I would like to declare something in C (or possibly C++, but not likely),<br>such that I might actually recognize the various low level operations<br>and "uncompile" it back to a typeful/typesafe form, like the above C++<br>to C transform.<br><br><br><br>I can't likely uncompile to C++ with virtual functions,<br>because the actual layout in C++ is not guaranteed.<br><br><br><br>Granted, I am being lazy.<br>I should/could compile some small samples.<br>But I might not get the entire story that way.<br><br><br><br>Thanks,<br>- Jay<br><br></div></div></span></blockquote></div><br></div></div></blockquote></div><br></div></div><br><br><div><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;font-size:medium;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;orphans:2;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;"><div style="word-wrap:break-word;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><div style="word-wrap:break-word;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><span class="ecxApple-style-span" style="border-collapse:separate;font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;orphans:2;white-space:normal;widows:2;word-spacing:0px;"><div><font class="ecxApple-style-span" color="#0000FF"><font class="ecxApple-style-span" face="Gill Sans"><span class="ecxApple-style-span" style="color:rgb(0, 0, 255);font-family:'Gill Sans';"><span class="ecxApple-style-span" style="color:rgb(0, 0, 255);font-family:'Gill Sans';">Antony Hosking</span></span></font></font><font class="ecxApple-style-span" face="Gill Sans"><span class="ecxApple-style-span" style="font-family:'Gill Sans';"><span class="ecxApple-style-span" style="font-family:'Gill Sans';"><span class="ecxApple-converted-space"> </span>|<span class="ecxApple-converted-space"> </span></span></span><span class="ecxApple-style-span" style="font-family:'Gill Sans';"><span class="ecxApple-style-span" style="font-family:'Gill Sans';">Associate Professor</span></span><span class="ecxApple-style-span" style="font-family:'Gill Sans';"><span class="ecxApple-style-span" style="font-family:'Gill Sans';"> | Computer Science | Purdue University</span></span></font></div><div><font class="ecxApple-style-span" face="GillSans-Light"><span class="ecxApple-style-span" style="font-family:GillSans-Light;">305 N. University Street | West Lafayette | IN 47907 | USA</span></font></div><div><font class="ecxApple-style-span" color="#0000FF" face="Gill Sans"><span class="ecxApple-style-span" style="color:rgb(0, 0, 255);font-family:'Gill Sans';"><span class="ecxApple-style-span" style="color:rgb(0, 0, 255);font-family:'Gill Sans';">Mobile</span></span></font><font class="ecxApple-style-span" face="GillSans-Light"><span class="ecxApple-style-span" style="font-family:GillSans-Light;"><span class="ecxApple-style-span" style="font-family:GillSans-Light;"><span class="ecxApple-converted-space"> </span>+1 765 427 5484</span></span></font></div></span></span></span></span></span></span></span></span></div></span></div></span></span></div></div></div></div></blockquote></div><br></div>                                       </div></body>
</html>