[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Making an extension of various files
From: |
Thomas Chust |
Subject: |
Re: [Chicken-users] Making an extension of various files |
Date: |
Sun, 06 Nov 2005 18:27:38 -0000 |
User-agent: |
Opera M2/8.02 (MacPPC, build 2148) |
Am 06.11.2005, 16:13 Uhr, schrieb Pupeno <address@hidden>:
How do I make an extension of two or more files ?
[...]
Hello,
the short answer is: It's possible, but why on earth would you want to
do that ;)
The long answer is that CHICKEN generates a C-function executing the
top-level expressions for every file it processes. If you set normal
extension compilation mode, this function is called C_toplevel, if you
set unit compilation mode for a unit called my-unit, the function will
be called C_my_unit_toplevel.
The only way to circumvent this and to get only one toplevel for multiple
files is to give up separate compilation, to include all parts of the
extension in a central file (either directly or using the include
statement) and to compile that.
So to make the whole thing work *with* separate compilation, you have to
do some magic. First you must compile both files in your example with a
(declare (unit sc-mfl1)) or
(declare (unit sc-mfl2))
statement respectively to get toplevel functions with distinct names.
From then on you have several alternatives:
1) Create an additional Scheme file containing
(declare (uses sc-mfl1 sc-mfl2))
and compile it in normal extension compilation mode. Link all three
objects together to form your new extension.
(I haven't tested it, but I remember faintly that someone has tried
this already and it worked)
2) Create a small C file by hand that defines C_toplevel and calls
C_sc_mfl1_toplevel as well as C_sc_mfl2_toplevel from there. Compile
it and all three objects together to form your new extension.
(I would have to take a look at the CHICKEN internals again to see how
this could be done)
3) Just link the two objects for the units into a shared library and use
load-library instead of require or require-extension to load the
two units separately into chicken.
(I haven't tested this either, but the documentation tells me that it
should work)
The recommended path is probably (1) if you want to load all the
expressions
from both original scheme files at once or (3) if you don't.
cu,
Thomas