Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!EU.net!Austria.EU.net!newsfeed.ACO.net!swidir.switch.ch!univ-lyon1.fr!news.imag.fr!cosmos.imag.fr!triggs
From: triggs@imag.fr (Bill Triggs )
Subject: Re: How do I do a FFI???
Message-ID: <1994Sep14.081314.9048@imag.fr>
Sender: news@imag.fr
Nntp-Posting-Host: cosmos
Organization: Institut Imag, Grenoble, France
References: <KAELIN.94Sep13175141@binki.bridge.com>
Date: Wed, 14 Sep 1994 08:13:14 GMT
Lines: 29

In article <KAELIN.94Sep13175141@binki.bridge.com> kaelin@bridge.com (Kaelin Colclasure) writes:
>I'm working on project which includes a minimal embedded interpreter
>to be used primarily for dynamic reconfiguration and debugging.
>...
>Thus the need for an FFI.  I want to implement these bottleneck
>primitives as "native" C++ functions, and then simply wrap a closure
>around them that takes the list of arguments and flattens it onto the
>C++ stack.
>
>My C experience says varargs.h-- now stdarg.h in C++.  However, I have
>seen no examples which show how to *construct* a variable-length
>argument list procedurally at runtime.  Am I simply on the wrong
>track, or can someone enlighten me as to how this is done?  Do most
>FFIs resort to (ugh) assembly language for this kind of thing?

There's no official portable way to build function argument lists in C
or C++.  If you have only integer and pointer arguments you can often
get away with passing them all as integers, but floating point,
structures and return values are harder.  

If you want something better and have a Sun 3 or 4, SG Iris or (LINUX)
PC you can ftp a small library /pub/ox.src/avcall0.1.tar.gz from
ftp.robots.ox.ac.uk that wraps the assembly-level grunge in a portable C
interface something like varargs in reverse. You should be able to port
it to most other processors with a little effort. However note that it's
alpha release and probably (?) no faster than consing a scheme arg list.

Bill Triggs <bill@robots.ox.ac.uk>

