--- a/slides/slides08.tex Thu Nov 26 00:11:10 2015 +0000
+++ b/slides/slides08.tex Thu Nov 26 12:55:59 2015 +0000
@@ -5,7 +5,7 @@
\usepackage{../graphics}
% beamer stuff
-\renewcommand{\slidecaption}{AFL 09, King's College London}
+\renewcommand{\slidecaption}{AFL 07, King's College London}
\newcommand{\bl}[1]{\textcolor{blue}{#1}}
\begin{document}
@@ -39,7 +39,8 @@
\begin{tikzpicture}
\node (rexp) {\bl{\bf Lexer}};
\node (nfa) [right=of rexp] {\bl{\bf Parser}};
-\node (dfa) [right=of nfa] {\bl{\begin{tabular}{c}\bf Machine Code/\\\bf Byte Code\end{tabular}}};
+\node (dfa) [right=of nfa]
+ {\bl{\begin{tabular}{c}\bf Machine Code/\\\bf Java Byte Code\end{tabular}}};
\path[->, red, line width=2mm] (rexp) edge node [above=4mm, black] {\begin{tabular}{c@{\hspace{9mm}}}token\\[-1mm]
sequence\end{tabular}} (nfa);
\path[->, red, line width=2mm] (nfa) edge node [above=4mm, black] {\begin{tabular}{c}parse\\[-1mm] tree\end{tabular}}(dfa);
@@ -51,16 +52,21 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
-\frametitle{JVM Code}
-\footnotesize
-\mbox{}\\[-20mm]\mbox{}
+\begin{textblock}{10}(0.5,0.5)
+ \LARGE
+ \fontspec{Hoefler Text Black}
+ \textcolor{ProcessBlue}{JVM\\ Code}
+\end{textblock}
+\fontsize{8}{10}\selectfont
+%\footnotesize
+\mbox{}\\[-8mm]\mbox{}
\begin{columns}
-\begin{column}{7cm}
+\begin{column}{2cm}
\lstinputlisting[numbers=none]{../progs/appHa.j}
\end{column}
-\begin{column}{7cm}
+\begin{column}{2cm}
\lstinputlisting[numbers=none]{../progs/appHb.j}
\end{column}
@@ -98,7 +104,6 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[c]
\frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}}
@@ -107,13 +112,12 @@
{\lstset{language=While}\fontsize{10}{12}\selectfont
\texttt{\lstinputlisting{../progs/fib.while}}}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
+\frametitle{Interpreter}
\begin{center}
\bl{\begin{tabular}{@{}lcl@{}}
@@ -128,13 +132,12 @@
\end{tabular}}
\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}}
+\frametitle{Interpreter (2)}
\begin{center}
\bl{\begin{tabular}{@{}lcl@{}}
@@ -153,25 +156,25 @@
\end{tabular}}
\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Test Program\end{tabular}}
+\frametitle{Test Program}
\mbox{}\\[-18mm]\mbox{}
{\lstset{language=While}\fontsize{10}{12}\selectfont
\texttt{\lstinputlisting{../progs/loops.while}}}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[c]
-\tiny
+\fontsize{7}{9}\selectfont
+
\begin{columns}
\begin{column}{7cm}
@@ -181,19 +184,14 @@
\begin{column}{7cm}
\lstinputlisting[numbers=none]{../progs/appHb.j}
\end{column}
-
\end{columns}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
+\frametitle{Interpreted Code}
\begin{center}
\begin{tikzpicture}
@@ -203,13 +201,12 @@
\end{tikzpicture}
\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}}
+\frametitle{Java Virtual Machine}
\begin{itemize}
\item introduced in 1995
@@ -220,13 +217,12 @@
\item some languages compiled to the JVM: Scala, Clojure\ldots
\end{itemize}
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+\frametitle{Compiling AExps}
{\Large\bl{1 + 2}}
@@ -236,7 +232,8 @@
ldc 2\\
iadd\\
\end{tabular}}
-\end{center}\end{frame}}
+\end{center}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -284,9 +281,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+\frametitle{Compiling AExps}
\begin{center}
\bl{\begin{tabular}{@{}lcl@{}}
@@ -298,9 +294,9 @@
$\text{compile}(a_1 * a_2)$ & $\dn$\\
\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{imul}$}\smallskip\\
\end{tabular}}
-\end{center}\pause
+\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -328,9 +324,8 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Variables\end{tabular}}
+\frametitle{Variables}
{\Large\bl{$x := 5 + y * 2$}}\bigskip\pause
@@ -346,54 +341,72 @@
\bl{$\text{compile}(a, E)$}
\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+\frametitle{Compiling AExps}
\begin{center}
\bl{\begin{tabular}{@{}lcl@{}}
$\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\
$\text{compile}(a_1 + a_2, E)$ & $\dn$\\
-\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{iadd}$}\smallskip\\
+\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{iadd}$}\smallskip\\
$\text{compile}(a_1 - a_2, E)$ & $\dn$\\
\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\
$\text{compile}(a_1 * a_2, E)$ & $\dn$\\
\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\
$\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\
\end{tabular}}
-\end{center}\pause
+\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
+\begin{frame}[c, fragile]
+\frametitle{Mathematical Functions}
+
+Compilation of some mathematical functions:
+
+\begin{center}
+\begin{tabular}{lcl}
+\texttt{Aop("+", a1, a2)} & $\Rightarrow$ & \texttt{...iadd}\\
+\texttt{Aop("-", a1, a2)} & $\Rightarrow$ & \texttt{...isub}\\
+\texttt{Aop("*", a1, a2)} & $\Rightarrow$ & \texttt{...imul}\\
+\texttt{Aop("/", a1, a2)} & $\Rightarrow$ & \texttt{...idiv}\\
+\texttt{Aop("\%", a1, a2)} & $\Rightarrow$ & \texttt{...irem}\\
+\end{tabular}
+\end{center}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling Statements\end{tabular}}
+\frametitle{Compiling Statements}
-We return a list of instructions and an environment for the variables
+We return a list of instructions and an environment for the
+variables
\begin{center}
\bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
-$\text{compile}(\text{skip}, E)$ & $\dn$ & $(N\!il, E)$\bigskip\\
+$\text{compile}(\text{skip}, E)$ & $\dn$ & $(\textit{Nil}, E)$\bigskip\\
$\text{compile}(x := a, E)$ & $\dn$\\
\multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\
\end{tabular}}
\end{center}\medskip
-where \bl{$index$} is \bl{$E(x)$} if it is already defined, or if it is not then the largest index not yet seen
+where \bl{$index$} is \bl{$E(x)$} if it is already defined,
+or if it is not, then the largest index not yet seen
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+\begin{frame}[c]
+\frametitle{Compiling Assignments}
{\Large\bl{$x := x + 1$}}
@@ -406,15 +419,15 @@
\end{tabular}}
\end{center}
-where \bl{$n_x$} is the index corresponding to the variable \bl{$x$}
+where \bl{$n_x$} is the index corresponding to the variable~\bl{$x$}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
+\frametitle{Compiling Ifs}
{\Large\bl{$\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2$}}\bigskip\bigskip
@@ -449,14 +462,12 @@
\end{tikzpicture}
\end{center}
-
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
-\frametitle{\begin{tabular}{c}Conditional Jumps\end{tabular}}
+\begin{frame}[t]
+\frametitle{Conditional Jumps}
\begin{minipage}{1.1\textwidth}
\begin{itemize}
@@ -483,13 +494,12 @@
\begin{textblock}{3.5}(11,12)
\only<3>{labels must be unique}
\end{textblock}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}}
+\frametitle{Compiling BExps}
{\Large\bl{$a_1 = a_2$}}
@@ -500,13 +510,54 @@
\end{tabular}}
\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
+\begin{frame}[c, fragile]
+\frametitle{Boolean Expressions}
+
+Compilation of boolean expressions:
+
+\begin{center}
+\begin{tikzpicture}[node distance=2mm and 4mm,
+ block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
+ point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
+ skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
+\node (A1) [point] {};
+\node (b) [block, right=of A1] {code of \bl{$b$}};
+\node (A2) [point, right=of b] {};
+\node (cs1) [block, right=of A2] {code of \bl{$cs_1$}};
+\node (A3) [point, right=of cs1] {};
+\node (cs2) [block, right=of A3] {code of \bl{$cs_2$}};
+\node (A4) [point, right=of cs2] {};
+
+\only<1>{
+\draw (A1) edge [->, red, line width=1mm] (b);
+\draw (b) edge [->, red, line width=1mm] (A2);
+\draw (A2) edge [skip loop] (A3);
+\draw (A3) edge [->, red, line width=1mm] (cs2);
+\draw (cs2) edge [->,red, line width=1mm] (A4);
+\node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};}
+\end{tikzpicture}
+\end{center}
+
+\begin{center}
+\begin{tabular}{lcl}
+\texttt{Bop("==", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpne...}\\
+\texttt{Bop("!=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpeq...}\\
+\texttt{Bop("<", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpge...}\\
+\texttt{Bop("<=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpgt...}\\
+\end{tabular}
+\end{center}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
+\frametitle{Compiling Ifs}
{\Large\bl{if $b$ then $cs_1$ else $cs_2$}}
@@ -526,13 +577,12 @@
\end{tabular}}
\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
+\frametitle{Compiling Whiles}
{\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip
@@ -564,14 +614,12 @@
\end{tikzpicture}
\end{center}
-
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
+\frametitle{Compiling Whiles}
{\Large\bl{while $b$ do $cs$}}
@@ -589,13 +637,12 @@
\end{tabular}}
\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}}
+\frametitle{Compiling Writes}
{\Large\bl{write $x$}}
@@ -617,41 +664,12 @@
\end{tabular}}
\end{center}
-\end{frame}}
+\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\mode<presentation>{
\begin{frame}[c]
-
-\begin{center}
-\small\bl{\begin{tabular}{l}
-.class public XXX.XXX\\
-.super java/lang/Object\\
-\\
-.method public <init>()V\\
-\;\; aload\_0\\
-\;\; invokenonvirtual java/lang/Object/<init>()V\\
- \;\; return\\
-.end method\\
-\\
-.method public static main([Ljava/lang/String;)V\\
-\;\; .limit locals 200\\
-\;\; .limit stack 200\\
-\\
- \textcolor{black}{(here comes the compiled code)}\\
-\\
-\;\; return\\
-.end method\\
-\end{tabular}}
-\end{center}
-
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
\frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}}
\begin{itemize}