<br><br><div class="gmail_quote">On Tue, May 22, 2012 at 12:07 AM, Colin Putney <span dir="ltr">&lt;<a href="mailto:colin@wiresong.com" target="_blank">colin@wiresong.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Hi all,<div><br></div><div>I&#39;ve just uploaded a package to the Inbox for review by the community:</div><div><br></div><div><a href="http://source.squeak.org/inbox/Mirrors-cwp.2.mcz" target="_blank">http://source.squeak.org/inbox/Mirrors-cwp.2.mcz</a></div>
<div><br></div><div>It&#39;s a simple first step at creating a mirror API for Squeak. I&#39;ve only implemented ObjectMirror and ObjectVmMirror, which provide high- and low-level reflection on an object. This implementation has a twist, however: it sends no messages to the object it&#39;s reflecting. That allows us to reflect on network proxies, ORM stubs, mock objects and the like without triggering any state changes. </div>
<div><br></div><div>As a proof of the concept, I&#39;ve implemented a rudimentary non-invasive MirrorInspector. The main thing that&#39;s missing is non-invasive printing, which would take a bit of work to implement, but isn&#39;t necessary for a demo. To see it in action do try the following in a workspace.</div>
<div><br></div><div>WARNING: Read the comments carefully, and don&#39;t do this in an image you care about!</div><div><br></div><div><div><font face="Courier">&quot;This creates a very dangerous object&quot;</font></div><div>
<font face="Courier">Object subclass: #Nuke</font></div><div><font face="Courier"><span style="white-space:pre-wrap">        </span>instanceVariableNames: &#39;one two three&#39;</font></div><div><font face="Courier"><span style="white-space:pre-wrap">        </span>classVariableNames: &#39;&#39;</font></div>
<div><font face="Courier"><span style="white-space:pre-wrap">        </span>poolDictionaries: &#39;&#39;</font></div><div><font face="Courier"><span style="white-space:pre-wrap">        </span>category: &#39;Test&#39;.</font></div><div>
<font face="Courier">class := Smalltalk at: #Nuke.</font></div><div><font face="Courier">class superclass: nil.</font></div><div><font face="Courier">inst := class basicNew.</font></div><div><font face="Courier"><br></font></div>
<div><font face="Courier">&quot;This is harmless&quot;</font></div><div><font face="Courier">MirrorInspector inspect: inst.</font></div><div><font face="Courier"><br></font></div><div><font face="Courier">&quot;This will crash your image&quot;</font></div>
<div><font face="Courier">inst yourself.</font></div><div><font face="Courier"><br></font></div></div><div>The implementation uses primitive 188 to directly execute CompiledMethods with the reflected object as the receiver, thus giving us access to the object&#39;s state without sending it a message. </div>
</div></blockquote><div><br></div><div>In part you can use the light-weigth mirror methods in ContextPart, these take the object operated on as an argument.  Non-invasive printing could be done via execution simulation.  I&#39;ve already modified the Squeak debugger in Qwaq/Teleplace images to use these light-weight mirror primitives so that messages are not sent to receivers when simulating execution in the debugger (i.e. when doing send instead of step).  If the mirror primitives now work on the interpreter I can fold this into trunk.  David, do the mirror primitive tests pass on the interpreter?</div>
<div><br></div><div>Doing this is also a good idea in general since it allows the debugger to correctly debug proxies also.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><br></div><div>So, what do you think? </div><span class="HOEnZb"><font color="#888888"><div><br></div><div>Colin</div></font></span></div><br><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>