slides/slides08.tex
author Christian Urban <urbanc@in.tum.de>
Mon, 01 Oct 2018 01:11:42 +0100
changeset 566 b153c04834eb
parent 535 095be64c03c1
child 598 e3ad67cd5123
permissions -rw-r--r--
updated
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}
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     2
\usepackage{../slides}
215
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 197
diff changeset
     3
\usepackage{../langs}
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 197
diff changeset
     4
\usepackage{../data}
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     5
\usepackage{../graphics}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     6
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
% beamer stuff 
459
780486571e38 updated
Christian Urban <urbanc@in.tum.de>
parents: 387
diff changeset
     8
\renewcommand{\slidecaption}{CFL 07, King's College London}
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    14
\begin{frame}[t]
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
\frametitle{%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    16
  \begin{tabular}{@ {}c@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
  \\[-3mm]
459
780486571e38 updated
Christian Urban <urbanc@in.tum.de>
parents: 387
diff changeset
    18
  \LARGE Compilers and \\[-2mm] 
532
Christian Urban <urbanc@in.tum.de>
parents: 500
diff changeset
    19
  \LARGE Formal Languages (7)\\[3mm] 
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    20
  \end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
  \normalsize
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
  \begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
  \begin{tabular}{ll}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
  Email:  & christian.urban at kcl.ac.uk\\
500
c502933be072 updated
Christian Urban <urbanc@in.tum.de>
parents: 459
diff changeset
    26
  Office: & N7.07 (North Wing, Bush House)\\
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  Slides: & KEATS (also home work is there)\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
  \end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    31
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    32
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    33
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    34
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    35
\begin{frame}[c]
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    36
\frametitle{Bird's Eye View}
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    37
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    38
\begin{center}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    39
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    40
\node (rexp)  {\bl{\bf Lexer}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    41
\node (nfa) [right=of rexp] {\bl{\bf Parser}};
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    42
\node (dfa) [right=of nfa] 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    43
 {\bl{\begin{tabular}{c}\bf Machine Code/\\\bf Java Byte Code\end{tabular}}};
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    44
\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
    45
sequence\end{tabular}} (nfa);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    46
\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
    47
\end{tikzpicture}\\
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    48
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    49
308
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    50
\end{frame}
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    51
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    52
 
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    53
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    54
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    55
\begin{textblock}{10}(0.5,0.5)
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    56
  \LARGE
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    57
  \fontspec{Hoefler Text Black}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    58
  \textcolor{ProcessBlue}{JVM\\ Code}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    59
\end{textblock}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    60
\fontsize{8}{10}\selectfont
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    61
%\footnotesize
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    62
\mbox{}\\[-8mm]\mbox{}
308
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    63
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    64
\begin{columns}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    65
\begin{column}{2cm} 
308
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    66
\lstinputlisting[numbers=none]{../progs/appHa.j}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    67
\end{column}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    68
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    69
\begin{column}{2cm} 
308
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    70
\lstinputlisting[numbers=none]{../progs/appHb.j}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    71
\end{column}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    72
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    73
\end{columns}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    74
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    75
\end{frame}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    76
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    77
 
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    78
 
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    79
 
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
    80
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    81
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    82
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    83
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    84
\begin{center}
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
    85
\bl{\begin{tabular}{@{}lcl@{}}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    86
\textit{Stmt} & $\rightarrow$ &  $\texttt{skip}$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    87
              & $|$ & \textit{Id}\;\texttt{:=}\;\textit{AExp}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    88
              & $|$ & \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
    89
              & $|$ & \texttt{while}\; \textit{BExp} \;\texttt{do}\; \textit{Block}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    90
              & $|$ & \texttt{read}\;\textit{Id}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    91
              & $|$ & \texttt{write}\;\textit{Id}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    92
              & $|$ & \texttt{write}\;\textit{String}\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    93
\textit{Stmts} & $\rightarrow$ &  \textit{Stmt} \;\texttt{;}\; \textit{Stmts}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    94
              & $|$ & \textit{Stmt}\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    95
\textit{Block} & $\rightarrow$ &  \texttt{\{}\,\textit{Stmts}\,\texttt{\}}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    96
                & $|$ & \textit{Stmt}\medskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    97
\textit{AExp} & $\rightarrow$ & \ldots\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    98
\textit{BExp} & $\rightarrow$ & \ldots\\
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    99
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   100
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   101
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   102
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   103
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   104
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   105
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   106
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   107
\begin{frame}[c]
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   108
\frametitle{\begin{tabular}{c}Fibonacci Numbers\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   109
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   110
\mbox{}\\[-18mm]\mbox{}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   111
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   112
{\lstset{language=While}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   113
\texttt{\lstinputlisting{../progs/fib.while}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   114
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   115
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   116
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   117
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   118
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   119
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   120
\frametitle{Interpreter}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   121
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   122
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   123
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   124
$\text{eval}(n, E)$ & $\dn$ & $n$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   125
$\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
   126
$\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
   127
$\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
   128
$\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
   129
$\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
   130
$\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
   131
$\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
   132
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   133
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   134
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   135
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   136
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   137
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   138
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   139
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   140
\frametitle{Interpreter (2)}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   141
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   142
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   143
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   144
$\text{eval}(\text{skip}, E)$ & $\dn$ & $E$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   145
$\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
   146
\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
   147
\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
   148
\text{eval}(cs_1,E)$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   149
\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
   150
\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
   151
\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
   152
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{then}\;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   153
\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
   154
\multicolumn{3}{@{}l@{}}{\hspace{2cm}$\text{else}\; E$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   155
$\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
   156
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   157
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   158
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   159
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   160
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   161
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{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   164
\frametitle{Test Program}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   165
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   166
\mbox{}\\[-18mm]\mbox{}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   167
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   168
{\lstset{language=While}\fontsize{10}{12}\selectfont
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   169
\texttt{\lstinputlisting{../progs/loops.while}}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   170
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   171
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   172
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   173
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   174
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
308
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   175
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   176
\fontsize{7}{9}\selectfont
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   177
308
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   178
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   179
\begin{columns}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   180
\begin{column}{7cm} 
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   181
\lstinputlisting[numbers=none]{../progs/appHa.j}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   182
\end{column}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   183
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   184
\begin{column}{7cm} 
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   185
\lstinputlisting[numbers=none]{../progs/appHb.j}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   186
\end{column}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   187
\end{columns}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   188
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   189
\end{frame}
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   190
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   191
 
3703ade9b17c updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 306
diff changeset
   192
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   193
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   194
\frametitle{Interpreted Code}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   195
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   196
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   197
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   198
\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
   199
\addplot+[smooth] file {interpreted.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   200
\end{axis}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   201
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   202
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   203
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   204
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   205
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   207
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   208
\begin{frame}[c]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   209
\frametitle{Java Virtual Machine}
196
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
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   212
\item introduced in 1995
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   213
\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
   214
\item contains a JIT compiler
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   215
\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
   216
\item is garbage collected $\Rightarrow$ no buffer overflows
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   217
\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
   218
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   219
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   220
\end{frame}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   221
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   222
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   223
\begin{frame}[t,fragile]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   224
\frametitle{Compiling AExps}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   225
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   226
For example \bl{$1 + ((2 * 3) + (4 - 3))$}:\medskip
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   227
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   228
\begin{columns}[T]
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   229
\begin{column}{.3\textwidth}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   230
\begin{center}
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   231
\bl{\begin{tikzpicture}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   232
\tikzset{level distance=12mm,sibling distance=4mm}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   233
\tikzset{edge from parent/.style={draw,very thick}}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   234
\Tree [.$+$ [.$1$ ] [.$+$ [.$*$ $2$ $3$ ] [.$-$ $4$ $3$ ]]]
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   235
\end{tikzpicture}}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   236
\end{center}
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   237
\end{column}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   238
\begin{column}{.3\textwidth}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   239
\begin{lstlisting}[language=JVMIS,numbers=none]
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   240
ldc 1 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   241
ldc 2 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   242
ldc 3 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   243
imul 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   244
ldc 4 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   245
ldc 3 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   246
isub 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   247
iadd 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   248
iadd
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   249
\end{lstlisting}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   250
\end{column}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   251
\end{columns}\bigskip
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   252
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   253
\small
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   254
Traverse tree in post-order \bl{$\Rightarrow$} code for 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   255
stack-machine
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   256
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   257
\end{frame}
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   258
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   259
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   260
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   261
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   262
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   263
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   264
{\Large\bl{1 + 2 + 3}}
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
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   267
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   268
ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   269
ldc 2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   270
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   271
ldc 3\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   272
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   273
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   274
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   275
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   276
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   277
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   278
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   279
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   280
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   281
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   282
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   283
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   284
{\Large\bl{1 + (2 + 3)}}
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   285
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   286
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   287
\bl{\begin{tabular}{l}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   288
ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   289
ldc 2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   290
ldc 3\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   291
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   292
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   293
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   294
\end{center}\bigskip\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   295
\vfill
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   296
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   297
\bl{dadd, fadd, ladd, \ldots}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   298
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   299
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   300
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   301
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   302
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
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   305
\frametitle{Compiling AExps}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   306
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   307
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   308
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   309
$\text{compile}(n)$ & $\dn$ & $\text{ldc}\;n$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   310
$\text{compile}(a_1 + a_2)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   311
\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
   312
$\text{compile}(a_1 - a_2)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   313
\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
   314
$\text{compile}(a_1 * a_2)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   315
\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
   316
\end{tabular}}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   317
\end{center}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   318
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   319
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   320
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   321
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   322
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   323
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   324
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   325
\frametitle{\begin{tabular}{c}Compiling AExps\end{tabular}}
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
{\Large\bl{1 + 2 * 3 + (4 - 3)}}
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
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   330
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   331
ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   332
ldc 2\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   333
ldc 3\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   334
imul\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   335
ldc 4\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   336
ldc 3\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   337
isub\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   338
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   339
iadd\\
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   340
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   341
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   342
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   343
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   344
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   345
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   346
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   347
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   348
\frametitle{Variables}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   349
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   350
{\Large\bl{$x := 5 + y * 2$}}\bigskip\pause   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   351
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   352
\begin{itemize}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   353
\item lookup: \bl{$\text{iload}\; index$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   354
\item store: \bl{$\text{istore}\; index$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   355
\end{itemize}\bigskip\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   356
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   357
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
   358
Java bytecode indices
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   359
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   360
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   361
\bl{$\text{compile}(a, E)$}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   362
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   363
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   364
\end{frame}
196
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   367
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   368
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   369
\frametitle{Compiling AExps}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   370
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   371
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   372
\bl{\begin{tabular}{@{}lcl@{}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   373
$\text{compile}(n, E)$ & $\dn$ & $\text{ldc}\;n$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   374
$\text{compile}(a_1 + a_2, E)$ & $\dn$\\ 
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   375
\multicolumn{3}{l}{$\qquad\text{compile}(a_1, E) \;@\;\text{compile}(a_2, E)\;@\; \text{iadd}$}\smallskip\\
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   376
$\text{compile}(a_1 - a_2, E)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   377
\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
   378
$\text{compile}(a_1 * a_2, E)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   379
\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
   380
$\text{compile}(x, E)$ & $\dn$ & $\text{iload}\;E(x)$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   381
\end{tabular}}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   382
\end{center}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   383
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   384
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   385
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   386
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   387
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   388
\begin{frame}[c, fragile]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   389
\frametitle{Mathematical Functions}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   390
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   391
Compilation of some mathematical functions:
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   392
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   393
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   394
\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   395
\texttt{Aop("+", a1, a2)} & $\Rightarrow$ & \texttt{...iadd}\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   396
\texttt{Aop("-", a1, a2)} & $\Rightarrow$ & \texttt{...isub}\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   397
\texttt{Aop("*", a1, a2)} & $\Rightarrow$ & \texttt{...imul}\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   398
\texttt{Aop("/", a1, a2)} & $\Rightarrow$ & \texttt{...idiv}\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   399
\texttt{Aop("\%", a1, a2)} & $\Rightarrow$ & \texttt{...irem}\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   400
\end{tabular}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   401
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   402
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   403
\end{frame}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   404
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   405
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   406
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   407
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   408
\frametitle{Compiling Statements}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   409
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   410
We return a list of instructions and an environment for the
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   411
variables
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   412
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   413
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   414
\bl{\begin{tabular}{@{}l@{\hspace{1mm}}c@{\hspace{1mm}}l@{}}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   415
$\text{compile}(\text{skip}, E)$ & $\dn$ & $(\textit{Nil}, E)$\bigskip\\
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   416
$\text{compile}(x := a, E)$ & $\dn$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   417
\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
   418
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   419
\end{center}\medskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   420
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   421
where \bl{$index$} is \bl{$E(x)$} if it is already defined, 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   422
or if it is not, then the largest index not yet seen
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   423
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   424
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   425
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   426
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   427
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   428
\begin{frame}[c]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   429
\frametitle{Compiling Assignments}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   430
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   431
{\Large\bl{$x := x + 1$}}
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
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   434
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   435
iload $n_x$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   436
ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   437
iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   438
istore $n_x$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   439
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   440
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   441
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   442
where \bl{$n_x$} is the index corresponding to the variable~\bl{$x$}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   443
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   444
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   445
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   446
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   447
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   448
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   449
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   450
\frametitle{Compiling Ifs}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   451
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   452
{\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
   453
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   454
\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
   455
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   456
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   457
\begin{tikzpicture}[node distance=2mm and 4mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   458
 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
   459
 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
   460
 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
   461
\node (A1) [point] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   462
\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
   463
\node (A2) [point, right=of b] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   464
\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
   465
\node (A3) [point, right=of cs1] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   466
\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
   467
\node (A4) [point, right=of cs2] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   468
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   469
\only<2>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   470
\draw (A1) edge [->, red, line width=1mm] (b);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   471
\draw (b) edge [->, red, line width=1mm] (cs1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   472
\draw (cs1) edge [->, red, line width=1mm] (A3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   473
\draw (A3) edge [->,skip loop] (A4);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   474
\node [below=of cs2] {\raisebox{-5mm}{\small{}jump}};}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   475
\only<3>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   476
\draw (A1) edge [->, red, line width=1mm] (b);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   477
\draw (b) edge [->, red, line width=1mm] (A2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   478
\draw (A2) edge [skip loop] (A3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   479
\draw (A3) edge [->, red, line width=1mm] (cs2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   480
\draw (cs2) edge [->,red, line width=1mm] (A4);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   481
\node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   482
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   483
\end{center}
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   484
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   485
\end{frame}
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   486
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
   487
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   488
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   489
\begin{frame}[t]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   490
\frametitle{Conditional Jumps}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   491
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   492
\begin{minipage}{1.1\textwidth}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   493
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   494
\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
   495
\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
   496
\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
   497
\item[]\ldots
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   498
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   499
\end{minipage}\pause
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   500
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   501
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   502
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   503
\bl{\begin{tabular}{l}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   504
$L_1$:\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   505
\hspace{5mm}if\_icmpeq\;$L_2$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   506
\hspace{5mm}iload 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   507
\hspace{5mm}ldc 1\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   508
\hspace{5mm}iadd\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   509
\hspace{5mm}if\_icmpeq\;$L_1$\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   510
$L_2$:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   511
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   512
\end{center}
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
\begin{textblock}{3.5}(11,12)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   515
\only<3>{labels must be unique}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   516
\end{textblock}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   517
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   518
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   521
\begin{frame}[c,fragile]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   522
\frametitle{Compiling Ifs}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   523
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   524
For example
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   525
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   526
\begin{lstlisting}[mathescape,numbers=none,language=While]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   527
if 1 = 1 then x := 2 else y := 3
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   528
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   529
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   530
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   531
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   532
\begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   533
   ldc 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   534
   ldc 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   535
   if_icmpne L_ifelse $\quad\tikz[remember picture] \node (C) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   536
   ldc 2
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   537
   istore 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   538
   goto L_ifend $\quad\tikz[remember picture] \node (A) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   539
L_ifelse: $\quad\tikz[remember picture] \node[] (D) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   540
   ldc 3
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   541
   istore 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   542
L_ifend: $\quad\tikz[remember picture] \node[] (B) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   543
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   544
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   545
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   546
\begin{tikzpicture}[remember picture,overlay]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   547
  \draw[->,very thick] (A) edge [->,to path={-- ++(10mm,0mm) 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   548
           -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (B.east);
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   549
  \draw[->,very thick] (C) edge [->,to path={-- ++(10mm,0mm) 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   550
           -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (D.east);
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   551
\end{tikzpicture}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   552
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   553
\end{frame}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   554
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   555
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   556
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   557
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   558
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   559
\frametitle{Compiling BExps}
196
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{$a_1 = a_2$}}
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
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   564
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   565
$\text{compile}(a_1 = a_2, E, lab)$ & $\dn$\\ 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   566
\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
   567
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   568
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   569
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   570
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   571
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   572
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   573
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   574
\begin{frame}[c, fragile]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   575
\frametitle{Boolean Expressions}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   576
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   577
Compilation of boolean expressions:
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   578
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   579
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   580
\begin{tikzpicture}[node distance=2mm and 4mm,
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   581
 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   582
 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   583
 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   584
\node (A1) [point] {};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   585
\node (b) [block, right=of A1] {code of \bl{$b$}};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   586
\node (A2) [point, right=of b] {};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   587
\node (cs1) [block, right=of A2] {code of \bl{$cs_1$}};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   588
\node (A3) [point, right=of cs1] {};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   589
\node (cs2) [block, right=of A3] {code of \bl{$cs_2$}};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   590
\node (A4) [point, right=of cs2] {};
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   591
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   592
\only<1>{
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   593
\draw (A1) edge [->, red, line width=1mm] (b);
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   594
\draw (b) edge [->, red, line width=1mm] (A2);
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   595
\draw (A2) edge [skip loop] (A3);
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   596
\draw (A3) edge [->, red, line width=1mm] (cs2);
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   597
\draw (cs2) edge [->,red, line width=1mm] (A4);
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   598
\node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   599
\end{tikzpicture}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   600
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   601
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   602
\begin{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   603
\begin{tabular}{lcl}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   604
\texttt{Bop("==", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpne...}\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   605
\texttt{Bop("!=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpeq...}\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   606
\texttt{Bop("<", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpge...}\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   607
\texttt{Bop("<=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpgt...}\\
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   608
\end{tabular}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   609
\end{center}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   610
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   611
\end{frame}
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   612
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   613
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   614
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   615
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   616
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   617
\frametitle{Compiling Ifs}
196
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
{\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
   620
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   621
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   622
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   623
$\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
   624
\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
   625
\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
   626
\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
   627
\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
   628
\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
   629
\multicolumn{3}{l}{$\quad\phantom{(}@\;is_1$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   630
\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{ifend}$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   631
\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifelse}:$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   632
\multicolumn{3}{l}{$\quad\phantom{(}@\;is_2$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   633
\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{ifend}:, E'')$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   634
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   635
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   636
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   637
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   638
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   639
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   640
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   641
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   642
\frametitle{Compiling Whiles}
196
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
{\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
   645
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   646
\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
   647
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   648
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   649
\begin{tikzpicture}[node distance=2mm and 4mm,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   650
 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
   651
 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
   652
 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
   653
\node (A0) [point, left=of A1] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   654
\node (A1) [point] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   655
\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
   656
\node (A2) [point, right=of b] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   657
\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
   658
\node (A3) [point, right=of cs1] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   659
\node (A4) [point, right=of A3] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   660
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   661
\only<2>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   662
\draw (A0) edge [->, red, line width=1mm] (b);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   663
\draw (b) edge [->, red, line width=1mm] (cs1);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   664
\draw (cs1) edge [->, red, line width=1mm] (A3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   665
\draw (A3) edge [->,skip loop] (A1);}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   666
\only<3>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   667
\draw (A0) edge [->, red, line width=1mm] (b);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   668
\draw (b) edge [->, red, line width=1mm] (A2);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   669
\draw (A2) edge [skip loop] (A3);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   670
\draw (A3) edge [->, red, line width=1mm] (A4);}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   671
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   672
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   673
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   674
\end{frame}
196
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   678
\begin{frame}[t]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   679
\frametitle{Compiling Whiles}
196
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
{\Large\bl{while $b$ do $cs$}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   682
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   683
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   684
\bl{\begin{tabular}{lcl}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   685
$\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
   686
\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
   687
\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
   688
\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
   689
\multicolumn{3}{l}{$\quad(l_{wbegin}:$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   690
\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
   691
\multicolumn{3}{l}{$\quad\phantom{(}@\;is$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   692
\multicolumn{3}{l}{$\quad\phantom{(}@\; \text{goto}\;l_{wbegin}$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   693
\multicolumn{3}{l}{$\quad\phantom{(}@\;l_{wend}:, E')$}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   694
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   695
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   696
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   697
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   698
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   699
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   700
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   701
\begin{frame}[c,fragile]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   702
\frametitle{Compiling Whiles}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   703
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   704
For example
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   705
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   706
\begin{lstlisting}[mathescape,numbers=none,language=While]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   707
while x <= 10 do x := x + 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   708
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   709
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   710
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   711
\begin{center}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   712
\begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   713
L_wbegin: $\quad\tikz[remember picture] \node[] (LB) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   714
   iload 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   715
   ldc 10
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   716
   if_icmpgt L_wend $\quad\tikz[remember picture] \node (LC) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   717
   iload 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   718
   ldc 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   719
   iadd
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   720
   istore 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   721
   goto L_wbegin $\quad\tikz[remember picture] \node (LA) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   722
L_wend: $\quad\tikz[remember picture] \node[] (LD) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   723
\end{lstlisting}
196
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
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   726
\begin{tikzpicture}[remember picture,overlay]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   727
  \draw[->,very thick] (LA) edge [->,to path={-- ++(12mm,0mm) 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   728
           -- ++(0mm,17.3mm) |- (\tikztotarget)},line width=1mm] (LB.east);
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   729
  \draw[->,very thick] (LC) edge [->,to path={-- ++(12mm,0mm) 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   730
           -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (LD.east);
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   731
\end{tikzpicture}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   732
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   733
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   734
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   735
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   736
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   737
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   738
\begin{frame}[c,fragile]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   739
\frametitle{Compiling Writes}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   740
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   741
\small
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   742
\begin{lstlisting}[language=JVMIS,mathescape,
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   743
                   numbers=none,xleftmargin=-6mm]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   744
.method public static write(I)V 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   745
  .limit locals 1 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   746
  .limit stack 2 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   747
  getstatic java/lang/System/out 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   748
                            Ljava/io/PrintStream; 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   749
  iload 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   750
  invokevirtual java/io/PrintStream/println(I)V 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   751
  return 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   752
.end method
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   753
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   754
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   755
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   756
iload $E(x)$ 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   757
invokestatic XXX/XXX/write(I)V
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   758
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   759
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   760
\end{frame}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   761
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   762
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   763
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   764
\begin{frame}[c,fragile]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   765
\frametitle{Compiling Main}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   766
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   767
\footnotesize
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   768
\begin{lstlisting}[language=JVMIS,mathescape,
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   769
                   numbers=none,xleftmargin=-6mm]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   770
.class public XXX.XXX
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   771
.super java/lang/Object
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   772
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   773
.method public <init>()V
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   774
    aload_0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   775
    invokenonvirtual java/lang/Object/<init>()V
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   776
    return
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   777
.end method
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   778
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   779
.method public static main([Ljava/lang/String;)V
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   780
    .limit locals 200
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   781
    .limit stack 200
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   782
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   783
      $\textit{\ldots{}here comes the compiled code\ldots}$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   784
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   785
    return
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   786
.end method
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   787
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   788
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   789
\end{frame}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   790
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   791
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   792
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   793
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   794
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   795
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   796
\frametitle{\begin{tabular}{c}Next Compiler Phases\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   797
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   798
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   799
\item assembly $\Rightarrow$ byte code (class file)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   800
\item labels $\Rightarrow$ absolute or relative jumps\bigskip\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   801
\item \texttt{javap} is a disassembler for class files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   802
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   803
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   804
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   805
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   806
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   807
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   808
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   809
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   810
\frametitle{\begin{tabular}{c}Compiled Code\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   811
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   812
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   813
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   814
\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
   815
\addplot+[smooth] file {compiled.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   816
\end{axis}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   817
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   818
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   819
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   820
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   821
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   822
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   823
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   824
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   825
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   826
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   827
\begin{frame}[t]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   828
\frametitle{\begin{tabular}{c}Compiler vs.~Interpreter\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   829
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   830
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   831
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   832
\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
   833
    xlabel=n,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   834
    enlargelimits=0.05,
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   835
    ybar interval=0.7, legend style=small]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   836
\addplot file {interpreted2.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   837
\addplot file {compiled2.data};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   838
%\legend{interpreted, compiled}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   839
\end{axis}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   840
\end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   841
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   842
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   843
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   844
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   845
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   846
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   847
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   848
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   849
\frametitle{Backend}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   850
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   851
\begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   852
\begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   853
\node (rexp)  {\bl{\bf Lexer}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   854
\node (nfa) [right=of rexp] {\bl{\bf Parser}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   855
\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
   856
\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
   857
sequence\end{tabular}} (nfa);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   858
\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
   859
\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
   860
\end{tabular}}(dfa);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   861
\path[->, red, line width=2mm] (dfa) edge (final);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   862
\end{tikzpicture}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   863
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   864
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   865
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   866
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   867
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   868
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   869
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   870
\begin{frame}[t]
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   871
\frametitle{\begin{tabular}{c}What is Next\end{tabular}}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   872
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   873
\begin{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   874
\item register spilling
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   875
\item dead code removal
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   876
\item loop optimisations
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   877
\item instruction selection
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   878
\item type checking
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   879
\item concurrency
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   880
\item fuzzy testing
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   881
\item verification\bigskip\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   882
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   883
\item GCC, LLVM, tracing JITs
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   884
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   885
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   886
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   887
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   888
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   889
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   890
\begin{frame}[c]
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   891
  \frametitle{Coursework: MkEps}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   892
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   893
\begin{center}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   894
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   895
  \bl{$mkeps([c_1 c_2 \ldots c_n])$}  & \bl{$\dn$} & $\bl{undefined}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   896
  \bl{$mkeps(r^*)$}                   & \bl{$\dn$} & $\bl{Stars\,[]}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   897
  \bl{$mkeps(r^{\{n\}})$}              & \bl{$\dn$} & $\bl{Stars\,(mkeps(r))^n}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   898
  \bl{$mkeps(r^{\{n..\}})$}            & \bl{$\dn$} & $\bl{Stars\,(mkeps(r))^n}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   899
  \bl{$mkeps(r^{\{..n\}})$}            & \bl{$\dn$} & $\bl{Stars\,[]}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   900
  \bl{$mkeps(r^{\{n..m\}})$}           & \bl{$\dn$} & $\bl{Stars\,(mkeps(r))^n}$\medskip\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   901
  
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   902
  \bl{$mkeps(r^+)$}                   & \bl{$\dn$} & \bl{$mkeps(r^{\{1..\}})$}\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   903
  \bl{$mkeps(r^?)$}                   & \bl{$\dn$} & \bl{$mkeps(r^{\{..1\}})$}\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   904
\end{tabular}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   905
\end{center}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   906
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   907
\end{frame}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   908
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   909
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   910
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   911
\begin{frame}[c]
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   912
  \frametitle{Coursework: Inj}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   913
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   914
\begin{center}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   915
\begin{tabular}{@ {}l@ {\hspace{2mm}}c@ {\hspace{2mm}}l@ {}}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   916
  \bl{$inj([c_1 c_2 \ldots c_n])\,c\,Empty$}  & \bl{$\dn$} & $\bl{Chr\,c}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   917
  \bl{$inj(r^*)\,c\;Seq\,v\,(Stars\,vs)$}                   & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   918
  \bl{$inj(r^{\{n\}})\,c\;Seq\,v\,(Stars\,vs)$}              & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   919
  \bl{$inj(r^{\{n..\}})\,c\;Seq\,v\,(Stars\,vs)$}            & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   920
  \bl{$inj(r^{\{..n\}})\,c\;Seq\,v\,(Stars\,vs)$}            & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   921
  \bl{$inj(r^{\{n..m\}})\,c\;Seq\,v\,(Stars\,vs)$}           & \bl{$\dn$} & $\bl{Stars\,(inj\,r\,c\,v::vs)}$\medskip\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   922
  
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   923
  \bl{$inj(r^+)\,c\,v$}                   & \bl{$\dn$} & \bl{$inj(r^{\{1..\}})\,c\,v$}\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   924
  \bl{$inj(r^?)\,c\,v$}                   & \bl{$\dn$} & \bl{$inj(r^{\{..1\}})\,c\,v$}\\
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   925
\end{tabular}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   926
\end{center}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   927
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   928
\end{frame}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   929
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   930
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   931
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   932
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   933
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   934
%%% Local Variables:  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   935
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   936
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   937
%%% End: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   938