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