|
1 \documentclass[dvipsnames,14pt,t]{beamer} |
|
2 \usepackage{beamerthemeplainculight} |
|
3 \usepackage[T1]{fontenc} |
|
4 \usepackage[latin1]{inputenc} |
|
5 \usepackage{mathpartir} |
|
6 \usepackage[absolute,overlay]{textpos} |
|
7 \usepackage{ifthen} |
|
8 \usepackage{tikz} |
|
9 \usepackage{pgf} |
|
10 \usepackage{calc} |
|
11 \usepackage{ulem} |
|
12 \usepackage{courier} |
|
13 \usepackage{listings} |
|
14 \renewcommand{\uline}[1]{#1} |
|
15 \usetikzlibrary{arrows} |
|
16 \usetikzlibrary{automata} |
|
17 \usetikzlibrary{shapes} |
|
18 \usetikzlibrary{shadows} |
|
19 \usetikzlibrary{positioning} |
|
20 \usetikzlibrary{calc} |
|
21 \usetikzlibrary{plotmarks} |
|
22 \usepackage{graphicx} |
|
23 \usepackage{pgfplots} |
|
24 |
|
25 |
|
26 \definecolor{javared}{rgb}{0.6,0,0} % for strings |
|
27 \definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments |
|
28 \definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords |
|
29 \definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc |
|
30 |
|
31 \lstset{language=Java, |
|
32 basicstyle=\ttfamily, |
|
33 keywordstyle=\color{javapurple}\bfseries, |
|
34 stringstyle=\color{javagreen}, |
|
35 commentstyle=\color{javagreen}, |
|
36 morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
37 numbers=left, |
|
38 numberstyle=\tiny\color{black}, |
|
39 stepnumber=1, |
|
40 numbersep=10pt, |
|
41 tabsize=2, |
|
42 showspaces=false, |
|
43 showstringspaces=false} |
|
44 |
|
45 \lstdefinelanguage{scala}{ |
|
46 morekeywords={abstract,case,catch,class,def,% |
|
47 do,else,extends,false,final,finally,% |
|
48 for,if,implicit,import,match,mixin,% |
|
49 new,null,object,override,package,% |
|
50 private,protected,requires,return,sealed,% |
|
51 super,this,throw,trait,true,try,% |
|
52 type,val,var,while,with,yield}, |
|
53 otherkeywords={=>,<-,<\%,<:,>:,\#,@}, |
|
54 sensitive=true, |
|
55 morecomment=[l]{//}, |
|
56 morecomment=[n]{/*}{*/}, |
|
57 morestring=[b]", |
|
58 morestring=[b]', |
|
59 morestring=[b]""" |
|
60 } |
|
61 |
|
62 |
|
63 \lstset{language=Scala, |
|
64 basicstyle=\ttfamily, |
|
65 keywordstyle=\color{javapurple}\bfseries, |
|
66 stringstyle=\color{javagreen}, |
|
67 commentstyle=\color{javagreen}, |
|
68 morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
69 numbers=left, |
|
70 numberstyle=\tiny\color{black}, |
|
71 stepnumber=1, |
|
72 numbersep=10pt, |
|
73 tabsize=2, |
|
74 showspaces=false, |
|
75 showstringspaces=false} |
|
76 |
|
77 \lstdefinelanguage{while}{ |
|
78 morekeywords={if,then,else,while,do,true,false,write}, |
|
79 otherkeywords={=,!=,:=,<,>,;}, |
|
80 sensitive=true, |
|
81 morecomment=[n]{/*}{*/}, |
|
82 } |
|
83 |
|
84 |
|
85 \lstset{language=While, |
|
86 basicstyle=\ttfamily, |
|
87 keywordstyle=\color{javapurple}\bfseries, |
|
88 stringstyle=\color{javagreen}, |
|
89 commentstyle=\color{javagreen}, |
|
90 morecomment=[s][\color{javadocblue}]{/**}{*/}, |
|
91 numbers=left, |
|
92 numberstyle=\tiny\color{black}, |
|
93 stepnumber=1, |
|
94 numbersep=10pt, |
|
95 tabsize=2, |
|
96 showspaces=false, |
|
97 showstringspaces=false} |
|
98 |
|
99 |
|
100 % beamer stuff |
|
101 \renewcommand{\slidecaption}{AFL 09, King's College London, 28.~November 2012} |
|
102 \newcommand{\bl}[1]{\textcolor{blue}{#1}} |
|
103 \newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions |
|
104 |
|
105 |
|
106 % The data files, written on the first run. |
|
107 \begin{filecontents}{compiled.data} |
|
108 %1 0.234146 |
|
109 %5000 0.227539 |
|
110 %10000 0.280748 |
|
111 50000 1.087897 |
|
112 100000 3.713165 |
|
113 250000 21.6624545 |
|
114 500000 85.872613 |
|
115 750000 203.6408015 |
|
116 1000000 345.736574 |
|
117 \end{filecontents} |
|
118 |
|
119 \begin{filecontents}{interpreted.data} |
|
120 %1 0.00503 |
|
121 200 1.005863 |
|
122 400 7.8296765 |
|
123 500 15.43106 |
|
124 600 27.2321885 |
|
125 800 65.249271 |
|
126 1000 135.4493445 |
|
127 1200 232.134097 |
|
128 1400 382.527227 |
|
129 \end{filecontents} |
|
130 |
|
131 \begin{filecontents}{interpreted2.data} |
|
132 %1 0.00503 |
|
133 200 1.005863 |
|
134 400 7.8296765 |
|
135 600 27.2321885 |
|
136 800 65.249271 |
|
137 1000 135.4493445 |
|
138 1200 232.134097 |
|
139 1400 382.527227 |
|
140 \end{filecontents} |
|
141 |
|
142 \begin{filecontents}{compiled2.data} |
|
143 200 0.222058 |
|
144 400 0.215204 |
|
145 600 0.202031 |
|
146 800 0.21986 |
|
147 1000 0.205934 |
|
148 1200 0.1981615 |
|
149 1400 0.207116 |
|
150 \end{filecontents} |
|
151 |
|
152 \begin{document} |
|
153 |
|
154 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
155 \mode<presentation>{ |
|
156 \begin{frame}<1>[t] |
|
157 \frametitle{% |
|
158 \begin{tabular}{@ {}c@ {}} |
|
159 \\[-3mm] |
|
160 \LARGE Automata and \\[-2mm] |
|
161 \LARGE Formal Languages (9)\\[3mm] |
|
162 \end{tabular}} |
|
163 |
|
164 \normalsize |
|
165 \begin{center} |
|
166 \begin{tabular}{ll} |
|
167 Email: & christian.urban at kcl.ac.uk\\ |
|
168 Of$\!$fice: & S1.27 (1st floor Strand Building)\\ |
|
169 Slides: & KEATS (also home work is there)\\ |
|
170 \end{tabular} |
|
171 \end{center} |
|
172 |
|
173 \end{frame}} |
|
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
175 |
|
176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
177 \mode<presentation>{ |
|
178 \begin{frame}[c] |
|
179 |
|
180 Imagine the following situation: You talk to somebody |
|
181 and you find out that she/he has implemented a compiler.\smallskip |
|
182 |
|
183 What is your reaction? Check all that apply.\bigskip\pause |
|
184 |
|
185 \begin{itemize} |
|
186 \item[$\Box$] You think she/he is God |
|
187 \item[$\Box$] \"Uberhacker |
|
188 \item[$\Box$] superhuman |
|
189 \item[$\Box$] wizard |
|
190 \item[$\Box$] supremo |
|
191 \end{itemize} |
|
192 |
|
193 \end{frame}} |
|
194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
195 |
|
196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
197 \mode<presentation>{ |
|
198 \begin{frame}[c] |
|
199 \frametitle{\begin{tabular}{c}While-Language\end{tabular}} |
|
200 |
|
201 |
|
202 \begin{center} |
|
203 \bl{\begin{tabular}{@{}lcl@{}} |
|
204 $Stmt$ & $\rightarrow$ & $\text{skip}$\\ |
|
205 & $|$ & $Id := AExp$\\ |
|
206 & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\ |
|
207 & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\\ |
|
208 & $|$ & $\alert{\text{write}\; Id}$\medskip\\ |
|
209 $Stmts$ & $\rightarrow$ & $Stmt \;\text{;}\; Stmts$\\ |
|
210 & $|$ & $Stmt$\medskip\\ |
|
211 $Block$ & $\rightarrow$ & $\{ Stmts \}$\\ |
|
212 & $|$ & $Stmt$\medskip\\ |
|
213 $AExp$ & $\rightarrow$ & \ldots\\ |
|
214 $BExp$ & $\rightarrow$ & \ldots\\ |
|
215 \end{tabular}} |
|
216 \end{center} |
|
217 |
|
218 |
|
219 \end{frame}} |
|
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
221 |
|
222 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
223 \mode<presentation>{ |
|
224 \begin{frame}[c] |
|
225 \frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}} |
|
226 |
|
227 \mbox{}\\[-18mm]\mbox{} |
|
228 |
|
229 {\lstset{language=While}\fontsize{10}{12}\selectfont |
|
230 \texttt{\lstinputlisting{fib.while}}} |
|
231 |
|
232 \end{frame}} |
|
233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
234 |
|
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
236 \mode<presentation>{ |
|
237 \begin{frame}[c] |
|
238 \frametitle{\begin{tabular}{c}Interpreter\end{tabular}} |
|
239 |
|
240 \begin{center} |
|
241 \bl{\begin{tabular}{@{}lcl@{}} |
|
242 $\text{eval}(n, E)$ & $\dn$ & $n$\\ |
|
243 $\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\ |
|
244 $\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\ |
|
245 $\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\ |
|
246 $\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\ |
|
247 $\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\ |
|
248 $\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\ |
|
249 $\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\ |
|
250 \end{tabular}} |
|
251 \end{center} |
|
252 |
|
253 \end{frame}} |
|
254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
255 |
|
256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
257 \mode<presentation>{ |
|
258 \begin{frame}[c] |
|
259 \frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}} |
|
260 |
|
261 \begin{center} |
|
262 \bl{\begin{tabular}{@{}lcl@{}} |
|
263 $\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\ |
|
264 $\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\ |
|
265 \multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\ |
|
266 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\; |
|
267 \text{eval}(cs_1,E)$}\\ |
|
268 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\ |
|
269 \multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\ |
|
270 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\ |
|
271 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\; |
|
272 \text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\ |
|
273 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\ |
|
274 $\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\ |
|
275 \end{tabular}} |
|
276 \end{center} |
|
277 |
|
278 \end{frame}} |
|
279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
280 |
|
281 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
282 \mode<presentation>{ |
|
283 \begin{frame}[c] |
|
284 \frametitle{\begin{tabular}{c}Test Program\end{tabular}} |
|
285 |
|
286 \mbox{}\\[-18mm]\mbox{} |
|
287 |
|
288 {\lstset{language=While}\fontsize{10}{12}\selectfont |
|
289 \texttt{\lstinputlisting{loops.while}}} |
|
290 |
|
291 \end{frame}} |
|
292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
293 |
|
294 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
295 \mode<presentation>{ |
|
296 \begin{frame}[t] |
|
297 \frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}} |
|
298 |
|
299 \begin{center} |
|
300 \begin{tikzpicture} |
|
301 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
|
302 \addplot+[smooth] file {interpreted.data}; |
|
303 \end{axis} |
|
304 \end{tikzpicture} |
|
305 \end{center} |
|
306 |
|
307 \end{frame}} |
|
308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
309 |
|
310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
311 \mode<presentation>{ |
|
312 \begin{frame}[c] |
|
313 \frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}} |
|
314 |
|
315 \begin{itemize} |
|
316 \item introduced in 1995 |
|
317 \item is a stack-based VM (like Postscript, CLR of .Net) |
|
318 \item contains a JIT compiler |
|
319 \item many languages take advantage of JVM's infrastructure (JRE) |
|
320 \item is garbage collected $\Rightarrow$ no buffer overflows |
|
321 \item some languages compiled to the JVM: Scala, Clojure\ldots |
|
322 \end{itemize} |
|
323 |
|
324 \end{frame}} |
|
325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
326 |
|
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
328 \mode<presentation>{ |
|
329 \begin{frame}[t] |
|
330 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
331 |
|
332 {\Large\bl{1 + 2}} |
|
333 |
|
334 \begin{center} |
|
335 \bl{\begin{tabular}{l} |
|
336 ldc 1\\ |
|
337 ldc 2\\ |
|
338 iadd\\ |
|
339 \end{tabular}} |
|
340 \end{center}\end{frame}} |
|
341 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
342 |
|
343 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
344 \mode<presentation>{ |
|
345 \begin{frame}[t] |
|
346 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
347 |
|
348 {\Large\bl{1 + 2 + 3}} |
|
349 |
|
350 \begin{center} |
|
351 \bl{\begin{tabular}{l} |
|
352 ldc 1\\ |
|
353 ldc 2\\ |
|
354 iadd\\ |
|
355 ldc 3\\ |
|
356 iadd\\ |
|
357 \end{tabular}} |
|
358 \end{center} |
|
359 |
|
360 \end{frame}} |
|
361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
362 |
|
363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
364 \mode<presentation>{ |
|
365 \begin{frame}[t] |
|
366 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
367 |
|
368 {\Large\bl{1 + (2 + 3)}} |
|
369 |
|
370 \begin{center} |
|
371 \bl{\begin{tabular}{l} |
|
372 ldc 1\\ |
|
373 ldc 2\\ |
|
374 ldc 3\\ |
|
375 iadd\\ |
|
376 iadd\\ |
|
377 \end{tabular}} |
|
378 \end{center}\bigskip\pause |
|
379 \vfill |
|
380 |
|
381 \bl{dadd, fadd, ladd, \ldots} |
|
382 |
|
383 \end{frame}} |
|
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
385 |
|
386 |
|
387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
388 \mode<presentation>{ |
|
389 \begin{frame}[t] |
|
390 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
391 |
|
392 \begin{center} |
|
393 \bl{\begin{tabular}{@{}lcl@{}} |
|
394 $\text{compile}(n)$ & $\dn$ & $\text{ldc}\;n$\\ |
|
395 $\text{compile}(a_1 + a_2)$ & $\dn$\\ |
|
396 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\;\text{compile}(a_2)\;@\; \text{iadd}$}\smallskip\\ |
|
397 $\text{compile}(a_1 - a_2)$ & $\dn$\\ |
|
398 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{isub}$}\smallskip\\ |
|
399 $\text{compile}(a_1 * a_2)$ & $\dn$\\ |
|
400 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{imul}$}\smallskip\\ |
|
401 \end{tabular}} |
|
402 \end{center}\pause |
|
403 |
|
404 \end{frame}} |
|
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
406 |
|
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
408 \mode<presentation>{ |
|
409 \begin{frame}[t] |
|
410 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
411 |
|
412 {\Large\bl{1 + 2 * 3 + (4 - 3)}} |
|
413 |
|
414 \begin{center} |
|
415 \bl{\begin{tabular}{l} |
|
416 ldc 1\\ |
|
417 ldc 2\\ |
|
418 ldc 3\\ |
|
419 imul\\ |
|
420 ldc 4\\ |
|
421 ldc 3\\ |
|
422 isub\\ |
|
423 iadd\\ |
|
424 iadd\\ |
|
425 \end{tabular}} |
|
426 \end{center} |
|
427 |
|
428 \end{frame}} |
|
429 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
430 |
|
431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
432 \mode<presentation>{ |
|
433 \begin{frame}[t] |
|
434 \frametitle{\begin{tabular}{c}Variables\end{tabular}} |
|
435 |
|
436 {\Large\bl{$x := 5 + y * 2$}}\bigskip\pause |
|
437 |
|
438 \begin{itemize} |
|
439 \item lookup: \bl{$\text{iload}\; index$} |
|
440 \item store: \bl{$\text{istore}\; index$} |
|
441 \end{itemize}\bigskip\pause |
|
442 |
|
443 while compilating we have to maintain a map between our identifiers and the |
|
444 Java bytecode indices |
|
445 |
|
446 \begin{center} |
|
447 \bl{$\text{compile}(a, E)$} |
|
448 \end{center} |
|
449 |
|
450 \end{frame}} |
|
451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
452 |
|
453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
454 \mode<presentation>{ |
|
455 \begin{frame}[t] |
|
456 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
457 |
|
458 \begin{center} |
|
459 \bl{\begin{tabular}{@{}lcl@{}} |
|
460 $\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\ |
|
461 $\text{compile}(a_1 + a_2, E)$ & $\dn$\\ |
|
462 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{iadd}$}\smallskip\\ |
|
463 $\text{compile}(a_1 - a_2, E)$ & $\dn$\\ |
|
464 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\ |
|
465 $\text{compile}(a_1 * a_2, E)$ & $\dn$\\ |
|
466 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\ |
|
467 $\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\ |
|
468 \end{tabular}} |
|
469 \end{center}\pause |
|
470 |
|
471 \end{frame}} |
|
472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
473 |
|
474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
475 \mode<presentation>{ |
|
476 \begin{frame}[t] |
|
477 \frametitle{\begin{tabular}{c}Compiling Statements\end{tabular}} |
|
478 |
|
479 We return a list of instructions and an environment for the variables |
|
480 |
|
481 \begin{center} |
|
482 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}} |
|
483 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(N\!il, E)$\bigskip\\ |
|
484 $\text{compile}(x := a, E)$ & $\dn$\\ |
|
485 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\ |
|
486 \end{tabular}} |
|
487 \end{center}\medskip |
|
488 |
|
489 where \bl{$index$} is \bl{$E(x)$} if it is already defined, or if it is not then the largest index not yet seen |
|
490 |
|
491 \end{frame}} |
|
492 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
493 |
|
494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
495 \mode<presentation>{ |
|
496 \begin{frame}[t] |
|
497 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
498 |
|
499 {\Large\bl{$x := x + 1$}} |
|
500 |
|
501 \begin{center} |
|
502 \bl{\begin{tabular}{l} |
|
503 iload $n_x$\\ |
|
504 ldc 1\\ |
|
505 iadd\\ |
|
506 istore $n_x$\\ |
|
507 \end{tabular}} |
|
508 \end{center} |
|
509 |
|
510 where \bl{$n_x$} is the index corresponding to the variable \bl{$x$} |
|
511 |
|
512 \end{frame}} |
|
513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
514 |
|
515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
516 \mode<presentation>{ |
|
517 \begin{frame}[t] |
|
518 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}} |
|
519 |
|
520 {\Large\bl{$\text{if}\;b\;\text{else}\;cs_1\;\text{then}\;cs_2$}}\bigskip\bigskip |
|
521 |
|
522 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:} |
|
523 |
|
524 \begin{center} |
|
525 \begin{tikzpicture}[node distance=2mm and 4mm, |
|
526 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm}, |
|
527 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red}, |
|
528 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}] |
|
529 \node (A1) [point] {}; |
|
530 \node (b) [block, right=of A1] {code of \bl{$b$}}; |
|
531 \node (A2) [point, right=of b] {}; |
|
532 \node (cs1) [block, right=of A2] {code of \bl{$cs_1$}}; |
|
533 \node (A3) [point, right=of cs1] {}; |
|
534 \node (cs2) [block, right=of A3] {code of \bl{$cs_2$}}; |
|
535 \node (A4) [point, right=of cs2] {}; |
|
536 |
|
537 \only<2>{ |
|
538 \draw (A1) edge [->, red, line width=1mm] (b); |
|
539 \draw (b) edge [->, red, line width=1mm] (cs1); |
|
540 \draw (cs1) edge [->, red, line width=1mm] (A3); |
|
541 \draw (A3) edge [->,skip loop] (A4); |
|
542 \node [below=of cs2] {\raisebox{-5mm}{\small{}jump}};} |
|
543 \only<3>{ |
|
544 \draw (A1) edge [->, red, line width=1mm] (b); |
|
545 \draw (b) edge [->, red, line width=1mm] (A2); |
|
546 \draw (A2) edge [skip loop] (A3); |
|
547 \draw (A3) edge [->, red, line width=1mm] (cs2); |
|
548 \draw (cs2) edge [->,red, line width=1mm] (A4); |
|
549 \node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};} |
|
550 \end{tikzpicture} |
|
551 \end{center} |
|
552 |
|
553 |
|
554 \end{frame}} |
|
555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
556 |
|
557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
558 \mode<presentation>{ |
|
559 \begin{frame}[c] |
|
560 \frametitle{\begin{tabular}{c}Conditional Jumps\end{tabular}} |
|
561 |
|
562 \begin{minipage}{1.1\textwidth} |
|
563 \begin{itemize} |
|
564 \item \bl{if\_icmpeq $label$} if two ints are equal, then jump\medskip |
|
565 \item \bl{if\_icmpne $label$} if two ints aren't equal, then jump\medskip |
|
566 \item \bl{if\_icmpge $label$} if one int is greater or equal then another, then jump |
|
567 \item[]\ldots |
|
568 \end{itemize} |
|
569 \end{minipage}\pause |
|
570 |
|
571 |
|
572 \begin{center} |
|
573 \bl{\begin{tabular}{l} |
|
574 $L_1$:\\ |
|
575 \hspace{5mm}if\_icmpeq\;$L_2$\\ |
|
576 \hspace{5mm}iload 1\\ |
|
577 \hspace{5mm}ldc 1\\ |
|
578 \hspace{5mm}iadd\\ |
|
579 \hspace{5mm}if\_icmpeq\;$L_1$\\ |
|
580 $L_2$: |
|
581 \end{tabular}} |
|
582 \end{center} |
|
583 |
|
584 \begin{textblock}{3.5}(11,12) |
|
585 \only<3>{labels must be unique} |
|
586 \end{textblock} |
|
587 \end{frame}} |
|
588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
589 |
|
590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
591 \mode<presentation>{ |
|
592 \begin{frame}[t] |
|
593 \frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}} |
|
594 |
|
595 {\Large\bl{$a_1 = a_2$}} |
|
596 |
|
597 \begin{center} |
|
598 \bl{\begin{tabular}{lcl} |
|
599 $\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ |
|
600 \multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$} |
|
601 \end{tabular}} |
|
602 \end{center} |
|
603 |
|
604 \end{frame}} |
|
605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
606 |
|
607 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
608 \mode<presentation>{ |
|
609 \begin{frame}[t] |
|
610 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}} |
|
611 |
|
612 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}} |
|
613 |
|
614 \begin{center} |
|
615 \bl{\begin{tabular}{lcl} |
|
616 $\text{compile}(\text{if}\;b\;\text{then}\; cs_1\;\text{else}\; cs_2, E)$ & $\dn$\\ |
|
617 \multicolumn{3}{l}{$\quad l_{ifelse}\;$ \textcolor{black}{(fresh label)}}\\ |
|
618 \multicolumn{3}{l}{$\quad l_{ifend}\;$ \textcolor{black}{(fresh label)}}\\ |
|
619 \multicolumn{3}{l}{$\quad (is_1, E') = \text{compile}(cs_1, E)$}\\ |
|
620 \multicolumn{3}{l}{$\quad (is_2, E'') = \text{compile}(cs_2, E')$}\\ |
|
621 \multicolumn{3}{l}{$\quad(\text{compile}(b, E, l_{ifelse})$}\\ |
|
622 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_1$}\\ |
|
623 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{ifend}$}\\ |
|
624 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifelse}:$}\\ |
|
625 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\ |
|
626 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\ |
|
627 \end{tabular}} |
|
628 \end{center} |
|
629 |
|
630 \end{frame}} |
|
631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
632 |
|
633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
634 \mode<presentation>{ |
|
635 \begin{frame}[t] |
|
636 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}} |
|
637 |
|
638 {\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip |
|
639 |
|
640 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:} |
|
641 |
|
642 \begin{center} |
|
643 \begin{tikzpicture}[node distance=2mm and 4mm, |
|
644 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm}, |
|
645 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red}, |
|
646 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}] |
|
647 \node (A0) [point, left=of A1] {}; |
|
648 \node (A1) [point] {}; |
|
649 \node (b) [block, right=of A1] {code of \bl{$b$}}; |
|
650 \node (A2) [point, right=of b] {}; |
|
651 \node (cs1) [block, right=of A2] {code of \bl{$cs$}}; |
|
652 \node (A3) [point, right=of cs1] {}; |
|
653 \node (A4) [point, right=of A3] {}; |
|
654 |
|
655 \only<2>{ |
|
656 \draw (A0) edge [->, red, line width=1mm] (b); |
|
657 \draw (b) edge [->, red, line width=1mm] (cs1); |
|
658 \draw (cs1) edge [->, red, line width=1mm] (A3); |
|
659 \draw (A3) edge [->,skip loop] (A1);} |
|
660 \only<3>{ |
|
661 \draw (A0) edge [->, red, line width=1mm] (b); |
|
662 \draw (b) edge [->, red, line width=1mm] (A2); |
|
663 \draw (A2) edge [skip loop] (A3); |
|
664 \draw (A3) edge [->, red, line width=1mm] (A4);} |
|
665 \end{tikzpicture} |
|
666 \end{center} |
|
667 |
|
668 |
|
669 \end{frame}} |
|
670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
671 |
|
672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
673 \mode<presentation>{ |
|
674 \begin{frame}[t] |
|
675 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}} |
|
676 |
|
677 {\Large\bl{while $b$ do $cs$}} |
|
678 |
|
679 \begin{center} |
|
680 \bl{\begin{tabular}{lcl} |
|
681 $\text{compile}(\text{while}\; b\; \text{do} \;cs, E)$ & $\dn$\\ |
|
682 \multicolumn{3}{l}{$\quad l_{wbegin}\;$ \textcolor{black}{(fresh label)}}\\ |
|
683 \multicolumn{3}{l}{$\quad l_{wend}\;$ \textcolor{black}{(fresh label)}}\\ |
|
684 \multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\ |
|
685 \multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\ |
|
686 \multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\ |
|
687 \multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\ |
|
688 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\ |
|
689 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E')$}\\ |
|
690 \end{tabular}} |
|
691 \end{center} |
|
692 |
|
693 \end{frame}} |
|
694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
695 |
|
696 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
697 \mode<presentation>{ |
|
698 \begin{frame}[t] |
|
699 \frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}} |
|
700 |
|
701 {\Large\bl{write $x$}} |
|
702 |
|
703 \begin{center} |
|
704 \small\bl{\begin{tabular}{l} |
|
705 .method public static write(I)V\hspace{1cm}\textcolor{black}{(library function)}\\ |
|
706 \;\; .limit locals 5 \\ |
|
707 \;\; .limit stack 5 \\ |
|
708 \;\; iload 0 \\ |
|
709 \;\; getstatic java/lang/System/out Ljava/io/PrintStream;\\ |
|
710 \;\; swap \\ |
|
711 \;\; invokevirtual java/io/PrintStream/println(I)V \\ |
|
712 \;\; return \\ |
|
713 .end method\bigskip\bigskip\\ |
|
714 % |
|
715 \normalsize |
|
716 iload $E(x)$\\ |
|
717 invokestatic write(I)V\\ |
|
718 \end{tabular}} |
|
719 \end{center} |
|
720 |
|
721 \end{frame}} |
|
722 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
723 |
|
724 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
725 \mode<presentation>{ |
|
726 \begin{frame}[c] |
|
727 |
|
728 \begin{center} |
|
729 \small\bl{\begin{tabular}{l} |
|
730 .class public XXX.XXX\\ |
|
731 .super java/lang/Object\\ |
|
732 \\ |
|
733 .method public <init>()V\\ |
|
734 \;\; aload\_0\\ |
|
735 \;\; invokenonvirtual java/lang/Object/<init>()V\\ |
|
736 \;\; return\\ |
|
737 .end method\\ |
|
738 \\ |
|
739 .method public static main([Ljava/lang/String;)V\\ |
|
740 \;\; .limit locals 200\\ |
|
741 \;\; .limit stack 200\\ |
|
742 \\ |
|
743 \textcolor{black}{(here comes the compiled code)}\\ |
|
744 \\ |
|
745 \;\; return\\ |
|
746 .end method\\ |
|
747 \end{tabular}} |
|
748 \end{center} |
|
749 |
|
750 \end{frame}} |
|
751 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
752 |
|
753 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
754 \mode<presentation>{ |
|
755 \begin{frame}[c] |
|
756 \frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}} |
|
757 |
|
758 \begin{itemize} |
|
759 \item assembly $\Rightarrow$ byte code (class file) |
|
760 \item labels $\Rightarrow$ absolute or relative jumps\bigskip\bigskip |
|
761 \item \texttt{javap} is a disassembler for class files |
|
762 \end{itemize} |
|
763 |
|
764 \end{frame}} |
|
765 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
766 |
|
767 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
768 \mode<presentation>{ |
|
769 \begin{frame}[t] |
|
770 \frametitle{\begin{tabular}{c}Compiled Code\end{tabular}} |
|
771 |
|
772 \begin{center} |
|
773 \begin{tikzpicture} |
|
774 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
|
775 \addplot+[smooth] file {compiled.data}; |
|
776 \end{axis} |
|
777 \end{tikzpicture} |
|
778 \end{center} |
|
779 |
|
780 \end{frame}} |
|
781 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
782 |
|
783 |
|
784 |
|
785 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
786 \mode<presentation>{ |
|
787 \begin{frame}[t] |
|
788 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}} |
|
789 |
|
790 \begin{center} |
|
791 \begin{tikzpicture} |
|
792 \begin{loglogaxis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
|
793 \addplot+[smooth] file {interpreted.data}; |
|
794 \addplot+[smooth] file {compiled.data}; |
|
795 \end{loglogaxis} |
|
796 \end{tikzpicture} |
|
797 \end{center} |
|
798 |
|
799 \end{frame}} |
|
800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
801 |
|
802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
803 \mode<presentation>{ |
|
804 \begin{frame}[t] |
|
805 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}} |
|
806 |
|
807 \begin{center} |
|
808 \begin{tikzpicture} |
|
809 \begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs, |
|
810 xlabel=n, |
|
811 enlargelimits=0.05, |
|
812 ybar interval=0.7, legend style=small] |
|
813 \addplot file {interpreted2.data}; |
|
814 \addplot file {compiled2.data}; |
|
815 %\legend{interpreted, compiled} |
|
816 \end{axis} |
|
817 \end{tikzpicture} |
|
818 \end{center} |
|
819 |
|
820 \end{frame}} |
|
821 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
822 |
|
823 |
|
824 |
|
825 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
826 \mode<presentation>{ |
|
827 \begin{frame}[t] |
|
828 \frametitle{\begin{tabular}{c}What Next\end{tabular}} |
|
829 |
|
830 \begin{itemize} |
|
831 \item register spilling |
|
832 \item dead code removal |
|
833 \item loop optimisations |
|
834 \item instruction selection |
|
835 \item type checking |
|
836 \item concurrency |
|
837 \item fuzzy testing |
|
838 \item verification\bigskip\\ |
|
839 |
|
840 \item GCC, LLVM, tracing JITs |
|
841 \end{itemize} |
|
842 |
|
843 \end{frame}} |
|
844 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
845 |
|
846 |
|
847 \end{document} |
|
848 |
|
849 %%% Local Variables: |
|
850 %%% mode: latex |
|
851 %%% TeX-master: t |
|
852 %%% End: |
|
853 |