guile-user
[Top][All Lists]
Advanced

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

Re: Difference when calling guile script from C vs interpreter


From: Roel Janssen
Subject: Re: Difference when calling guile script from C vs interpreter
Date: Tue, 20 Oct 2020 16:37:22 +0200
User-agent: Evolution 3.38.1 (3.38.1-1.fc33)

On Tue, 2020-10-20 at 16:27 +0200, Taylan Kammer wrote:
> On 20.10.2020 14:58, Jean Rene Dawin wrote:
> > Hi,
> > 
> > when following guile script:
> > ______ gp.guile _________
> > 
> > (snip)
> > ______________________________
> > 
> > is run from the interpreter, the output shows the following:
> > 
> > (snip)
> > Total time: 0.327908556 seconds (0.121140347 seconds in GC)
> > #t
> > 
> > 
> > 
> > When the same script is loaded from following C program:
> > _____ gp.c _______
> > #include <libguile.h>
> > 
> > int main(int argc, char **argv)
> > {
> >     scm_init_guile();
> >     scm_c_primitive_load("/home/gp.guile");
> >     return 0;
> > }
> > ___________________
> > 
> > the result looks like this:
> > 
> > (snip)
> > Total time: 1.939099187 seconds (0.570765622 seconds in GC)
> > #t
> > 
> > Is this difference expected?
> 
> When you use the "guile" executable to run a file, it automatically 
> compiles it first, then runs the compiled version.  (For this reason
> I 
> wouldn't use the term "interpreter" in this case.)
> 
> When using primitive-load, it doesn't auto-compile it (and I think it
> doesn't even look for an already compiled version), instead it
> directly 
> calls the interpreter on the source code.  (This time it really is
> the 
> interpreter.)
> 
> It's generally preferable to *extend* Guile with C code, rather than
> to 
> *embed* it in C code.  This means you turn your C code into
> libraries, 
> which are turned into Guile modules, then you write a Guile program
> that 
> uses those modules.  I.e. you call to C code from Guile, not to Guile
> code from C.
> 
> If you want to really prefer to embed and not extend, then perhaps
> you 
> can make your Guile files available in the %load-path and use 
> scm_primitive_load_path (see documentation).
> 
> I don't know if/how the Guile compiler can be called from C.  Maybe 
> someone more experienced can help further.
> 
> 
> - Taylan
> 
> 

Once you've compiled the Guile module, it should be enough to set the
GUILE_LOAD_COMPILED_PATH environment variable before booting Guile in
C.  Here's what I use:

https://github.com/UMCUGenetics/sparqling-genomics/blob/master/web/sg-web.c.in#L314-L356

Kind regards,
Roel Janssen





reply via email to

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