diff -r 3be23d0df3db -r 33cff35bdc1a slides/slides09.tex --- a/slides/slides09.tex Thu Dec 01 13:07:32 2022 +0000 +++ b/slides/slides09.tex Fri Dec 02 16:26:20 2022 +0000 @@ -22,16 +22,17 @@ \begin{tabular}{@ {}c@ {}} \\[-3mm] \LARGE Compilers and \\[-2mm] - \LARGE Formal Languages\\[3mm] + \LARGE Formal Languages\\[-3mm] \end{tabular}} \normalsize \begin{center} \begin{tabular}{ll} - Email: & christian.urban at kcl.ac.uk\\ - %Office Hours: & Thursdays 12 -- 14\\ - %Location: & N7.07 (North Wing, Bush House)\\ - Slides \& Progs: & KEATS (also homework is there)\\ + Email: & christian.urban at kcl.ac.uk\\ + Office Hour: & Fridays 11 -- 12\\ + Location: & N7.07 (North Wing, Bush House)\\ + Slides \& Progs: & KEATS\\ + Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\ \end{tabular} \end{center} @@ -75,7 +76,41 @@ \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame}[c, fragile] +\frametitle{Stack Estimation} +\small +\mbox{}\\[-15mm] + +\bl{\begin{center} +\begin{tabular}{@{\hspace{-4mm}}l@{\hspace{2mm}}c@{\hspace{2mm}}l@{}} +$\textit{estimate}(n)$ & $\dn$ & $1$\\ +$\textit{estimate}(x)$ & $\dn$ & $1$\\ +$\textit{estimate}(a_1\;aop\;a_2)$ & $\dn$ & +$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\ +$\textit{estimate}(\pcode{if}\;b\;\pcode{then}\;e_1\;\pcode{else}\;e_2)$ & $\dn$ & +$\textit{estimate}(b) +$\\ +& & $\quad max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\ +$\textit{estimate}(\pcode{write}(e))$ & $\dn$ & +$\textit{estimate}(e) + 1$\\ +$\textit{estimate}(e_1 ; e_2)$ & $\dn$ & +$max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\ +$\textit{estimate}(f(e_1, ..., e_n))$ & $\dn$ & +$\sum_{i = 1..n}\;estimate(e_i)$\medskip\\ +$\textit{estimate}(a_1\;bop\;a_2)$ & $\dn$ & +$\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\ +\end{tabular} +\end{center}} + +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + \begin{frame}[c,fragile] \frametitle{\mbox{}\hspace{5cm}Factorial} @@ -229,52 +264,69 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[c,fragile] -\frametitle{Factorial Funct.~on the JVM} +\frametitle{Peephole Optimisations} -\begin{textblock}{7}(1,1.8)\footnotesize -\begin{minipage}{6cm} -\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none] -.method public static facT(II)I -.limit locals 2 -.limit stack 6 - iload 0 - ldc 0 - if_icmpne If_else_2 - iload 1 - goto If_end_3 -If_else_2: - iload 0 - ldc 1 - isub - iload 0 - iload 1 - imul - invokestatic fact/fact/facT(II)I -If_end_3: - ireturn -.end method -\end{lstlisting} -\end{minipage} -\end{textblock} - -\begin{textblock}{7}(6,7) -\begin{bubble}[7cm]\small -\begin{lstlisting}[language=Lisp, - basicstyle=\ttfamily, - numbers=none, - xleftmargin=1mm,linebackgroundcolor=\color{cream}] -def facT(n, acc) = - if n == 0 then acc - else facT(n - 1, n * acc); -\end{lstlisting} -\end{bubble} -\end{textblock} +\begin{center} +\begin{tabular}{ll} + \texttt{ldc}: & \texttt{iconst\_0} \ldots \texttt{iconst\_5}\\ + & \texttt{bipush} $n$ where $-128 < n <= 128$\bigskip\\ + \texttt{iload}: & \texttt{iload\_0} \ldots \texttt{iload\_3}\bigskip\\ + \texttt{istore}: & \texttt{istore\_0} \ldots \texttt{istore\_3}\\ +\end{tabular} +\end{center} \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%\begin{frame}[c,fragile] +%\frametitle{Factorial Funct.~on the JVM} +% +%\begin{textblock}{7}(1,1.8)\footnotesize +%\begin{minipage}{6cm} +%\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none] +%.method public static facT(II)I +%.limit locals 2 +%.limit stack 6 +% iload 0 +% ldc 0 +% if_icmpne If_else_2 +% iload 1 +% goto If_end_3 +%If_else_2: +% iload 0 +% ldc 1 +% isub +% iload 0 +% iload 1 +% imul +% invokestatic fact/fact/facT(II)I +%If_end_3: +% ireturn +%.end method +%\end{lstlisting} +%\end{minipage} +%\end{textblock} +% +%\begin{textblock}{7}(6,7) +%\begin{bubble}[7cm]\small +%\begin{lstlisting}[language=Lisp, +% basicstyle=\ttfamily, +% numbers=none, +% xleftmargin=1mm,linebackgroundcolor=\color{cream}] +%def facT(n, acc) = +% if n == 0 then acc +% else facT(n - 1, n * acc); +%\end{lstlisting} +%\end{bubble} +%\end{textblock} +% +%\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[fragile,c] \frametitle{LLVM}