[Prev][Next][Index][Thread]

Re: a table of c funtion pointers



On Mon, 24 Jul 2000, Futeh Kao wrote:
> Because of some other issues, I ended up having to resort to write some C
> glue
> code.  The C glue code is fairly small and entirely platform independent (no
> Win32 specific calls). In any case, I've successfully started a Java VM and
> called some methods.  I do have one additional problem:  there is a <C-long>
> class, however, it is the same size as <machine-word>, whereas Java long is
> 64 bit.  Hmm ... any clean solutions besides resorting to my C glue code
> again?

I don't think so; I think FunDev may support 64-bit integers but I don't
think it's standard in the C-FFI.  What does C use to represent Java's
"long"?  A "long long"?

> Another question I have, because of my limited few days of experience with
> Dylan, is that how does it support delegation and dynamic compiling.  In
> Smalltalk or Objective-C, when a method is not understood by an object,
> the object is given the chance to handle it by implementing the
> doesNotUnderstand: method. 

Dylan doesn't support this, since methods don't belong to classes, but to
generic functions.  One might hope that an exception handler for
inapplicable methods could inspect the error and do something based on
that knowledge, which would provide a form of delegation.  However, the
object-class of errors for "No applicable method" is not named and has no
reflection functions.  I believe this is for performance reasons, rather
than just an oversight: Dylan does try to perform better than Java :-)
(Don't know about the performance of Objective-C, though.)

> ... Second, in Java, I can generate source code at runtime, then invoke
> an external process to compile the code and finally load the resulting
> class file using a ClassLoader, all during while the application is
> running.  In Smalltalk, one can [do something similar ...]
> How does Dylan accomplishes this given that everything is compiled to
> an exe and that I am not aware of a platform independent bytecode
> representation? 

There is no platform-independent bytecode format for Dylan, nor even a
common binary interface (which C has but nearly everything else, including
C++, doesn't).  There's no standard way to do what you want, though it can
be done in Functional Developer under Win32.

Roughly speaking, you could invoke the FunDev command-line compiler (*)
from your program and compile a DLL which used some library also used
by your program and extended some classes/GFs from that library.  Then you
can use the Win32 LoadLibrary API to load this DLL and the new classes and
methods will become available.  Andy Armstrong was the first to post a
working example of this, I think, but I don't know if it's up on any
websites.

(* You have to pay extra for this.  You probably need plus you'd need the
Core Libraries pack and the Microsoft Linker pack, or the Win32 Platform
Headers pack, to get at LoadLibrary.  You do get a 30 day trial on each
library pack, though.) 

If you really need to execute code generated at runtime (like tha above,
or like "eval" in languages like Lisp, Perl and JavaScript) then Dylan
isn't going to suit you.  But you may find that you don't need to do that
after all :-)

> Rob Myers wrote:
> > Futeh Kao wrote:
> > > ...
> > > Second question.  How do I declare a vararg function and use it in
> > > Dylan.
> >
> > A C vararg function? I don't know. If there isn't an API for this, you'd
> > have to build the va_list by hand in a buffer, and call the function as
> > normal passing the va_list as a <C-void*>.

If you have a version of the varargs function which takes a va_list (like
vprintf instead of printf -- I think that's the right name), this will
work.  For functions with just the "simple" varargs form (like normal
printf), you're stuck.  The only way to use them would be to write one or
more fixed-argument C functions and call those from Dylan; e.g.:

  void printf_1 (char *format, void *arg1) {
    (void) printf(format, arg1);
  }

  void printf_2 (char *format, void *arg1, void *arg2) {
    (void) printf(format, arg1, arg2);
  }

  /* etc. */


I hope that's helpful (and not too discouraging -- Dylan can't do these
things but it can do a lot of other cool things :-).

Hugh





Follow-Ups: References: