John, &nbsp;I&#39;d write it like this<div><span class="Apple-style-span" style="border-collapse: collapse; "><br>who primFFICallResult: (Alien new: 8)</span></div><div><span class="Apple-style-span" style="border-collapse: collapse; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; floatParmsSignature:&nbsp;(ByteArray with: 8 with: 8)<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: alien1<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: alien2.</span><br></div><div><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></div><div><span class="Apple-style-span" style="border-collapse: collapse;">I&#39;d also modify the compiler so that, like VW, #[8 8] is a literal ByteArray equal to&nbsp;(ByteArray with: 8 with: 8).</span></div>
<div><br>If floatParmsSignature is nil that is equivalent to passing a ByteArray with all 0&#39;s.</div><div><br></div><div>I&#39;d also make sure that the signature byte array only has to be long enough, i.e. if there are more parameters than the signature byte array then their type is effectively 0.</div>
<div><br></div><div><br><div class="gmail_quote">On Thu, Dec 11, 2008 at 12:32 PM, John M McIntosh <span dir="ltr">&lt;<a href="mailto:johnmci@smalltalkconsulting.com">johnmci@smalltalkconsulting.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">For the very few folks that are working with Alien I&#39;m about to make a structural change that is<br>
needed to support floating point arguments on &nbsp;PowerPC.<br>
<br>
Because of how the os-x powerpc abi works we *do* need to know what type the parameters are<br>
in order to decide if that 32bit data item is a float or long, or if 64bit a long long or double. Parms are passed<br>
based on if they are Floating point or non-floating point.<br>
<br>
This is a bit of a pain because MacIntel users still can pass integer, float, long long, double without regard to<br>
typing, yet if they expect to run on PowerPC a bit more care and typing is required.<br>
<br>
In the example below the primFFICallResult:with:with: call has no idea if the alien 1 or alien 2 are<br>
long long or double.<br>
<br>
testCallingSquenceLongLong2<br>
 &nbsp; &nbsp; &nbsp; &nbsp;| alien1 alien2 result who |<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;alien1 := Alien newC: 8.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;alien2 := Alien newC: 8.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;alien1 signedLongLongAt: 1 put: 1.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;alien2 signedLongLongAt: 1 put: 42.<br>
er or is that<br>
 &nbsp; &nbsp; &nbsp; &nbsp;alien1 doubleAt: 1 put: 1.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;alien2 doubleAt: 1 put: 42.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;who := Alien lookup: &#39;ffiTestLongLong&#39; inLibrary: &#39;IA32ABI&#39;.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;result := who primFFICallResult: (Alien new: 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: alien1<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: alien2.<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;self should: [(result signedLongLongAt: 1) = (1+42)].<br>
 &nbsp; &nbsp; &nbsp; &nbsp;alien1 free.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;alien2 free.<br>
<br>
In talking to Eliot we feel this will become<br>
<br>
for Double<br>
who primFFICallResultWithFloatParms: (Alien new: 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: alien1<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: alien2.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: (ByteArray with: 8 with: 8)<br>
<br>
for Float<br>
<br>
who primFFICallResultWithFloatParms: (Alien new: 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: alien1<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: alien2.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: (ByteArray with: 4 with: 4)<br>
<br>
The last parm is a tag array that contains information about the size of the floating point object.<br>
<br>
Now in order to cheat a bit here we will allow you to say<br>
<br>
who primFFICallResult: (Alien new: 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: 1.0<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: 42.0.<br>
<br>
because we know the element being passed is a floating point squeak object so we will assume<br>
we should treat it as a Double parm. This of course won&#39;t work very well if you are dealing with a Float<br>
so you would need to use the<br>
<br>
who primFFICallResultWithFloatParms: (Alien new: 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: 1.0<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: 42.0.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: (ByteArray with: 4 with: 4)<br>
<br>
Remember if you do:<br>
<br>
who primFFICallResult: (Alien new: 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: oneParm<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: twoParm.<br>
<br>
where oneParm/twoParm is *usually* a float you really need to take care and say<br>
<br>
who primFFICallResult: (Alien new: 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: oneParm asFloat<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: twoParm asFloat.<br>
<br>
Lastly if you do<br>
<br>
who primFFICallResultWithFloatParms: (Alien new: 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: 1<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: 42.<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with: (ByteArray with: 4 with: 4)<br>
<br>
The we&#39;ll assume oneParm and twoParm are floats and not do any autoconversion if say you pass an<br>
integer and your results will be unexpected, or trigger an primitive failure.<br><font color="#888888">
<br>
--<br>
===========================================================================<br>
John M. McIntosh &lt;<a href="mailto:johnmci@smalltalkconsulting.com" target="_blank">johnmci@smalltalkconsulting.com</a>&gt;<br>
Corporate Smalltalk Consulting Ltd. &nbsp;<a href="http://www.smalltalkconsulting.com" target="_blank">http://www.smalltalkconsulting.com</a><br>
===========================================================================<br>
<br>
<br>
<br>
<br>
</font></blockquote></div><br></div>