<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><p style="font-family: Times; "><div style="font-family: Helvetica; ">From the language spec:</div><div><br></div></p><p style="font-family: Times; ">There are two kinds of revelations, <em>partial</em> and <em>complete</em>. A program can contain any number of partial revelations for an opaque type; it must contain exactly one complete revelation.</p>
<br><div><div>Are you typing the method table as an array?</div><div>Why not simply index the array?</div><div><br></div><div>I don’t think there is any C type that natively captures the notion of opaque types.</div><div>The whole point is that you don’t know all the parent types.</div><div>But you do know that, given the offset of the opaque type’s methods in the method table, you can compute the offset of any given method.</div><div><br></div><div>For example:</div><div><br></div><div>TYPE T <: U;</div><div><br></div><div>Without seeing the revelation of T there is no way to know what methods are inherited from everything between T and U.</div><div>But, so long as at run time you are told the method offset of T’s methods in its method table then you can find any method defined in T at a known index from that offset.</div><div><br></div><div>On Mar 22, 2013, at 2:18 PM, Jay <<a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div dir="auto"><div>Can it have zero revelations?</div><div><br></div><div><br></div><div>Can you assist lazy me and suggest an accurate way to describe opaque types in a typeful way in C? </div><div><br></div><div><br></div><div>Ultimate goal would be to get m3front & m3back optionally out of the business of computing offsets, instead using C structs and members and pointers and leave layout to the C compiler.</div><div>Ultimately generating one architecture-independent, pointer-size-independent C.</div><div><br></div><div><br></div><div> I understand there are multiple challenges here and eventually m3cg and m3front will need changes, to pass down more higher level information.<br><br><br> - Jay</div><div><br>On Mar 22, 2013, at 11:11 AM, Tony Hosking <<a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a>> wrote:<br><br></div><blockquote type="cite"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>Every opaque type in a linkage must have only one revelation.<br><br>Sent from my iPad</div><div><br>On Mar 22, 2013, at 12:13 PM, Jay K <<a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a>> wrote:<br><br></div><blockquote type="cite">
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style>
<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: <a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>Date: Fri, 22 Mar 2013 03:08:04 -0500<br>To: <a href="mailto:jay.krell@cornell.edu">jay.krell@cornell.edu</a><br>CC: <a href="mailto:m3devel@elegosoft.com">m3devel@elegosoft.com</a><br>Subject: Re: [M3devel] layout of objects?<br><br><div><div>x>=0 means a known constant method offset at compile time.</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><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>
</blockquote></blockquote></div></blockquote></div><br></body></html>