-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8716 day of my life [EMAIL PROTECTED] wrote:
> I don't think you can do it directly with either CMUCL Alien or UFFI.
> However, you might to be able to translate into versions of these
> functions that are defined with specific numbers of arguments.
>
> The slick way to do it would be to have a macro that, when it sees a
> call with a number of arguments it hasn't seen before, automatically
> defines the appropriate function (i.e., call-pvm-packf-six-args).  I
> don't know if this possible or not; I forget the details of whether
> you have to declare all the functions you're accessing before loading
> the library or not.
>
> The less slick way would be to just predeclare some number of
> functions, and impose a maximum argument limit --- no one's going to
> want to call this thing with *that* many arguments, and if they do,
> they go into the code and change one constant.

First argument of pvm_packf is string, but other arguments can be
element of different types: double/float, (signed/unsigned) integers
of different sizes, strings, arrays.  For example, we will use 10
types and 3 arguments; there are 10^3=100 argument functions...

And I'd like to have non-constant first argument...  It is why macros
are not good here.

> Would either of these actually work, or is there some deeper problem
> I'm missing?  I haven't actually tried to do this, although I've been
> meaning to.

I have found better solution:  I can parse format string, learn types
and 

(defun pvm_packf (fmt &rest args)
   (apply #'alien:alien-funcall
          (eval (parse-fmt-string fmt))
          fmt args))

PARSE-FMT-STRING would return list like this:

(alien:extern-alien "pvm_packf" (function c-call:int c-call:c-string
c-call:int))

And then the list will be EVAL'ed, because ALIEN:EXTERN-ALIEN is
macro, not a function.

I don't like the solution, it will cons a lot on each call, but I
don't know anything better...

* (time (eval '(alien:extern-alien "pvm_packf"
                 (alien:function c-call:int c-call:c-string c-call:int))))
; Compiling LAMBDA NIL: 
; Compiling Top-Level Form: 

; Evaluation took:
;   0.0 seconds of real time
;   0.01 seconds of user run time
;   0.0 seconds of system run time
;   1,911,433 CPU cycles
;   0 page faults and
;   37,952 bytes consed.

Of course, I will memoize result of EVAL.  And proper COMPILER-MACRO
will improve situation if FMT is static string...

- -- 
Ivan Boldyrev

                                                  Your bytes are bitten.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.3.5 (GNU/Linux)

iQEVAwUBQH/tkg4ALcwzZFpVAQI5rQf/fDZLz5fayTJGnUboc+213/SBQatiKYLs
MyPYe5qQiCKaoMNlzrZT8D0v0S3V31Y/X3qWdkVTG0FsP20O5BqLoPvrXVjRxXmF
IQe0EQoG9DISPP2HHfdJhVNIwnnxmW2nM+xkVL/SQdfU65hS6jTRI6D+0st7dbGg
C7yYnFf2PAly2Z8ZgEyWcpggSwAswb45AeqERrLya0K/Fm4Ec/J1Di8KA6eblDU4
ng5V9w+26CHpgu/QPPEv6Woum2g9iYWAkmi7/HU8JxpNfqu1kaAQYhMYvBv/6poP
2pN+dKNHEz/x1X1jqS6fizsvFx/drBZ4yyOFEuypNcaShhVnkxe/3g==
=amC1
-----END PGP SIGNATURE-----


Reply via email to