2 @c This is part of the GNU Guile Reference Manual.
4 @c Free Software Foundation, Inc.
5 @c See the file guile.texi for copying conditions.
7 @node Compiling to the Virtual Machine
8 @section Compiling to the Virtual Machine
10 Compilers have a mystique about them that is attractive and
11 off-putting at the same time. They are attractive because they are
12 magical -- they transform inert text into live results, like throwing
13 the switch on Frankenstein. However, this magic is perceived by many
16 This section aims to pull back the veil from over Guile's compiler
17 implementation, some reference to the wizard of oz FIXME.
19 REFFIXME, if you're lost and you just wanted to know how to compile
24 * The Scheme Compiler::
31 @subsection Compiler Tower
33 Guile's compiler is quite simple, actually -- its @emph{compilers}, to
34 put it more accurately. Guile defines a tower of languages, starting
35 at Scheme and progressively simplifying down to languages that
36 resemble the VM instruction set (REFFIXME).
38 Each language knows how to compile to the next, so each step is simple
39 and understandable. Furthermore, this set of languages is not
40 hardcoded into Guile, so it is possible for the user to add new
41 high-level languages, new passes, or even different compilation
47 (system-base-language)
51 (define-record <language>
62 (define-macro (define-language name . spec)
64 (lookup-compilation-order from to)
68 compiling from here to there
70 the normal tower: scheme, ghil, glil, object code
71 maybe from there serialized to disk
72 or if at repl, brought back to life by compiling to ``value''
74 compile-file defaults to compiling to objcode
75 compile defaults to compiling to value
77 ((lambda (x) ((compile x) x)) '(lambda (x) ((compile x) x)))
80 @node The Scheme Compiler
81 @subsection The Scheme Compiler
85 define-scheme-translator
89 format of the environment
91 compile-time-environment
93 symbols resolved as local, external, or toplevel
100 structured, typed intermediate language, close to scheme
101 with an s-expression representation
105 some pre-optimization
107 real name of the game is closure elimination -- fixing letrec
112 structured, typed intermediate language, close to object code
114 passes through the env
116 no let, no lambda, no closures, just labels and branches and constants
117 and code. Well, there's a bit more, but that's the flavor of GLIL.
119 Compiled code will effectively be a thunk, of no arguments, but
120 optionally closing over some number of variables (which should be
121 captured via `make-closure' REFFIXME.
124 @subsection Object Code
126 describe the env -- module + externals (the actual values!)
128 The env is used when compiling to value -- effectively calling the
129 thunk from objcode->program with a certain current module and with
130 those externals. so you can recompile a closure at runtime, a trick