slides/slides08.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Sun, 01 Dec 2013 09:58:41 +0000
changeset 215 828303e8e4af
parent 197 6622bd256029
child 306 fecffce112fa
permissions -rw-r--r--
updated slides
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
\documentclass[dvipsnames,14pt,t]{beamer}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     2
\usepackage{beamerthemeplaincu}
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
\usepackage[absolute,overlay]{textpos}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
\usepackage{ifthen}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
\usepackage{tikz}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
\usepackage{pgf}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
\usepackage{calc} 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
\usepackage{ulem}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
\usepackage{listings}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
\renewcommand{\uline}[1]{#1}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
\usetikzlibrary{arrows}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
\usetikzlibrary{automata}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
\usetikzlibrary{shapes}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
\usetikzlibrary{shadows}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
\usetikzlibrary{positioning}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
\usetikzlibrary{calc}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
\usetikzlibrary{plotmarks}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
\usepackage{graphicx} 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    19
\usepackage{pgfplots}
215
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 197
diff changeset
    20
\usepackage{../langs}
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 197
diff changeset
    21
\usepackage{../data}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    22
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
% beamer stuff 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    24
\renewcommand{\slidecaption}{AFL 09, King's College London, 20.~November 2013}
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
\newcommand{\dn}{\stackrel{\mbox{\scriptsize def}}{=}}% for definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
\begin{frame}<1>[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
\frametitle{%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    34
  \begin{tabular}{@ {}c@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  \\[-3mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
  \LARGE Automata and \\[-2mm] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  \LARGE Formal Languages (8)\\[3mm] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  \end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  \normalsize
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
  \begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  \begin{tabular}{ll}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  Email:  & christian.urban at kcl.ac.uk\\
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    44
  Office: & S1.27 (1st floor Strand Building)\\
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
  Slides: & KEATS (also home work is there)\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  \end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
\end{frame}}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    50
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    51
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    52
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    53
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    54
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    55
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    56
Imagine the following situation: You talk to somebody
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    57
and you find out that she/he has implemented a compiler.\smallskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    58
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    59
What is your reaction? \pause Check all that apply.\bigskip
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    60
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    61
 \begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    62
 \item[$\Box$] You think she/he is God
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    63
 \item[$\Box$] \"Uberhacker
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    64
 \item[$\Box$] superhuman
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    65
 \item[$\Box$] wizard
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    66
 \item[$\Box$] supremo
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    67
 \end{itemize}
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    68
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    69
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    70
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    71
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    72
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    73
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    74
\begin{frame}[c]
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    75
\frametitle{Bird's Eye View}
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    77
\begin{center}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    78
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    79
\node (rexp)  {\bl{\bf Lexer}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    80
\node (nfa) [right=of rexp] {\bl{\bf Parser}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    81
\node (dfa) [right=of nfa] {\bl{\begin{tabular}{c}\bf Machine Code/\\\bf Byte Code\end{tabular}}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    82
\path[->, red, line width=2mm] (rexp) edge node [above=4mm, black] {\begin{tabular}{c@{\hspace{9mm}}}token\\[-1mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    83
sequence\end{tabular}} (nfa);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    84
\path[->, red, line width=2mm] (nfa) edge node [above=4mm, black] {\begin{tabular}{c}parse\\[-1mm] tree\end{tabular}}(dfa);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    85
\end{tikzpicture}\\
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    86
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    87
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    88
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    89
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    90
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    91
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    92
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    93
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    94
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    95
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    96
\includegraphics[scale=0.7]{../pics/machine_code.jpg}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    97
\end{center}
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    98
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    99
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   100
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   101
 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   102
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   103
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   104
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   105
\frametitle{Assembly Code}
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   106
\mbox{}\\[-12mm]\mbox{}
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   107
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   108
\begin{center}
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   109
\includegraphics[scale=0.65]{../pics/assembly.jpg}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   110
\end{center}
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   111
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   112
\small\mbox{}\\[-10mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   113
Jasmin assembler for Java bytecode
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   114
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   115
\end{frame}}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   116
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   117
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   118
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   119
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   120
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   121
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
   122
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   123
\begin{center}
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
   124
\bl{\begin{tabular}{@{}lcl@{}}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   125
\textit{Stmt} & $\rightarrow$ &  $\texttt{skip}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   126
              & $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   127
              & $|$ & \texttt{if}\; \textit{BExp} \;\texttt{then}\; \textit{Block} \;\texttt{else}\; \textit{Block}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   128
              & $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   129
              & $|$ & \texttt{read}\;\textit{Id}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   130
              & $|$ & \texttt{write}\;\textit{Id}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   131
              & $|$ & \texttt{write}\;\textit{String}\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   132
\textit{Stmts} & $\rightarrow$ &  \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   133
              & $|$ & \textit{Stmt}\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   134
\textit{Block} & $\rightarrow$ &  \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   135
                & $|$ & \textit{Stmt}\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   136
\textit{AExp} & $\rightarrow$ & \ldots\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   137
\textit{BExp} & $\rightarrow$ & \ldots\\
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   138
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   139
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   140
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   141
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   142
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   143
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   144
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   145
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   146
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   147
\begin{frame}[c]
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   148
\frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   149
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   150
\mbox{}\\[-18mm]\mbox{}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   151
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   152
{\lstset{language=While}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   153
\texttt{\lstinputlisting{../progs/fib.while}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   154
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   155
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   156
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   157
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   158
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   159
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   160
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   161
\frametitle{\begin{tabular}{c}Interpreter\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   162
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   163
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   164
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   165
$\text{eval}(n, E)$ & $\dn$ & $n$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   166
$\text{eval}(x, E)$ & $\dn$ & $E(x)$ \;\;\;\textcolor{black}{lookup \bl{$x$} in \bl{$E$}}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   167
$\text{eval}(a_1 + a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) + \text{eval}(a_2, E)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   168
$\text{eval}(a_1 - a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) - \text{eval}(a_2, E)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   169
$\text{eval}(a_1 * a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) * \text{eval}(a_2, E)$\bigskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   170
$\text{eval}(a_1 = a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) = \text{eval}(a_2, E)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   171
$\text{eval}(a_1\,!\!= a_2, E)$ & $\dn$ & $\neg(\text{eval}(a_1, E) = \text{eval}(a_2, E))$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   172
$\text{eval}(a_1 < a_2, E)$ & $\dn$ & $\text{eval}(a_1, E) < \text{eval}(a_2, E)$\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   173
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   174
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   175
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   176
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   177
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   178
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   179
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   180
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   181
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   182
\frametitle{\begin{tabular}{c}Interpreter (2)\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   183
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   184
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   185
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   186
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   187
$\text{eval}(x:=a, E)$ & $\dn$ & \bl{$E(x \mapsto \text{eval}(a, E))$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   188
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2 , E) \dn$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   189
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)\;\text{then}\;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   190
\text{eval}(cs_1,E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   191
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\phantom{\text{if}\;\text{eval}(b,E)\;}\text{else}\;\text{eval}(cs_2,E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   192
\multicolumn{3}{@{}l@{}}{$\text{eval}(\text{while}\;b\;\text{do}\;cs, E) \dn$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   193
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{if}\;\text{eval}(b,E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   194
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   195
\text{eval}(\text{while}\;b\;\text{do}\;cs, \text{eval}(cs,E))$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   196
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   197
$\text{eval}(\text{write}\; x, E)$ & $\dn$ & $\{\;\text{println}(E(x))\; ;\;E\;\}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   198
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   199
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   200
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   201
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   202
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   203
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   204
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   205
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   206
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   207
\frametitle{\begin{tabular}{c}Test Program\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   208
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   209
\mbox{}\\[-18mm]\mbox{}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   210
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   211
{\lstset{language=While}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   212
\texttt{\lstinputlisting{../progs/loops.while}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   213
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   214
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   215
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   216
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   217
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   218
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   219
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   220
\frametitle{\begin{tabular}{c}Interpreted Code\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   221
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   222
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   223
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   224
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   225
\addplot+[smooth] file {interpreted.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   226
\end{axis}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   227
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   228
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   229
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   230
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   231
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   232
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   233
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   234
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   235
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   236
\frametitle{\begin{tabular}{c}Java Virtual Machine\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   237
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   238
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   239
\item introduced in 1995
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   240
\item is a stack-based VM (like Postscript, CLR of .Net)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   241
\item contains a JIT compiler
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   242
\item many languages take advantage of JVM's infrastructure (JRE)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   243
\item is garbage collected $\Rightarrow$ no buffer overflows
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   244
\item some languages compiled to the JVM: Scala, Clojure\ldots
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   245
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   246
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   247
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   248
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   249
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   250
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   251
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   252
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   253
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   254
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   255
{\Large\bl{1 + 2}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   256
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   257
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   258
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   259
ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   260
ldc 2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   261
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   262
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   263
\end{center}\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   264
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   265
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   266
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   267
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   268
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   269
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   270
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   271
{\Large\bl{1 + 2 + 3}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   272
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   273
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   274
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   275
ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   276
ldc 2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   277
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   278
ldc 3\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   279
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   280
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   281
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   282
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   283
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   284
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   285
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   286
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   287
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   288
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   289
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   290
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   291
{\Large\bl{1 + (2 + 3)}}
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   292
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   293
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   294
\bl{\begin{tabular}{l}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   295
ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   296
ldc 2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   297
ldc 3\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   298
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   299
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   300
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   301
\end{center}\bigskip\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   302
\vfill
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   303
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   304
\bl{dadd, fadd, ladd, \ldots}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   305
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   306
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   307
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   308
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   309
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   310
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   311
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   312
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   313
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   314
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   315
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   316
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   317
$\text{compile}(n)$ & $\dn$ & $\text{ldc}\;n$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   318
$\text{compile}(a_1 + a_2)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   319
\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\;\text{compile}(a_2)\;@\; \text{iadd}$}\smallskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   320
$\text{compile}(a_1 - a_2)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   321
\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{isub}$}\smallskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   322
$\text{compile}(a_1 * a_2)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   323
\multicolumn{3}{l}{$\qquad\text{compile}(a_1) \;@\; \text{compile}(a_2)\;@\; \text{imul}$}\smallskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   324
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   325
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   326
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   327
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   328
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   329
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   330
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   331
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   332
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   333
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   334
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   335
{\Large\bl{1 + 2 * 3 + (4 - 3)}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   336
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   337
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   338
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   339
ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   340
ldc 2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   341
ldc 3\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   342
imul\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   343
ldc 4\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   344
ldc 3\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   345
isub\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   346
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   347
iadd\\
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   348
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   349
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   350
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   351
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   352
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   353
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   354
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   355
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   356
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   357
\frametitle{\begin{tabular}{c}Variables\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   358
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   359
{\Large\bl{$x := 5 + y * 2$}}\bigskip\pause   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   360
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   361
\begin{itemize}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   362
\item lookup: \bl{$\text{iload}\; index$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   363
\item store: \bl{$\text{istore}\; index$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   364
\end{itemize}\bigskip\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   365
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   366
while compilating we have to maintain a map between our identifiers and the
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   367
Java bytecode indices
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   368
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   369
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   370
\bl{$\text{compile}(a, E)$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   371
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   372
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   373
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   374
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   375
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   376
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   377
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   378
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   379
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   380
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   381
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   382
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   383
$\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   384
$\text{compile}(a_1 + a_2, E)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   385
\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2. E)\;@\; \text{iadd}$}\smallskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   386
$\text{compile}(a_1 - a_2, E)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   387
\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{isub}$}\smallskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   388
$\text{compile}(a_1 * a_2, E)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   389
\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\; \text{compile}(a_2, E)\;@\; \text{imul}$}\bigskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   390
$\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   391
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   392
\end{center}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   393
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   394
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   395
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   396
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   397
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   398
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   399
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   400
\frametitle{\begin{tabular}{c}Compiling Statements\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   401
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   402
We return a list of instructions and an environment for the variables
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   403
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   404
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   405
\bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   406
$\text{compile}(\text{skip}, E)$ & $\dn$ & $(N\!il, E)$\bigskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   407
$\text{compile}(x := a, E)$ & $\dn$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   408
\multicolumn{3}{l}{$(\text{compile}(a, E) \;@\;\text{istore}\;index, E(x\mapsto index))$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   409
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   410
\end{center}\medskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   411
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   412
where \bl{$index$} is \bl{$E(x)$} if it is already defined, or if it is not then the largest index not yet seen
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   413
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   414
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   415
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   416
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   417
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   418
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   419
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   420
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   421
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   422
{\Large\bl{$x := x + 1$}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   423
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   424
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   425
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   426
iload $n_x$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   427
ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   428
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   429
istore $n_x$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   430
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   431
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   432
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   433
where \bl{$n_x$} is the index corresponding to the variable \bl{$x$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   434
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   435
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   436
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   437
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   438
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   439
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   440
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   441
\frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   442
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   443
{\Large\bl{$\text{if}\;b\;\text{then}\;cs_1\;\text{else}\;cs_2$}}\bigskip\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   444
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   445
\onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   446
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   447
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   448
\begin{tikzpicture}[node distance=2mm and 4mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   449
 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   450
 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   451
 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   452
\node (A1) [point] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   453
\node (b) [block, right=of A1] {code of \bl{$b$}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   454
\node (A2) [point, right=of b] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   455
\node (cs1) [block, right=of A2] {code of \bl{$cs_1$}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   456
\node (A3) [point, right=of cs1] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   457
\node (cs2) [block, right=of A3] {code of \bl{$cs_2$}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   458
\node (A4) [point, right=of cs2] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   459
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   460
\only<2>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   461
\draw (A1) edge [->, red, line width=1mm] (b);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   462
\draw (b) edge [->, red, line width=1mm] (cs1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   463
\draw (cs1) edge [->, red, line width=1mm] (A3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   464
\draw (A3) edge [->,skip loop] (A4);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   465
\node [below=of cs2] {\raisebox{-5mm}{\small{}jump}};}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   466
\only<3>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   467
\draw (A1) edge [->, red, line width=1mm] (b);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   468
\draw (b) edge [->, red, line width=1mm] (A2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   469
\draw (A2) edge [skip loop] (A3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   470
\draw (A3) edge [->, red, line width=1mm] (cs2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   471
\draw (cs2) edge [->,red, line width=1mm] (A4);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   472
\node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   473
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   474
\end{center}
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   475
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   476
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   477
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   478
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   479
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   480
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   481
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   482
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   483
\frametitle{\begin{tabular}{c}Conditional Jumps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   484
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   485
\begin{minipage}{1.1\textwidth}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   486
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   487
\item \bl{if\_icmpeq $label$} if two ints are equal, then jump\medskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   488
\item \bl{if\_icmpne $label$} if two ints aren't equal, then jump\medskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   489
\item \bl{if\_icmpge $label$} if one int is greater or equal then another, then jump
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   490
\item[]\ldots
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   491
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   492
\end{minipage}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   493
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   494
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   495
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   496
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   497
$L_1$:\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   498
\hspace{5mm}if\_icmpeq\;$L_2$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   499
\hspace{5mm}iload 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   500
\hspace{5mm}ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   501
\hspace{5mm}iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   502
\hspace{5mm}if\_icmpeq\;$L_1$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   503
$L_2$:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   504
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   505
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   506
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   507
\begin{textblock}{3.5}(11,12)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   508
\only<3>{labels must be unique}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   509
\end{textblock}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   510
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   511
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   512
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   513
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   514
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   515
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   516
\frametitle{\begin{tabular}{c}Compiling BExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   517
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   518
{\Large\bl{$a_1 = a_2$}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   519
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   520
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   521
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   522
$\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   523
\multicolumn{3}{l}{$\quad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{if\_icmpne}\;lab$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   524
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   525
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   526
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   527
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   528
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   529
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   530
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   531
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   532
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   533
\frametitle{\begin{tabular}{c}Compiling Ifs\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   534
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   535
{\Large\bl{if $b$ then $cs_1$ else $cs_2$}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   536
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   537
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   538
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   539
$\text{compile}(\text{if}\;b\;\text{then}\; cs_1\;\text{else}\; cs_2, E)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   540
\multicolumn{3}{l}{$\quad l_{ifelse}\;$ \textcolor{black}{(fresh label)}}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   541
\multicolumn{3}{l}{$\quad l_{ifend}\;$ \textcolor{black}{(fresh label)}}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   542
\multicolumn{3}{l}{$\quad (is_1, E') = \text{compile}(cs_1, E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   543
\multicolumn{3}{l}{$\quad (is_2, E'') = \text{compile}(cs_2, E')$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   544
\multicolumn{3}{l}{$\quad(\text{compile}(b, E, l_{ifelse})$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   545
\multicolumn{3}{l}{$\quad\phantom{(}@\;is_1$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   546
\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{ifend}$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   547
\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifelse}:$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   548
\multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   549
\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   550
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   551
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   552
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   553
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   554
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   555
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   556
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   557
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   558
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   559
\frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   560
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   561
{\Large\bl{$\text{while}\;b\;\text{do}\;cs$}}\bigskip\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   562
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   563
\onslide<2->{Case }\only<2>{{\bf True}:}\only<3>{{\bf False}:}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   564
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   565
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   566
\begin{tikzpicture}[node distance=2mm and 4mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   567
 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   568
 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   569
 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   570
\node (A0) [point, left=of A1] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   571
\node (A1) [point] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   572
\node (b) [block, right=of A1] {code of \bl{$b$}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   573
\node (A2) [point, right=of b] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   574
\node (cs1) [block, right=of A2] {code of \bl{$cs$}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   575
\node (A3) [point, right=of cs1] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   576
\node (A4) [point, right=of A3] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   577
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   578
\only<2>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   579
\draw (A0) edge [->, red, line width=1mm] (b);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   580
\draw (b) edge [->, red, line width=1mm] (cs1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   581
\draw (cs1) edge [->, red, line width=1mm] (A3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   582
\draw (A3) edge [->,skip loop] (A1);}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   583
\only<3>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   584
\draw (A0) edge [->, red, line width=1mm] (b);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   585
\draw (b) edge [->, red, line width=1mm] (A2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   586
\draw (A2) edge [skip loop] (A3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   587
\draw (A3) edge [->, red, line width=1mm] (A4);}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   588
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   589
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   590
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   591
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   592
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   593
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   594
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   595
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   596
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   597
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   598
\frametitle{\begin{tabular}{c}Compiling Whiles\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   599
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   600
{\Large\bl{while $b$ do $cs$}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   601
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   602
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   603
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   604
$\text{compile}(\text{while}\; b\; \text{do} \;cs, E)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   605
\multicolumn{3}{l}{$\quad l_{wbegin}\;$ \textcolor{black}{(fresh label)}}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   606
\multicolumn{3}{l}{$\quad l_{wend}\;$ \textcolor{black}{(fresh label)}}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   607
\multicolumn{3}{l}{$\quad (is, E') = \text{compile}(cs_1, E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   608
\multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   609
\multicolumn{3}{l}{$\quad\phantom{(}@\;\text{compile}(b, E, l_{wend})$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   610
\multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   611
\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   612
\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E')$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   613
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   614
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   615
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   616
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   617
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   618
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   619
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   620
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   621
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   622
\frametitle{\begin{tabular}{c}Compiling Writes\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   623
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   624
{\Large\bl{write $x$}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   625
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   626
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   627
\small\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   628
.method public static write(I)V\hspace{1cm}\textcolor{black}{(library function)}\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   629
\;\;    .limit locals 5 \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   630
\;\;    .limit stack 5 \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   631
\;\;    iload 0 \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   632
\;\;    getstatic java/lang/System/out Ljava/io/PrintStream;\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   633
\;\;    swap \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   634
\;\;    invokevirtual java/io/PrintStream/println(I)V \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   635
\;\;    return \\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   636
.end method\bigskip\bigskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   637
%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   638
\normalsize
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   639
iload $E(x)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   640
invokestatic write(I)V\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   641
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   642
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   643
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   644
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   645
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   646
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   647
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   648
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   649
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   650
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   651
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   652
\small\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   653
.class public XXX.XXX\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   654
.super java/lang/Object\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   655
\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   656
.method public <init>()V\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   657
\;\;     aload\_0\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   658
\;\;     invokenonvirtual java/lang/Object/<init>()V\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   659
 \;\;    return\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   660
.end method\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   661
\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   662
.method public static main([Ljava/lang/String;)V\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   663
\;\;   .limit locals 200\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   664
\;\;     .limit stack 200\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   665
\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   666
   \textcolor{black}{(here comes the compiled code)}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   667
\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   668
\;\;     return\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   669
.end method\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   670
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   671
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   672
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   673
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   674
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   675
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   676
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   677
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   678
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   679
\frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   680
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   681
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   682
\item assembly $\Rightarrow$ byte code (class file)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   683
\item labels $\Rightarrow$ absolute or relative jumps\bigskip\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   684
\item \texttt{javap} is a disassembler for class files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   685
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   686
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   687
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   688
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   689
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   690
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   691
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   692
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   693
\frametitle{\begin{tabular}{c}Compiled Code\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   694
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   695
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   696
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   697
\begin{axis}[axis x line=bottom, axis y line=left, xlabel=n, ylabel=secs, legend style=small]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   698
\addplot+[smooth] file {compiled.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   699
\end{axis}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   700
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   701
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   702
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   703
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   704
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   705
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   706
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   707
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   708
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   709
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   710
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   711
\frametitle{\begin{tabular}{c}Compiler vs.~Interpreter\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   712
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   713
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   714
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   715
\begin{axis}[axis x line=bottom, axis y line=left, ylabel=secs,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   716
    xlabel=n,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   717
    enlargelimits=0.05,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   718
    ybar interval=0.7, legend style=small]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   719
\addplot file {interpreted2.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   720
\addplot file {compiled2.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   721
%\legend{interpreted, compiled}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   722
\end{axis}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   723
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   724
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   725
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   726
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   727
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   728
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   729
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   730
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   731
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   732
\frametitle{Backend}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   733
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   734
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   735
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   736
\node (rexp)  {\bl{\bf Lexer}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   737
\node (nfa) [right=of rexp] {\bl{\bf Parser}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   738
\node (dfa) [right=of nfa] {\bl{\begin{tabular}{c}\bf Optimizations\end{tabular}}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   739
\path[->, red, line width=2mm] (rexp) edge node [above=4mm, black] {\begin{tabular}{c@{\hspace{9mm}}}token\\[-1mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   740
sequence\end{tabular}} (nfa);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   741
\node (final) [below=of dfa] {\bl{\begin{tabular}{c}\bf Machine Code/\\\bf Byte Code\end{tabular}}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   742
\path[->, red, line width=2mm] (nfa) edge node [above=4mm, black] {\begin{tabular}{c}parse\\[-1mm] tree
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   743
\end{tabular}}(dfa);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   744
\path[->, red, line width=2mm] (dfa) edge (final);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   745
\end{tikzpicture}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   746
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   747
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   748
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   749
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   750
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   751
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   752
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   753
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   754
\frametitle{\begin{tabular}{c}What Next\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   755
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   756
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   757
\item register spilling
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   758
\item dead code removal
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   759
\item loop optimisations
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   760
\item instruction selection
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   761
\item type checking
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   762
\item concurrency
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   763
\item fuzzy testing
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   764
\item verification\bigskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   765
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   766
\item GCC, LLVM, tracing JITs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   767
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   768
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   769
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   770
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   771
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   772
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   773
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   774
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   775
%%% Local Variables:  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   776
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   777
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   778
%%% End: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   779