125ec92a5aa96558fdd66615c2365b3cb821a037
[bpt/guile.git] / doc / ref / compiler.texi
1 @c -*-texinfo-*-
2 @c This is part of the GNU Guile Reference Manual.
3 @c Copyright (C) 2008
4 @c Free Software Foundation, Inc.
5 @c See the file guile.texi for copying conditions.
6
7 @node Compiling to the Virtual Machine
8 @section Compiling to the Virtual Machine
9
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
14 to be impenetrable.
15
16 This section aims to pull back the veil from over Guile's compiler
17 implementation, some reference to the wizard of oz FIXME.
18
19 REFFIXME, if you're lost and you just wanted to know how to compile
20 your .scm file.
21
22 @menu
23 * Compiler Tower::
24 * The Scheme Compiler::
25 * GHIL::
26 * GLIL::
27 * Object Code::
28 @end menu
29
30 @node Compiler Tower
31 @subsection Compiler Tower
32
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).
37
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
42 targets.
43
44 lookup-language
45 (lang xxx spec)
46
47 (system-base-language)
48
49 describe:
50
51 (define-record <language>
52 name
53 title
54 version
55 reader
56 printer
57 (parser #f)
58 (read-file #f)
59 (compilers '())
60 (evaluator #f))
61
62 (define-macro (define-language name . spec)
63
64 (lookup-compilation-order from to)
65
66 language definition
67
68 compiling from here to there
69
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''
73
74 compile-file defaults to compiling to objcode
75 compile defaults to compiling to value
76
77 ((lambda (x) ((compile x) x)) '(lambda (x) ((compile x) x)))
78 quine
79
80 @node The Scheme Compiler
81 @subsection The Scheme Compiler
82
83 macro expansion
84
85 define-scheme-translator
86
87 inlining
88
89 format of the environment
90
91 compile-time-environment
92
93 symbols resolved as local, external, or toplevel
94
95 @node GHIL
96 @subsection GHIL
97
98 ghil environments
99
100 structured, typed intermediate language, close to scheme
101 with an s-expression representation
102
103 ,lang ghil
104
105 some pre-optimization
106
107 real name of the game is closure elimination -- fixing letrec
108
109 @node GLIL
110 @subsection GLIL
111
112 structured, typed intermediate language, close to object code
113
114 passes through the env
115
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.
118
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.
122
123 @node Object Code
124 @subsection Object Code
125
126 describe the env -- module + externals (the actual values!)
127
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
131 that goops uses.
132