[squeak-dev] Re: [Vm-dev] Better VM <-> plugin API

Igor Stasenko siguctua at gmail.com
Fri Nov 21 21:43:41 UTC 2008


2008/11/21 Andreas Raab <andreas.raab at gmx.de>:
> Igor Stasenko wrote:
>>
>> I was pretty unhappy with some places in VM, where it loads a function
>> from plugin by calling ioLoadFunction...
>> Also, even more painful to see when one plugin wants to call another
>> plugin function.
>
> Why would it be advantageous to write:
>
>  static sqInt bitBlitAtom = makeAtom('ioBitBlt');
>  registerService(bitBlitAtom, (void*) bitBlt);
>  bitBltFn = getService(bitBlitAtom);
>
> instead of using
>
>  bitBltFn = ioLoadFunctionFrom("ioBitBlt", "BitBltPlugin");
>
> Is there any reason for making things even more lengthy than they are
> already?
>

First, you are statically associating functionality with specific
module ("ioBitBlt" in your example), while using atoms i don't care
which module may set it , i care only about specific functionality.
Second, with ioLoadFunctionFrom you can retrieve function, not
arbitrary value(s).
Third - you can change atom value dynamically , while
ioLoadFunctionFrom doomed to return same value all the time - null if
no module found or no such function in module , or function address on
success.
Fourth, there are many cases where i wouldn't want to expose functions
of my module directly (by exporting them), only indirectly.

> Cheers,
>  - Andreas
>
>> IMO things would be much better , if we formalize these things in VM.
>> An idea is simple and easy to implement:
>>
>> We need only few functions implemented in VM:
>>
>> sqInt makeAtom(char * name);  "registers new atom or returns id of
>> already existing one"
>>
>> sqInt registerService (sqInt atom, void * service);  "associate a
>> value with service id"
>> sqInt unregisterService(sqInt atom);  "clear association with service
>> id (make value=0)"
>>
>> And finally,
>>
>> void * getService(sqInt atom);
>>
>>
>> Now, plugins first, should declare the atoms they would want to use or
>> provide. This can be done once at plugin initialization stage, for
>> instance:
>>
>> static sqInt bitBlitAtom = makeAtom('ioBitBlt');
>>
>> Now, after acquiring atom, plugin can register a service fn under this
>> atom:
>>
>> registerService(bitBlitAtom, (void*) bitBlt);
>> and upon unloading
>> unregisterService(bitBlitAtom);
>>
>> now, any other plugin can do:
>>
>> bitBltFn = getService(bitBlitAtom);
>>
>> if (bitBltFn) { bitBltFn( a, b,c blabla); }
>>
>> VM maintains a simple list of atom values and list of atom names and
>> their numeric correspondence.
>> A getService(bitBlitAtom) is very fast, because its simple access by
>> index:
>>
>> getService(sqInt atom)
>> {
>> if (atom>=0 && atom<atomsCount)
>>   return atoms[atom];
>> return 0;
>> }
>>
>>
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list