slides/slides08.tex
changeset 600 d488a3e7b0ec
parent 598 e3ad67cd5123
child 601 208b0f67a3d0
--- a/slides/slides08.tex	Mon Nov 12 11:33:51 2018 +0000
+++ b/slides/slides08.tex	Tue Nov 13 08:16:48 2018 +0000
@@ -3,6 +3,7 @@
 \usepackage{../langs}
 \usepackage{../data}
 \usepackage{../graphics}
+\usepackage{../grammar}
 
 % beamer stuff 
 \renewcommand{\slidecaption}{CFL 07, King's College London}
@@ -23,7 +24,7 @@
   \begin{center}
   \begin{tabular}{ll}
   Email:  & christian.urban at kcl.ac.uk\\
-  Office: & N7.07 (North Wing, Bush House)\\
+  Office: & N\liningnums{7.07} (North Wing, Bush House)\\
   Slides: & KEATS (also home work is there)\\
   \end{tabular}
   \end{center}
@@ -56,7 +57,15 @@
   \LARGE
   \fontspec{Hoefler Text Black}
   \textcolor{ProcessBlue}{JVM\\ Code}
+  \\[12mm]
+
+  \normalsize
+  Jasmin\\
+  Krakatau\\
+  ASM lib
 \end{textblock}
+
+
 \fontsize{8}{10}\selectfont
 %\footnotesize
 \mbox{}\\[-8mm]\mbox{}
@@ -76,32 +85,30 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
  
  
- 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[c]
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[t]
 
 \begin{center}
 \bl{\begin{tabular}{@{}lcl@{}}
-\textit{Stmt} & $\rightarrow$ &  $\texttt{skip}$\\
-              & $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\
-              & $|$ & \texttt{if}\; \textit{BExp} \;\texttt{then}\; \textit{Block} \;\texttt{else}\; \textit{Block}\\
-              & $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\
+\\[-12mm]        
+\meta{Stmt} & $::=$ &  $\texttt{skip}$\\
+              & $|$ & \textit{Id}\;\texttt{:=}\;\meta{AExp}\\
+              & $|$ & \texttt{if}\; \meta{BExp} \;\texttt{then}\; \meta{Block} \;\texttt{else}\; \meta{Block}\\
+              & $|$ & \texttt{while}\; \meta{BExp} \;\texttt{do}\; \meta{Block}\\
               & $|$ & \texttt{read}\;\textit{Id}\\
               & $|$ & \texttt{write}\;\textit{Id}\\
               & $|$ & \texttt{write}\;\textit{String}\medskip\\
-\textit{Stmts} & $\rightarrow$ &  \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\
-              & $|$ & \textit{Stmt}\medskip\\
-\textit{Block} & $\rightarrow$ &  \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\
-                & $|$ & \textit{Stmt}\medskip\\
-\textit{AExp} & $\rightarrow$ & \ldots\\
-\textit{BExp} & $\rightarrow$ & \ldots\\
+\meta{Stmts} & $::=$ &  \meta{Stmt} \;\texttt{;}\; \meta{Stmts}\\
+              & $|$ & \meta{Stmt}\medskip\\
+\meta{Block} & $::=$ &  \texttt{\{}\,\meta{Stmts}\,\texttt{\}}\\
+                & $|$ & \meta{Stmt}\medskip\\
+\meta{AExp} & $::=$ & \ldots\\
+\meta{BExp} & $::=$ & \ldots\\
 \end{tabular}}
 \end{center}
-
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
-\end{frame}}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{frame}[c]
@@ -218,13 +225,14 @@
 \end{itemize}
 
 \end{frame}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{frame}[t,fragile]
 \frametitle{Compiling AExps}
 
-For example \bl{$1 + ((2 * 3) + (4 - 3))$}:\medskip
-
+For example \liningnums{\bl{$1 + ((2 * 3) + (4 - 3))$}}:\medskip
+  
 \begin{columns}[T]
 \begin{column}{.3\textwidth}
 \begin{center}
@@ -235,7 +243,7 @@
 \end{tikzpicture}}
 \end{center}
 \end{column}
-\begin{column}{.3\textwidth}
+\begin{column}{.3\textwidth}  
 \begin{lstlisting}[language=JVMIS,numbers=none]
 ldc 1 
 ldc 2 
@@ -258,45 +266,44 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+\begin{frame}[t,fragile]
+\frametitle{Compiling AExps}
 
-{\Large\bl{1 + 2 + 3}}
+\liningnums{\textbf{\Large\bl{1 + 2 + 3}}}
 
-\begin{center}
-\bl{\begin{tabular}{l}
-ldc 1\\
-ldc 2\\
-iadd\\
-ldc 3\\
-iadd\\
-\end{tabular}}
-\end{center}
+\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=6cm]  
+ldc 1
+ldc 2
+iadd
+ldc 3
+iadd
+\end{lstlisting}
+
 
 \end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[t]
-\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
+\begin{frame}[t,fragile]
+\frametitle{Compiling AExps}
 
-{\Large\bl{1 + (2 + 3)}}
+\liningnums{\textbf{\Large\bl{1 + (2 + 3)}}}
 
-\begin{center}
-\bl{\begin{tabular}{l}
-ldc 1\\
-ldc 2\\
-ldc 3\\
-iadd\\
-iadd\\
-\end{tabular}}
-\end{center}\bigskip\pause
+\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=6cm]  
+ldc 1
+ldc 2
+ldc 3
+iadd
+iadd
+\end{lstlisting}
+\bigskip\pause
 \vfill
 
-\bl{dadd, fadd, ladd, \ldots}
+\textcolor{codepurple}{\textbf{\texttt{dadd}}},
+\textcolor{codepurple}{\textbf{\texttt{fadd}}},
+\textcolor{codepurple}{\textbf{\texttt{ladd}}}, \ldots
 
-\end{frame}}
+\end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
 
@@ -320,38 +327,34 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\mode<presentation>{
-\begin{frame}[t]
+\begin{frame}[t,fragile]
 \frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
 
-{\Large\bl{1 + 2 * 3 + (4 - 3)}}
+\liningnums{\textbf{\Large\bl{1 $+$ 2 $*$ 3 $+$ (4 $-$ 3)}}}
 
-\begin{center}
-\bl{\begin{tabular}{l}
-ldc 1\\
-ldc 2\\
-ldc 3\\
-imul\\
-ldc 4\\
-ldc 3\\
-isub\\
-iadd\\
-iadd\\
-\end{tabular}}
-\end{center}
+\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=6cm]         
+ldc 1
+ldc 2
+ldc 3
+imul
+ldc 4
+ldc 3
+isub
+iadd
+iadd
+\end{lstlisting}
 
-\end{frame}}
+\end{frame}
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[t]
+\begin{frame}[c]
 \frametitle{Variables}
-
-{\Large\bl{$x := 5 + y * 2$}}\bigskip\pause   
+\liningnums{\textbf{\Large\bl{x $:=$ 5 $+$ y $*$ 2}}}\bigskip\pause   
 
 \begin{itemize}
-\item lookup: \bl{$\text{iload}\; index$}
-\item store: \bl{$\text{istore}\; index$}
+\item lookup: \bl{$\textcolor{codepurple}{\textbf{\texttt{iload}}}\; index$}
+\item store: \bl{$\textcolor{codepurple}{\textbf{\texttt{istore}}}\; index$}
 \end{itemize}\bigskip\pause
 
 while compilating we have to maintain a map between our identifiers and the
@@ -404,7 +407,7 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[t]
+\begin{frame}[c]
 \frametitle{Compiling Statements}
 
 We return a list of instructions and an environment for the
@@ -425,19 +428,17 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[c]
+\begin{frame}[c,fragile]
 \frametitle{Compiling Assignments}
 
-{\Large\bl{$x := x + 1$}}
+\liningnums{\textbf{\Large\bl{x $:=$ x $+$ 1}}}
 
-\begin{center}
-\bl{\begin{tabular}{l}
-iload $n_x$\\
-ldc 1\\
-iadd\\
-istore $n_x$\\
-\end{tabular}}
-\end{center}
+\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=6cm]        
+iload /*@\bl{$n_x$}@*/
+ldc 1
+iadd
+istore /*@\bl{$n_x$}@*/
+\end{lstlisting}\medskip
 
 where \bl{$n_x$} is the index corresponding to the variable~\bl{$x$}
 
@@ -486,30 +487,31 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\begin{frame}[t]
+\begin{frame}[t,fragile]
 \frametitle{Conditional Jumps}
 
 \begin{minipage}{1.1\textwidth}
 \begin{itemize}
-\item \bl{if\_icmpeq $label$} if two ints are equal, then jump\medskip
-\item \bl{if\_icmpne $label$} if two ints aren't equal, then jump\medskip
-\item \bl{if\_icmpge $label$} if one int is greater or equal then another, then jump
+\item \textcolor{codepurple}{\textbf{\texttt{if\_icmpeq}}} \bl{$label$}
+  if two ints are equal, then jump\medskip
+\item \textcolor{codepurple}{\textbf{\texttt{if\_icmpne}}} \bl{$label$}
+  if two ints aren't equal, then jump\medskip
+\item \textcolor{codepurple}{\textbf{\texttt{if\_icmpge}}} \bl{$label$}
+  if one int is greater or equal then another, then jump
 \item[]\ldots
 \end{itemize}
 \end{minipage}\pause
 
+\begin{lstlisting}[language=JVMIS,numbers=none,xleftmargin=2cm]
+/*@\bl{$L_1$:}@*/
+  if_icmpeq /*@\bl{$L_2$}@*/
+  iload 1
+  ldc 1
+  iadd
+  if_icmpeq /*@\bl{$L_1$}@*/
+/*@\bl{$L_2$:}@*/
+\end{lstlisting}
 
-\begin{center}
-\bl{\begin{tabular}{l}
-$L_1$:\\
-\hspace{5mm}if\_icmpeq\;$L_2$\\
-\hspace{5mm}iload 1\\
-\hspace{5mm}ldc 1\\
-\hspace{5mm}iadd\\
-\hspace{5mm}if\_icmpeq\;$L_1$\\
-$L_2$:
-\end{tabular}}
-\end{center}
 
 \begin{textblock}{3.5}(11,12)
 \only<3>{labels must be unique}