slides09.tex
changeset 84 719fd738d2a0
parent 82 06c3ec0b452e
equal deleted inserted replaced
83:bd61b03b9eaa 84:719fd738d2a0
    73 	tabsize=2,
    73 	tabsize=2,
    74 	showspaces=false,
    74 	showspaces=false,
    75 	showstringspaces=false}
    75 	showstringspaces=false}
    76 
    76 
    77 \lstdefinelanguage{while}{
    77 \lstdefinelanguage{while}{
    78   morekeywords={if,then,else,while,do,true,false},
    78   morekeywords={if,then,else,while,do,true,false,write},
    79   otherkeywords={=,!=,:=,<,>},
    79   otherkeywords={=,!=,:=,<,>,;},
    80   sensitive=true,
    80   sensitive=true,
    81   morecomment=[n]{/*}{*/},
    81   morecomment=[n]{/*}{*/},
    82 }
    82 }
    83 
    83 
    84 
    84 
   315 \begin{itemize}
   315 \begin{itemize}
   316 \item introduced in 1995
   316 \item introduced in 1995
   317 \item is a stack-based VM (like Postscript, CLR of .Net)
   317 \item is a stack-based VM (like Postscript, CLR of .Net)
   318 \item contains a JIT compiler
   318 \item contains a JIT compiler
   319 \item many languages take advantage of JVM's infrastructure (JRE)
   319 \item many languages take advantage of JVM's infrastructure (JRE)
   320 \item languages compiled to the JVM: Scala, Clojure\ldots
       
   321 \item is garbage collected $\Rightarrow$ no buffer overflows
   320 \item is garbage collected $\Rightarrow$ no buffer overflows
       
   321 \item some languages compiled to the JVM: Scala, Clojure\ldots
   322 \end{itemize}
   322 \end{itemize}
   323 
   323 
   324 \end{frame}}
   324 \end{frame}}
   325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   325 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   326 
   326 
   434 \frametitle{\begin{tabular}{c}Variables\end{tabular}}
   434 \frametitle{\begin{tabular}{c}Variables\end{tabular}}
   435 
   435 
   436 {\Large\bl{$x := 5 + y * 2$}}\bigskip\pause   
   436 {\Large\bl{$x := 5 + y * 2$}}\bigskip\pause   
   437 
   437 
   438 \begin{itemize}
   438 \begin{itemize}
   439 \item lookup: \bl{$\text{iload}\; number$}
   439 \item lookup: \bl{$\text{iload}\; index$}
   440 \item store: \bl{$\text{istore}\; number$}
   440 \item store: \bl{$\text{istore}\; index$}
   441 \end{itemize}\bigskip\pause
   441 \end{itemize}\bigskip\pause
   442 
   442 
   443 during compilation we have to maintain a map between our identifiers and the
   443 while compilating we have to maintain a map between our identifiers and the
   444 Java bytecode numbers
   444 Java bytecode indices
   445 
   445 
   446 \begin{center}
   446 \begin{center}
   447 \bl{$\text{compile}(a, E)$}
   447 \bl{$\text{compile}(a, E)$}
   448 \end{center}
   448 \end{center}
   449 
   449 
   478 
   478 
   479 We return a list of instructions and an environment for the variables
   479 We return a list of instructions and an environment for the variables
   480 
   480 
   481 \begin{center}
   481 \begin{center}
   482 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
   482 \bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
   483 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(Nil, E)$\bigskip\\
   483 $\text{compile}(\text{skip}, E)$ & $\dn$ & $(N\!il, E)$\bigskip\\
   484 $\text{compile}(x := a, E)$ & $\dn$\\
   484 $\text{compile}(x := a, E)$ & $\dn$\\
   485 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\
   485 \multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\
   486 \end{tabular}}
   486 \end{tabular}}
   487 \end{center}\medskip
   487 \end{center}\medskip
   488 
   488 
   505 iadd\\
   505 iadd\\
   506 istore $n_x$\\
   506 istore $n_x$\\
   507 \end{tabular}}
   507 \end{tabular}}
   508 \end{center}
   508 \end{center}
   509 
   509 
   510 where \bl{$n_x$} is the number corresponding to the variable \bl{$x$}
   510 where \bl{$n_x$} is the index corresponding to the variable \bl{$x$}
   511 
   511 
   512 \end{frame}}
   512 \end{frame}}
   513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   513 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   514 
   514 
   515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   517 \begin{frame}[t]
   517 \begin{frame}[t]
   518 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
   518 \frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
   519 
   519 
   520 {\Large\bl{$\text{if}\;b\;\text{else}\;cs_1\;\text{then}\;cs_2$}}\bigskip\bigskip
   520 {\Large\bl{$\text{if}\;b\;\text{else}\;cs_1\;\text{then}\;cs_2$}}\bigskip\bigskip
   521 
   521 
   522 \onslide<2->{Case }\only<2>{True:}\only<3>{False:}
   522 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
   523 
   523 
   524 \begin{center}
   524 \begin{center}
   525 \begin{tikzpicture}[node distance=2mm and 4mm,
   525 \begin{tikzpicture}[node distance=2mm and 4mm,
   526  block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
   526  block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
   527  point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
   527  point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
   595 {\Large\bl{$a_1 = a_2$}}
   595 {\Large\bl{$a_1 = a_2$}}
   596 
   596 
   597 \begin{center}
   597 \begin{center}
   598 \bl{\begin{tabular}{lcl}
   598 \bl{\begin{tabular}{lcl}
   599 $\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ 
   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$}
   600 \multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$}
   601 \end{tabular}}
   601 \end{tabular}}
   602 \end{center}
   602 \end{center}
   603 
   603 
   604 \end{frame}}
   604 \end{frame}}
   605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   605 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   635 \begin{frame}[t]
   635 \begin{frame}[t]
   636 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
   636 \frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
   637 
   637 
   638 {\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip
   638 {\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip
   639 
   639 
   640 \onslide<2->{Case }\only<2>{True:}\only<3>{False:}
   640 \onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
   641 
   641 
   642 \begin{center}
   642 \begin{center}
   643 \begin{tikzpicture}[node distance=2mm and 4mm,
   643 \begin{tikzpicture}[node distance=2mm and 4mm,
   644  block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
   644  block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
   645  point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
   645  point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
   684 \multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\
   684 \multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\
   685 \multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\
   685 \multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\
   686 \multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\
   686 \multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\
   687 \multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\
   687 \multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\
   688 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\
   688 \multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\
   689 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E'')$}\\
   689 \multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E')$}\\
   690 \end{tabular}}
   690 \end{tabular}}
   691 \end{center}
   691 \end{center}
   692 
   692 
   693 \end{frame}}
   693 \end{frame}}
   694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   694 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   700 
   700 
   701 {\Large\bl{write $x$}}
   701 {\Large\bl{write $x$}}
   702 
   702 
   703 \begin{center}
   703 \begin{center}
   704 \small\bl{\begin{tabular}{l}
   704 \small\bl{\begin{tabular}{l}
   705 .method public static write(I)V\\ 
   705 .method public static write(I)V\hspace{1cm}\textcolor{black}{(library function)}\\ 
   706 \;\;    .limit locals 5 \\
   706 \;\;    .limit locals 5 \\
   707 \;\;    .limit stack 5 \\
   707 \;\;    .limit stack 5 \\
   708 \;\;    iload 0 \\
   708 \;\;    iload 0 \\
   709 \;\;    getstatic java/lang/System/out Ljava/io/PrintStream;\\ 
   709 \;\;    getstatic java/lang/System/out Ljava/io/PrintStream;\\ 
   710 \;\;    swap \\
   710 \;\;    swap \\