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