[Top][All Lists]

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

Re: Difference when calling guile script from C vs interpreter

From: Taylan Kammer
Subject: Re: Difference when calling guile script from C vs interpreter
Date: Tue, 20 Oct 2020 16:27:16 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1

On 20.10.2020 14:58, Jean Rene Dawin wrote:

when following guile script:
______ gp.guile _________


is run from the interpreter, the output shows the following:

Total time: 0.327908556 seconds (0.121140347 seconds in GC)

When the same script is loaded from following C program:
_____ gp.c _______
#include <libguile.h>

int main(int argc, char **argv)
    return 0;

the result looks like this:

Total time: 1.939099187 seconds (0.570765622 seconds in GC)

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

reply via email to

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