[Openmcl-devel] How do I make a cocoa method that returns a float

Anders Conradi beque at telia.com
Tue Feb 22 06:46:11 PST 2005

On tisdag, feb 22, 2005, at 00:32 Europe/Stockholm, Dan Knapp wrote:

>> How do I implement cocoa methods that return floats? I
>   It's not implemented yet - I ran into this a little while
> ago.  For now, you should probably just reconsider whether
> you really need to.  And I should make sure it's documented...

I need that float return since I am overriding a method that returns a 
Anyway, it is more fun to at least try to implement it first.

I dug into the internals of OpenMCL to see what is going on.
When I do defcallback the callback body is wrapped inside a lambda that 
takes a mac-ptr and places the result of the body into that ptr. Then 
the named lambda and some auxiliary information is wrapped into a pfe 
vector. The pfe vector is added to %pascal-functions%. Then a 
trampoline is created. The trampoline is some ppc-code that calls the 
subprim .SPcallback with the index to the pfe vector. When the callback 
is called the trampoline is called and it calls the subprim. The 
subprim must call the lambda containing the callback body with a 
mac-ptr for the result. Then it places the result into gpr3 and returns 
to the foreign code. My hope is that it would be easy to hack the 
subprim to also place the result into fpr1, which is used to return 
floating point values. Since fpr1 isn't preserved across function calls 
this shouldn't break code that wants integer results.

I am sure that I have underestimated the difficulty and missed 
something. I don't even know PPC assembly, but by adding one line to 
spentry.s and rebuilding the kernel my callback test seems to return 
the correct value. Unfortunately callbacks can't recieve floats and 
still can't return doubles.

Well, anyway here it is.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: spentry.patch
Type: application/octet-stream
Size: 569 bytes
Desc: not available
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20050222/3a879eee/attachment.obj>
-------------- next part --------------

> -- Dan Knapp
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list