-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
374 lines (290 loc) · 14.2 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<!doctype HTML>
<html>
<head>
<meta charset='utf-8'>
<style>
body {
font-family: helvetica
margin: 0 auto;
padding-left: 5em;
max-width: 40em;
}
h1, h2 {
text-align: center;
}
li {
margin-top: 10px;
}
</style>
</head>
<body>
<h1>Python: The Full Monty</h1>
<h2>A Tested Semantics for the Python Programming Language</h2>
<h2><em>Artifact Evaluation Submission</em></h2>
<h3>What this Document Covers</h3>
<ul>
<li>Starting the lambda-py virtual machine and verifying the paper's results</li>
<li>Exploring the lambda-py implementation and tests</li>
<li>Building lambda-py from scratch</li>
</ul>
<h3>Getting Started</h3>
<p>
The virtual machine is in the <code>vm</code> directory of this archive as
<code>lambda-py.vmdk</code>. You can start it via VirtualBox by [FILL
VirtualBox starting instructions].
</p>
<p>There is one useful user on the virtual machine, <code>reviewer</code>,
with <code>sudo</code> privileges and password <code>reviewer</code>. When
the machine starts, enter these credentials and you should be presented
with a desktop that looks like:
[FILL screenshot]
</p>
<p>The files for review are all in the directory
<code>/home/reviewer/lambda-py</code>. The implementation and tests for
lambda-py at artifact submission time are in
<code>lambda-py-artifact-submission</code>. We focus on the current state
of the implementation, which enjoys some significant improvements over the
implementation at submission time. It passes all the same tests as the
submission-time version and more, but we include the version from
submission time with instructions (at the end of this document) for
completeness.</p>
<p>Our first goal should be to simply verify the results from Figure 12 in
the paper. Open a terminal ("Applications Menu" at the top left, then
"Terminal Emulator"), and let's first run a very small test so we can find
out if anything goes wrong right away (if you have the opportunity to ask
the authors for help, we're putting this here for quick diagnosis): </p>
<pre>
$ cd lambda-py/lambda-py-artifact-submission
$ echo "print('lambda-py works')" | racket python-main.rkt --interp
lambda-py works
</pre>
<p> This should take a few seconds to run, and confirms that the lambda-py
interpreter is up and running for you.</p>
<p>To run all the tests that we report in the paper, you can run:</p>
<pre>
$ racket python-main.rkt --test ../../lambda-py-oopsla2013/tests/python-reference/
175 tests succeeded
0 tests failed
</pre>
<p>This runs the tests that we report in the paper using the current
implementation. This will take around an hour, depending on your machine.
We provide a perl script called <code>cloc</code> to count the lines of
code in each directory of <code>python-reference</code> (the "Built-in
Datatypes" count is the combination of the directories function, bool,
builtin, tuple, lists, and dict, "Iteration" is the combination of
directories iter and range, and "(Multiple) Inheritance" is the combination
of directories super and multiple-inheritance).</p>
<p>We've added an additional suite of features via desugaring since
submission time, documented in CHANGES.txt. The new test cases are in the
<code>tests/python-reference</code> subdirectory of
<code>lambda-py-artifact-submission</code>. So if you run the following,
you will see the additional tests passing: </p>
<pre>
$ racket python-main.rkt --test ../tests/python-reference/
[FILL] tests succeeded
0 tests failed
</pre>
<p>The repository is also set up to run all the same tests using Python.
We've included an installation of Python 3.2.3 (the version we are
modelling) in the VM, and these tests can be run with:</p>
<pre>
$ racket python-main.rkt --python-path ~/install-stuff/Python-3.2.3/python --test-py ../tests/python-reference
</pre>
<p>That's enough to get started and verify what's in the paper, and some
of what we've worked on since then.</p>
<h3>Looking Around</h3>
<h4>Code from the paper</h4>
<p>Many of the discussions in the paper directly correspond to a few places
in the code; it is useful to see how they translate. These are presented
as links to Github sources, since they have a nice viewer for the
files.</p>
<ul>
<li>The Redex definition of the language (which is also used to typeset
the paper's code examples) is in <a
href="https://github.com/brownplt/lambda-py/blob/master/redex/lambdapy-core.rkt">lambda-py-core.rkt</a>,
and the definition of the reduction steps and related metafunctions
(which are also used to typeset the semantics shown in the paper) are in
<a
href="https://github.com/brownplt/lambda-py/blob/master/redex/lambdapy-reduction.rkt">lambda-py-reduction.rkt</a>.
The <code>redex/</code> directory contains a number of tests for these.
</li>
<li>The interpreter implementation (dubbed λ<sub>π↓</sub> in the paper)
defines its abstract syntax in <a
href="https://github.com/brownplt/lambda-py/blob/master/base/python-core-syntax.rkt"><code>python-core-syntax.rkt</code></a>,
which is simply an encoding in Racket structs of the AST from
<code>lambda-py-core.rkt</code>. Similarly,
<code>python-interp.rkt</code> is a (much) more efficiently
implementation of the reduction relation from
<code>lambda-py-reduction.rkt</code>.
</li>
<li> A number of straightforward operator desugarings are in <a
href="https://github.com/brownplt/lambda-py/blob/master/base/python-desugar.rkt#L371"><code>python-desugar.rkt</code></a>.
</li>
<li> The composition of all the steps of scope desugaring is split
between <a
href="https://github.com/brownplt/lambda-py/blob/master/base/python-phase1.rkt#L147"><code>python-phase1.rkt</code></a>,
which desugars identifiers down to global variables, local variables, and instance variables, and <a
href="https://github.com/brownplt/lambda-py/blob/master/base/python-phase2.rkt#L19"><code>python-phase2.rkt</code></a>,
which rewrites rewrites class bodies, eliminating instance variables and introducing bindings for local and global variables.
These do other less fundamental work that doesn't appear in the paper for
straightforward desugarings of default arguments and decorators.</li>
<li>The CPS transformation and code for the skeleton in Figure 11 are in
the file <a
href="https://github.com/brownplt/lambda-py/blob/master/base/python-cps.rkt#L379"><code>python-cps.rkt</code></a>
</li>
<li>We try to push functionality out of Racket and into
Python-implemented libraries (with some macros, as indicated in Section
6.2). These are in the <code>base/pylib/</code> directory. For example
the <code>object</code> and <code>type</code> base classes implement a
whole bunch of built-in functionality; they are implemented in Python
with macros for primitive operators, at <a
href="https://github.com/brownplt/lambda-py/blob/master/base/pylib/type.py"><code>type.py</code></a>
and <a
href="https://github.com/brownplt/lambda-py/blob/master/base/pylib/object.py"><code>object.py</code></a>.
</li>
</ul>
<p>As noted in the paper, lambda-py isn't quite to the point of running
Python's full <code>unittest</code> library, so these tests use a limited
language of assertions. For example, if we look at
<code>tests/python-reference/multiple-inheritance/methods.py</code>, we see
lines like:
<pre>
___assertEqual(Foo.getx(foo), 1)
</pre>
The implementation of <code>___assertEqual</code> is Python code that
simply checks that the arguments are equal according to Python's
<code>==</code> operator, and its implementation is in
<code>base/py-prelude.py</code>.
<h4>Playing around with lambda-py</h4>
<p>It's easy to tweak the Python-implemented libraries of lambda-py to see
what their effects are on Python programs. Since these libraries implement
so much built-in behavior, tweaking them can have interesting effects. You
can run individual Python programs through lambda-py by passing them
through standard input and using the <code>--interp</code> option:</p>
<pre>
$ racket python-main.rkt --interp < some-python-file.py
</pre>
<p>Some things you might try:</p>
<ul>
<li>Change the definition of the <code>__str__</code> method in
<code>pylib/dict.py</code> and run a simple program like <code>print({'x':5})</code>.
</li>
<li>Change the definition of the <code>__getitem__</code> method on a
built-in type like <code>pylib/list</code> or <code>pylib/dict</code> and
see the effects on lookup statements like <code>print([1,2,3][0])</code>.
Similarly, change <code>__add__</code> or <code>__sub__</code> and see
the effect on <code>+</code> and <code>-</code> expressions.</li>
<li>Change the behavior of the various <code>__getattribute__</code>
functions in <code>pylib/object.py</code> and see how it affects simple
attribute lookup
</ul>
<h3>Building from Scratch</h3>
<p>These instructions are included so reviewers can see the build process
for lambda-py on their own machines. Reviewers should be able to evaluate
the artifact's performance relative to the paper from the VM, but a manual
installation helps demonstrate that the artifact is easy to install and
extend.</p>
<p>
The code for lambda-py is available at <a
href="https://github.com/brownplt/lambda-py">https://github.com/brownplt/lambda-py</a>.
</p>
<p> We have two points in the repository's history that may interest
reviewers: One at the time of our OOPSLA submission (28 March, 2013), and
one at the time of our artifact submission (1 June 2013). They are tagged
in the repository as <code>oopsla2013</code> and <code>[FILL]
oopsla2013-ae</code>.
</p>
<h5>Getting Racket</h5>
<p>Both require that you install Racket; the main download link at <a
href="http://racket-lang.org/download/">http://racket-lang.org/download/</a>
has installers for many platforms. We have tested on several different
Ubuntus from 11.04 to 12.10, and on OSX, with both Racket 5.3.3 and Racket
5.3.4. For review, we recommend Racket 5.3.4. Download the installer and
run it; you can pick any of the options for installing Racket (for example,
you can install UNIX-style in <code>/usr/</code>, or keep the installation
in your home directory). In the instructions that follow, we assume that
the <code>$PATH</code> environment variable is pointing to the
<code>bin/</code> directory of the Racket installation that holds the
<code>raco</code> and <code>racket</code> commands (this may be done for
you automatically depending on which options you choose in the Racket
installer). </p>
<p><b>Example:</b></p>
<pre>
$ wget http://download.racket-lang.org/installers/5.3.4/racket/racket-5.3.4-bin-i386-linux-ubuntu-karmic.sh
$ sh racket-5.3.4-bin-i386-linux-ubuntu-karmic.sh
</pre>
<h5>Getting the Source of Lambda-py</h5>
<p>Github is the easiest way to get a copy of the code:</p>
<pre>
$ git clone https://github.com/brownplt/lambda-py
</pre>
<p>
Please <b>DO NOT</b> fork the repository on Github, as it will leak your
identity to us.
</p>
<h4>Artifact Submission-time Build</h4>
<li><p><b>PLAI-Typed:</b> Lambda-py is built in a language that sits on
top of Racket called plai-typed. We have it included with the repository
as <code>plai-typed-18Feb2013.plt</code> in the root of the repository. To
install it, use the <code>raco</code> command:</p>
<pre>
$ raco setup -A plai-typed-18Feb2013.plt
</pre>
</li>
<li><p><b>Ragg:</b></p> Since publication, we had a third-party
contribution of a pure Racket parser for Python (see <a
href="https://github.com/brownplt/lambda-py/commit/ef26e932e7f7f10b3273ec618e7b819f91ca1acf">this
merge</a>). It uses the Ragg parser package for Racket; to install it, use
the <code>raco</code> command:</p>
<pre>
$ raco setup -A ragg-mangled.plt
</pre>
<li><p><b>Building:</b> The implementation of lambda-py is in the
<code>base/</code> directory. To build, simply build the :</p>
<pre>
$ cd base
$ make
</pre>
<h4>Paper Submission-time Build</h4>
<p><em>We recommend using the provided virtual machine to review the code
as it was at submission time, since it involves additional build steps
that we have since made much easier.</em></p>
<ul>
<li><b>Python</b>
<p>At the time of submission, we used Python's parser to get original ASTs
for desugaring (we have since switched to a pure-Racket Python parser).
So, to run tests at the <code>oopsla2013</code> tag, you will also need to
install Python3 (source is available at <a
href="http://www.python.org/download/releases/3.2.3/">http://www.python.org/download/releases/3.2.3/</a>).
</p>
<p><b>Example:</b></p>
<pre>
$ wget http://www.python.org/ftp/python/3.2.3/Python-3.2.3.tgz
$ tar xzf Python-3.2.3.tgz
$ cd Python-3.2.3
$ ./configure
$ make
</pre>
</li>
<li>
<p>To view the code as it was at submission time, check out the <code>oopsla2013</code> tag:</p>
<pre>
$ git checkout oopsla2013
</pre>
</li>
<li><p><b>PLAI-Typed:</b> Lambda-py is built in a language that sits on
top of Racket called plai-typed. We have it included with the repository
as <code>plai-typed-18Feb2013.plt</code> in the root of the repository. To
install it, use the <code>raco</code> command:</p>
<pre>
$ raco setup -A plai-typed-18Feb2013.plt
</pre>
</li>
<li><p><b>Running:</b> To run the tests that were reported in the paper, run:</p>
<pre>
$ racket python-main.rkt --python-path ~/install-stuff/Python-3.2.3/python --test ../tests/python-reference/
175 tests succeeded
0 tests failed
</pre>
</body>
</html>