Ben:

On Mon, Nov 1, 2010 at 12:44 AM, Ben Kloosterman <[email protected]> wrote:
> Trying to work out how the C integration works...

Me too! :-)

So first, you should know that there really *isn't* any serious C
integration yet. There are a couple of runtime support routines, and
these simply won't work in their present form given concurrent GC.
They are enough for bring-up, nothing more. We need to understand the
GC environment in more detail before we can really address that. For
now, the best thing to do is not integrate any more C code than we can
help.

The .bits files have nothing to do with C integration. Where a .bits
file exists, it is typically an implementation module that implements
the functionality of some interface.

The present "support" is part of the "black magic runtime", and it
consists of two parts:

1. For some functions declared in prelude.bitc, the corresponding
implementations are *macros* in runtime.h. These are generally
low-level intrinsics. Use of macros allows us to re-use the function
syntax and processing mechanisms without incurring a call overhead.

2. For "legitemate" external functions, the model is that you declare
the function in bitc with:

  def foo(args-with-types) : type external "optional external name"

Such a function may not be polymorphic. If no external name is
provided, the bitc mangling scheme prevails. You'll see a few of each
in prelude.bitc and in the vector library.

However, the interaction model between these functions and the runtime
is largely undefined at this point, and can't really be nailed down
until we have a sufficiently complete understanding of what GC options
we eventually want to support. There is no finalization model yet, for
example.

For purposes of header synthesis, the process looks like this:

1. Set up some interface. The functions that you want to implement in
C should be specified as "external".
2. Set up a "gathering" interface - this is an otherwise empty
interface that imports all of the interfaces of your library. An
example is in libbitc/bitc-runtime.bitc. The purpose of this file is
to act as a root for instantiation and header synthesis.
3. Run bitc in header generation mode on your "gather" file. This will
produce the header[s] you need to import into your C code for linkup.


Hope some of that is helpful.


shap
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to