This chapter describes the Bigloo evaluator.
Bigloo includes an interpreter. Unfortunately, the language accepted by the
interpreter is a proper subset of that accepted by the compiler. The main
differences are:
- No foreign objects can be handled by interpreter. 
- Classes of the object system cannot be declared within interpreted
      code.
- The interpreter ignores modules, and has a unique global environment.
Compiled code and interpreted code can be mixed together. That
is, interpreted code is allowed to call compiled code and vice
versa. This connection can be use to circumvent the missing
features of the interpreter (see Section see 
Module Declaration, 
for a description of how to connect compiled and interpreted code).
By default the evaluator assumes that operators from the standard
library (e.g., 
+, 
car) are immutable. Hence, it optimizes
these operators's calls. This optimization can be disabled using
the 
bigloo-eval-strict-module parameter described in
the chapter describing the parameters (see see 
Parameters). 
 
| 23.2 Eval standard functions
 | 
| This form evaluates exp. The second argument is optional. It can be
the evaluation of one of these three function forms:
| (scheme-report-environment 5)
(null-environment 5)
(interaction-environment)
 |  | 
| 
| scheme-report-environment version | procedure |  
| null-environment version | procedure |  
These three procedures have the definitions given in the R5RS so see
info-file `r5rs.info', 6.5 Eval, for more
details.| interaction-environment version | procedure |  | 
| 
| byte-code-compile exp [env (default-environment)] | bigloo procedure |  
The function| byte-code-run byte-code | bigloo procedure |  byte-code-compilecompiles a Scheme expression into
a sequence of byte codes that is implemented as a string. 
The functionbyte-code-runexecute such a sequence. | 
| This invokes the read-eval-printloop. Severalreplcan be embedded.
 The
 replfunction can be used to implement custom Bigloo interpreters.
For instance, one may write:
 When compiled, this will deliver an executable containingthe sole Bigloo interpreter.
 | 
| This exits from the currently running repl. If the currentreplis the first one then this function ends the interpreter. | 
| 
The argument| set-prompter! proc | bigloo procedure |  prochas to be a procedure of one argument and invoking
this function sets thereplprompter. That is, to display its prompt,replinvokesprocgiving it the nesting level of the 
current loop as its argument. | 
| 
Returns the current| get-prompter | bigloo procedure |  replprompter. | 
| 
The argument| set-repl-printer! proc | bigloo procedure |  prochas to be a procedure accepting one or two arguments.
This function sets therepldisplay function. That is, to display the
result of its evaluations,replinvokesprocgiving it the 
evaluated expression as first argument and the current output port (or
a file in case of transcript) as second argument.Set-repl-printer!returns the formerrepldisplay function.
 For instance, one may write:
 
 
 
| 1:=> (define x (cons 1 2))         -| X
1:=> (define y (cons x x))         -| Y
1:=> y                             -| (#0=(1 . 2) . #0#)
1:=> (set-repl-printer! display)   -| #<procedure:83b8c70.-2>
1:=> y                             -| ((1 . 2) 1 . 2)
 |  | 
| 
Returns the native (default)| native-repl-printer | bigloo procedure |  repldisplay function. | 
| 
Returns the value of| expand exp | bigloo procedure |  expafter all macro expansions 
have been performed. | 
| 
Returns the value of| expand-once exp | bigloo procedure |  expafter one macro expansion has been performed. | 
It is possible to specify files which have to be loaded when the interpreter
is invoked. For this, see section see 
Compiler Description.
If a Bigloo file starts with the line:
and if this file is executable (in the meaning of the system) and if the user
tries to execute it, Bigloo will evaluate it. Note also that SRFI-22 support
enables to run any Unix interpreter (see 
SRFIs).
| 
| load filename | bigloo procedure |  
| loadq filename | bigloo procedure |  Filenameshould be a string naming an existing file which contains
Bigloo source code. This file is searched in the current directory and
in all the directories mentioned in the variable*load-path*.
Theloadprocedure reads expressions and
definitions from the file, evaluating them sequentially. If the file
loaded is a module (i.e. if it begins with a regular
module clause), load behaves as module initialization. Otherwise, this
function returns the result of the last evaluation. The functionloadqdiffers from the functionloadin the sense thatloadqdoes 
not print any intermediate evaluations.
 Both functions return the full path of the loaded file.
 | 
| 
Loads an ``access file'', which allows the interpreter to find 
the modules imported by a loaded module. It returns the full path 
of the loaded file.| loada filename | bigloo procedure |  | 
| 
A list of search paths for the| *load-path* | bigloo variable |  loadfunctions. | 
| 
Loads a shared library named| dynamic-load filename #!optional (init init-point) | bigloo procedure |  filename. Returns the value of the
last top-level expression.
 Important note:  The function
 dynamic-loadcan only be
used from interpreters linked against dynamic libraries. In particular,
thedynamic-loadfunction can be issued from thebigloocommand if and only if the option--sharedcompiler=yeshas been
used when configuring Bigloo. If thebigloocommand is not linked
against dynamic libraries and ifdynamic-loadis
required inside a read-eval-print loop (REPL) it exists a simple workaround.
It consists in implementing a new REPL and linking it against dynamic 
libraries. This can be done as:
 
 
| $ cat > new-repl.scm <<EOF
(module new-repl)
(repl)
EOF
$ bigloo new-repl.scm -o new-repl
$ new-repl
1:=> (dynamic-load ...)
 |  
 
 If
 init-pointis specified and if it is a string and if the
library defines a function namedinit-point, this function is
called when the library is loaded.Init-pointis a C identifier,
not a Scheme identifier. In order to set the C name a Scheme function,
use the externexportclause (see Section see C Interface). If theinit-pointis provided and is not a string,
no initialization function is called after the library is loaded. If
theinit-pointvalue is not provided, once the library is
loaded,dynamic-loaduses the Bigloo default entry
point. Normally you should not provide aninit-pointtodynamic-loadunless you known what you are doing. When
producing C code, to force the Bigloo compiler to emit such a default
entry point, use the-dload-symcompilation option (see Section
see Compiler Description). This option is useless when using the
JVM code generator. Let's assume a Linux system and two Bigloo
modules. The first:
 
 
The second:| (module mod1
   (eval (export foo))
   (export (foo x)))
 (define (foo x)
   (print "foo: " x))
 
 (foo 4)
 |  
 
 
If these modules are compiled as:| (module mod2
   (import (mod1 "mod1.scm"))
   (eval (export bar))
   (export (bar x)))
 (define (bar x)
   (print "bar: " x))
 
 (bar 5)
 |  
 
 
Then, if a shared library is built using these two modules (note that on
non Linux systems, a different command line is required):| $ bigloo mod1.scm -c -o mod1.o 
$ bigloo mod2.scm -c -o mod2.o -dload-sym
 |  
 
 
Then,| $ ld -G -o lib.so mod1.o mod2.o
 |  lib.socant be dynamically loaded and the variables it defines
used such as :
 
 
As the example illustrates, when Bigloo modules are dynamically loaded,
they are initialized. This initialization is ensure only if| $ bigloo -i
(dynamic-load "lib.so")
     -| foo: 4
       bar: 5
1:=> (foo 6)
     -| foo: 7
 |  dynamic-loadis called with exactly one parameter. Ifdynamic-loadis called with two parameters, it is of the
responsibility of the program to initialize the dynamically loaded
module before using any Scheme reference.
 Note:  In order to let the loaded module accesses the variables
defined by the loader application, special compilation flags must be
used (e.g.,
 -rdynamicunder the Linux operating
system).Dynamic-loadis implemented on the top of thedlopenfacility. For more information read thedlopenandldmanuals.
 
 | 
| 
On the operating system that supports this facility, unloads a shared library.
Returns| dynamic-unload filename | bigloo procedure |  #ton success. Returns#fotherwise. | 
| 
A list of search paths for the| *dynamic-load-path* | bigloo variable |  dynamic-loadfunctions. | 
| 
| transcript-on filename | procedure |  | 
 
| 23.3 Eval command line options
 | 
This section presents the Bigloo compiler options that impact the interaction
between compiled and interpreted code. The whole list of the Bigloo
compiler options can be found in 
The Bigloo command line.
- -iDon't compile a module, interpret it!
- -export-allMake all the bindings defined by 
      the compiled module available from the interpreter.
- -export-exportMake all the bindings exported by the 
      compiled module available from the interpreter.
- -export-mutableMake all the bindings exported by the 
      compiled module mutable from outside the module. This option is
      dangerous! Either all the modules composing the application 
      must be compiled with or without- -export-mutable. It is impossible
      to mix- -export-mutableenabled and disabled compilations.
 
| 23.4 Eval and the foreign interface
 | 
To be able to get access to foreign functions within the Bigloo 
interpreter, some extra measurements have to be taken. The foreign 
functions have to be present in the interpreter binary, which means you 
have to compile a custom interpreter. This is described in 
Section 
Using C bindings within the interpreter.