[gambit-list] runtime settings
Marc Feeley
feeley at iro.umontreal.ca
Thu Jul 27 23:49:58 EDT 2006
On 27-Jul-06, at 5:04 PM, Ryan Prescott wrote:
> What is the proper way to set runtime settings for a compiled
> scheme program?
> Does an executable compiled with:
>
> gsc -:tl myfile.scm
>
> "inherit" the -:tl setting?
No it doesn't. However, if you write your program as a script, that
is it starts with a line with "#! gsi ..." (on Unix) or "@;
gsi ..." (on Windows) then the compiled program will set the same
runtime options as the one specified to the script interpreter,
unless it is overridden with an explicit "-:..." options when the
program is started. Note that the script interpreter will not be
executed by the compiled program, the first line is only parsed by
the compiler to get the default runtime options.
Here's a detailed example. Let's say you want the program to use CR-
LF as the end-of-line encoding for all file I/O by default. You
would write "myfile.scm" as a script like this (on Unix):
#! gsi-script -:fcl
(define (main)
(display "hello\n"))
then you would compile and execute it like this:
% gsc myfile.scm
% gcc myfile.c myfile_.c -lgambc -lm -ldl -lutil
% ./a.out | od -a
0000000 h e l l o cr nl
0000007
The nice thing about this way of getting the default runtime options
is that you get the same result as executing the script:
% chmod +x myfile.scm
% ./myfile.scm | od -a
0000000 h e l l o cr nl
0000007
Yet another approach is to set the GAMBCOPT environment variable:
% export GAMBCOPT=tcl
Gambit compiled programs executed after this will use the default
runtime options "-:tcl" (these can be overridden on the program
command line).
>
> Likewise for c initiated scheme apps? by setting the setup struct's
> members?
Yes you can do that, for example:
#define MY_LINKER ____20_myprog__
___BEGIN_C_LINKAGE
extern ___mod_or_lnk MY_LINKER (___global_state_struct*);
___END_C_LINKAGE
void setup_gambit ()
{
___setup_params_struct setup_params;
___setup_params_reset (&setup_params);
setup_params.version = ___VERSION;
setup_params.linker = MY_LINKER;
/* set UTF-8 character encoding for file I/O */
setup_params.file_settings = ___FILE_SETTINGS_INITIAL;
setup_params.file_settings = ___CHAR_ENCODING_MASK
(setup_params.file_settings)
|___CHAR_ENCODING_UTF_8;
___setup (&setup_params);
}
Marc
More information about the Gambit-list
mailing list