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