chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] "Dynamically Loading" non-entry-point code


From: Felix Winkelmann
Subject: Re: [Chicken-users] "Dynamically Loading" non-entry-point code
Date: Wed, 16 Jun 2004 08:08:38 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113

Daniel B. Faken wrote:
On Mon, 14 Jun 2004, felix wrote:

basically, you want to access two compiled Scheme files in a C application,
right? What you can do is compile one of them with `define-external', and
use the fundamental ##sys#call-host interface.
But perhaps you can explain the problem a bit simpler, since I have some 
problems
understanding what exactly you need.


I think the basic problem is: I want to have scheme bindings within a library, but - since the library is already dynamically loaded by the linker - I don't want to call (load-library ..) again. Normally I could solve this by just having the code within the 'main' unit, but I already have another, independent 'main' unit.

Looking at the generated C, it seems I could do this by calling C_foobar_toplevel() to initialize the code with respect to the scheme runtime, but I'm not sure what values to pass (esp. for the continuation).

Here a simple example (tested with MSVC):

(x.scm has some Scheme code)

c:\home>csc x.scm -unit foo -kvc
csc x.scm -unit foo -kvc
x.c
c:\chicken\chicken x.scm -output-file x.c -quiet -unit foo
cl x.c /Fox.obj /DPIC /nologo /c /I%CHICKEN_HOME% /DC_NO_PIC_NO_DLL

y.scm:

#>
extern C_foo_toplevel(C_word, C_word, C_word) C_noret;

void run_foo_unit(C_word c, C_word self, C_word k)
{
  C_foo_toplevel(2, C_SCHEME_UNDEFINED, k);
}
<#

(define run-foo-unit (##core#primitive "run_foo_unit"))

(run-foo-unit)
(print (pack '(a b d d d)))  ; pack is provided by x.scm

c:\home>csc y.scm x.obj -v -uses srfi-1  ; x.obj needs srfi-1 in this example
csc y.scm x.obj -v -uses srfi-1
y.c
   Bibliothek y.lib und Objekt y.exp wird erstellt
c:\chicken\chicken y.scm -output-file y.c -quiet -uses srfi-1
cl y.c /Foy.obj /DPIC /nologo /c /I%CHICKEN_HOME% /DC_NO_PIC_NO_DLL
del y.c
link /out:y.exe /nologo x.obj y.obj c:\chicken\libchicken.lib c:\chicken\libsrfi-chicken.lib c:\chicken\libstuffed-chicken.lib
del y.exp
del y.lib
del y.obj

c:\home>y
y
(1 a 1 b 3 d)

Basically, you call C_<xxx>_toplevel(2, C_SCHEME_UNDEFINED, <kont>), where
<kont> is the continuation passed to your ##core#primitive.

If you want to call C_<xxx>_toplevel from C, then it gets complicated...


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]