Working on slides for p4
authorpimjager <pim@pimjager.nl>
Mon, 30 May 2016 15:31:15 +0000 (17:31 +0200)
committerpimjager <pim@pimjager.nl>
Mon, 30 May 2016 15:31:15 +0000 (17:31 +0200)
deliverables/p4/p4.tex
deliverables/p4/spl.sty [new file with mode: 0644]

index 382f8ee..adc62d2 100644 (file)
@@ -3,6 +3,7 @@
 \usepackage{xcolor}
 \usepackage{listings}
 \usepackage{clean}
+\usepackage{spl}
 
 \title[cc1516]{SPLC}
 \subtitle{\texttt{<splc>~::= <spl> <parser> `,' <lexer> `and' <compiler>}}
 
 \begin{document}
 \frame{\titlepage}
+
+\begin{frame}[fragile]
+       \frametitle{Higher order functions implemented using function pointers}
+
+       \begin{SPLCode}
+map(f, xs) :: (a -> b) -> [a] -> [b] {
+       if( isEmpty(xs) ) { return []; }
+       else { return f(xs.hd) : map(f, xs.tl); }
+}
+id(x) { return x; }
+
+main() {
+       map(id, 1:2:3:[]);
+}
+       \end{SPLCode}
+       \pause
+       \begin{itemize}
+               \item Function arguments are passed by name.
+               \item During compilation these are replaced by unique function ID's
+               \item During runtime the corresponding function label is retrieved using
+                       a dictionary like approach. 
+       \end{itemize}
+
+\end{frame}
+
+\begin{frame}[fragile]
+       \frametitle{Functions application can be curried}
+
+       \begin{SPLCode}
+plus(x,y) :: Int -> Int -> Int {
+       return x + y;
+}
+
+main() {
+       map(plus(1), 1:2:3:[]);
+}
+       \end{SPLCode}
+       \pause
+       \begin{columns}[T]
+               \begin{column}[T]{0.5\textwidth}
+                       \begin{enumerate}
+                               \item Function ID is placed on the heap
+                               \item Number of passed arguments is placed on the heap
+                               \item Arguments are pushed on the heap
+                       \end{enumerate}
+               \end{column}
+               \pause
+               \begin{column}[T]{0.5\textwidth}
+                       \begin{block}{Heap contents}
+                       \begin{tabular}{c | l | r}
+                               address & Content & \\  \hline
+                               n       & 8 & (1)\\  
+                               n+1 & 1 & (2)\\  
+                               n+2 & 4 & (3)
+                       \end{tabular}
+                       \end{block}
+               \end{column}
+       \end{columns}
+
+\end{frame}
+
 \end{document}
diff --git a/deliverables/p4/spl.sty b/deliverables/p4/spl.sty
new file mode 100644 (file)
index 0000000..8533252
--- /dev/null
@@ -0,0 +1,30 @@
+\usepackage{listings}
+
+\lstdefinelanguage{SPLCode}{%
+       alsoletter={ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_1234567890},
+       morekeywords={print,isEmpty,if,else,while,read},
+       sensitive=true,
+       morecomment=[l]{//},
+       morecomment=[n]{/*}{*/},
+       morestring=[b]",
+       morestring=[b]',
+       basicstyle=\small,
+       identifierstyle=\small\ttfamily,
+       commentstyle=\itshape,
+       keywordstyle=\bfseries,
+       stringstyle=\ttfamily,
+       showstringspaces=false,
+       basewidth=0.45em,
+       columns=[c]fixed,
+       keepspaces=true,
+       breaklines=true,
+       tabsize=4,
+       texcl=true,
+}
+
+\newcommand{\SPLInline}[1]{\lstinline[language=SPLCode]¦#1¦}
+\newcommand{\SI}[1]{\SPLInline{#1}}
+
+\lstdefinestyle{numbers}{numbers=left, stepnumber=1, numberstyle=\tiny, numbersep=5pt}
+
+\lstnewenvironment{SPLCode}{\lstset{language=SPLCode}}{}