[squeak-dev] The Primitive: I am not a number- I am a named prim!
- SqueakPeople article
tim Rowledge
tim at rowledge.org
Tue Jul 1 20:34:47 UTC 2008
On 1-Jul-08, at 1:20 PM, Eliot Miranda wrote:
>
> One doesn't have to *use* the FFI. If the FFI isn't exposed via a
> primitive then no FFI. One can still have named primitives
> supported by the image and not by the VM and not use the FFI. To
> call a named primitive in a primitive plugin the following sequence
> occurs:
>
> the method containing a named primitive spec is activated and the
> primitive call fails because its function pointer is null.
> the failure code extracts the plugin name and invokes a primitive to
> load the plugin library
> the failure code extracts the primitive name and uses the lookup
> primitive to find the function in the loaded plugin library
> the failure code uses a primitive to slam the function pointer into
> the method
> the failure code uses the executeMethodWithArgs primitive to retry
> the bound named primitive method
>
> So the FFI is an optional extra. One needs four primitives, load
> library, lookup name in library, insert primitive function pointer.
> and executemethodWithArgs (thanks Tim!). Slamming the function into
> the method could also be done using, say, objectAt:.
>
> So one can still have a nice small safe VM and have no direct
> support for named primitives in the VM.
>
Leaving aside my like of all-named-prims, I *like* this enhancement to
the support for named prims.
It would slightly complicate the post-prim-call code in each method
because you would need to handle the failed-to-find-prim case as well
as all the prim-failed cases. It would be helped by an old idea that
I'm pretty sure eliot has plans for anyway (as indeed I have written
about a few times) to add primitive error return values. For those
that haven't heard of them, this is just a way of having the first
temp in a context involved in a prim call be a slot for a return value
from the prim if any error occurs. This means you can actually know
wtf went wrong instead of guessing - "ooh, was the first arg a
SmallInteger? Um, if not, was it a Float that might round nicley? Err,
was the second arg a ByteArray with the first byte = 255?" etc.
Instead you get "ah, errorValue was 1, so we have to explode the
reactor core in order to stop the Dreen from eating the children".
Much nicer.
tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
CITOKATE - Criticism is the Only Known Antidote to Error
More information about the Squeak-dev
mailing list
|