slides/slides09.tex
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 18 Nov 2015 01:53:01 +0000
changeset 380 1e88390e81aa
parent 379 fa2589ec0fae
child 381 47eceea734c5
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}
309
640e4a05cd9b 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: 207
diff changeset
     3
\usepackage{../langs}
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 207
diff changeset
     4
\usepackage{../data}
309
640e4a05cd9b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     5
\usepackage{../graphics}
379
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
     6
\usepackage{../grammar}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
     7
\usepackage{soul}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
     8
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
     9
\tikzset{onslide/.code args={<#1>#2}{%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    10
  \only<#1>{\pgfkeysalso{#2}} % \pgfkeysalso doesn't change the path
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    11
}}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    12
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    13
\makeatletter
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    14
\newenvironment<>{btHighlight}[1][]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    15
{\begin{onlyenv}#2\begingroup\tikzset{bt@Highlight@par/.style={#1}}\begin{lrbox}{\@tempboxa}}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    16
{\end{lrbox}\bt@HL@box[bt@Highlight@par]{\@tempboxa}\endgroup\end{onlyenv}}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    17
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    18
\newcommand<>\btHL[1][]{%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    19
  \only#2{\begin{btHighlight}[#1]\bgroup\aftergroup\bt@HL@endenv}%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    20
}
379
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    21
\def\bt@HL@endenv{%b jm 
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    22
  \end{btHighlight}%   
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    23
  \egroup
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    24
}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    25
\newcommand{\bt@HL@box}[2][]{%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    26
  \tikz[#1]{%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    27
    \pgfpathrectangle{\pgfpoint{1pt}{0pt}}{\pgfpoint{\wd #2}{\ht #2}}%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    28
    \pgfusepath{use as bounding box}%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    29
    \node[anchor=base west, fill=orange!30,outer sep=0pt,inner xsep=1pt, inner ysep=0pt, rounded corners=3pt, minimum height=\ht\strutbox+1pt,#1]{\raisebox{1pt}{\strut}\strut\usebox{#2}};
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    30
  }%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    31
}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    32
\makeatother
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    33
379
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    34
\lstset{morekeywords={def,if,then,else,write,read},keywordstyle=\color{codepurple}\bfseries}
77
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
    35
312
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 310
diff changeset
    36
% beamer stuff
309
640e4a05cd9b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    37
\renewcommand{\slidecaption}{AFL 09, King's College London}
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    40
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309
640e4a05cd9b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    44
\begin{frame}[t]
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
\frametitle{%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
  \begin{tabular}{@ {}c@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
  \\[-3mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
  \LARGE Automata and \\[-2mm] 
76
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 70
diff changeset
    49
  \LARGE Formal Languages (9)\\[3mm] 
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
  \end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
  \normalsize
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
  \begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
  \begin{tabular}{ll}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
  Email:  & christian.urban at kcl.ac.uk\\
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
    56
  Office: & S1.27 (1st floor Strand Building)\\
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
  Slides: & KEATS (also home work is there)\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
  \end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
309
640e4a05cd9b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    61
\end{frame}
77
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 76
diff changeset
    62
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    65
\begin{frame}[c,fragile]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    66
\frametitle{Functional Programming}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    67
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    68
\footnotesize
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    69
\begin{textblock}{13}(0.9,3)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    70
\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    71
def fib(n) = if n == 0 then 0 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    72
             else if n == 1 then 1 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    73
             else fib(n - 1) + fib(n - 2);
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    74
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    75
def fact(n) = if n == 0 then 1 else n * fact(n - 1);
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    76
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    77
def ack(m, n) = if m == 0 then n + 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    78
                else if n == 0 then ack(m - 1, 1)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    79
                else ack(m - 1, ack(m, n - 1));
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    80
                
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    81
def gcd(a, b) = if b == 0 then a else gcd(b, a % b);                
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    82
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    83
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    84
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    85
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    86
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    87
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    88
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
    89
\begin{frame}[c]
379
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    90
\frametitle{Fun Grammar}
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    91
\bl{
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    92
\begin{plstx}[rhs style=]
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    93
: \meta{Exp} ::= \meta{Var} | \meta{Num}{\hspace{3cm}}
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
    94
             |   \meta{Exp} + \meta{Exp} | ... | (\meta{Exp})
379
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    95
             |   \code{if} \meta{BExp} \code{then} \meta{Exp} \code{else} \meta{Exp}
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    96
             |   \code{write} \meta{Exp} {\hspace{3cm}}
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    97
             |   \meta{Exp} ; \meta{Exp}
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
    98
             |   \textit{FunName} (\meta{Exp}, ... , \meta{Exp})\\
379
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
    99
: \meta{BExp} ::= ...\\
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
   100
: \meta{Decl} ::= \meta{Def} ; \meta{Decl}
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
   101
             | \meta{Exp}\\
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   102
: \meta{Def} ::= \code{def} \textit{FunName} ($\hspace{0.4mm}x_1$, ... , $x_n$) = \meta{Exp}\\               
379
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
   103
\end{plstx}}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   104
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   105
379
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
   106
fa2589ec0fae updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 312
diff changeset
   107
\end{frame}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   108
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   109
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   110
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   111
\begin{frame}[c, fragile]
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   112
\frametitle{Abstract Syntax Trees}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   113
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   114
\footnotesize
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   115
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   116
abstract class Exp
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   117
abstract class BExp 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   118
abstract class Decl
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   119
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   120
case class 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   121
  Def(name: String, args: List[String], body: Exp) 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   122
                                          extends Decl
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   123
case class Main(e: Exp) extends Decl
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   124
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   125
case class Call(name: String, args: List[Exp]) extends Exp
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   126
case class If(a: BExp, e1: Exp, e2: Exp) extends Exp
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   127
case class Write(e: Exp) extends Exp
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   128
case class Var(s: String) extends Exp
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   129
case class Num(i: Int) extends Exp
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   130
case class Aop(o: String, a1: Exp, a2: Exp) extends Exp
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   131
case class Sequ(e1: Exp, e2: Exp) extends Exp
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   132
case class Bop(o: String, a1: Exp, a2: Exp) extends BExp
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   133
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   134
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   135
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   136
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   137
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   138
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   139
\begin{frame}[c]
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   140
\frametitle{Arithmetic Functions}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   141
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   142
Compilation of some aritmetic functions:
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   143
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   144
\begin{center}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   145
\begin{tabular}{lcl}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   146
\texttt{Aop("+", a1, a2)} & $\Rightarrow$ & \texttt{...iadd}\\
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   147
\texttt{Aop("-", a1, a2)} & $\Rightarrow$ & \texttt{...isub}\\
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   148
\texttt{Aop("*", a1, a2)} & $\Rightarrow$ & \texttt{...imul}\\
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   149
\texttt{Aop("/", a1, a2)} & $\Rightarrow$ & \texttt{...idiv}\\
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   150
\texttt{Aop("\%", a1, a2)} & $\Rightarrow$ & \texttt{...irem}\\
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   151
\end{tabular}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   152
\end{center}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   153
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   154
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   155
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   156
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   157
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   158
\begin{frame}[c]
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   159
\frametitle{Boolean Expressions}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   160
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   161
Compilation of Boolean expressions:
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   162
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   163
\begin{center}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   164
\begin{tikzpicture}[node distance=2mm and 4mm,
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   165
 block/.style={rectangle, minimum size=1cm, draw=black, line width=1mm},
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   166
 point/.style={rectangle, inner sep=0mm, minimum size=0mm, fill=red},
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   167
 skip loop/.style={red, line width=1mm, to path={-- ++(0,-10mm) -| (\tikztotarget)}}]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   168
\node (A1) [point] {};
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   169
\node (b) [block, right=of A1] {code of \bl{$b$}};
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   170
\node (A2) [point, right=of b] {};
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   171
\node (cs1) [block, right=of A2] {code of \bl{$cs_1$}};
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   172
\node (A3) [point, right=of cs1] {};
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   173
\node (cs2) [block, right=of A3] {code of \bl{$cs_2$}};
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   174
\node (A4) [point, right=of cs2] {};
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   175
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   176
\only<1>{
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   177
\draw (A1) edge [->, red, line width=1mm] (b);
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   178
\draw (b) edge [->, red, line width=1mm] (A2);
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   179
\draw (A2) edge [skip loop] (A3);
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   180
\draw (A3) edge [->, red, line width=1mm] (cs2);
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   181
\draw (cs2) edge [->,red, line width=1mm] (A4);
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   182
\node [below=of cs1] {\raisebox{-5mm}{\small{}conditional jump}};}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   183
\end{tikzpicture}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   184
\end{center}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   185
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   186
\begin{center}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   187
\begin{tabular}{lcl}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   188
\texttt{Bop("==", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpne...}\\
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   189
\texttt{Bop("!=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpeq...}\\
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   190
\texttt{Bop("<", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpge...}\\
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   191
\texttt{Bop("<=", a1, a2)} & $\Rightarrow$ & \texttt{...if\_icmpgt...}\\
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   192
\end{tabular}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   193
\end{center}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   194
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   195
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   196
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   197
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   198
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   199
\begin{frame}[c, fragile]
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   200
\frametitle{Sequences}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   201
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   202
Compiling \texttt{arg1 ; arg2}:\bigskip
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   203
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   204
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   205
\begin{lstlisting}[language=JVMIS, numbers=none]
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   206
...arg1...
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   207
pop
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   208
...arg1...
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   209
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   210
  
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   211
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   212
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   213
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   214
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   215
\begin{frame}[c, fragile]
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   216
\frametitle{Write}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   217
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   218
Compiling call to \texttt{write(arg)}:\bigskip
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   219
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   220
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   221
\begin{lstlisting}[language=JVMIS, numbers=none]
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   222
...arg...
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   223
dup
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   224
invokestatic XXX/XXX/write(I)V
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   225
\end{lstlisting}\bigskip
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   226
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   227
\small
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   228
needs a helper function
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   229
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   230
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   231
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   232
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   233
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   234
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   235
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   236
\begin{frame}[c, fragile]
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   237
\frametitle{Function Definitions}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   238
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   239
\footnotesize
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   240
\begin{lstlisting}[language=JVMIS, 
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   241
                   xleftmargin=2mm, 
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   242
                   numbers=none]
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   243
.method public static write(I)V 
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   244
   .limit locals 1
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   245
   .limit stack 2
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   246
   getstatic java/lang/System/out Ljava/io/PrintStream; 
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   247
   iload 0 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   248
   invokevirtual java/io/PrintStream/println(I)V 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   249
   return 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   250
.end method
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   251
\end{lstlisting}\bigskip
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   252
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   253
\small We will need for definitions\footnotesize\medskip
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   254
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   255
\begin{lstlisting}[language=JVMIS, 
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   256
                   xleftmargin=2mm, 
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   257
                   numbers=none]
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   258
.method public static f (I...I)I
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   259
  .limit locals ??
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   260
  .limit stack ?? 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   261
  ??
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   262
.end method
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   263
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   264
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   265
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   266
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   267
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   268
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   269
\begin{frame}[c, fragile]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   270
\frametitle{Stack Estimation}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   271
\footnotesize
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   272
\begin{center}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   273
\begin{lstlisting}[language=Scala,basicstyle=\ttfamily, numbers=none]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   274
def max_stack_exp(e: Exp): Int = e match {
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   275
  case Call(_, args) => args.map(max_stack_exp).sum
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   276
  case If(a, e1, e2) => max_stack_bexp(a) + 
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   277
    (List(max_stack_exp(e1), max_stack_exp(e1)).max)
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   278
  case Write(e) => max_stack_exp(e) + 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   279
  case Var(_) => 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   280
  case Num(_) => 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   281
  case Aop(_, a1, a2) => 
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   282
    max_stack_exp(a1) + max_stack_exp(a2)
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   283
  case Sequ(e1, e2) => 
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   284
    List(max_stack_exp(e1), max_stack_exp(e2)).max
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   285
}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   286
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   287
def max_stack_bexp(e: BExp): Int = e match {
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   288
  case Bop(_, a1, a2) => 
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   289
    max_stack_exp(a1) + max_stack_exp(a2)
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   290
}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   291
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   292
\end{center}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   293
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   294
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   295
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   296
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   297
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   298
\begin{frame}[fragile]
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   299
\frametitle{Successor Function}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   300
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   301
\begin{textblock}{7}(1,2.5)\footnotesize
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   302
\begin{minipage}{6cm}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   303
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   304
.method public static suc(I)I 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   305
.limit locals 1
312
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 310
diff changeset
   306
.limit stack 3
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   307
  iload 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   308
  ldc 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   309
  iadd
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   310
  ireturn
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   311
.end method 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   312
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   313
\end{minipage}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   314
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   315
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   316
\begin{textblock}{7}(6,8)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   317
\begin{bubble}[5cm]\small
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   318
\begin{lstlisting}[language=Lisp,
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   319
                   basicstyle=\ttfamily, 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   320
                   numbers=none,
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   321
                   xleftmargin=1mm]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   322
def suc(x) = x + 1;
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   323
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   324
\end{bubble}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   325
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   326
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   327
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   328
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   329
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   330
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   331
\begin{frame}[fragile]
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   332
\frametitle{Addition Function}
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   333
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   334
\begin{textblock}{7}(1,1.9)\footnotesize
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   335
\begin{minipage}{6cm}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   336
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   337
.method public static add(II)I 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   338
.limit locals 2
312
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 310
diff changeset
   339
.limit stack 6
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   340
  iload 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   341
  ldc 0
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   342
  if_icmpne If_else
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   343
  iload 1
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   344
  goto If_end
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   345
If_else:
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   346
  iload 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   347
  ldc 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   348
  isub
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   349
  iload 1
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   350
  invokestatic XXX/XXX/add(II)I
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   351
  invokestatic XXX/XXX/suc(I)I
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   352
If_end:
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   353
  ireturn
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   354
.end method
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   355
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   356
\end{minipage}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   357
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   358
380
1e88390e81aa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 379
diff changeset
   359
\begin{textblock}{7}(6,6.6)
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   360
\begin{bubble}[7cm]\small
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   361
\begin{lstlisting}[language=Lisp,
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   362
                   basicstyle=\ttfamily, 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   363
                   numbers=none,
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   364
                   xleftmargin=1mm]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   365
def add(x, y) = 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   366
    if x == 0 then y 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   367
    else suc(add(x - 1, y));
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   368
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   369
\end{bubble}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   370
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   371
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   372
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   373
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   374
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   375
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   376
\begin{frame}[fragile]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   377
\frametitle{Factorial}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   378
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   379
\begin{textblock}{7}(1,1.5)\footnotesize
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   380
\begin{minipage}{6cm}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   381
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   382
.method public static facT(II)I 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   383
.limit locals 2
312
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 310
diff changeset
   384
.limit stack 6
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   385
  iload 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   386
  ldc 0	
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   387
  if_icmpne If_else_2
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   388
  iload 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   389
  goto If_end_3
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   390
If_else_2:
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   391
  iload 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   392
  ldc 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   393
  isub
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   394
  iload 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   395
  iload 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   396
  imul
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   397
  invokestatic fact/fact/facT(II)I
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   398
If_end_3:
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   399
  ireturn
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   400
.end method 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   401
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   402
\end{minipage}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   403
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   404
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   405
\begin{textblock}{7}(6,7)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   406
\begin{bubble}[7cm]\small
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   407
\begin{lstlisting}[language=Lisp,
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   408
                   basicstyle=\ttfamily, 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   409
                   numbers=none,
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   410
                   xleftmargin=1mm]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   411
def facT(n, acc) = 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   412
  if n == 0 then acc 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   413
  else facT(n - 1, n * acc);
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   414
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   415
\end{bubble}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   416
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   417
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   418
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   419
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   420
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   421
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   422
\begin{frame}[fragile]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   423
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   424
\begin{textblock}{7}(1,-0.2)\footnotesize
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   425
\begin{minipage}{6cm}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   426
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none, escapeinside={(*@}{@*)}]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   427
.method public static facT(II)I 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   428
.limit locals 2
312
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 310
diff changeset
   429
.limit stack 7
310
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   430
(*@\hl{facT\_Start:} @*)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   431
  iload 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   432
  ldc 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   433
  if_icmpne If_else_2
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   434
  iload 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   435
  goto If_end_3
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   436
If_else_2:
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   437
  iload 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   438
  ldc 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   439
  isub
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   440
  iload 0
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   441
  iload 1
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   442
  imul
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   443
  (*@\hl{istore 1} @*)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   444
  (*@\hl{istore 0} @*)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   445
  (*@\hl{goto facT\_Start} @*)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   446
If_end_3:
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   447
  ireturn
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   448
.end method 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   449
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   450
\end{minipage}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   451
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   452
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   453
\begin{textblock}{7}(6,7)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   454
\begin{bubble}[7cm]\small
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   455
\begin{lstlisting}[language=Lisp,
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   456
                   basicstyle=\ttfamily, 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   457
                   numbers=none,
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   458
                   xleftmargin=1mm]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   459
def facT(n, acc) = 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   460
  if n == 0 then acc 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   461
  else facT(n - 1, n * acc);
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   462
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   463
\end{bubble}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   464
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   465
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   466
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   467
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   468
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   469
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   470
\begin{frame}[c, fragile]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   471
\frametitle{Tail Recursion}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   472
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   473
A call to \texttt{f(args)} is usually compiled as\medskip
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   474
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   475
{\small\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   476
  args onto stack
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   477
  invokestatic  .../f 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   478
\end{lstlisting}}\pause
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   479
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   480
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   481
A call is in tail position provided:\medskip
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   482
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   483
{\small\begin{itemize}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   484
\item \texttt{if Bexp then \hl{Exp} else \hl{Exp}}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   485
\item \texttt{Exp ; \hl{Exp}}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   486
\item \texttt{Exp  op Exp}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   487
\end{itemize}}\medskip
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   488
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   489
then a call \texttt{f(args)} can be compiled as\medskip\small
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   490
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   491
\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   492
  prepare environment
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   493
  jump to start of function
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   494
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   495
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   496
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   497
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   498
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   499
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   500
\begin{frame}[c, fragile]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   501
\frametitle{Tail Recursive Call}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   502
\footnotesize
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   503
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   504
\begin{textblock}{13}(-0.3,2)
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   505
\begin{lstlisting}[language=Scala,basicstyle=\ttfamily, numbers=none]
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   506
def compile_expT(a: Exp, env: Mem, name: String): Instrs = 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   507
  ...
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   508
  case Call(n, args) => if (name == n) 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   509
  { 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   510
    val stores = args.zipWithIndex.map 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   511
       { case (x, y) => "istore " + y.toString + "\n" } 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   512
    args.flatMap(a => compile_expT(a, env, "")) ++
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   513
    stores.reverse ++ 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   514
    List ("goto " + n + "_Start\n") 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   515
  } 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   516
  else 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   517
  {
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   518
    val is = "I" * args.length
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   519
    args.flatMap(a => compile_expT(a, env, "")) ++
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   520
    List ("invokestatic XXX/XXX/" + n + "(" + is + ")I\n")
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   521
  }
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   522
\end{lstlisting}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   523
\end{textblock}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   524
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   525
\end{frame}
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   526
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   527
d384fe01d0e8 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 309
diff changeset
   528
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   529
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   530
\begin{frame}[c]
80
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   531
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   532
\large\bf
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   533
Using a compiler, \\how can you mount the\\ perfect attack against a system?
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   534
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   535
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   536
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   537
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   538
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   539
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   540
\begin{frame}[c]
80
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   541
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   542
{\large\bf
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   543
What is a \alert{perfect} attack?}\bigskip
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   544
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   545
\begin{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   546
\item you can potentially completely take over a target system
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   547
\item your attack is (nearly) undetectable
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   548
\item the victim has (almost) no chance to recover
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   549
\end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   550
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   551
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   552
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
80
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   553
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   554
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   555
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   556
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   557
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   558
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   559
  \begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   560
  \begin{tikzpicture}[scale=1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   561
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   562
  \onslide<1->{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   563
  \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=17mm] {};
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   564
  \node [below right] at (A.north west) {\footnotesize\begin{tabular}{@{}l@{}}
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   565
  \only<1,2>{clean}\only<3->{\alert{hacked}}\\compiler\end{tabular}};}
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   566
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   567
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   568
  \onslide<2->{
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   569
  \node (B) at (-2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   570
  \node [below right] at (B.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(src)\end{tabular}};
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   571
  
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   572
  \node (C) at (2,2)  [draw=black, rectangle, very thick, minimum height=10mm, minimum width=12mm] {};
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   573
  \node [below right] at (C.north west) {\footnotesize\begin{tabular}{@{}l@{}}login\\(bin)\end{tabular}};
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   574
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   575
  \draw[->, line width=2mm] (B) -- (C);
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   576
  }
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   577
  
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   578
 \onslide<3->{\node [above left=-1.5mm] at (C.south east) {\footnotesize \alert{$\blacksquare$}};}
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   579
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   580
  \end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   581
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   582
80
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   583
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   584
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 79
diff changeset
   585
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   586
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   587
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   588
\mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   589
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   590
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   591
  \begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   592
  \begin{tikzpicture}[scale=1]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   593
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   594
  \onslide<1->{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   595
  \node (A) at (0,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   596
  \node [below right] at (A.north west) {\small V0.01};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   597
  \node [below right] (A1) at (A.south west) {\small Scala};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   598
  \node [below right] (A1) at (A1.south west) {\small\textcolor{gray}{host language}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   599
  \node [above right] at (A.north west) {my compiler (src)};}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   600
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   601
  \onslide<2->{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   602
  \node (B) at (1.8,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   603
  \node [below right] at (B.north west) {\small V0.02};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   604
  \node [below right] at (B.south west) {\small Scala};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   605
  \node at (3,0) {\ldots};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   606
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   607
  \node (C) at (5,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   608
  \node [below right] at (C.north west) {\small V1.00};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   609
  \node [below right] at (C.south west) {\small Scala};}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   610
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   611
  \onslide<3->{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   612
  \node (D) at (6.8,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   613
  \node [below right] at (D.north west) {\small V1.00};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   614
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   615
  \node (E) at (6.8,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   616
  \node [below right] at (E.north west) {\small V1.01};}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   617
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   618
  \onslide<4->{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   619
  \node (F) at (8.6,0)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   620
  \node [below right] at (F.north west) {\small V1.01};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   621
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   622
  \node (G) at (8.6,2)  [draw=black, rectangle, very thick, minimum height=18mm, minimum width=14mm] {};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   623
  \node [below right] at (G.north west) {\small V1.02};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   624
  \node at (9.8,0) {\ldots};
207
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   625
  \node at (9.8,2) {\ldots};
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   626
  \node at (8,-2) {\textcolor{gray}{\begin{tabular}{@{}l@{}}no host language\\needed\end{tabular}}};
f824e1331fc6 added slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 206
diff changeset
   627
  }
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   628
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   629
  \end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   630
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   631
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   632
\end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   633
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   634
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   635
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   636
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   637
  \mode<presentation>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   638
  \begin{frame}<1-3>
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   639
  \frametitle{\LARGE\begin{tabular}{c}Hacking Compilers 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   640
  \end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   641
  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   642
  %Why is it so paramount to have a small trusted code base (TCB)?
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   643
  \bigskip\bigskip
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   644
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   645
  \begin{columns}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   646
  \begin{column}{2.7cm}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   647
  \begin{minipage}{2.5cm}%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   648
  \begin{tabular}{c@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   649
  \includegraphics[scale=0.2]{../pics/ken-thompson.jpg}\\[-1.8mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   650
  \footnotesize Ken Thompson\\[-1.8mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   651
  \footnotesize Turing Award, 1983\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   652
  \end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   653
  \end{minipage}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   654
  \end{column}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   655
  \begin{column}{9cm}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   656
  \begin{tabular}{l@ {\hspace{1mm}}p{8cm}}
309
640e4a05cd9b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   657
 
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   658
  & Ken Thompson showed how to hide a Trojan Horse in a 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   659
  compiler \textcolor{red}{without} leaving any traces in the source code.\\[2mm]
309
640e4a05cd9b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
   660
  
206
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   661
  & No amount of source level verification will protect 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   662
  you from such Thompson-hacks.\\[2mm]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   663
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   664
  & Therefore in safety-critical systems it is important to rely 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   665
  on only a very small TCB.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   666
  \end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   667
  \end{column}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   668
  \end{columns}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   669
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   670
  \only<2>{
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   671
  \begin{textblock}{6}(4,2)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   672
  \begin{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   673
  \draw (0,0) node[inner sep=3mm,fill=cream, ultra thick, draw=red, rounded corners=2mm] 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   674
  {\normalsize
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   675
  \begin{minipage}{8cm}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   676
  \begin{quote}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   677
  \includegraphics[scale=0.05]{../pics/evil.png}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   678
  \begin{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   679
  \item[1)] Assume you ship the compiler as binary and also with sources.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   680
  \item[2)] Make the compiler aware when it compiles itself.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   681
  \item[3)] Add the Trojan horse.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   682
  \item[4)] Compile.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   683
  \item[5)] Delete Trojan horse from the sources of the compiler.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   684
  \item[6)] Go on holiday for the rest of your life. ;o)\\[-7mm]\mbox{}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   685
  \end{enumerate}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   686
  \end{quote}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   687
  \end{minipage}};
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   688
  \end{tikzpicture}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   689
  \end{textblock}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   690
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   691
  \end{frame}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   692
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   693
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 151
diff changeset
   694
82
06c3ec0b452e updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 81
diff changeset
   695
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   696
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   697
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   698
%%% Local Variables:  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   699
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   700
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   701
%%% End: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   702