Working on slides for p4
[cc1516.git] / deliverables / p4 / p4.tex
1 \documentclass{beamer}
2
3 \usepackage{xcolor}
4 \usepackage{listings}
5 \usepackage{clean}
6 \usepackage{spl}
7
8 \title[cc1516]{SPLC}
9 \subtitle{\texttt{<splc>~::= <spl> <parser> `,' <lexer> `and' <compiler>}}
10 \author[P. Jager, M. Lubbers]{Pim Jager\inst{1}\and Mart Lubbers\inst{1}}
11 \institute[Radboud University]{%
12 \inst{1}%
13 Computer Science: Software Science\\
14 Radboud University
15 }
16 \subject{SPL Compiler}
17 \date{\today}
18
19 \lstset{%
20 basicstyle=\ttfamily\footnotesize,
21 breaklines
22 }
23
24 \usetheme{Warsaw}
25 \usecolortheme{beaver}
26
27 \begin{document}
28 \frame{\titlepage}
29
30 \begin{frame}[fragile]
31 \frametitle{Higher order functions implemented using function pointers}
32
33 \begin{SPLCode}
34 map(f, xs) :: (a -> b) -> [a] -> [b] {
35 if( isEmpty(xs) ) { return []; }
36 else { return f(xs.hd) : map(f, xs.tl); }
37 }
38 id(x) { return x; }
39
40 main() {
41 map(id, 1:2:3:[]);
42 }
43 \end{SPLCode}
44 \pause
45 \begin{itemize}
46 \item Function arguments are passed by name.
47 \item During compilation these are replaced by unique function ID's
48 \item During runtime the corresponding function label is retrieved using
49 a dictionary like approach.
50 \end{itemize}
51
52 \end{frame}
53
54 \begin{frame}[fragile]
55 \frametitle{Functions application can be curried}
56
57 \begin{SPLCode}
58 plus(x,y) :: Int -> Int -> Int {
59 return x + y;
60 }
61
62 main() {
63 map(plus(1), 1:2:3:[]);
64 }
65 \end{SPLCode}
66 \pause
67 \begin{columns}[T]
68 \begin{column}[T]{0.5\textwidth}
69 \begin{enumerate}
70 \item Function ID is placed on the heap
71 \item Number of passed arguments is placed on the heap
72 \item Arguments are pushed on the heap
73 \end{enumerate}
74 \end{column}
75 \pause
76 \begin{column}[T]{0.5\textwidth}
77 \begin{block}{Heap contents}
78 \begin{tabular}{c | l | r}
79 address & Content & \\ \hline
80 n & 8 & (1)\\
81 n+1 & 1 & (2)\\
82 n+2 & 4 & (3)
83 \end{tabular}
84 \end{block}
85 \end{column}
86 \end{columns}
87
88 \end{frame}
89
90 \end{document}