slides/slides09.tex
changeset 901 33cff35bdc1a
parent 871 94b84d880c2b
child 940 46eee459a999
equal deleted inserted replaced
900:3be23d0df3db 901:33cff35bdc1a
    20 \begin{frame}[t]
    20 \begin{frame}[t]
    21 \frametitle{%
    21 \frametitle{%
    22   \begin{tabular}{@ {}c@ {}}
    22   \begin{tabular}{@ {}c@ {}}
    23   \\[-3mm]
    23   \\[-3mm]
    24   \LARGE Compilers and \\[-2mm] 
    24   \LARGE Compilers and \\[-2mm] 
    25   \LARGE Formal Languages\\[3mm] 
    25   \LARGE Formal Languages\\[-3mm] 
    26   \end{tabular}}
    26   \end{tabular}}
    27 
    27 
    28   \normalsize
    28   \normalsize
    29   \begin{center}
    29   \begin{center}
    30   \begin{tabular}{ll}
    30   \begin{tabular}{ll}
    31     Email:  & christian.urban at kcl.ac.uk\\
    31   Email:  & christian.urban at kcl.ac.uk\\
    32     %Office Hours: & Thursdays 12 -- 14\\
    32   Office Hour: & Fridays 11 -- 12\\
    33     %Location: & N7.07 (North Wing, Bush House)\\
    33   Location: & N7.07 (North Wing, Bush House)\\
    34     Slides \& Progs: & KEATS (also homework is there)\\  
    34   Slides \& Progs: & KEATS\\
       
    35   Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\  
    35   \end{tabular}
    36   \end{tabular}
    36   \end{center}
    37   \end{center}
    37 
    38 
    38   \begin{center}
    39   \begin{center}
    39     \begin{tikzpicture}
    40     \begin{tikzpicture}
    73 \end{lstlisting}
    74 \end{lstlisting}
    74 \end{textblock}
    75 \end{textblock}
    75 
    76 
    76 \end{frame}
    77 \end{frame}
    77 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
    78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
    78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    79 
       
    80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
    81 \begin{frame}[c, fragile]
       
    82 \frametitle{Stack Estimation}
       
    83 \small
       
    84 \mbox{}\\[-15mm]
       
    85 
       
    86 \bl{\begin{center}
       
    87 \begin{tabular}{@{\hspace{-4mm}}l@{\hspace{2mm}}c@{\hspace{2mm}}l@{}}
       
    88 $\textit{estimate}(n)$ & $\dn$ & $1$\\
       
    89 $\textit{estimate}(x)$ & $\dn$ & $1$\\
       
    90 $\textit{estimate}(a_1\;aop\;a_2)$ & $\dn$ &
       
    91 $\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
       
    92 $\textit{estimate}(\pcode{if}\;b\;\pcode{then}\;e_1\;\pcode{else}\;e_2)$ & $\dn$ & 
       
    93 $\textit{estimate}(b) +$\\ 
       
    94 & & $\quad max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
       
    95 $\textit{estimate}(\pcode{write}(e))$ & $\dn$ & 
       
    96 $\textit{estimate}(e) + 1$\\
       
    97 $\textit{estimate}(e_1 ; e_2)$ & $\dn$ & 
       
    98 $max(\textit{estimate}(e_1), \textit{estimate}(e_2))$\\
       
    99 $\textit{estimate}(f(e_1, ..., e_n))$ & $\dn$ & 
       
   100 $\sum_{i = 1..n}\;estimate(e_i)$\medskip\\
       
   101 $\textit{estimate}(a_1\;bop\;a_2)$ & $\dn$ &
       
   102 $\textit{estimate}(a_1) + \textit{estimate}(a_2)$\\
       
   103 \end{tabular}
       
   104 \end{center}}
       
   105 
       
   106 \end{frame}
       
   107 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
       
   108 
       
   109 
       
   110 
       
   111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       
   112 
       
   113 
    79 \begin{frame}[c,fragile]
   114 \begin{frame}[c,fragile]
    80 \frametitle{\mbox{}\hspace{5cm}Factorial}
   115 \frametitle{\mbox{}\hspace{5cm}Factorial}
    81 
   116 
    82 \begin{textblock}{7}(0,1.0)\footnotesize
   117 \begin{textblock}{7}(0,1.0)\footnotesize
    83 \begin{minipage}{6cm}
   118 \begin{minipage}{6cm}
   227 \end{frame}
   262 \end{frame}
   228 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   263 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
   229 
   264 
   230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   265 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   231 \begin{frame}[c,fragile]
   266 \begin{frame}[c,fragile]
   232 \frametitle{Factorial Funct.~on the JVM}
   267 \frametitle{Peephole Optimisations}
   233 
   268 
   234 \begin{textblock}{7}(1,1.8)\footnotesize
   269 \begin{center}
   235 \begin{minipage}{6cm}
   270 \begin{tabular}{ll}
   236 \begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
   271   \texttt{ldc}:  & \texttt{iconst\_0} \ldots \texttt{iconst\_5}\\
   237 .method public static facT(II)I 
   272                  & \texttt{bipush} $n$ where $-128 < n <= 128$\bigskip\\  
   238 .limit locals 2
   273   \texttt{iload}: &  \texttt{iload\_0} \ldots \texttt{iload\_3}\bigskip\\
   239 .limit stack 6
   274   \texttt{istore}: &  \texttt{istore\_0} \ldots \texttt{istore\_3}\\
   240   iload 0
   275 \end{tabular}
   241   ldc 0
   276 \end{center}  
   242   if_icmpne If_else_2
   277 
   243   iload 1
   278 \end{frame}
   244   goto If_end_3
   279 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   245 If_else_2:
   280 
   246   iload 0
   281 
   247   ldc 1
   282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   248   isub
   283 %\begin{frame}[c,fragile]
   249   iload 0
   284 %\frametitle{Factorial Funct.~on the JVM}
   250   iload 1
   285 %
   251   imul
   286 %\begin{textblock}{7}(1,1.8)\footnotesize
   252   invokestatic fact/fact/facT(II)I
   287 %\begin{minipage}{6cm}
   253 If_end_3:
   288 %\begin{lstlisting}[language=JVMIS,basicstyle=\ttfamily, numbers=none]
   254   ireturn
   289 %.method public static facT(II)I 
   255 .end method 
   290 %.limit locals 2
   256 \end{lstlisting}
   291 %.limit stack 6
   257 \end{minipage}
   292 %  iload 0
   258 \end{textblock}
   293 %  ldc 0
   259 
   294 %  if_icmpne If_else_2
   260 \begin{textblock}{7}(6,7)
   295 %  iload 1
   261 \begin{bubble}[7cm]\small
   296 %  goto If_end_3
   262 \begin{lstlisting}[language=Lisp,
   297 %If_else_2:
   263                    basicstyle=\ttfamily, 
   298 %  iload 0
   264                    numbers=none,
   299 %  ldc 1
   265                    xleftmargin=1mm,linebackgroundcolor=\color{cream}]
   300 %  isub
   266 def facT(n, acc) = 
   301 %  iload 0
   267   if n == 0 then acc 
   302 %  iload 1
   268   else facT(n - 1, n * acc);
   303 %  imul
   269 \end{lstlisting}
   304 %  invokestatic fact/fact/facT(II)I
   270 \end{bubble}
   305 %If_end_3:
   271 \end{textblock}
   306 %  ireturn
   272 
   307 %.end method 
   273 \end{frame}
   308 %\end{lstlisting}
       
   309 %\end{minipage}
       
   310 %\end{textblock}
       
   311 %
       
   312 %\begin{textblock}{7}(6,7)
       
   313 %\begin{bubble}[7cm]\small
       
   314 %\begin{lstlisting}[language=Lisp,
       
   315 %                   basicstyle=\ttfamily, 
       
   316 %                   numbers=none,
       
   317 %                   xleftmargin=1mm,linebackgroundcolor=\color{cream}]
       
   318 %def facT(n, acc) = 
       
   319 %  if n == 0 then acc 
       
   320 %  else facT(n - 1, n * acc);
       
   321 %\end{lstlisting}
       
   322 %\end{bubble}
       
   323 %\end{textblock}
       
   324 %
       
   325 %\end{frame}
   274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
   275 
   327 
   276 
   328 
   277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   329 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   278 \begin{frame}[fragile,c]
   330 \begin{frame}[fragile,c]