175 \frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}} |
205 \frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}} |
176 |
206 |
177 \mbox{}\\[-18mm]\mbox{} |
207 \mbox{}\\[-18mm]\mbox{} |
178 |
208 |
179 {\lstset{language=While}\fontsize{10}{12}\selectfont |
209 {\lstset{language=While}\fontsize{10}{12}\selectfont |
180 \texttt{\lstinputlisting{app9.while}}} |
210 \texttt{\lstinputlisting{fib.while}}} |
181 |
211 |
182 \end{frame}} |
212 \end{frame}} |
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
184 |
214 |
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
215 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
186 \mode<presentation>{ |
216 \mode<presentation>{ |
187 \begin{frame}[c] |
217 \begin{frame}[c] |
188 \frametitle{\begin{tabular}{c}Interpreter\end{tabular}} |
218 \frametitle{\begin{tabular}{c}Interpreter\end{tabular}} |
189 |
219 |
190 |
220 \begin{center} |
191 |
221 \bl{\begin{tabular}{@{}lcl@{}} |
192 \end{frame}} |
222 $\text{eval}(n, E)$ & $\dn$ & $n$\\ |
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
223 $\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\ |
194 |
224 $\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\ |
195 |
225 $\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\ |
196 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
226 $\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\ |
197 \mode<presentation>{ |
227 $\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\ |
198 \begin{frame}[t] |
228 $\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\ |
199 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}} |
229 $\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\ |
|
230 \end{tabular}} |
|
231 \end{center} |
|
232 |
|
233 \end{frame}} |
|
234 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
235 |
|
236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
237 \mode<presentation>{ |
|
238 \begin{frame}[c] |
|
239 \frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}} |
|
240 |
|
241 \begin{center} |
|
242 \bl{\begin{tabular}{@{}lcl@{}} |
|
243 $\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\ |
|
244 $\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\ |
|
245 \multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\ |
|
246 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\; |
|
247 \text{eval}(cs_1,E)$}\\ |
|
248 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\ |
|
249 \multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\ |
|
250 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\ |
|
251 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\; |
|
252 \text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\ |
|
253 \multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\ |
|
254 $\text{eval}(\text{print}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\ |
|
255 \end{tabular}} |
|
256 \end{center} |
|
257 |
|
258 \end{frame}} |
|
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
260 |
|
261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
262 \mode<presentation>{ |
|
263 \begin{frame}[c] |
|
264 \frametitle{\begin{tabular}{c}Test Program\end{tabular}} |
|
265 |
|
266 \mbox{}\\[-18mm]\mbox{} |
|
267 |
|
268 {\lstset{language=While}\fontsize{10}{12}\selectfont |
|
269 \texttt{\lstinputlisting{loops.while}}} |
|
270 |
|
271 \end{frame}} |
|
272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
273 |
|
274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
275 \mode<presentation>{ |
|
276 \begin{frame}[t] |
|
277 \frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}} |
200 |
278 |
201 \begin{center} |
279 \begin{center} |
202 \begin{tikzpicture} |
280 \begin{tikzpicture} |
203 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=mins] |
281 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs] |
204 \addplot file {compiled.data}; |
282 \addplot+[smooth] file {interpreted.data}; |
205 \end{axis} |
283 \end{axis} |
206 \end{tikzpicture} |
284 \end{tikzpicture} |
207 \end{center} |
285 \end{center} |
208 |
286 |
209 \end{frame}} |
287 \end{frame}} |
210 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
211 |
289 |
212 |
290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
291 \mode<presentation>{ |
|
292 \begin{frame}[c] |
|
293 \frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}} |
|
294 |
|
295 \begin{itemize} |
|
296 \item introduced in 1995 |
|
297 \item is a stack-based VM (like Postscript, CLR of .Net) |
|
298 \item contains a JIT compiler |
|
299 \item many languages take advantage of the infrastructure (JRE) |
|
300 \item languages compiled to the JVM: Scala, Clojure\ldots |
|
301 \item garbage collected |
|
302 \end{itemize} |
|
303 |
|
304 \end{frame}} |
|
305 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
306 |
|
307 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
308 \mode<presentation>{ |
|
309 \begin{frame}[t] |
|
310 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
311 |
|
312 {\Large\bl{1 + 2}} |
|
313 |
|
314 \begin{center} |
|
315 \bl{\begin{tabular}{l} |
|
316 ldc 1\\ |
|
317 ldc 2\\ |
|
318 iadd\\ |
|
319 \end{tabular}} |
|
320 \end{center}\end{frame}} |
|
321 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
322 |
|
323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
324 \mode<presentation>{ |
|
325 \begin{frame}[t] |
|
326 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
327 |
|
328 {\Large\bl{1 + 2 + 3}} |
|
329 |
|
330 \begin{center} |
|
331 \bl{\begin{tabular}{l} |
|
332 ldc 1\\ |
|
333 ldc 2\\ |
|
334 iadd\\ |
|
335 ldc 3\\ |
|
336 iadd\\ |
|
337 \end{tabular}} |
|
338 \end{center} |
|
339 |
|
340 \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 ldc 3\\ |
|
355 iadd\\ |
|
356 iadd\\ |
|
357 \end{tabular}} |
|
358 \end{center}\bigskip\pause |
|
359 \vfill |
|
360 |
|
361 \bl{dadd, fadd, ladd, \ldots} |
|
362 |
|
363 \end{frame}} |
|
364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
365 |
|
366 |
|
367 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
368 \mode<presentation>{ |
|
369 \begin{frame}[t] |
|
370 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
371 |
|
372 \begin{center} |
|
373 \bl{\begin{tabular}{@{}lcl@{}} |
|
374 $\text{compile}(n)$ & $\dn$ & $\text{ldc}\;n$\\ |
|
375 $\text{compile}(a_1 + a_2)$ & $\dn$\\ |
|
376 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\;\text{compile}(a_2)\;@\; \text{iadd}$}\smallskip\\ |
|
377 $\text{compile}(a_1 - a_2)$ & $\dn$\\ |
|
378 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{isub}$}\smallskip\\ |
|
379 $\text{compile}(a_1 * a_2)$ & $\dn$\\ |
|
380 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{imul}$}\smallskip\\ |
|
381 \end{tabular}} |
|
382 \end{center}\pause |
|
383 |
|
384 \end{frame}} |
|
385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
386 |
|
387 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
388 \mode<presentation>{ |
|
389 \begin{frame}[t] |
|
390 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
391 |
|
392 {\Large\bl{1 + 2 * 3 + (4 - 3)}} |
|
393 |
|
394 \begin{center} |
|
395 \bl{\begin{tabular}{l} |
|
396 ldc 1\\ |
|
397 ldc 2\\ |
|
398 ldc 3\\ |
|
399 imul\\ |
|
400 ldc 4\\ |
|
401 ldc 3\\ |
|
402 isub\\ |
|
403 iadd\\ |
|
404 iadd\\ |
|
405 \end{tabular}} |
|
406 \end{center} |
|
407 |
|
408 \end{frame}} |
|
409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
410 |
|
411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
412 \mode<presentation>{ |
|
413 \begin{frame}[t] |
|
414 \frametitle{\begin{tabular}{c}Variables\end{tabular}} |
|
415 |
|
416 {\Large\bl{$x := 5 + y * 2$}}\bigskip\pause |
|
417 |
|
418 \begin{itemize} |
|
419 \item lookup: \bl{$\text{iload}\; number$} |
|
420 \item store: \bl{$\text{istore}\; number$} |
|
421 \end{itemize}\bigskip\pause |
|
422 |
|
423 during compilation we have to maintain a map between our identifiers and the |
|
424 java bytecode numbers |
|
425 |
|
426 \begin{center} |
|
427 \bl{$\text{compile}(a, E)$} |
|
428 \end{center} |
|
429 |
|
430 \end{frame}} |
|
431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
432 |
|
433 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
434 \mode<presentation>{ |
|
435 \begin{frame}[t] |
|
436 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
437 |
|
438 \begin{center} |
|
439 \bl{\begin{tabular}{@{}lcl@{}} |
|
440 $\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\ |
|
441 $\text{compile}(a_1 + a_2, E)$ & $\dn$\\ |
|
442 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{iadd}$}\smallskip\\ |
|
443 $\text{compile}(a_1 - a_2, E)$ & $\dn$\\ |
|
444 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\ |
|
445 $\text{compile}(a_1 * a_2, E)$ & $\dn$\\ |
|
446 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\ |
|
447 $\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\ |
|
448 \end{tabular}} |
|
449 \end{center}\pause |
|
450 |
|
451 \end{frame}} |
|
452 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
453 |
|
454 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
455 \mode<presentation>{ |
|
456 \begin{frame}[t] |
|
457 \frametitle{\begin{tabular}{c}Compiling Statements\end{tabular}} |
|
458 |
|
459 We return a list of instructions and an environment for the variables |
|
460 |
|
461 \begin{center} |
|
462 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}} |
|
463 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(Nil, E)$\bigskip\\ |
|
464 $\text{compile}(x := a, E)$ & $\dn$\\ |
|
465 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\ |
|
466 \end{tabular}} |
|
467 \end{center}\medskip |
|
468 |
|
469 where \bl{$index$} is \bl{$E(x)$} if it is already defined, or if it is not then the largest index not yet seen |
|
470 |
|
471 \end{frame}} |
|
472 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
473 |
|
474 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
475 \mode<presentation>{ |
|
476 \begin{frame}[t] |
|
477 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
478 |
|
479 {\Large\bl{$x := x + 1$}} |
|
480 |
|
481 \begin{center} |
|
482 \bl{\begin{tabular}{l} |
|
483 iload $n_x$\\ |
|
484 ldc 1\\ |
|
485 iadd\\ |
|
486 istore $n_x$\\ |
|
487 \end{tabular}} |
|
488 \end{center} |
|
489 |
|
490 where \bl{$n_x$} is the number corresponding to the variable \bl{$x$} |
|
491 |
|
492 \end{frame}} |
|
493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
494 |
|
495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
496 \mode<presentation>{ |
|
497 \begin{frame}[t] |
|
498 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}} |
|
499 |
|
500 {\Large\bl{$\text{if}\;b\;\text{else}\;cs_1\;\text{then}\;cs_2$}}\bigskip\bigskip |
|
501 |
|
502 \onslide<2->{Case }\only<2>{True:}\only<3>{False:} |
|
503 |
|
504 \begin{center} |
|
505 \begin{tikzpicture}[node distance=2mm and 4mm, |
|
506 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm}, |
|
507 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red}, |
|
508 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}] |
|
509 \node (A1) [point] {}; |
|
510 \node (b) [block, right=of A1] {code of \bl{$b$}}; |
|
511 \node (A2) [point, right=of b] {}; |
|
512 \node (cs1) [block, right=of A2] {code of \bl{$cs_1$}}; |
|
513 \node (A3) [point, right=of cs1] {}; |
|
514 \node (cs2) [block, right=of A3] {code of \bl{$cs_2$}}; |
|
515 \node (A4) [point, right=of cs2] {}; |
|
516 |
|
517 \only<2>{ |
|
518 \draw (A1) edge [->, red, line width=1mm] (b); |
|
519 \draw (b) edge [->, red, line width=1mm] (cs1); |
|
520 \draw (cs1) edge [->, red, line width=1mm] (A3); |
|
521 \draw (A3) edge [->,skip loop] (A4); |
|
522 \node [below=of cs2] {\raisebox{-5mm}{\small{}jump}};} |
|
523 \only<3>{ |
|
524 \draw (A1) edge [->, red, line width=1mm] (b); |
|
525 \draw (b) edge [->, red, line width=1mm] (A2); |
|
526 \draw (A2) edge [skip loop] (A3); |
|
527 \draw (A3) edge [->, red, line width=1mm] (cs2); |
|
528 \draw (cs2) edge [->,red, line width=1mm] (A4); |
|
529 \node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};} |
|
530 \end{tikzpicture} |
|
531 \end{center} |
|
532 |
|
533 |
|
534 \end{frame}} |
|
535 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
536 |
|
537 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
538 \mode<presentation>{ |
|
539 \begin{frame}[c] |
|
540 \frametitle{\begin{tabular}{c}Conditional Jumps\end{tabular}} |
|
541 |
|
542 \begin{minipage}{1.1\textwidth} |
|
543 \begin{itemize} |
|
544 \item \bl{if\_icmpeq $label$} if two ints are equal, then jump\medskip |
|
545 \item \bl{if\_icmpne $label$} if two ints aren't equal, then jump\medskip |
|
546 \item \bl{if\_icmpge $label$} if one int is greater or equal then another, then jump |
|
547 \item[]\ldots |
|
548 \end{itemize} |
|
549 \end{minipage}\pause |
|
550 |
|
551 |
|
552 \begin{center} |
|
553 \bl{\begin{tabular}{l} |
|
554 $L_1$:\\ |
|
555 \hspace{5mm}if\_icmpeq\;$L_2$\\ |
|
556 \hspace{5mm}iload 1\\ |
|
557 \hspace{5mm}ldc 1\\ |
|
558 \hspace{5mm}iadd\\ |
|
559 \hspace{5mm}if\_icmpeq\;$L_1$\\ |
|
560 $L_1$: |
|
561 \end{tabular}} |
|
562 \end{center} |
|
563 |
|
564 |
|
565 \end{frame}} |
|
566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
567 |
|
568 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
569 \mode<presentation>{ |
|
570 \begin{frame}[t] |
|
571 \frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}} |
|
572 |
|
573 {\Large\bl{$a_1 = a_2$}} |
|
574 |
|
575 \begin{center} |
|
576 \bl{\begin{tabular}{l} |
|
577 iload $n_x$\\ |
|
578 ldc 1\\ |
|
579 iadd\\ |
|
580 istore $n_x$\\ |
|
581 \end{tabular}} |
|
582 \end{center} |
|
583 |
|
584 \end{frame}} |
|
585 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
586 |
|
587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
588 \mode<presentation>{ |
|
589 \begin{frame}[t] |
|
590 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}} |
|
591 |
|
592 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}} |
|
593 |
|
594 \begin{center} |
|
595 \bl{\begin{tabular}{l} |
|
596 iload $n_x$\\ |
|
597 ldc 1\\ |
|
598 iadd\\ |
|
599 istore $n_x$\\ |
|
600 \end{tabular}} |
|
601 \end{center} |
|
602 |
|
603 \end{frame}} |
|
604 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
605 |
|
606 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
607 \mode<presentation>{ |
|
608 \begin{frame}[t] |
|
609 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}} |
|
610 |
|
611 {\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip |
|
612 |
|
613 \onslide<2->{Case }\only<2>{True:}\only<3>{False:} |
|
614 |
|
615 \begin{center} |
|
616 \begin{tikzpicture}[node distance=2mm and 4mm, |
|
617 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm}, |
|
618 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red}, |
|
619 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}] |
|
620 \node (A0) [point, left=of A1] {}; |
|
621 \node (A1) [point] {}; |
|
622 \node (b) [block, right=of A1] {code of \bl{$b$}}; |
|
623 \node (A2) [point, right=of b] {}; |
|
624 \node (cs1) [block, right=of A2] {code of \bl{$cs$}}; |
|
625 \node (A3) [point, right=of cs1] {}; |
|
626 \node (A4) [point, right=of A3] {}; |
|
627 |
|
628 \only<2>{ |
|
629 \draw (A0) edge [->, red, line width=1mm] (b); |
|
630 \draw (b) edge [->, red, line width=1mm] (cs1); |
|
631 \draw (cs1) edge [->, red, line width=1mm] (A3); |
|
632 \draw (A3) edge [->,skip loop] (A1);} |
|
633 \only<3>{ |
|
634 \draw (A0) edge [->, red, line width=1mm] (b); |
|
635 \draw (b) edge [->, red, line width=1mm] (A2); |
|
636 \draw (A2) edge [skip loop] (A3); |
|
637 \draw (A3) edge [->, red, line width=1mm] (A4);} |
|
638 \end{tikzpicture} |
|
639 \end{center} |
|
640 |
|
641 |
|
642 \end{frame}} |
|
643 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
644 |
|
645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
646 \mode<presentation>{ |
|
647 \begin{frame}[t] |
|
648 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}} |
|
649 |
|
650 {\Large\bl{while $b$ do $cs$}} |
|
651 |
|
652 \begin{center} |
|
653 \bl{\begin{tabular}{l} |
|
654 iload $n_x$\\ |
|
655 ldc 1\\ |
|
656 iadd\\ |
|
657 istore $n_x$\\ |
|
658 \end{tabular}} |
|
659 \end{center} |
|
660 |
|
661 \end{frame}} |
|
662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
663 |
|
664 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
665 \mode<presentation>{ |
|
666 \begin{frame}[t] |
|
667 \frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}} |
|
668 |
|
669 {\Large\bl{write $x$}} |
|
670 |
|
671 \begin{center} |
|
672 \bl{\begin{tabular}{l} |
|
673 iload $n_x$\\ |
|
674 ldc 1\\ |
|
675 iadd\\ |
|
676 istore $n_x$\\ |
|
677 \end{tabular}} |
|
678 \end{center} |
|
679 |
|
680 \end{frame}} |
|
681 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
213 |
682 |
214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
683 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
215 \mode<presentation>{ |
684 \mode<presentation>{ |
216 \begin{frame}[t] |
685 \begin{frame}[t] |
217 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}} |
686 \frametitle{\begin{tabular}{c}Compiled vs.~Interpreted Code\end{tabular}} |
218 |
687 |
219 \mbox{}\\[-25mm]\mbox{} |
688 \begin{center} |
220 |
689 \begin{tikzpicture} |
221 \begin{center} |
690 \begin{loglogaxis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs] |
222 \begin{tikzpicture}[y=.4cm, x=.00000009cm] |
691 \addplot+[smooth] file {interpreted.data}; |
223 %axis |
692 \addplot+[smooth] file {compiled.data}; |
224 \draw (0,0) -- coordinate (x axis mid) (5,0); |
693 \end{loglogaxis} |
225 \draw (0,0) -- coordinate (y axis mid) (0,5); |
|
226 %ticks |
|
227 \foreach \x in {0, 1000,...,10000} |
|
228 \draw (\x,1pt) -- (\x,-3pt) |
|
229 node[anchor=north] {\small \x{}00}; |
|
230 \foreach \y in {0,0.5,1, ..., 5.5} |
|
231 \draw (1pt,\y) -- (-3pt,\y) |
|
232 node[anchor=east] {\small\y}; |
|
233 %labels |
|
234 \node[below=0.6cm] at (x axis mid) {\bl{1}s}; |
|
235 \node[rotate=90, left=1.2cm] at (y axis mid) {secs}; |
|
236 |
|
237 %plots |
|
238 %\draw[color=blue] plot[mark=*, mark options={fill=white}] |
|
239 % file {compiled.data}; |
|
240 %\only<2->{\draw[color=red] plot[mark=triangle*, mark options={fill=white} ] |
|
241 % file {interpreted.data};} |
|
242 %legend |
|
243 %\begin{scope}[shift={(400,20)}] |
|
244 %\draw[color=blue] (0,0) -- |
|
245 % plot[mark=*, mark options={fill=white}] (0.25,0) -- (0.5,0) |
|
246 % node[right]{\small unambiguous}; |
|
247 %\only<2->{\draw[yshift=\baselineskip, color=red] (0,0) -- |
|
248 % plot[mark=triangle*, mark options={fill=white}] (0.25,0) -- (0.5,0) |
|
249 % node[right]{\small ambiguous};} |
|
250 %\end{scope} |
|
251 \end{tikzpicture} |
694 \end{tikzpicture} |
252 \end{center} |
695 \end{center} |
253 |
696 |
254 \end{frame}} |
697 \end{frame}} |
255 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
698 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
256 |
699 |
257 |
700 |
258 |
701 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
702 \mode<presentation>{ |
|
703 \begin{frame}[t] |
|
704 \frametitle{\begin{tabular}{c}Compiled Code\end{tabular}} |
|
705 |
|
706 \begin{center} |
|
707 \begin{tikzpicture} |
|
708 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs] |
|
709 \addplot+[smooth] file {compiled.data}; |
|
710 \end{axis} |
|
711 \end{tikzpicture} |
|
712 \end{center} |
|
713 |
|
714 \end{frame}} |
|
715 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
259 |
716 |
260 |
717 |
261 \end{document} |
718 \end{document} |
262 |
719 |
263 %%% Local Variables: |
720 %%% Local Variables: |