<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 6 January 2014 18:30, Eliot Miranda <span dir="ltr">&lt;<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br><div dir="ltr">Hi All,<div><br></div><div>    I&#39;m just revising plugin treatment in Spur and came across this old snippet of mysterious code:</div>
<div><br></div><div>InterpreterSimulator&gt;&gt;loadNewPlugin: pluginString</div>
<div><span style="white-space:pre-wrap">        </span>| plugin simClass |</div><div><span style="white-space:pre-wrap">        </span>transcript cr; show:&#39;Looking for module &#39;, pluginString.</div><div><span style="white-space:pre-wrap">        </span>(#(&#39;FloatArrayPlugin&#39; &#39;Matrix2x3Plugin&#39;)</div>

<div><span style="white-space:pre-wrap">                </span>includes: pluginString) ifTrue:</div><div><span style="white-space:pre-wrap">                </span>[transcript show: &#39; ... defeated&#39;. ^ nil].</div><div><br></div></div></blockquote>
<div>rofl, my applauds to anyone who wrote this code :)<br><br></div><div>Sadly (or happily), except from this little comment there not much i can offer right now,<br></div><div>and have to shut up and vanish in a puff of smoke :)<br>
</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>In the past I got as far as rewriting it to read...</div>

<div><br></div><div>InterpreterSimulator&gt;&gt;loadNewPlugin: pluginString<div><span style="white-space:pre-wrap">        </span>| plugin plugins simulatorClasses |</div><div><span style="white-space:pre-wrap">        </span>transcript cr; show: &#39;Looking for module &#39;, pluginString.</div>

<div><span style="white-space:pre-wrap">        </span>&quot;but *why*??&quot;</div><div><span style="white-space:pre-wrap">        </span>(#(&#39;FloatArrayPlugin&#39; &#39;Matrix2x3Plugin&#39;) includes: pluginString) ifTrue:</div>
<div><span style="white-space:pre-wrap">                </span>[transcript show: &#39; ... defeated&#39;. ^nil].</div><div><span style="white-space:pre-wrap">        </span>plugins := InterpreterPlugin allSubclasses select: [:psc| psc moduleName asString = pluginString asString].</div>

<div><br></div><div>In revising the code for Spur I removed the defeat code and found out more.  It&#39;s essentially because the BalloonPlugin has difficulty simulating accesses of 32-bit floats.  If you simply defeat the code and let things run soon you get failures in FloatArrayPlugin &amp; Matrix2x3Plugin primitives.  These can be fixed by implementing the following in the FloatArrayPlugin &amp; Matrix2x3Plugin:</div>

<div><br></div><div>cCoerce: value to: cType</div><div><span style="white-space:pre-wrap">        </span>^cType = &#39;float&#39;</div><div><span style="white-space:pre-wrap">                </span>ifTrue: [value asIEEE32BitWord]</div>
<div><span style="white-space:pre-wrap">                </span>ifFalse: [value]</div><div><br></div><div>But soon you hit more difficult failures in the BalloonEnginePlugin, e.g. in </div><div><div><br></div><div>BalloonEngineBase&gt;&gt;transformPointX: xValue y: yValue into: dstPoint</div>

<div><span style="white-space:pre-wrap">        </span>&quot;Transform srcPoint into dstPoint by using the currently loaded matrix&quot;</div><div><span style="white-space:pre-wrap">        </span>&quot;Note: This should be rewritten so that inlining works (e.g., removing</div>

<div><span style="white-space:pre-wrap">        </span>the declarations and adding argument coercions at the appropriate points)&quot;</div><div><span style="white-space:pre-wrap">        </span>| x y transform |</div><div><span style="white-space:pre-wrap">        </span>&lt;inline: true&gt;</div>

<div><span style="white-space:pre-wrap">        </span>&lt;var: #dstPoint type:&#39;int *&#39;&gt;</div><div><span style="white-space:pre-wrap">        </span>&lt;var: #xValue type: &#39;double &#39;&gt;</div><div><span style="white-space:pre-wrap">        </span>&lt;var: #yValue type: &#39;double &#39;&gt;</div>

<div><span style="white-space:pre-wrap">        </span>&lt;var: #transform type:&#39;float *&#39;&gt;</div><div><span style="white-space:pre-wrap">        </span>transform := self edgeTransform.</div><div><span style="white-space:pre-wrap">        </span>x := ((((transform at: 0) * xValue) +</div>

<div><span style="white-space:pre-wrap">                </span>((transform at: 1) * yValue) +</div><div><span style="white-space:pre-wrap">                </span>(transform at: 2)) * self aaLevelGet asFloat) asInteger.</div><div><span style="white-space:pre-wrap">        </span>y := ((((transform at: 3) * xValue) +</div>

<div><span style="white-space:pre-wrap">                </span>((transform at: 4) * yValue) +</div><div><span style="white-space:pre-wrap">                </span>(transform at: 5)) * self aaLevelGet asFloat) asInteger.</div><div><span style="white-space:pre-wrap">        </span>dstPoint at: 0 put: x.</div>

<div><span style="white-space:pre-wrap">        </span>dstPoint at: 1 put: y.</div></div><div><br></div><div>where x and y end up being the integer representation of 64-bit floats while dstPoint accepts the integer representation of 32-bit floats.  At least I think that&#39;s what&#39;s going on.</div>

<div><br></div><div>In any case I need to focus on Spur and can&#39;t spare the time to fix this.  But I find it unsatisfactory.  It means the VM simulation isn&#39;t accurate.  In the simulation the primitives fail and Smalltalk code is run.  In the real VM the primitives work.  And that&#39;s deeply unsatisfying.</div>

<div><br></div><div>So if there&#39;s anyone itching for a VM challenge try and make the BalloonEnginePlugin, FloatArrayPlugin &amp; Matrix2x3Plugin primitives simulate correctly, removing the defeat code above.  That would be a great new year&#39;s gift.</div>

<div>-- <br>best,<div>Eliot</div>
</div></div></div>
<br></blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Igor Stasenko.
</div></div>