First version slides
[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
91 \begin{frame}[fragile]
92 \frametitle{SPLC has lambda functions through AST rewriting}
93 \framesubtitle{\texttt{<LamdaExpr> ::= `\textbackslash'<id>*
94 `->' <Expr>}}
95 \begin{block}{Implementation}<3->
96 Implemented by promoting lambdas to regular named functions
97 prior to semantical analysis.
98 \end{block}
99 \begin{columns}
100 \begin{column}[T]{0.5\textwidth}<1->
101 \begin{SPLCode}
102 main() {
103 map(\x-> x+1, 1:2:3:[]);
104 }
105 \end{SPLCode}
106 \end{column}
107 \begin{column}[T]{0.5\textwidth}<4->
108 \begin{SPLCode}
109 1lambda_23(x) {
110 return x+1;
111 }
112 main() {
113 map(1lambda_23, 1:2:3:[]);
114 }
115 \end{SPLCode}
116 \end{column}
117 \end{columns}
118 \begin{itemize}
119 \item<2-> SPLC supports anonymous lambda functions with arbitrary arity
120 \item<2-> Lambdas are fully type checked, same as regular functions
121 \end{itemize}
122 \end{frame}
123
124 \begin{frame}[fragile]
125 \frametitle{Syntactic sugar to ease our programmers lives}
126 \begin{block}{Global constants}
127 \begin{itemize}
128 \item SPLC does \emph{not} feature global variables.
129 \begin{itemize}
130 \item We want to protect our users from global state (as much
131 as possible).
132 \end{itemize}
133 \item Global constants allowed through \texttt{Let} statements
134 \item \texttt{<LetDecl> ::= `Let' <type> <id> `=' <Expr> `;'}
135 \item Lets are rewritten to constant functions
136 \end{itemize}
137 \begin{columns}[T]
138 \begin{column}[T]{0.4\linewidth}
139 \begin{SPLCode}
140 Let Int x = 5;
141 \end{SPLCode}
142 \end{column}
143 \begin{column}[T]{0.4\linewidth}
144 \begin{SPLCode}
145 x() :: Int { return 5; }
146 \end{SPLCode}
147 \end{column}
148 \end{columns}
149 \end{block}
150 \end{frame}
151
152 \begin{frame}[fragile]
153 \frametitle{Syntactic sugar to ease our programmers lives}
154 \framesubtitle{continued}
155 \begin{block}{String Literals}
156 \begin{columns}[T]
157 \begin{column}[T]{0.34\linewidth}
158 \begin{SPLCode}
159 var a = "Hello world!";
160 \end{SPLCode}
161 \end{column}
162 \begin{column}[T]{0.5\linewidth}
163 \begin{SPLCode}
164 var a = 'H':'e':'l':'l':'o':' ':
165 'w':'o':'r':'l':'d':'!':[];
166 \end{SPLCode}
167 \end{column}
168 \end{columns}
169 \end{block}
170 \begin{block}{List Literals}
171 \begin{columns}[T]
172 \begin{column}[T]{0.34\linewidth}
173 \begin{SPLCode}
174 var xs = [1,2,3];
175 \end{SPLCode}
176 \end{column}
177 \begin{column}[T]{0.5\linewidth}
178 \begin{SPLCode}
179 var xs = 1:2:3:[];
180 \end{SPLCode}
181 \end{column}
182 \end{columns}
183 \end{block}
184 \begin{block}{Variable argument printing}
185 \begin{columns}[T]
186 \begin{column}[T]{0.34\linewidth}
187 \begin{SPLCode}
188 print("x is: ", x);
189 \end{SPLCode}
190 \end{column}
191 \begin{column}[T]{0.5\linewidth}
192 \begin{SPLCode}
193 print("x is: ");
194 print(x);
195 \end{SPLCode}
196 \end{column}
197 \end{columns}
198 \end{block}
199 \end{frame}
200
201
202
203 \end{document}