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: Daniel B. Faken
Subject: Re: [Chicken-users] "Dynamically Loading" non-entry-point code
Date: Mon, 21 Jun 2004 10:01:16 -0400 (EDT)

Hello..

On Wed, 16 Jun 2004, Felix Winkelmann wrote:
> 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):
> 
<snip>
> 
> Basically, you call C_<xxx>_toplevel(2, C_SCHEME_UNDEFINED, <kont>), where
> <kont> is the continuation passed to your ##core#primitive.

Thanks!

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

I need to call it from C (because I want the library to basically load 
some of its own bindings), so I defined this in my "scmif" interface
layer (see below)

Do you see any problem with this?  (I wasn't too sure what you meant by 
"it gets complicated")   Will this work with arbitrarily nested layers of 
callback?

#>
static void *scmif_tmp_toplevel_fn = NULL;
static void _scmif_run_toplevel(C_word c, C_word self, C_word k)
{
  void (*fn)(C_word, C_word, C_word) = scmif_tmp_toplevel_fn;
  assert(fn);
  fn(2, C_SCHEME_UNDEFINED, k);
}
#<
(define 
(scmif-run-that-toplevel uname)
  (when debug-scmif?
    (mpi-print "Running toplevel for unit '" uname "'..") )
  ((##core#primitive "_scmif_run_toplevel")) )

#>
int scmif_run_this_toplevel(char *name, void (*fn)(C_word, C_word, 
C_word))
{
  char *err = NULL;

  assert(fn);

  scmif_init(0, NULL);

  scmif_tmp_toplevel_fn = fn;
  // this uses CHICKEN_is_running() & so is valid whether or not you're
  // in a callback..
  scmif_eval_stringf(&err, "(scmif-run-that-toplevel \"%s\")", name);
  scmif_tmp_toplevel_fn = NULL;

  if(err) {
    fprintf(stderr, "WARNING: scmif_run_this_toplevel: executing toplevel 
for unit '%s': %s\n", name, err);
    fflush(stderr);
    return 0;
  }

  return 1;
}
<#


thanks again,
Daniel






reply via email to

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