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