37 |
37 |
38 \begin{center} |
38 \begin{center} |
39 \begin{tikzpicture} |
39 \begin{tikzpicture} |
40 \node (rexp) {\bl{\bf Lexer}}; |
40 \node (rexp) {\bl{\bf Lexer}}; |
41 \node (nfa) [right=of rexp] {\bl{\bf Parser}}; |
41 \node (nfa) [right=of rexp] {\bl{\bf Parser}}; |
42 \node (dfa) [right=of nfa] {\bl{\begin{tabular}{c}\bf Machine Code/\\\bf Byte Code\end{tabular}}}; |
42 \node (dfa) [right=of nfa] |
|
43 {\bl{\begin{tabular}{c}\bf Machine Code/\\\bf Java Byte Code\end{tabular}}}; |
43 \path[->, red, line width=2mm] (rexp) edge node [above=4mm, black] {\begin{tabular}{c@{\hspace{9mm}}}token\\[-1mm] |
44 \path[->, red, line width=2mm] (rexp) edge node [above=4mm, black] {\begin{tabular}{c@{\hspace{9mm}}}token\\[-1mm] |
44 sequence\end{tabular}} (nfa); |
45 sequence\end{tabular}} (nfa); |
45 \path[->, red, line width=2mm] (nfa) edge node [above=4mm, black] {\begin{tabular}{c}parse\\[-1mm] tree\end{tabular}}(dfa); |
46 \path[->, red, line width=2mm] (nfa) edge node [above=4mm, black] {\begin{tabular}{c}parse\\[-1mm] tree\end{tabular}}(dfa); |
46 \end{tikzpicture}\\ |
47 \end{tikzpicture}\\ |
47 \end{center} |
48 \end{center} |
96 |
102 |
97 \end{frame}} |
103 \end{frame}} |
98 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
99 |
105 |
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
101 \mode<presentation>{ |
|
102 \begin{frame}[c] |
107 \begin{frame}[c] |
103 \frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}} |
108 \frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}} |
104 |
109 |
105 \mbox{}\\[-18mm]\mbox{} |
110 \mbox{}\\[-18mm]\mbox{} |
106 |
111 |
107 {\lstset{language=While}\fontsize{10}{12}\selectfont |
112 {\lstset{language=While}\fontsize{10}{12}\selectfont |
108 \texttt{\lstinputlisting{../progs/fib.while}}} |
113 \texttt{\lstinputlisting{../progs/fib.while}}} |
109 |
114 |
110 \end{frame}} |
115 \end{frame} |
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
112 |
117 |
113 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
114 \mode<presentation>{ |
119 \begin{frame}[c] |
115 \begin{frame}[c] |
120 \frametitle{Interpreter} |
116 \frametitle{\begin{tabular}{c}Interpreter\end{tabular}} |
|
117 |
121 |
118 \begin{center} |
122 \begin{center} |
119 \bl{\begin{tabular}{@{}lcl@{}} |
123 \bl{\begin{tabular}{@{}lcl@{}} |
120 $\text{eval}(n, E)$ & $\dn$ & $n$\\ |
124 $\text{eval}(n, E)$ & $\dn$ & $n$\\ |
121 $\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\ |
125 $\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\ |
126 $\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\ |
130 $\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\ |
127 $\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\ |
131 $\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\ |
128 \end{tabular}} |
132 \end{tabular}} |
129 \end{center} |
133 \end{center} |
130 |
134 |
131 \end{frame}} |
135 \end{frame} |
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
136 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
133 |
137 |
134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
135 \mode<presentation>{ |
139 \begin{frame}[c] |
136 \begin{frame}[c] |
140 \frametitle{Interpreter (2)} |
137 \frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}} |
|
138 |
141 |
139 \begin{center} |
142 \begin{center} |
140 \bl{\begin{tabular}{@{}lcl@{}} |
143 \bl{\begin{tabular}{@{}lcl@{}} |
141 $\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\ |
144 $\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\ |
142 $\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\ |
145 $\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\ |
151 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\ |
154 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\ |
152 $\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\ |
155 $\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\ |
153 \end{tabular}} |
156 \end{tabular}} |
154 \end{center} |
157 \end{center} |
155 |
158 |
156 \end{frame}} |
159 \end{frame} |
157 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
160 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
158 |
161 |
159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
162 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
160 \mode<presentation>{ |
163 \begin{frame}[c] |
161 \begin{frame}[c] |
164 \frametitle{Test Program} |
162 \frametitle{\begin{tabular}{c}Test Program\end{tabular}} |
|
163 |
165 |
164 \mbox{}\\[-18mm]\mbox{} |
166 \mbox{}\\[-18mm]\mbox{} |
165 |
167 |
166 {\lstset{language=While}\fontsize{10}{12}\selectfont |
168 {\lstset{language=While}\fontsize{10}{12}\selectfont |
167 \texttt{\lstinputlisting{../progs/loops.while}}} |
169 \texttt{\lstinputlisting{../progs/loops.while}}} |
168 |
170 |
169 \end{frame}} |
171 \end{frame} |
170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
171 |
173 |
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
173 \begin{frame}[c] |
175 \begin{frame}[c] |
174 \tiny |
176 \fontsize{7}{9}\selectfont |
|
177 |
175 |
178 |
176 \begin{columns} |
179 \begin{columns} |
177 \begin{column}{7cm} |
180 \begin{column}{7cm} |
178 \lstinputlisting[numbers=none]{../progs/appHa.j} |
181 \lstinputlisting[numbers=none]{../progs/appHa.j} |
179 \end{column} |
182 \end{column} |
180 |
183 |
181 \begin{column}{7cm} |
184 \begin{column}{7cm} |
182 \lstinputlisting[numbers=none]{../progs/appHb.j} |
185 \lstinputlisting[numbers=none]{../progs/appHb.j} |
183 \end{column} |
186 \end{column} |
184 |
|
185 \end{columns} |
187 \end{columns} |
186 |
188 |
187 \end{frame} |
189 \end{frame} |
188 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
190 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
189 |
191 |
190 |
192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
191 |
193 \begin{frame}[t] |
192 |
194 \frametitle{Interpreted Code} |
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
194 \mode<presentation>{ |
|
195 \begin{frame}[t] |
|
196 \frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}} |
|
197 |
195 |
198 \begin{center} |
196 \begin{center} |
199 \begin{tikzpicture} |
197 \begin{tikzpicture} |
200 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
198 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
201 \addplot+[smooth] file {interpreted.data}; |
199 \addplot+[smooth] file {interpreted.data}; |
202 \end{axis} |
200 \end{axis} |
203 \end{tikzpicture} |
201 \end{tikzpicture} |
204 \end{center} |
202 \end{center} |
205 |
203 |
206 \end{frame}} |
204 \end{frame} |
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
208 |
206 |
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
210 \mode<presentation>{ |
208 \begin{frame}[c] |
211 \begin{frame}[c] |
209 \frametitle{Java Virtual Machine} |
212 \frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}} |
|
213 |
210 |
214 \begin{itemize} |
211 \begin{itemize} |
215 \item introduced in 1995 |
212 \item introduced in 1995 |
216 \item is a stack-based VM (like Postscript, CLR of .Net) |
213 \item is a stack-based VM (like Postscript, CLR of .Net) |
217 \item contains a JIT compiler |
214 \item contains a JIT compiler |
218 \item many languages take advantage of JVM's infrastructure (JRE) |
215 \item many languages take advantage of JVM's infrastructure (JRE) |
219 \item is garbage collected $\Rightarrow$ no buffer overflows |
216 \item is garbage collected $\Rightarrow$ no buffer overflows |
220 \item some languages compiled to the JVM: Scala, Clojure\ldots |
217 \item some languages compiled to the JVM: Scala, Clojure\ldots |
221 \end{itemize} |
218 \end{itemize} |
222 |
219 |
223 \end{frame}} |
220 \end{frame} |
224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
225 |
222 |
226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
223 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
227 \mode<presentation>{ |
224 \begin{frame}[t] |
228 \begin{frame}[t] |
225 \frametitle{Compiling AExps} |
229 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
230 |
226 |
231 {\Large\bl{1 + 2}} |
227 {\Large\bl{1 + 2}} |
232 |
228 |
233 \begin{center} |
229 \begin{center} |
234 \bl{\begin{tabular}{l} |
230 \bl{\begin{tabular}{l} |
235 ldc 1\\ |
231 ldc 1\\ |
236 ldc 2\\ |
232 ldc 2\\ |
237 iadd\\ |
233 iadd\\ |
238 \end{tabular}} |
234 \end{tabular}} |
239 \end{center}\end{frame}} |
235 \end{center} |
|
236 \end{frame} |
240 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
241 |
238 |
242 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
243 \mode<presentation>{ |
240 \mode<presentation>{ |
244 \begin{frame}[t] |
241 \begin{frame}[t] |
344 |
339 |
345 \begin{center} |
340 \begin{center} |
346 \bl{$\text{compile}(a, E)$} |
341 \bl{$\text{compile}(a, E)$} |
347 \end{center} |
342 \end{center} |
348 |
343 |
349 \end{frame}} |
344 \end{frame} |
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
351 |
346 |
352 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
353 \mode<presentation>{ |
348 \begin{frame}[t] |
354 \begin{frame}[t] |
349 \frametitle{Compiling AExps} |
355 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
356 |
350 |
357 \begin{center} |
351 \begin{center} |
358 \bl{\begin{tabular}{@{}lcl@{}} |
352 \bl{\begin{tabular}{@{}lcl@{}} |
359 $\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\ |
353 $\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\ |
360 $\text{compile}(a_1 + a_2, E)$ & $\dn$\\ |
354 $\text{compile}(a_1 + a_2, E)$ & $\dn$\\ |
361 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{iadd}$}\smallskip\\ |
355 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{iadd}$}\smallskip\\ |
362 $\text{compile}(a_1 - a_2, E)$ & $\dn$\\ |
356 $\text{compile}(a_1 - a_2, E)$ & $\dn$\\ |
363 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\ |
357 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\ |
364 $\text{compile}(a_1 * a_2, E)$ & $\dn$\\ |
358 $\text{compile}(a_1 * a_2, E)$ & $\dn$\\ |
365 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\ |
359 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\ |
366 $\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\ |
360 $\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\ |
367 \end{tabular}} |
361 \end{tabular}} |
368 \end{center}\pause |
362 \end{center} |
369 |
363 |
370 \end{frame}} |
364 \end{frame} |
371 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
365 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
372 |
366 |
373 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
374 \mode<presentation>{ |
368 \begin{frame}[c, fragile] |
375 \begin{frame}[t] |
369 \frametitle{Mathematical Functions} |
376 \frametitle{\begin{tabular}{c}Compiling Statements\end{tabular}} |
370 |
377 |
371 Compilation of some mathematical functions: |
378 We return a list of instructions and an environment for the variables |
372 |
|
373 \begin{center} |
|
374 \begin{tabular}{lcl} |
|
375 \texttt{Aop("+", a1, a2)} & $\Rightarrow$ & \texttt{...iadd}\\ |
|
376 \texttt{Aop("-", a1, a2)} & $\Rightarrow$ & \texttt{...isub}\\ |
|
377 \texttt{Aop("*", a1, a2)} & $\Rightarrow$ & \texttt{...imul}\\ |
|
378 \texttt{Aop("/", a1, a2)} & $\Rightarrow$ & \texttt{...idiv}\\ |
|
379 \texttt{Aop("\%", a1, a2)} & $\Rightarrow$ & \texttt{...irem}\\ |
|
380 \end{tabular} |
|
381 \end{center} |
|
382 |
|
383 \end{frame} |
|
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
385 |
|
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
387 \begin{frame}[t] |
|
388 \frametitle{Compiling Statements} |
|
389 |
|
390 We return a list of instructions and an environment for the |
|
391 variables |
379 |
392 |
380 \begin{center} |
393 \begin{center} |
381 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}} |
394 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}} |
382 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(N\!il, E)$\bigskip\\ |
395 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(\textit{Nil}, E)$\bigskip\\ |
383 $\text{compile}(x := a, E)$ & $\dn$\\ |
396 $\text{compile}(x := a, E)$ & $\dn$\\ |
384 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\ |
397 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\ |
385 \end{tabular}} |
398 \end{tabular}} |
386 \end{center}\medskip |
399 \end{center}\medskip |
387 |
400 |
388 where \bl{$index$} is \bl{$E(x)$} if it is already defined, or if it is not then the largest index not yet seen |
401 where \bl{$index$} is \bl{$E(x)$} if it is already defined, |
389 |
402 or if it is not, then the largest index not yet seen |
390 \end{frame}} |
403 |
391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
404 \end{frame} |
392 |
405 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
406 |
394 \mode<presentation>{ |
407 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
395 \begin{frame}[t] |
408 \begin{frame}[c] |
396 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
409 \frametitle{Compiling Assignments} |
397 |
410 |
398 {\Large\bl{$x := x + 1$}} |
411 {\Large\bl{$x := x + 1$}} |
399 |
412 |
400 \begin{center} |
413 \begin{center} |
401 \bl{\begin{tabular}{l} |
414 \bl{\begin{tabular}{l} |
447 \draw (cs2) edge [->,red, line width=1mm] (A4); |
460 \draw (cs2) edge [->,red, line width=1mm] (A4); |
448 \node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};} |
461 \node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};} |
449 \end{tikzpicture} |
462 \end{tikzpicture} |
450 \end{center} |
463 \end{center} |
451 |
464 |
452 |
465 \end{frame} |
453 \end{frame}} |
466 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
467 |
455 |
468 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
456 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
469 \begin{frame}[t] |
457 \mode<presentation>{ |
470 \frametitle{Conditional Jumps} |
458 \begin{frame}[c] |
|
459 \frametitle{\begin{tabular}{c}Conditional Jumps\end{tabular}} |
|
460 |
471 |
461 \begin{minipage}{1.1\textwidth} |
472 \begin{minipage}{1.1\textwidth} |
462 \begin{itemize} |
473 \begin{itemize} |
463 \item \bl{if\_icmpeq $label$} if two ints are equal, then jump\medskip |
474 \item \bl{if\_icmpeq $label$} if two ints are equal, then jump\medskip |
464 \item \bl{if\_icmpne $label$} if two ints aren't equal, then jump\medskip |
475 \item \bl{if\_icmpne $label$} if two ints aren't equal, then jump\medskip |
481 \end{center} |
492 \end{center} |
482 |
493 |
483 \begin{textblock}{3.5}(11,12) |
494 \begin{textblock}{3.5}(11,12) |
484 \only<3>{labels must be unique} |
495 \only<3>{labels must be unique} |
485 \end{textblock} |
496 \end{textblock} |
486 \end{frame}} |
497 \end{frame} |
487 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
498 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
488 |
499 |
489 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
490 \mode<presentation>{ |
501 \begin{frame}[t] |
491 \begin{frame}[t] |
502 \frametitle{Compiling BExps} |
492 \frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}} |
|
493 |
503 |
494 {\Large\bl{$a_1 = a_2$}} |
504 {\Large\bl{$a_1 = a_2$}} |
495 |
505 |
496 \begin{center} |
506 \begin{center} |
497 \bl{\begin{tabular}{lcl} |
507 \bl{\begin{tabular}{lcl} |
498 $\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ |
508 $\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ |
499 \multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$} |
509 \multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$} |
500 \end{tabular}} |
510 \end{tabular}} |
501 \end{center} |
511 \end{center} |
502 |
512 |
503 \end{frame}} |
513 \end{frame} |
504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
514 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
505 |
515 |
506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
516 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
507 \mode<presentation>{ |
517 \begin{frame}[c, fragile] |
508 \begin{frame}[t] |
518 \frametitle{Boolean Expressions} |
509 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}} |
519 |
|
520 Compilation of boolean expressions: |
|
521 |
|
522 \begin{center} |
|
523 \begin{tikzpicture}[node distance=2mm and 4mm, |
|
524 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm}, |
|
525 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red}, |
|
526 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}] |
|
527 \node (A1) [point] {}; |
|
528 \node (b) [block, right=of A1] {code of \bl{$b$}}; |
|
529 \node (A2) [point, right=of b] {}; |
|
530 \node (cs1) [block, right=of A2] {code of \bl{$cs_1$}}; |
|
531 \node (A3) [point, right=of cs1] {}; |
|
532 \node (cs2) [block, right=of A3] {code of \bl{$cs_2$}}; |
|
533 \node (A4) [point, right=of cs2] {}; |
|
534 |
|
535 \only<1>{ |
|
536 \draw (A1) edge [->, red, line width=1mm] (b); |
|
537 \draw (b) edge [->, red, line width=1mm] (A2); |
|
538 \draw (A2) edge [skip loop] (A3); |
|
539 \draw (A3) edge [->, red, line width=1mm] (cs2); |
|
540 \draw (cs2) edge [->,red, line width=1mm] (A4); |
|
541 \node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};} |
|
542 \end{tikzpicture} |
|
543 \end{center} |
|
544 |
|
545 \begin{center} |
|
546 \begin{tabular}{lcl} |
|
547 \texttt{Bop("==", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpne...}\\ |
|
548 \texttt{Bop("!=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpeq...}\\ |
|
549 \texttt{Bop("<", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpge...}\\ |
|
550 \texttt{Bop("<=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpgt...}\\ |
|
551 \end{tabular} |
|
552 \end{center} |
|
553 |
|
554 \end{frame} |
|
555 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
556 |
|
557 |
|
558 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
559 \begin{frame}[t] |
|
560 \frametitle{Compiling Ifs} |
510 |
561 |
511 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}} |
562 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}} |
512 |
563 |
513 \begin{center} |
564 \begin{center} |
514 \bl{\begin{tabular}{lcl} |
565 \bl{\begin{tabular}{lcl} |
615 iload $E(x)$\\ |
662 iload $E(x)$\\ |
616 invokestatic write(I)V\\ |
663 invokestatic write(I)V\\ |
617 \end{tabular}} |
664 \end{tabular}} |
618 \end{center} |
665 \end{center} |
619 |
666 |
620 \end{frame}} |
667 \end{frame} |
621 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
668 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
622 |
|
623 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
624 \mode<presentation>{ |
|
625 \begin{frame}[c] |
|
626 |
|
627 \begin{center} |
|
628 \small\bl{\begin{tabular}{l} |
|
629 .class public XXX.XXX\\ |
|
630 .super java/lang/Object\\ |
|
631 \\ |
|
632 .method public <init>()V\\ |
|
633 \;\; aload\_0\\ |
|
634 \;\; invokenonvirtual java/lang/Object/<init>()V\\ |
|
635 \;\; return\\ |
|
636 .end method\\ |
|
637 \\ |
|
638 .method public static main([Ljava/lang/String;)V\\ |
|
639 \;\; .limit locals 200\\ |
|
640 \;\; .limit stack 200\\ |
|
641 \\ |
|
642 \textcolor{black}{(here comes the compiled code)}\\ |
|
643 \\ |
|
644 \;\; return\\ |
|
645 .end method\\ |
|
646 \end{tabular}} |
|
647 \end{center} |
|
648 |
|
649 \end{frame}} |
|
650 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
651 |
669 |
652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
670 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
653 \mode<presentation>{ |
671 \mode<presentation>{ |
654 \begin{frame}[c] |
672 \begin{frame}[c] |
655 \frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}} |
673 \frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}} |