353 |
354 |
354 |
355 |
355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
356 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
356 \mode<presentation>{ |
357 \mode<presentation>{ |
357 \begin{frame}[c] |
358 \begin{frame}[c] |
|
359 \frametitle{Our Compiler} |
|
360 |
|
361 \begin{center} |
|
362 \begin{tikzpicture}[scale=1] |
|
363 |
|
364 \node (0) at (-2.3,0) {}; |
|
365 |
|
366 \node (A) at (0,0) [draw=black, rectangle, very thick, minimum height=18mm, minimum width=20mm] {}; |
|
367 \node [below right] at (A.north west) {lexer}; |
|
368 |
|
369 \node (B) at (3,0) [draw=black, rectangle, very thick, minimum height=18mm, minimum width=20mm] {}; |
|
370 \node [below right=1mm] at (B.north west) {\mbox{}\hspace{-1mm}parser}; |
|
371 |
|
372 \node (C) at (6,0) [draw=black, rectangle, very thick, minimum height=18mm, minimum width=20mm] {}; |
|
373 \node [below right] at (C.north west) {\mbox{}\hspace{-1mm}code gen}; |
|
374 |
|
375 \node (1) at (8.4,0) {}; |
|
376 |
|
377 \draw [->,line width=4mm] (0) -- (A); |
|
378 \draw [->,line width=4mm] (A) -- (B); |
|
379 \draw [->,line width=4mm] (B) -- (C); |
|
380 \draw [->,line width=4mm] (C) -- (1); |
|
381 \end{tikzpicture} |
|
382 \end{center} |
|
383 |
|
384 lexer input: string\medskip\\ |
|
385 lexer output: sequence of tokens\\ |
|
386 \mbox{}\hfill(white space and comments filtered out)\medskip\\ |
|
387 parser output: abstract syntax tree\medskip\\ |
|
388 code gen output: assembler byte code / \\ |
|
389 \mbox{}\hfill assembler machine code |
|
390 \end{frame}} |
|
391 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
392 |
|
393 |
|
394 |
|
395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
396 \mode<presentation>{ |
|
397 \begin{frame}[c] |
|
398 \frametitle{\begin{tabular}{c}For-Loops\end{tabular}} |
|
399 |
|
400 |
|
401 \begin{center}\Large |
|
402 \texttt{for} \;\textit{Id} \texttt{:=} \textit{AExp}\; \texttt{upto} \;\textit{AExp}\; \texttt{do} \textit{Block} |
|
403 \end{center}\bigskip |
|
404 |
|
405 \begin{center} |
|
406 \begin{minipage}{8cm} |
|
407 \begin{tabular}{l} |
|
408 \texttt{for i := 2 upto 4 do \{}\\ |
|
409 \hspace{5mm}\texttt{write i}\\ |
|
410 \texttt{\}}\ |
|
411 \end{tabular} |
|
412 \end{minipage} |
|
413 \end{center} |
|
414 \end{frame}} |
|
415 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
421 \mode<presentation>{ |
|
422 \begin{frame}[c] |
358 \frametitle{\begin{tabular}{c}While-Language\end{tabular}} |
423 \frametitle{\begin{tabular}{c}While-Language\end{tabular}} |
359 |
424 |
360 |
425 |
361 \begin{center} |
426 \begin{center} |
362 \bl{\begin{tabular}{@{}lcl@{}} |
427 \bl{\begin{tabular}{@{}lcl@{}} |
363 $Stmt$ & $\rightarrow$ & $\text{skip}$\\ |
428 $Stmt$ & $\rightarrow$ & $\text{skip}$\\ |
364 & $|$ & $Id := AExp$\\ |
429 & $|$ & $Id := AExp$\\ |
365 & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\ |
430 & $|$ & $\text{if}\; B\!Exp \;\text{then}\; Block \;\text{else}\; Block$\\ |
366 & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\\ |
431 & $|$ & $\text{while}\; B\!Exp \;\text{do}\; Block$\\ |
367 & $|$ & $\alert{\text{write}\; Id}$\medskip\\ |
432 & $|$ & $\alert{\text{write}\; Id}$\\ |
|
433 & $|$ & $\alert{\text{read}\; Id}$\medskip\\ |
368 $Stmts$ & $\rightarrow$ & $Stmt \;\text{;}\; Stmts$\\ |
434 $Stmts$ & $\rightarrow$ & $Stmt \;\text{;}\; Stmts$\\ |
369 & $|$ & $Stmt$\medskip\\ |
435 & $|$ & $Stmt$\medskip\\ |
370 $Block$ & $\rightarrow$ & $\{ Stmts \}$\\ |
436 $Block$ & $\rightarrow$ & $\{ Stmts \}$\\ |
371 & $|$ & $Stmt$\medskip\\ |
437 & $|$ & $Stmt$\medskip\\ |
372 $AExp$ & $\rightarrow$ & \ldots\\ |
438 $AExp$ & $\rightarrow$ & \ldots\\ |
435 \end{center} |
490 \end{center} |
436 |
491 |
437 \end{frame}} |
492 \end{frame}} |
438 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
493 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
439 |
494 |
440 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
495 |
441 \mode<presentation>{ |
|
442 \begin{frame}[c] |
|
443 \frametitle{\begin{tabular}{c}Test Program\end{tabular}} |
|
444 |
|
445 \mbox{}\\[-18mm]\mbox{} |
|
446 |
|
447 {\lstset{language=While}\fontsize{10}{12}\selectfont |
|
448 \texttt{\lstinputlisting{../progs/loops.while}}} |
|
449 |
|
450 \end{frame}} |
|
451 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
452 |
|
453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
454 \mode<presentation>{ |
|
455 \begin{frame}[t] |
|
456 \frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}} |
|
457 |
|
458 \begin{center} |
|
459 \begin{tikzpicture} |
|
460 \begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small] |
|
461 \addplot+[smooth] file {interpreted.data}; |
|
462 \end{axis} |
|
463 \end{tikzpicture} |
|
464 \end{center} |
|
465 |
|
466 \end{frame}} |
|
467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
468 |
|
469 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
470 \mode<presentation>{ |
|
471 \begin{frame}[c] |
|
472 \frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}} |
|
473 |
|
474 \begin{itemize} |
|
475 \item introduced in 1995 |
|
476 \item is a stack-based VM (like Postscript, CLR of .Net) |
|
477 \item contains a JIT compiler |
|
478 \item many languages take advantage of JVM's infrastructure (JRE) |
|
479 \item is garbage collected $\Rightarrow$ no buffer overflows |
|
480 \item some languages compiled to the JVM: Scala, Clojure\ldots |
|
481 \end{itemize} |
|
482 |
|
483 \end{frame}} |
|
484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
485 |
|
486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
487 \mode<presentation>{ |
|
488 \begin{frame}[t] |
|
489 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
490 |
|
491 {\Large\bl{1 + 2}} |
|
492 |
|
493 \begin{center} |
|
494 \bl{\begin{tabular}{l} |
|
495 ldc 1\\ |
|
496 ldc 2\\ |
|
497 iadd\\ |
|
498 \end{tabular}} |
|
499 \end{center}\end{frame}} |
|
500 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
501 |
|
502 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
503 \mode<presentation>{ |
|
504 \begin{frame}[t] |
|
505 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
506 |
|
507 {\Large\bl{1 + 2 + 3}} |
|
508 |
|
509 \begin{center} |
|
510 \bl{\begin{tabular}{l} |
|
511 ldc 1\\ |
|
512 ldc 2\\ |
|
513 iadd\\ |
|
514 ldc 3\\ |
|
515 iadd\\ |
|
516 \end{tabular}} |
|
517 \end{center} |
|
518 |
|
519 \end{frame}} |
|
520 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
521 |
|
522 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
523 \mode<presentation>{ |
|
524 \begin{frame}[t] |
|
525 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
526 |
|
527 {\Large\bl{1 + (2 + 3)}} |
|
528 |
|
529 \begin{center} |
|
530 \bl{\begin{tabular}{l} |
|
531 ldc 1\\ |
|
532 ldc 2\\ |
|
533 ldc 3\\ |
|
534 iadd\\ |
|
535 iadd\\ |
|
536 \end{tabular}} |
|
537 \end{center}\bigskip\pause |
|
538 \vfill |
|
539 |
|
540 \bl{dadd, fadd, ladd, \ldots} |
|
541 |
|
542 \end{frame}} |
|
543 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
544 |
|
545 |
|
546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
547 \mode<presentation>{ |
|
548 \begin{frame}[t] |
|
549 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
550 |
|
551 \begin{center} |
|
552 \bl{\begin{tabular}{@{}lcl@{}} |
|
553 $\text{compile}(n)$ & $\dn$ & $\text{ldc}\;n$\\ |
|
554 $\text{compile}(a_1 + a_2)$ & $\dn$\\ |
|
555 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\;\text{compile}(a_2)\;@\; \text{iadd}$}\smallskip\\ |
|
556 $\text{compile}(a_1 - a_2)$ & $\dn$\\ |
|
557 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{isub}$}\smallskip\\ |
|
558 $\text{compile}(a_1 * a_2)$ & $\dn$\\ |
|
559 \multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{imul}$}\smallskip\\ |
|
560 \end{tabular}} |
|
561 \end{center}\pause |
|
562 |
|
563 \end{frame}} |
|
564 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
565 |
|
566 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
567 \mode<presentation>{ |
|
568 \begin{frame}[t] |
|
569 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
570 |
|
571 {\Large\bl{1 + 2 * 3 + (4 - 3)}} |
|
572 |
|
573 \begin{center} |
|
574 \bl{\begin{tabular}{l} |
|
575 ldc 1\\ |
|
576 ldc 2\\ |
|
577 ldc 3\\ |
|
578 imul\\ |
|
579 ldc 4\\ |
|
580 ldc 3\\ |
|
581 isub\\ |
|
582 iadd\\ |
|
583 iadd\\ |
|
584 \end{tabular}} |
|
585 \end{center} |
|
586 |
|
587 \end{frame}} |
|
588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
589 |
|
590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
591 \mode<presentation>{ |
|
592 \begin{frame}[t] |
|
593 \frametitle{\begin{tabular}{c}Variables\end{tabular}} |
|
594 |
|
595 {\Large\bl{$x := 5 + y * 2$}}\bigskip\pause |
|
596 |
|
597 \begin{itemize} |
|
598 \item lookup: \bl{$\text{iload}\; index$} |
|
599 \item store: \bl{$\text{istore}\; index$} |
|
600 \end{itemize}\bigskip\pause |
|
601 |
|
602 while compilating we have to maintain a map between our identifiers and the |
|
603 Java bytecode indices |
|
604 |
|
605 \begin{center} |
|
606 \bl{$\text{compile}(a, E)$} |
|
607 \end{center} |
|
608 |
|
609 \end{frame}} |
|
610 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
611 |
|
612 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
613 \mode<presentation>{ |
|
614 \begin{frame}[t] |
|
615 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
616 |
|
617 \begin{center} |
|
618 \bl{\begin{tabular}{@{}lcl@{}} |
|
619 $\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\ |
|
620 $\text{compile}(a_1 + a_2, E)$ & $\dn$\\ |
|
621 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{iadd}$}\smallskip\\ |
|
622 $\text{compile}(a_1 - a_2, E)$ & $\dn$\\ |
|
623 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\ |
|
624 $\text{compile}(a_1 * a_2, E)$ & $\dn$\\ |
|
625 \multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\ |
|
626 $\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\ |
|
627 \end{tabular}} |
|
628 \end{center}\pause |
|
629 |
|
630 \end{frame}} |
|
631 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
632 |
|
633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
634 \mode<presentation>{ |
|
635 \begin{frame}[t] |
|
636 \frametitle{\begin{tabular}{c}Compiling Statements\end{tabular}} |
|
637 |
|
638 We return a list of instructions and an environment for the variables |
|
639 |
|
640 \begin{center} |
|
641 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}} |
|
642 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(N\!il, E)$\bigskip\\ |
|
643 $\text{compile}(x := a, E)$ & $\dn$\\ |
|
644 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\ |
|
645 \end{tabular}} |
|
646 \end{center}\medskip |
|
647 |
|
648 where \bl{$index$} is \bl{$E(x)$} if it is already defined, or if it is not then the largest index not yet seen |
|
649 |
|
650 \end{frame}} |
|
651 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
652 |
|
653 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
654 \mode<presentation>{ |
|
655 \begin{frame}[t] |
|
656 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}} |
|
657 |
|
658 {\Large\bl{$x := x + 1$}} |
|
659 |
|
660 \begin{center} |
|
661 \bl{\begin{tabular}{l} |
|
662 iload $n_x$\\ |
|
663 ldc 1\\ |
|
664 iadd\\ |
|
665 istore $n_x$\\ |
|
666 \end{tabular}} |
|
667 \end{center} |
|
668 |
|
669 where \bl{$n_x$} is the index corresponding to the variable \bl{$x$} |
|
670 |
|
671 \end{frame}} |
|
672 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
673 |
|
674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
675 \mode<presentation>{ |
|
676 \begin{frame}[t] |
|
677 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}} |
|
678 |
|
679 {\Large\bl{$\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2$}}\bigskip\bigskip |
|
680 |
|
681 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:} |
|
682 |
|
683 \begin{center} |
|
684 \begin{tikzpicture}[node distance=2mm and 4mm, |
|
685 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm}, |
|
686 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red}, |
|
687 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}] |
|
688 \node (A1) [point] {}; |
|
689 \node (b) [block, right=of A1] {code of \bl{$b$}}; |
|
690 \node (A2) [point, right=of b] {}; |
|
691 \node (cs1) [block, right=of A2] {code of \bl{$cs_1$}}; |
|
692 \node (A3) [point, right=of cs1] {}; |
|
693 \node (cs2) [block, right=of A3] {code of \bl{$cs_2$}}; |
|
694 \node (A4) [point, right=of cs2] {}; |
|
695 |
|
696 \only<2>{ |
|
697 \draw (A1) edge [->, red, line width=1mm] (b); |
|
698 \draw (b) edge [->, red, line width=1mm] (cs1); |
|
699 \draw (cs1) edge [->, red, line width=1mm] (A3); |
|
700 \draw (A3) edge [->,skip loop] (A4); |
|
701 \node [below=of cs2] {\raisebox{-5mm}{\small{}jump}};} |
|
702 \only<3>{ |
|
703 \draw (A1) edge [->, red, line width=1mm] (b); |
|
704 \draw (b) edge [->, red, line width=1mm] (A2); |
|
705 \draw (A2) edge [skip loop] (A3); |
|
706 \draw (A3) edge [->, red, line width=1mm] (cs2); |
|
707 \draw (cs2) edge [->,red, line width=1mm] (A4); |
|
708 \node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};} |
|
709 \end{tikzpicture} |
|
710 \end{center} |
|
711 |
|
712 |
|
713 \end{frame}} |
|
714 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
715 |
|
716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
717 \mode<presentation>{ |
|
718 \begin{frame}[c] |
|
719 \frametitle{\begin{tabular}{c}Conditional Jumps\end{tabular}} |
|
720 |
|
721 \begin{minipage}{1.1\textwidth} |
|
722 \begin{itemize} |
|
723 \item \bl{if\_icmpeq $label$} if two ints are equal, then jump\medskip |
|
724 \item \bl{if\_icmpne $label$} if two ints aren't equal, then jump\medskip |
|
725 \item \bl{if\_icmpge $label$} if one int is greater or equal then another, then jump |
|
726 \item[]\ldots |
|
727 \end{itemize} |
|
728 \end{minipage}\pause |
|
729 |
|
730 |
|
731 \begin{center} |
|
732 \bl{\begin{tabular}{l} |
|
733 $L_1$:\\ |
|
734 \hspace{5mm}if\_icmpeq\;$L_2$\\ |
|
735 \hspace{5mm}iload 1\\ |
|
736 \hspace{5mm}ldc 1\\ |
|
737 \hspace{5mm}iadd\\ |
|
738 \hspace{5mm}if\_icmpeq\;$L_1$\\ |
|
739 $L_2$: |
|
740 \end{tabular}} |
|
741 \end{center} |
|
742 |
|
743 \begin{textblock}{3.5}(11,12) |
|
744 \only<3>{labels must be unique} |
|
745 \end{textblock} |
|
746 \end{frame}} |
|
747 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
748 |
|
749 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
750 \mode<presentation>{ |
|
751 \begin{frame}[t] |
|
752 \frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}} |
|
753 |
|
754 {\Large\bl{$a_1 = a_2$}} |
|
755 |
|
756 \begin{center} |
|
757 \bl{\begin{tabular}{lcl} |
|
758 $\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ |
|
759 \multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$} |
|
760 \end{tabular}} |
|
761 \end{center} |
|
762 |
|
763 \end{frame}} |
|
764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
765 |
|
766 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
767 \mode<presentation>{ |
|
768 \begin{frame}[t] |
|
769 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}} |
|
770 |
|
771 {\Large\bl{if $b$ then $cs_1$ else $cs_2$}} |
|
772 |
|
773 \begin{center} |
|
774 \bl{\begin{tabular}{lcl} |
|
775 $\text{compile}(\text{if}\;b\;\text{then}\; cs_1\;\text{else}\; cs_2, E)$ & $\dn$\\ |
|
776 \multicolumn{3}{l}{$\quad l_{ifelse}\;$ \textcolor{black}{(fresh label)}}\\ |
|
777 \multicolumn{3}{l}{$\quad l_{ifend}\;$ \textcolor{black}{(fresh label)}}\\ |
|
778 \multicolumn{3}{l}{$\quad (is_1, E') = \text{compile}(cs_1, E)$}\\ |
|
779 \multicolumn{3}{l}{$\quad (is_2, E'') = \text{compile}(cs_2, E')$}\\ |
|
780 \multicolumn{3}{l}{$\quad(\text{compile}(b, E, l_{ifelse})$}\\ |
|
781 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_1$}\\ |
|
782 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{ifend}$}\\ |
|
783 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifelse}:$}\\ |
|
784 \multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\ |
|
785 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\ |
|
786 \end{tabular}} |
|
787 \end{center} |
|
788 |
|
789 \end{frame}} |
|
790 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
791 |
|
792 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
793 \mode<presentation>{ |
|
794 \begin{frame}[t] |
|
795 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}} |
|
796 |
|
797 {\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip |
|
798 |
|
799 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:} |
|
800 |
|
801 \begin{center} |
|
802 \begin{tikzpicture}[node distance=2mm and 4mm, |
|
803 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm}, |
|
804 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red}, |
|
805 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}] |
|
806 \node (A0) [point, left=of A1] {}; |
|
807 \node (A1) [point] {}; |
|
808 \node (b) [block, right=of A1] {code of \bl{$b$}}; |
|
809 \node (A2) [point, right=of b] {}; |
|
810 \node (cs1) [block, right=of A2] {code of \bl{$cs$}}; |
|
811 \node (A3) [point, right=of cs1] {}; |
|
812 \node (A4) [point, right=of A3] {}; |
|
813 |
|
814 \only<2>{ |
|
815 \draw (A0) edge [->, red, line width=1mm] (b); |
|
816 \draw (b) edge [->, red, line width=1mm] (cs1); |
|
817 \draw (cs1) edge [->, red, line width=1mm] (A3); |
|
818 \draw (A3) edge [->,skip loop] (A1);} |
|
819 \only<3>{ |
|
820 \draw (A0) edge [->, red, line width=1mm] (b); |
|
821 \draw (b) edge [->, red, line width=1mm] (A2); |
|
822 \draw (A2) edge [skip loop] (A3); |
|
823 \draw (A3) edge [->, red, line width=1mm] (A4);} |
|
824 \end{tikzpicture} |
|
825 \end{center} |
|
826 |
|
827 |
|
828 \end{frame}} |
|
829 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
830 |
|
831 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
832 \mode<presentation>{ |
|
833 \begin{frame}[t] |
|
834 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}} |
|
835 |
|
836 {\Large\bl{while $b$ do $cs$}} |
|
837 |
|
838 \begin{center} |
|
839 \bl{\begin{tabular}{lcl} |
|
840 $\text{compile}(\text{while}\; b\; \text{do} \;cs, E)$ & $\dn$\\ |
|
841 \multicolumn{3}{l}{$\quad l_{wbegin}\;$ \textcolor{black}{(fresh label)}}\\ |
|
842 \multicolumn{3}{l}{$\quad l_{wend}\;$ \textcolor{black}{(fresh label)}}\\ |
|
843 \multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\ |
|
844 \multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\ |
|
845 \multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\ |
|
846 \multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\ |
|
847 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\ |
|
848 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E')$}\\ |
|
849 \end{tabular}} |
|
850 \end{center} |
|
851 |
|
852 \end{frame}} |
|
853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
|
854 |
|
855 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
856 \mode<presentation>{ |
497 \mode<presentation>{ |
857 \begin{frame}[t] |
498 \begin{frame}[t] |
858 \frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}} |
499 \frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}} |
859 |
500 |