forked from rubinius/rubinius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
223 lines (157 loc) · 7.82 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE html>
<html>
<head>
<title>Compiler Transforms - Rubinius</title>
<meta content='text/html;charset=utf-8' http-equiv='content-type'>
<meta content='de' http-equiv='content-language'>
<meta content='Rubinius is an implementation of the Ruby programming language. The Rubinius bytecode virtual machine is written in C++. The bytecode compiler is written in pure Ruby. The vast majority of the core library is also written in Ruby, with some supporting primitives that interact with the VM directly.' name='description'>
<meta content='Less Than Three. <3. http://less.thanthree.com' name='author'>
<link href='/' rel='home'>
<link href='/' rel='start'>
<link href='/doc/de/bytecode-compiler/compiler' rel='prev' title='Compiler'>
<link href='/doc/de/bytecode-compiler/generator' rel='next' title='Generator'>
<!--[if IE]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script><![endif]-->
<script src="/javascripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="/javascripts/paging_keys.js" type="text/javascript"></script>
<script src="/javascripts/application.js" type="text/javascript"></script>
<style>article, aside, dialog, figure, footer, header, hgroup, menu, nav, section { display: block; }</style>
<link href="/stylesheets/blueprint/screen.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
<link href="/stylesheets/blueprint/print.css" media="print" rel="stylesheet" type="text/css" />
<!--[if IE]><link href="/stylesheets/blueprint/ie.css" media="screen" rel="stylesheet" type="text/css" /><![endif]-->
<!--[if IE]><link href="/stylesheets/ie.css" media="screen" rel="stylesheet" type="text/css" /><![endif]-->
<link href="/stylesheets/pygments.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div class='container'>
<div class='span-21 doc_menu'>
<header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a id="blog" href="/blog/">Blog</a></li>
<li><a id="documentation" href="/doc/en/">Documentation</a></li>
<li><a href="/projects/">Projects</a></li>
<li><a href="/roadmap/">Roadmap</a></li>
<li><a href="/releases/">Releases</a></li>
</ul>
</nav>
</header>
</div>
<div class='span-3 last'>
<div id='version'>
<a href="/releases/1.2.2">1.2.2</a>
</div>
</div>
</div>
<div class="container languages">
<nav>
<span class="label">Sprachen:</span>
<ul>
<li><a href="/doc/de/"
class="current"
>de</a></li>
<li><a href="/doc/en/"
>en</a></li>
<li><a href="/doc/es/"
>es</a></li>
<li><a href="/doc/ja/"
>ja</a></li>
<li><a href="/doc/pl/"
>pl</a></li>
<li><a href="/doc/ru/"
>ru</a></li>
</ul>
</nav>
</div>
<div class="container doc_page_nav">
<span class="label">Vorherige:</span>
<a href="/doc/de/bytecode-compiler/compiler">Compiler</a>
<span class="label">Aufwärts:</span>
<a href="/doc/de/">Inhaltsverzeichnis</a>
<span class="label">Nächste:</span>
<a href="/doc/de/bytecode-compiler/generator">Generator</a>
</div>
<div class="container documentation">
<h2>Compiler Transforms</h2>
<p>The bytecode compiler has a simple AST transform mechanism that recognizes
certain AST forms and replaces them. The replaced forms emit different
bytecode than the original form would have emitted. The source for the
transforms is in lib/compiler/ast/transforms.rb</p>
<p>TODO: document the compiler plugin architecture.</p>
<h3 id="safe-math-compiler-transform">Safe Math Compiler Transform</h3>
<p>Since the core libraries are built of the same blocks as any other Ruby code
and since Ruby is a dynamic language with open classes and late binding, it is
possible to change fundamental classes like Fixnum in ways that violate the
semantics that other classes depend on. For example, imagine we did the
following:</p>
<p>class Fixnum
def +(other)
(self + other) % 5
end
end</p>
<p>While it is certainly possible to redefine fixed point arithmetic plus to be
modulo 5, doing so will certainly cause some class like Array to be unable to
calculate the correct length when it needs to. The dynamic nature of Ruby is
one of its cherished features but it is also truly a double-edged sword in
some respects.</p>
<p>In the standard library the ‘mathn’ library redefines Fixnum#/ in an unsafe
and incompatible manner. The library aliases Fixnum#/ to Fixnum#quo, which
returns a Float by default.</p>
<p>Because of this there is a special compiler plugin that emits a different
method name when it encounters the #/ method. The compiler emits #divide
instead of #/. The numeric classes Fixnum, Bignum, Float, and Numeric all
define this method.</p>
<p>The safe math transform is enabled during the compilation of the Core
libraries to enable the plugin. During regular ‘user code’ compilation, the
plugin is not enabled. This enables us to support mathn without breaking the
core libraries or forcing inconvenient practices.</p>
</div>
<div class="container doc_page_nav">
<span class="label">Vorherige:</span>
<a href="/doc/de/bytecode-compiler/compiler">Compiler</a>
<span class="label">Aufwärts:</span>
<a href="/doc/de/">Inhaltsverzeichnis</a>
<span class="label">Nächste:</span>
<a href="/doc/de/bytecode-compiler/generator">Generator</a>
</div>
<div class="container">
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'rubinius';
var disqus_identifier = '/doc/de/bytecode-compiler/transformations/';
var disqus_url = 'http://rubini.us/doc/de/bytecode-compiler/transformations/';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
<footer>
<div class='container'>
<nav>
<ul>
<li><a href="http://twitter.com/rubinius">Follow Rubinius on Twitter</a></li>
<li><a href="http://github.com/evanphx/rubinius">Fork Rubinius on github</a></li>
<li><a href="http://engineyard.com">An Engine Yard project</a></li>
<li id='credit'>
Site design by
<a href="http://less.thanthree.com">Less Than Three</a>
</li>
</ul>
</nav>
</div>
</footer>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-12328521-1");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>