Binary file handouts/ho07.pdf has changed
--- a/handouts/ho07.tex Mon Nov 12 11:33:51 2018 +0000
+++ b/handouts/ho07.tex Tue Nov 13 08:16:48 2018 +0000
@@ -61,7 +61,7 @@
integer instructions in the JVM (alternatives are \code{d} for
doubles, \code{l} for longs and \code{f} for floats).
-Recall our grammar for arithmetic expressions ($E$ is the
+Recall our grammar for arithmetic expressions (\meta{E} is the
starting symbol):
Binary file handouts/ho08.pdf has changed
--- a/handouts/ho08.tex Mon Nov 12 11:33:51 2018 +0000
+++ b/handouts/ho08.tex Tue Nov 13 08:16:48 2018 +0000
@@ -60,8 +60,8 @@
\begin{plstx}[rhs style=,margin=1.5cm]
-: \meta{Exp} ::= \meta{Id} | \meta{Num} {\hspace{3cm}}
- | \meta{Exp} + \meta{Exp} | ... | (\meta{Exp})
+: \meta{Exp} ::= \meta{Id} | \meta{Num} {\hspace{3.7cm}}
+ | \meta{Exp} + \meta{Exp} | ... | (\meta{Exp}) {\hspace{3.7cm}}
| \code{if} \meta{BExp} \code{then} \meta{Exp} \code{else} \meta{Exp}
| \code{write} \meta{Exp} {\hspace{5cm}}
| \meta{Exp} ; \meta{Exp} {\hspace{5cm}}
--- a/progs/compile.scala Mon Nov 12 11:33:51 2018 +0000
+++ b/progs/compile.scala Tue Nov 13 08:16:48 2018 +0000
@@ -94,7 +94,7 @@
.end method
"""
-println("starting")
+println("Start compilation")
// for generating new labels
--- a/progs/fib.j Mon Nov 12 11:33:51 2018 +0000
+++ b/progs/fib.j Tue Nov 13 08:16:48 2018 +0000
@@ -3,104 +3,92 @@
.super java/lang/Object
.method public <init>()V
- aload_0
- invokenonvirtual java/lang/Object/<init>()V
- return
+ aload_0
+ invokenonvirtual java/lang/Object/<init>()V
+ return
.end method
-.method public static print(Ljava/lang/String;)V
- .limit locals 5
- .limit stack 5
- aload 0
- getstatic java/lang/System/out Ljava/io/PrintStream;
- swap
- invokevirtual java/io/PrintStream/print(Ljava/lang/String;)V
- return
+.method public static write(I)V
+ .limit locals 1
+ .limit stack 2
+ getstatic java/lang/System/out Ljava/io/PrintStream;
+ iload 0
+ invokevirtual java/io/PrintStream/println(I)V
+ return
.end method
-.method public static write(I)V
- .limit locals 1
- .limit stack 2
- getstatic java/lang/System/out Ljava/io/PrintStream;
- iload 0
- invokevirtual java/io/PrintStream/println(I)V
- return
-.end method
-
-.method public static read()I
- .limit locals 10
+.method public static read()I
+ .limit locals 10
.limit stack 10
- ldc 0
- istore 1 ; this will hold our final integer
-Label1:
- getstatic java/lang/System/in Ljava/io/InputStream;
- invokevirtual java/io/InputStream/read()I
- istore 2
- iload 2
- ldc 10 ; the newline delimiter
- isub
- ifeq Label2
- iload 2
- ldc 32 ; the space delimiter
- isub
+ ldc 0
+ istore 1 ; this will hold our final integer
+Label1:
+ getstatic java/lang/System/in Ljava/io/InputStream;
+ invokevirtual java/io/InputStream/read()I
+ istore 2
+ iload 2
+ ldc 10 ; the newline delimiter
+ isub
+ ifeq Label2
+ iload 2
+ ldc 32 ; the space delimiter
+ isub
ifeq Label2
- iload 2
- ldc 48 ; we have our digit in ASCII, have to subtract it from 48
- isub
- ldc 10
- iload 1
- imul
- iadd
- istore 1
- goto Label1
-Label2:
- ;when we come here we have our integer computed in local variable 1
- iload 1
- ireturn
+ iload 2
+ ldc 48 ; we have our digit in ASCII, have to subtract it from 48
+ isub
+ ldc 10
+ iload 1
+ imul
+ iadd
+ istore 1
+ goto Label1
+Label2:
+ ;when we come here we have our integer computed in local variable 1
+ iload 1
+ ireturn
.end method
.method public static main([Ljava/lang/String;)V
- .limit locals 200
- .limit stack 200
+ .limit locals 200
+ .limit stack 200
- ldc "Fib"
- invokestatic fib/fib/print(Ljava/lang/String;)V
- invokestatic fib/fib/read()I
- istore 0
- ldc 0
- istore 1
- ldc 1
- istore 2
+invokestatic fib/fib/read()I
+istore 0
+ldc 0
+istore 1
+ldc 1
+istore 2
+ldc 0
+istore 3
-Loop_start_1:
-
- iload 0
- ldc 0
- if_icmple Loop_end_0
+Loop_begin_2:
- iload 2
- istore 3
- iload 1
- iload 2
- iadd
- istore 2
- iload 3
- istore 1
- iload 0
- ldc 1
- isub
- istore 0
+ldc 0
+iload 0
+if_icmpge Loop_end_3
+iload 2
+istore 3
+iload 1
+iload 2
+iadd
+istore 2
+iload 3
+istore 1
+iload 0
+ldc 1
+isub
+istore 0
+goto Loop_begin_2
- goto Loop_start_1
+Loop_end_3:
-Loop_end_0:
+iload 1
+invokestatic fib/fib/write(I)V
- ldc "Result"
- invokestatic fib/fib/print(Ljava/lang/String;)V
- iload 2
- invokestatic fib/fib/write(I)V
- return
+ return
+
.end method
--- a/slides/slides07.tex Mon Nov 12 11:33:51 2018 +0000
+++ b/slides/slides07.tex Tue Nov 13 08:16:48 2018 +0000
@@ -25,7 +25,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}
Binary file slides/slides08.pdf has changed
--- 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}
Binary file slides/slides09.pdf has changed