slides/slides08.tex
author Christian Urban <urbanc@in.tum.de>
Tue, 20 Nov 2018 13:37:40 +0000
changeset 608 3db4970ad0aa
parent 601 208b0f67a3d0
child 697 370508e4d7f6
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}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
     2
\usepackage{xcolor}
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     3
\usepackage{../slides}
215
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 197
diff changeset
     4
\usepackage{../langs}
828303e8e4af updated slides
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 197
diff changeset
     5
\usepackage{../data}
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
     6
\usepackage{../graphics}
600
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
     7
\usepackage{../grammar}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
     8
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
     9
\usepackage[most]{tcolorbox}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    10
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    11
\newtcbox{\hl}[1][]{%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    12
     size=fbox,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    13
    tcbox raise base, nobeforeafter, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    14
    enhanced, colframe=gray,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    15
    colback=gray!30, boxrule=1pt,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    16
    fontupper=\ttfamily,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    17
    #1}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    18
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    19
\lstset{morekeywords={def,if,then,else,write,read},keywordstyle=\color{codepurple}\bfseries}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    20
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    21
% beamer stuff
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    22
\renewcommand{\slidecaption}{CFL 09, King's College London}
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
\newcommand{\bl}[1]{\textcolor{blue}{#1}}       
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    25
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
\begin{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    29
\begin{frame}[t]
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
\frametitle{%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    31
  \begin{tabular}{@ {}c@ {}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    32
  \\[-3mm]
459
780486571e38 updated
Christian Urban <urbanc@in.tum.de>
parents: 387
diff changeset
    33
  \LARGE Compilers and \\[-2mm] 
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    34
  \LARGE Formal Languages (8)\\[3mm] 
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
  \end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    37
  \normalsize
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    38
  \begin{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
  \begin{tabular}{ll}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
  Email:  & christian.urban at kcl.ac.uk\\
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    41
  Office: & N7.07 (North Wing, Bush House)\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    42
  Slides: & KEATS (also home work is there)\\
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
  \end{tabular}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
  \end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
306
fecffce112fa updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 215
diff changeset
    46
\end{frame}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    47
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    48
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    49
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    50
\begin{frame}[c]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 65
diff changeset
    51
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    52
\begin{center}
70
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 69
diff changeset
    53
\bl{\begin{tabular}{@{}lcl@{}}
600
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    54
\meta{Stmt} & $::=$ &  $\texttt{skip}$\\
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    55
              & $|$ & \textit{Id}\;\texttt{:=}\;\meta{AExp}\\
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    56
              & $|$ & \texttt{if}\; \meta{BExp} \;\texttt{then}\; \meta{Block} \;\texttt{else}\; \meta{Block}\\
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    57
              & $|$ & \texttt{while}\; \meta{BExp} \;\texttt{do}\; \meta{Block}\\
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    58
              & $|$ & \texttt{read}\;\textit{Id}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    59
              & $|$ & \texttt{write}\;\textit{Id}\\
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    60
              & $|$ & \texttt{write}\;\textit{String}\medskip\\
600
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    61
\meta{Stmts} & $::=$ &  \meta{Stmt} \;\texttt{;}\; \meta{Stmts}\\
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    62
              & $|$ & \meta{Stmt}\medskip\\
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    63
\meta{Block} & $::=$ &  \texttt{\{}\,\meta{Stmts}\,\texttt{\}}\\
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    64
                & $|$ & \meta{Stmt}\medskip\\
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    65
\meta{AExp} & $::=$ & \ldots\\
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    66
\meta{BExp} & $::=$ & \ldots\\
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    67
\end{tabular}}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    68
\end{center}
600
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    69
\end{frame}
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
    70
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
69
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 67
diff changeset
    71
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    72
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    73
\begin{frame}[t,fragile]
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    74
\frametitle{Compiling AExps}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    75
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    76
For example \bl{$1 + ((2 * 3) + (4 - 3))$}:\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    77
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    78
\begin{columns}[T]
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    79
\begin{column}{.3\textwidth}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
    80
\begin{center}
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    81
\bl{\begin{tikzpicture}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    82
\tikzset{level distance=12mm,sibling distance=4mm}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    83
\tikzset{edge from parent/.style={draw,very thick}}
\Tree [.$+$ [.$1$ ] [.$+$ [.$*$ $2$ $3$ ] [.$-$ $4$ $3$ ]]]
\end{tikzpicture}}
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
    84
\end{center}
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    85
\end{column}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
    86
\begin{column}{.3\textwidth}
535
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    87
\begin{lstlisting}[language=JVMIS,numbers=none]
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    88
ldc 1 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    89
ldc 2 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    90
ldc 3 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    91
imul 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    92
ldc 4 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    93
ldc 3 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    94
isub 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    95
iadd 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    96
iadd
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    97
\end{lstlisting}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    98
\end{column}
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
    99
\end{columns}\bigskip
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   100
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   101
\small
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   102
Traverse tree in post-order \bl{$\Rightarrow$} code for 
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   103
stack-machine
095be64c03c1 updated
Christian Urban <urbanc@in.tum.de>
parents: 534
diff changeset
   104
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   105
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   106
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   107
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   108
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
600
d488a3e7b0ec updated
Christian Urban <urbanc@in.tum.de>
parents: 598
diff changeset
   109
\begin{frame}[c,fragile]
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   110
\frametitle{Compiling AExps}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   111
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   112
\bl{
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   113
\begin{center}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   114
\begin{tabular}{lcl}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   115
$\textit{compile}(n, E)$ & $\dn$ & $\pcode{ldc}\;n$\smallskip\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   116
$\textit{compile}(a_1 + a_2, E)$ & $\dn$ \\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   117
\multicolumn{3}{c}{$\qquad\textit{compile}(a_1, E) \;@\;\textit{compile}(a_2, E)\;@\; \pcode{iadd}$}\smallskip\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   118
$\textit{compile}(a_1 - a_2, E)$ & $\dn$ \\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   119
\multicolumn{3}{c}{$\qquad\textit{compile}(a_1, E) \;@\; \textit{compile}(a_2, E)\;@\; \pcode{isub}$}\smallskip\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   120
$\textit{compile}(a_1 * a_2, E)$ & $\dn$ \\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   121
\multicolumn{3}{c}{$\qquad\textit{compile}(a_1, E) \;@\; \textit{compile}(a_2, E)\;@\; \pcode{imul}$}\smallskip\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   122
$\textit{compile}(a_1 \backslash a_2, E)$ & $\dn$\\ 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   123
\multicolumn{3}{c}{$\qquad\textit{compile}(a_1, E) \;@\; \textit{compile}(a_2, E)\;@\; \pcode{idiv}$}\smallskip\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   124
$\textit{compile}(x, E)$ & $\dn$ & $\pcode{iload}\;E(x)$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   125
\end{tabular}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   126
\end{center}}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   127
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   128
\end{frame}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   129
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   130
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   131
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   132
\begin{frame}[c,fragile]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   133
\frametitle{Compiling Ifs}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   134
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   135
For example
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   136
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   137
\begin{lstlisting}[mathescape,numbers=none,language=While]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   138
if 1 = 1 then x := 2 else y := 3
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   139
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   140
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   141
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   142
\begin{center}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   143
\begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   144
   ldc 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   145
   ldc 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   146
   if_icmpne L_ifelse $\quad\tikz[remember picture] \node (C) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   147
   ldc 2
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   148
   istore 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   149
   goto L_ifend $\quad\tikz[remember picture] \node (A) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   150
L_ifelse: $\quad\tikz[remember picture] \node[] (D) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   151
   ldc 3
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   152
   istore 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   153
L_ifend: $\quad\tikz[remember picture] \node[] (B) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   154
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   155
\end{center}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   156
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   157
\begin{tikzpicture}[remember picture,overlay]
  \draw[->,very thick] (A) edge [->,to path={-- ++(10mm,0mm) 
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   158
           -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (B.east);
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   159
  \draw[->,very thick] (C) edge [->,to path={-- ++(10mm,0mm) 
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   160
           -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (D.east);
\end{tikzpicture}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   161
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   162
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   163
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   164
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   165
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   166
\begin{frame}[c,fragile]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   167
\frametitle{Compiling Whiles}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   168
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   169
For example
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   170
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   171
\begin{lstlisting}[mathescape,numbers=none,language=While]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   172
while x <= 10 do x := x + 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   173
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   174
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   175
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   176
\begin{center}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   177
\begin{lstlisting}[mathescape,language=JVMIS,numbers=none]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   178
L_wbegin: $\quad\tikz[remember picture] \node[] (LB) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   179
   iload 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   180
   ldc 10
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   181
   if_icmpgt L_wend $\quad\tikz[remember picture] \node (LC) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   182
   iload 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   183
   ldc 1
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   184
   iadd
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   185
   istore 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   186
   goto L_wbegin $\quad\tikz[remember picture] \node (LA) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   187
L_wend: $\quad\tikz[remember picture] \node[] (LD) {\mbox{}};$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   188
\end{lstlisting}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   189
\end{center}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   190
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   191
\begin{tikzpicture}[remember picture,overlay]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   192
  \draw[->,very thick] (LA) edge [->,to path={-- ++(12mm,0mm) 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   193
           -- ++(0mm,17.3mm) |- (\tikztotarget)},line width=1mm] (LB.east);
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   194
  \draw[->,very thick] (LC) edge [->,to path={-- ++(12mm,0mm) 
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   195
           -- ++(0mm,-17.3mm) |- (\tikztotarget)},line width=1mm] (LD.east);
\end{tikzpicture}
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   196
387
8aa406adfde0 updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 308
diff changeset
   197
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   198
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   199
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   200
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   201
\begin{frame}[c,fragile]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   202
\frametitle{Compiling Writes}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   203
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   204
\small
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   205
\begin{lstlisting}[language=JVMIS,mathescape,
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   206
                   numbers=none,xleftmargin=-6mm]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   207
.method public static write(I)V 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   208
  .limit locals 1 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   209
  .limit stack 2 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   210
  getstatic java/lang/System/out 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   211
                            Ljava/io/PrintStream; 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   212
  iload 0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   213
  invokevirtual java/io/PrintStream/println(I)V 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   214
  return 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   215
.end method
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   216
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   217
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   218
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   219
iload $E(x)$ 
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   220
invokestatic XXX/XXX/write(I)V
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   221
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   222
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   223
\end{frame}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   224
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   225
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   226
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
534
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   227
\begin{frame}[c,fragile]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   228
\frametitle{Compiling Main}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   229
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   230
\footnotesize
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   231
\begin{lstlisting}[language=JVMIS,mathescape,
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   232
                   numbers=none,xleftmargin=-6mm]
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   233
.class public XXX.XXX
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   234
.super java/lang/Object
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   235
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   236
.method public <init>()V
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   237
    aload_0
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   238
    invokenonvirtual java/lang/Object/<init>()V
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   239
    return
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   240
.end method
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   241
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   242
.method public static main([Ljava/lang/String;)V
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   243
    .limit locals 200
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   244
    .limit stack 200
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   245
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   246
      $\textit{\ldots{}here comes the compiled code\ldots}$
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   247
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   248
    return
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   249
.end method
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   250
\end{lstlisting}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   251
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   252
\end{frame}
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   253
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   254
Christian Urban <urbanc@in.tum.de>
parents: 532
diff changeset
   255
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   256
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   257
\begin{frame}[c,fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   258
\frametitle{Functional Programming}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   259
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   260
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   261
\begin{textblock}{13}(0.9,3)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   262
\begin{lstlisting}[]numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   263
def fib(n) = if n == 0 then 0 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   264
             else if n == 1 then 1 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   265
             else fib(n - 1) + fib(n - 2);
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   266
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   267
def fact(n) = if n == 0 then 1 else n * fact(n - 1);
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   268
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   269
def ack(m, n) = if m == 0 then n + 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   270
                else if n == 0 then ack(m - 1, 1)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   271
                else ack(m - 1, ack(m, n - 1));
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   272
                
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   273
def gcd(a, b) = if b == 0 then a else gcd(b, a % b);                
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   274
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   275
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   276
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   277
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   278
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   279
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   280
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   281
\begin{frame}[c]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   282
\frametitle{Fun Grammar}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   283
\bl{
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   284
\begin{plstx}[rhs style=]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   285
: \meta{Exp} ::= \meta{Var} | \meta{Num}{\hspace{3cm}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   286
             |   \meta{Exp} + \meta{Exp} | ... | (\meta{Exp})
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   287
             |   \code{if} \meta{BExp} \code{then} \meta{Exp} \code{else} \meta{Exp}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   288
             |   \code{write} \meta{Exp} {\hspace{3cm}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   289
             |   \meta{Exp} ; \meta{Exp}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   290
             |   \textit{FunName} (\meta{Exp}, ... , \meta{Exp})\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   291
: \meta{BExp} ::= ...\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   292
: \meta{Def} ::= \code{def} \textit{FunName} ($\hspace{0.4mm}x_1$, ... , $x_n$) = \meta{Exp}\\               
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   293
: \meta{Prog} ::= \meta{Def} ; \meta{Prog}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   294
               | \meta{Exp} ; \meta{Prog}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   295
               | \meta{Exp}\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   296
\end{plstx}}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   297
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   298
% Almost what is implemented - Exp ; Exp is left-recursive
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   299
%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   300
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   301
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   302
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   303
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   304
\begin{frame}[c, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   305
\frametitle{Abstract Syntax Trees}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   306
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   307
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   308
\begin{lstlisting}[language=Scala, numbers=none, xleftmargin=-1mm]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   309
abstract class Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   310
abstract class BExp 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   311
abstract class Decl
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   312
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   313
case class Var(s: String) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   314
case class Num(i: Int) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   315
case class Aop(o: String, a1: Exp, a2: Exp) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   316
case class If(a: BExp, e1: Exp, e2: Exp) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   317
case class Write(e: Exp) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   318
case class Sequ(e1: Exp, e2: Exp) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   319
case class Call(name: String, args: List[Exp]) extends Exp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   320
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   321
case class Bop(o: String, a1: Exp, a2: Exp) extends BExp
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   322
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   323
case class Def(name: String, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   324
               args: List[String], 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   325
               body: Exp) extends Decl
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   326
case class Main(e: Exp) extends Decl
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   327
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   328
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   329
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   330
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   331
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   332
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   333
\begin{frame}[c, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   334
\frametitle{Idea}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   335
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   336
Compile \texttt{exp} such that the result of the expression
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   337
is on top of the stack.\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   338
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   339
\begin{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   340
\item \texttt{\color{codepurple}{write}}\texttt{(1 + 2)}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   341
\item \texttt{1 + 2; 3 + 4} 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   342
\end{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   343
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   344
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   345
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   346
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   347
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   348
\begin{frame}[c, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   349
\frametitle{Sequences}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   350
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   351
Compiling \texttt{exp1 ; exp2}:\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   352
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   353
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   354
\begin{lstlisting}[mathescape,language=JVMIS, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   355
$\textit{compile}$(exp1)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   356
pop
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   357
$\textit{compile}$(exp2)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   358
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   359
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   360
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   361
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   362
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   363
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   364
\begin{frame}[t, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   365
\frametitle{Write}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   366
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   367
Compiling call to \texttt{write(1+2)}:\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   368
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   369
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   370
\begin{lstlisting}[mathescape,language=JVMIS, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   371
$\textit{compile}$(1+2)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   372
dup
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   373
invokestatic XXX/XXX/write(I)V
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   374
\end{lstlisting}\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   375
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   376
\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   377
needs the helper method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   378
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   379
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   380
\begin{lstlisting}[language=JVMIS, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   381
                   xleftmargin=2mm, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   382
                   numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   383
.method public static write(I)V 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   384
   .limit locals 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   385
   .limit stack 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   386
   getstatic java/lang/System/out Ljava/io/PrintStream; 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   387
   iload 0 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   388
   invokevirtual java/io/PrintStream/println(I)V 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   389
   return 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   390
.end method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   391
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   392
\end{frame}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   393
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   394
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   395
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   396
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   397
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   398
\begin{frame}[t, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   399
\frametitle{Function Definitions}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   400
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   401
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   402
\begin{lstlisting}[language=JVMIS, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   403
                   xleftmargin=2mm, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   404
                   numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   405
.method public static write(I)V 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   406
   .limit locals 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   407
   .limit stack 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   408
   getstatic java/lang/System/out Ljava/io/PrintStream; 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   409
   iload 0 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   410
   invokevirtual java/io/PrintStream/println(I)V 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   411
   return 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   412
.end method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   413
\end{lstlisting}\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   414
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   415
\small We will need for definitions, like\footnotesize\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   416
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   417
\begin{lstlisting}[language=JVMIS, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   418
                   xleftmargin=2mm, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   419
                   numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   420
def fname (x1, ... , xn) = ...                   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   421
                   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   422
.method public static fname (I...I)I
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   423
  .limit locals ??
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   424
  .limit stack ?? 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   425
  ??
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   426
.end method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   427
\end{lstlisting}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   428
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   429
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   430
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   431
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   432
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   433
\begin{frame}[c, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   434
\frametitle{Stack Estimation}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   435
\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   436
\mbox{}\\[-15mm]
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   437
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   438
\bl{\begin{center}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   439
\begin{tabular}{@{\hspace{-4mm}}l@{\hspace{2mm}}c@{\hspace{2mm}}l@{}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   440
$\textit{estimate}(n)$ & $\dn$ & $1$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   441
$\textit{estimate}(x)$ & $\dn$ & $1$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   442
$\textit{estimate}(a_1\;aop\;a_2)$ & $\dn$ &
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   443
$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   444
$\textit{estimate}(\pcode{if}\;b\;\pcode{then}\;e_1\;\pcode{else}\;e_2)$ & $\dn$ & 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   445
$\textit{estimate}(b) +$\\ 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   446
& & $\quad max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   447
$\textit{estimate}(\pcode{write}(e))$ & $\dn$ & 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   448
$\textit{estimate}(e) + 1$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   449
$\textit{estimate}(e_1 ; e_2)$ & $\dn$ & 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   450
$max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   451
$\textit{estimate}(f(e_1, ..., e_n))$ & $\dn$ & 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   452
$\sum_{i = 1..n}\;estimate(e_i)$\medskip\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   453
$\textit{estimate}(a_1\;bop\;a_2)$ & $\dn$ &
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   454
$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   455
\end{tabular}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   456
\end{center}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   457
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   458
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   459
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   460
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   461
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   462
\begin{frame}[fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   463
\frametitle{Successor Function}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   464
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   465
\begin{textblock}{7}(1,2.5)\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   466
\begin{minipage}{6cm}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   467
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   468
.method public static suc(I)I 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   469
.limit locals 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   470
.limit stack 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   471
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   472
  ldc 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   473
  iadd
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   474
  ireturn
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   475
.end method 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   476
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   477
\end{minipage}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   478
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   479
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   480
\begin{textblock}{7}(6,8)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   481
\begin{bubble}[5cm]\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   482
\begin{lstlisting}[language=Lisp,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   483
                   basicstyle=\ttfamily, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   484
                   numbers=none,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   485
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   486
def suc(x) = x + 1;
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   487
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   488
\end{bubble}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   489
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   490
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   491
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   492
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   493
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   494
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   495
\begin{frame}[fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   496
\frametitle{Addition Function}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   497
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   498
\begin{textblock}{7}(1,1.9)\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   499
\begin{minipage}{6cm}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   500
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   501
.method public static add(II)I 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   502
.limit locals 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   503
.limit stack 5
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   504
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   505
  ldc 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   506
  if_icmpne If_else
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   507
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   508
  goto If_end
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   509
If_else:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   510
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   511
  ldc 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   512
  isub
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   513
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   514
  invokestatic XXX/XXX/add(II)I
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   515
  invokestatic XXX/XXX/suc(I)I
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   516
If_end:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   517
  ireturn
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   518
.end method
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   519
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   520
\end{minipage}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   521
\end{textblock}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   522
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   523
\begin{textblock}{7}(6,6.6)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   524
\begin{bubble}[7cm]\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   525
\begin{lstlisting}[language=Lisp,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   526
                   basicstyle=\ttfamily, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   527
                   numbers=none,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   528
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   529
def add(x, y) = 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   530
    if x == 0 then y 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   531
    else suc(add(x - 1, y));
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   532
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   533
\end{bubble}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   534
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   535
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   536
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   537
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   538
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   539
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   540
\begin{frame}[c,fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   541
\frametitle{Factorial}
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   542
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   543
\begin{textblock}{7}(1,1.8)\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   544
\begin{minipage}{6cm}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   545
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   546
.method public static facT(II)I 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   547
.limit locals 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   548
.limit stack 6
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   549
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   550
  ldc 0	
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   551
  if_icmpne If_else_2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   552
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   553
  goto If_end_3
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   554
If_else_2:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   555
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   556
  ldc 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   557
  isub
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   558
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   559
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   560
  imul
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   561
  invokestatic fact/fact/facT(II)I
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   562
If_end_3:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   563
  ireturn
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   564
.end method 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   565
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   566
\end{minipage}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   567
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   568
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   569
\begin{textblock}{7}(6,7)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   570
\begin{bubble}[7cm]\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   571
\begin{lstlisting}[language=Lisp,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   572
                   basicstyle=\ttfamily, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   573
                   numbers=none,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   574
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   575
def facT(n, acc) = 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   576
  if n == 0 then acc 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   577
  else facT(n - 1, n * acc);
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   578
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   579
\end{bubble}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   580
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   581
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   582
\end{frame}
197
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 196
diff changeset
   583
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   584
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   585
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   586
\begin{frame}[fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   587
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   588
\begin{textblock}{7}(1,-0.2)\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   589
\begin{minipage}{6cm}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   590
\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none, escapeinside={(*@}{@*)}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   591
.method public static facT(II)I 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   592
.limit locals 2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   593
.limit stack 6
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   594
(*@\hl{facT\_Start:} @*)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   595
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   596
  ldc 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   597
  if_icmpne If_else_2
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   598
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   599
  goto If_end_3
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   600
If_else_2:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   601
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   602
  ldc 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   603
  isub
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   604
  iload 0
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   605
  iload 1
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   606
  imul
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   607
  (*@\hl{istore 1} @*)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   608
  (*@\hl{istore 0} @*)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   609
  (*@\hl{goto facT\_Start} @*)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   610
If_end_3:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   611
  ireturn
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   612
.end method 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   613
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   614
\end{minipage}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   615
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   616
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   617
\begin{textblock}{7}(6,7)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   618
\begin{bubble}[7cm]\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   619
\begin{lstlisting}[language=Lisp,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   620
                   basicstyle=\ttfamily, 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   621
                   numbers=none,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   622
                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   623
def facT(n, acc) = 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   624
  if n == 0 then acc 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   625
  else facT(n - 1, n * acc);
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   626
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   627
\end{bubble}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   628
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   629
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   630
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   631
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   632
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   633
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   634
\begin{frame}[t, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   635
\frametitle{Tail Recursion}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   636
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   637
A call to \texttt{f(args)} is usually compiled as\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   638
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   639
{\small\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   640
  args onto stack
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   641
  invokestatic  .../f 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   642
\end{lstlisting}}\pause
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   643
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   644
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   645
A call is in tail position provided:\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   646
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   647
{\small\begin{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   648
\item \texttt{if Bexp then \hl{Exp} else \hl{Exp}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   649
\item \texttt{Exp ; \hl{Exp}}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   650
\item \texttt{Exp  op Exp}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   651
\end{itemize}}\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   652
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   653
then a call \texttt{f(args)} can be compiled as\medskip\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   654
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   655
\begin{lstlisting}[basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   656
  prepare environment
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   657
  jump to start of function
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   658
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   659
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   660
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   661
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   662
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   663
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   664
\begin{frame}[c, fragile]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   665
\frametitle{Tail Recursive Call}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   666
\footnotesize
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   667
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   668
\begin{textblock}{13}(-0.3,2)
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   669
\begin{lstlisting}[language=Scala,basicstyle=\ttfamily, numbers=none]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   670
def compile_expT(a: Exp, env: Mem, name: String): Instrs = 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   671
  ...
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   672
  case Call(n, args) => if (name == n) 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   673
  { 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   674
    val stores = args.zipWithIndex.map 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   675
       { case (x, y) => "istore " + y.toString + "\n" } 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   676
    args.flatMap(a => compile_expT(a, env, "")) ++
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   677
    stores.reverse ++ 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   678
    List ("goto " + n + "_Start\n") 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   679
  } 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   680
  else 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   681
  {
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   682
    val is = "I" * args.length
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   683
    args.flatMap(a => compile_expT(a, env, "")) ++
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   684
    List ("invokestatic XXX/XXX/" + n + "(" + is + ")I\n")
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   685
  }
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   686
\end{lstlisting}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   687
\end{textblock}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   688
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   689
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   690
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   691
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   692
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   693
  \begin{frame}[c]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   694
  \frametitle{Dijkstra on Testing}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   695
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   696
  \begin{bubble}[10cm]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   697
  ``Program testing can be a very effective way to show the
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   698
  presence of bugs, but it is hopelessly inadequate for showing
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   699
  their absence.''
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   700
  \end{bubble}\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   701
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   702
  \small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   703
  What is good about compilers: the either seem to work,
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   704
  or go horribly wrong (most of the time).
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   705
  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   706
  \end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   707
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   708
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   709
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   710
\begin{frame}[c]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   711
\frametitle{\Large Proving Programs to be Correct}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   712
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   713
\begin{bubble}[10cm]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   714
\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   715
{\bf Theorem:} There are infinitely many prime 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   716
numbers.\medskip\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   717
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   718
{\bf Proof} \ldots\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   719
\end{bubble}\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   720
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   721
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   722
similarly\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   723
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   724
\begin{bubble}[10cm]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   725
\small
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   726
{\bf Theorem:} The program is doing what 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   727
it is supposed to be doing.\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   728
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   729
{\bf Long, long proof} \ldots\\
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   730
\end{bubble}\bigskip\medskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   731
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   732
\small This can be a gigantic proof. The only hope is to have
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   733
help from the computer. `Program' is here to be understood to be
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   734
quite general (compiler, OS, \ldots).
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   735
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   736
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   737
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   738
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   739
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   740
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   741
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   742
\begin{frame}[c]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   743
\frametitle{Can This Be Done?}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   744
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   745
\begin{itemize}
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   746
\item in 2008, verification of a small C-compiler
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   747
\begin{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   748
\item ``if my input program has a certain behaviour, then the compiled machine code has the same behaviour''
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   749
\item is as good as \texttt{gcc -O1}, but much, much less buggy 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   750
\end{itemize}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   751
\end{itemize}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   752
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   753
\begin{center}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   754
  \includegraphics[scale=0.12]{../pics/compcert.png}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   755
\end{center}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   756
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   757
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   758
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   759
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   760
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   761
\begin{frame}[c]
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   762
\frametitle{Fuzzy Testing C-Compilers}
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   763
608
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   764
\begin{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   765
\item tested GCC, LLVM and others by randomly generating 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   766
C-programs
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   767
\item found more than 300 bugs in GCC and also
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   768
many in LLVM (some of them highest-level critical)\bigskip
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   769
\item about CompCert:
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   770
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   771
\begin{bubble}[10cm]\small ``The striking thing about our CompCert
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   772
results is that the middle-end bugs we found in all other
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   773
compilers are absent. As of early 2011, the under-development
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   774
version of CompCert is the only compiler we have tested for
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   775
which Csmith cannot find wrong-code errors. This is not for
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   776
lack of trying: we have devoted about six CPU-years to the
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   777
task.'' 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   778
\end{bubble} 
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   779
\end{itemize}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   780
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   781
\end{frame}
3db4970ad0aa updated
Christian Urban <urbanc@in.tum.de>
parents: 601
diff changeset
   782
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     
196
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 93
diff changeset
   783
65
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   784
\end{document}
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   785
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   786
%%% Local Variables:  
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   787
%%% mode: latex
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   788
%%% TeX-master: t
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   789
%%% End: 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   790