improved presentation
[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{Today}
32 \begin{itemize}
33 \item Higher order functions
34 \item Anonymous lambda functions
35 \item Syntactic sugar
36 \item Future work
37 \item Demo
38 \end{itemize}
39 \end{frame}
40
41 \begin{frame}[fragile]
42 \frametitle{Higher order functions implemented using function pointers}
43
44 \begin{SPLCode}
45 map(f, xs) :: (a -> b) -> [a] -> [b] {
46 if( isEmpty(xs) ) { return []; }
47 else { return f(xs.hd) : map(f, xs.tl); }
48 }
49 id(x) { return x; }
50
51 main() {
52 map(id, 1:2:3:[]);
53 }
54 \end{SPLCode}
55 \pause
56 \begin{itemize}
57 \item Function arguments are passed by name.
58 \item During compilation these are replaced by unique function ID's
59 \item During runtime the corresponding function label is retrieved using
60 a dictionary like approach.
61 \end{itemize}
62
63 \end{frame}
64
65 \begin{frame}[fragile]
66 \frametitle{Function application can be curried}
67
68 \begin{SPLCode}
69 plus(x,y) :: Int -> Int -> Int {
70 return x + y;
71 }
72
73 main() {
74 map(plus(4), 1:2:3:[]);
75 }
76 \end{SPLCode}
77 \pause
78 \begin{columns}[T]
79 \begin{column}[T]{0.5\textwidth}
80 \begin{enumerate}
81 \item Function ID is placed on the heap
82 \item Number of passed arguments is placed on the heap
83 \item Arguments are pushed on the heap
84 \end{enumerate}
85 \end{column}
86 \pause
87 \begin{column}[T]{0.5\textwidth}
88 \begin{block}{Heap contents}
89 \begin{tabular}{c | l | r}
90 address & Content & \\ \hline
91 n & 8 & (1)\\
92 n+1 & 1 & (2)\\
93 n+2 & 4 & (3)
94 \end{tabular}
95 \end{block}
96 \end{column}
97 \end{columns}
98
99 \end{frame}
100
101
102 \begin{frame}[fragile]
103 \frametitle{SPLC has lambda functions through AST rewriting}
104 \framesubtitle{\texttt{<LamdaExpr> ::= `\textbackslash'<id>*
105 `->' <Expr>}}
106 \begin{block}{Implementation}<3->
107 Implemented by promoting lambdas to regular named functions
108 prior to semantical analysis.
109 \end{block}
110 \begin{columns}
111 \begin{column}[T]{0.5\textwidth}<1->
112 \begin{SPLCode}
113 main() {
114 map(\x-> x+1, 1:2:3:[]);
115 }
116 \end{SPLCode}
117 \end{column}
118 \begin{column}[T]{0.5\textwidth}<4->
119 \begin{SPLCode}
120 1lambda_23(x) {
121 return x+1;
122 }
123 main() {
124 map(1lambda_23, 1:2:3:[]);
125 }
126 \end{SPLCode}
127 \end{column}
128 \end{columns}
129 \begin{itemize}
130 \item<2-> SPLC supports anonymous lambda functions with arbitrary arity
131 \item<2-> Lambdas are fully type checked, same as regular functions
132 \end{itemize}
133 \end{frame}
134
135 \begin{frame}[fragile]
136 \frametitle{Syntactic sugar to ease our programmers lives}
137 \begin{block}{Global constants}
138 \begin{itemize}
139 \item SPLC does \emph{not} feature global variables.
140 \begin{itemize}
141 \item We want to protect our users from global state (as much
142 as possible).
143 \end{itemize}
144 \item Global constants allowed through \texttt{let} statements
145 \item \texttt{<LetDecl> ::= `let' <type> <id> `=' <Expr> `;'}
146 \item Lets are rewritten to constant functions
147 \end{itemize}
148 \begin{columns}[T]
149 \begin{column}[T]{0.4\linewidth}
150 \begin{SPLCode}
151 let Int x = 5;
152 \end{SPLCode}
153 \end{column}
154 \begin{column}[T]{0.4\linewidth}
155 \begin{SPLCode}
156 x() :: Int { return 5; }
157 \end{SPLCode}
158 \end{column}
159 \end{columns}
160 \end{block}
161 \end{frame}
162
163 \begin{frame}[fragile]
164 \frametitle{Syntactic sugar to ease our programmers lives}
165 \framesubtitle{continued}
166 \begin{block}{String Literals}
167 \begin{columns}[T]
168 \begin{column}[T]{0.34\linewidth}
169 \begin{SPLCode}
170 var a = "Hello world!";
171 \end{SPLCode}
172 \end{column}
173 \begin{column}[T]{0.5\linewidth}
174 \begin{SPLCode}
175 var a = 'H':'e':'l':'l':'o':' ':
176 'w':'o':'r':'l':'d':'!':[];
177 \end{SPLCode}
178 \end{column}
179 \end{columns}
180 \end{block}
181 \begin{block}{List Literals}
182 \begin{columns}[T]
183 \begin{column}[T]{0.34\linewidth}
184 \begin{SPLCode}
185 var xs = [1,2,3];
186 \end{SPLCode}
187 \end{column}
188 \begin{column}[T]{0.5\linewidth}
189 \begin{SPLCode}
190 var xs = 1:2:3:[];
191 \end{SPLCode}
192 \end{column}
193 \end{columns}
194 \end{block}
195 \begin{block}{Variable argument printing}
196 \begin{columns}[T]
197 \begin{column}[T]{0.34\linewidth}
198 \begin{SPLCode}
199 print("x is: ", x, "\n");
200 \end{SPLCode}
201 \end{column}
202 \begin{column}[T]{0.5\linewidth}
203 \begin{SPLCode}
204 print("x is: ");
205 print(x);
206 print("\n");
207 \end{SPLCode}
208 \end{column}
209 \end{columns}
210 \end{block}
211 \end{frame}
212
213 \begin{frame}[fragile]
214 \frametitle{Improvements and Future Work}
215 \begin{block}{Improve type checker}
216 Type checker allows some programs which should not be allowed\\
217 e.g. the polymorphic value examples of Markus.
218 \end{block}
219 \pause
220 \begin{block}{Improve overloaded equality}
221 Equality only preforms shallow (JAVA-style) equality on Lists and Tuple
222 types.
223 \end{block}
224 \pause
225 \begin{block}{Improve error reporting}
226 Not all errors are reported with the position the error occurs in. Most
227 notably type errors always occur on position (0,0).
228 \end{block}
229 \end{frame}
230
231 \begin{frame}
232 \frametitle{Questions \& Cool demo's}
233
234 \end{frame}
235
236
237 \end{document}