Calling functions by name?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling functions by name?

Carl E Gundel-2
Can Dolphin Smalltalk call API and DLL functions by name the way that VSE
does?

Thanks,

-Carl
------------------------------------------------------------------
 Carl Gundel  [hidden email]  Shoptalk Systems
 author of Liberty BASIC, twice a PC Magazine Awards Finalist!
 http://www.libertybasic.com
------------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Calling functions by name?

Bill Schwab-2
Carl,

> Can Dolphin Smalltalk call API and DLL functions by name

Yes.  Dolphin has excellent FFI features.


> the way that VSE does?

I've never used VSE so I can't comment on the degree of similarity.  Somehow
I doubt you'd be disappointed, especially given the type library analyzer.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Calling functions by name?

Carl E Gundel-2
Bill Schwab <[hidden email]> wrote:
: Carl,

:> Can Dolphin Smalltalk call API and DLL functions by name

: Yes.  Dolphin has excellent FFI features.


:> the way that VSE does?

: I've never used VSE so I can't comment on the degree of similarity.  Somehow
: I doubt you'd be disappointed, especially given the type library analyzer.

I guess what I meant when I said "by name" is that you can call a function
by passing its name as a parameter, so that the function name doesn't have
to be hard coded in to a method's source.

The method on DynamicLinkLibrary looks like this:

 call: procName arguments: anArray types: anArray returns: returnType

This allows me to provide FFI features to my Liberty BASIC users (LB is
written in VSE).

-Carl

--
------------------------------------------------------------------
 Carl Gundel  [hidden email]  Shoptalk Systems
 author of Liberty BASIC, twice a PC Magazine Awards Finalist!
 http://www.libertybasic.com
------------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

Re: Calling functions by name?

Christopher J. Demers
Carl E Gundel <[hidden email]> wrote in message
news:[hidden email]...
...

> I guess what I meant when I said "by name" is that you can call a function
> by passing its name as a parameter, so that the function name doesn't have
> to be hard coded in to a method's source.
>
> The method on DynamicLinkLibrary looks like this:
>
>  call: procName arguments: anArray types: anArray returns: returnType
>
> This allows me to provide FFI features to my Liberty BASIC users (LB is
> written in VSE).

I don't think you can easily do this in Dolphin (perhaps a guru knows
better).  I suppose you could make use of the runtime compiler support to
get around this issue.  Another option would be to look at the VSE
implementation to see if it could be migrated to Dolphin, if it is in the VM
you are probably out of luck.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: Calling functions by name?

Blair McGlashan
"Christopher J. Demers" <[hidden email]> wrote in
message news:aju2u2$1e3m6p$[hidden email]...
> Carl E Gundel <[hidden email]> wrote in message
> news:[hidden email]...
> ...
> > I guess what I meant when I said "by name" is that you can call a
function
> > by passing its name as a parameter, so that the function name doesn't
have

> > to be hard coded in to a method's source.
> >
> > The method on DynamicLinkLibrary looks like this:
> >
> >  call: procName arguments: anArray types: anArray returns: returnType
> >
> > This allows me to provide FFI features to my Liberty BASIC users (LB is
> > written in VSE).
>
> I don't think you can easily do this in Dolphin (perhaps a guru knows
> better).  I suppose you could make use of the runtime compiler support to
> get around this issue.  Another option would be to look at the VSE
> implementation to see if it could be migrated to Dolphin, if it is in the
VM
> you are probably out of luck.

As Chris says, Dolphin doesn't expose a primitive to do a direct FFI
call-by-name like that, although of course it is essentially the same
mechanism as used by the primitive associated with external method calls.
I've thought for a while t hat it would be useful to call an arbitrary
function pointer just from its address and a descriptor, rather than having
to have a compiled method to make the call, so I might well add that
capability in a forthcoming release. Given that primitive it would be
relatively easy to layer on a bit of Smalltalk code to do call by name using
the GetProcAddress() API to map the name to an address.

However this is only an informal "it would be nice if", since the
alternative approach of compiling up a method is entirely workable, and I
have used it on a couple of occassions in the past. It has a signficant
performance advantage too, in that it is not necessary to perform any
processing on the argument type descriptions (since that is done once by the
compiler), and neither is it necessary for the function address to be looked
up on every call (i.e that call to GetProcAddress()), since it gets cached
by the VM on first invocation.

Generating and compiling the method text is pretty easy - the
AXTypeLibraryAnalyzer and associated AXTypeInfoAnalyzer classes provide an
example (albeit not a simple one) in the image. It isn't necessary that the
methods actually be installed into an external library class, although they
must be associated with one so that the VM knows what library handle to pass
to GetProcAddress(), although even that is not necessary if one calls
GetProcAddress() oneself and pre-caches the proc-address in the first
4-bytes of the descriptor literal (the first literal of the external
method), in which case the methods can be compiled and held as a valuable
object that can be evaluated at any time using the #value:withArguments:.

BTW: You should find that FFI support in Dolphin (with the obvious exception
of a direct call-by-name mechanism) is both more powerful and faster than
that in VSE. Where you find that not to be the case, please let us know and
we'll endeavour to do something about it.

Regards

Blair