--- /dev/null
+VerbEnvir { CleanCode CI }
--- /dev/null
+LATEX:=pdflatex
+LATEXFLAGS:=-shell-escape
+DOCUMENT:=p3
+
+.PHONY: all clean
+.SECONDARY: $(DOCUMENT).fmt
+
+all: $(DOCUMENT).pdf
+
+%.pdf: %.tex %.fmt
+ $(LATEX) $(LATEXFLAGS) $(basename $@)
+ $(LATEX) $(LATEXFLAGS) $(basename $@)
+
+%.fmt: pre.tex
+ $(LATEX) $(LATEXFLAGS) -ini -jobname="$(basename $@)" "&$(LATEX) $<\dump"
+
+clean:
+ $(RM) -v $(addprefix $(DOCUMENT).,aux fmt log nav out snm toc vrb pdf)
--- /dev/null
+\usepackage{listings}
+
+\lstdefinelanguage{Clean}{%
+ alsoletter={ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_`1234567890},
+ alsoletter={~!@\#$\%^\&*-+=?<>:|\\.},
+ morekeywords={generic,implementation,definition,dynamic,module,import,from,where,in,of,case,let,infix,infixr,infixl,class,instance,with,if,derive},
+ sensitive=true,
+ morecomment=[l]{//},
+ morecomment=[n]{/*}{*/},
+ morestring=[b]",
+ morestring=[b]',
+ emptylines=1,
+ basicstyle=\small,
+ identifierstyle=\small\ttfamily,
+ commentstyle=\itshape,
+ keywordstyle=\bfseries,
+ stringstyle=\ttfamily,
+ numbers=none,
+ showstringspaces=false,
+ basewidth=0.45em,
+ columns=[c]fixed,
+ keepspaces=true,
+ breaklines=false,
+ tabsize=4,
+ texcl=true,
+ escapeinside={(\#}{\#)},
+ literate=%
+ % Basic Clean constructs
+ {\\}{{$\lambda\:$}}1
+ {A.}{{$\forall\;\,$}}1
+ {E.}{{$\exists\;\,$}}1
+ {>}{{$>$}}1
+ {<}{{$<$}}1
+ {<=}{{$\leq$}}1
+ {>=}{{$\geq$}}1
+ {<>}{{$\neq$}}1
+ {->}{{$\rightarrow$}}2
+ {<-}{{$\leftarrow$}}1
+ {=}{{$=$}}1
+ {~}{{$\sim$}}1
+ {\#}{{$\sharp$}}1
+ {\{|}{{$\{\!|\!$}}1
+ {|\}}{{$\!|\!\}$}}1
+ {:=}{{$:=$}}2
+ {==}{{$==$}}2
+ {++}{{$+\!\!+$}}2
+ {+++}{{$+\!\!\!\!+\!\!\!\!+$}}2
+ {:==}{{$:==$}}3
+ {\{|*|\}}{{$\{\!|\!\!\star\!\!|\!\}$}}3
+ %
+ % Basic iTask constructs
+ {>||>}{{$\triangleright\triangleright$}}2
+ {>>=}{{\texttt{>>=}}}3
+ {>>|}{{\texttt{>>|}}}3
+ {?>>}{{\texttt{?>>}}}3
+ {!>>}{{\texttt{!>>}}}3
+ {-||-}{{\texttt{-||-}}}4
+ {.||.}{{\texttt{.||.}}}4
+ {.&&.}{{\texttt{.\&\&.}}}4
+}
+
+\newcommand{\CleanInline}[1]{\lstinline[language=Clean]¦#1¦}
+\newcommand{\CI}[1]{\CleanInline{#1}}
+
+\lstdefinestyle{numbers}{numbers=left, stepnumber=1, numberstyle=\tiny, numbersep=5pt}
+
+\lstnewenvironment{CleanCode}{\lstset{language=Clean,identifierstyle=\ttfamily}}{}
+\lstnewenvironment{CleanCodeN}{\lstset{language=Clean,style=numbers}}{}
+\lstnewenvironment{CleanCodeB}{\lstset{language=Clean,frame=single}}{}
+\lstnewenvironment{CleanCodeNB}{\lstset{language=Clean,style=numbers,frame=single}}{}
--- /dev/null
+%&p3
+\begin{document}
+\frame{\titlepage}
+
+\begin{frame}
+ \frametitle{\textsc{SPLC}}
+ \begin{block}{Features}
+ \begin{itemize}
+ \item Implementation language:
+ Clean ({\tiny\url{http://clean.cs.ru.nl}})
+ \item Type checking and type inference
+% \item No multiple recursion\ldots\pause\ yet\ldots\pause%
+ \item Higher order functions
+ \end{itemize}
+ \end{block}
+\end{frame}
+
+\begin{frame}
+ \frametitle{Progress since previous presentation}
+ \begin{itemize}[<+->]
+ \item Completely redid typechecking and inference
+ \item Extended semantic analysis with
+ \begin{itemize}[<+->]
+ \item Complain when unknown functions are used
+ \item Complain when there is no main
+ \item Complain when \CI{Void} is used as a non terminal type
+ \item Complain when duplicate functions are used
+ \item Complain when the main is not of the correct form
+ \end{itemize}
+ \item Higher order functions
+ \item Code generation for expressions
+ \item A lot needs to be done\ldots
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Type checking}
+ \begin{block}{Two pass}
+ \begin{itemize}
+ \item Constraint collecting
+ \item Constraint satisfaction
+ \end{itemize}
+ \end{block}
+ \pause%
+ \begin{block}{\CI{RWST}}
+ \begin{CleanCode}
+:: Scheme = Forall [TVar] Type
+:: Gamma :== Map String Scheme
+:: Typing a :== StateT (Gamma, [TVar]) (Either SemError) a
+:: Substitution :== `Map'.Map TVar Type
+:: Constraints :== [(Type, Type)]
+:: SemError
+ \end{CleanCode}
+ \end{block}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Code generation}
+ \begin{block}{}
+ \begin{CleanCode}
+:: SSMProgram :== [Instr]
+:: Instr = Instr String [Arg] String
+ | Lab Label
+:: Label :== String
+:: Arg = L Label | Lit Int | Raw String
+:: GenError = Error String
+:: GenMap :== Map String LoadPlace
+:: LoadPlace = LDA Int | LDC Int | LDH Int | LDL Int
+ | LDR Int | LDS Int
+ | FUNC Label
+ \end{CleanCode}
+ \end{block}
+ \pause%
+ \begin{block}{\CI{RWST} we meet again}
+ \begin{CleanCode}
+:: Gen a :== RWST () SSMProgram (GenMap, [Label]) (Either GenError) a
+ \end{CleanCode}
+ \end{block}
+\end{frame}
+
+\begin{frame}[fragile]
+ \frametitle{Future}
+ \begin{block}{Higher order functions}
+ Read up on how to implement higher order functions
+ \end{block}
+ \pause%
+ \begin{block}{Hand in hand with code generation}
+ To get a fully working compiler and report before the deadline
+ \end{block}
+\end{frame}
+\end{document}
--- /dev/null
+\documentclass{beamer}
+
+\usepackage{xcolor}
+\usepackage{listings}
+\usepackage{clean}
+
+\title[cc1516: Semantic analysis]{SPLC}
+\subtitle{\texttt{<splc>~::= <spl> <parser> `,' <lexer> `and' <compiler>}}
+\author[P. Jager, M. Lubbers]{Pim Jager\inst{1}\and Mart Lubbers\inst{1}}
+\institute[Radboud University]{%
+ \inst{1}%
+ Computer Science: Software Science\\
+ Radboud University
+}
+\subject{Code generation}
+\date{\today}
+
+\lstset{%
+ basicstyle=\ttfamily\footnotesize,
+ breaklines
+}
+
+\usetheme{Warsaw}
+\usecolortheme{beaver}
flop(n, l) {
return flip(n, 1:l);
}
+
+main() {
+ return 0;
+}
definition module gen
import AST
+import Data.Either
-gen :: AST -> String
\ No newline at end of file
+gen :: AST -> Either String String
labelStream :: [Label]
labelStream = ["lbl_" +++ toString i\\i<-[1..]]
-gen :: AST -> String
+gen :: AST -> Either String String
gen (AST fds) = case evalRWST prog "" ('Map'.newMap, labelStream) of
- Left (Error e) = e
- Right (_, p) = toString p
+ Left (Error e) = Left e
+ Right (_, p) = Right $ toString p
where
prog = tell [Instr "bra" [L "main"] ""] >>| mapM_ g fds
//gen _ = prog
parseFunType = satTok DoubleColonToken *> parseFT
where
parseFT :: Parser Token Type
- parseFT = (liftM2 (->>)
- ((parseBBraces parseFT <|> parseType) <* satTok ArrowToken)
- parseFT) <|> parseType
+ parseFT = (liftM2 (->>) (parseSF <* satTok ArrowToken) (parseFT)) <|>
+ parseSF
+ parseSF :: Parser Token Type
+ parseSF = parseBBraces parseFT <|> parseType
parseVarDecl :: Parser Token VarDecl
parseVarDecl = liftM4 VarDecl
import AST
-
:: Scheme = Forall [TVar] Type
:: Gamma :== 'Map'.Map String Scheme //map from Variables! to types
:: Typing a :== StateT (Gamma, [TVar]) (Either SemError) a
generalize t = gamma >>= \g-> pure $ Forall (difference (ftv t) (ftv g)) t
lookup :: String -> Typing Type
+lookup "isEmpty" = ListType <$> fresh
lookup k = gamma >>= \g-> case 'Map'.member k g of
False = liftT (Left $ UndeclaredVariableError zero k)
True = instantiate $ 'Map'.find k g
<<< " --version Show the version\n"
<<< " --[no-]lex Lexer output(default: disabled)\n"
<<< " --[no-]parse Parser output(default: disabled)\n"
- <<< " --[no-]sem Semantic analysis output(default: enabled)\n"
+ <<< " --[no-]sem Semantic analysis output(default: disabled)\n"
+ <<< " --[no-]code Code generation output(default: enabled)\n"
= snd $ fclose stdin w
# (contents, stdin, w) = readFileOrStdin stdin args.fp w
= case contents of
(Right ast)
# stdin = if (not args.sem) stdin (stdin
<<< "//SEM G\n" <<< toString ast <<< "//SEMA\n")
- # stdin = if (not args.gen) stdin (stdin
- <<< "//CODE GEN\n" <<< gen ast <<< "\n//CODE GEN\n")
- = snd $ fclose (stdin <<< "\n") w
+ = case gen ast of
+ (Left e) = snd $ fclose (stdin <<< e) w
+ (Right asm)
+ # stdin = if (not args.gen) stdin (stdin
+ <<< ";CODE GEN\n" <<< asm <<< "\n;CODE GEN\n")
+ = snd $ fclose (stdin <<< "\n") w
where
printConstraints :: Constraints -> String
printConstraints [] = ""
version=False,
lex=False,
parse=False,
- sem=True,
+ sem=False,
gen=True,
fp=Nothing,
help=False}, w)
pa ["--no-parse":r] o = pa r {o & parse=False}
pa ["--sem":r] o = pa r {o & sem=True}
pa ["--no-sem":r] o = pa r {o & sem=False}
- pa ["--gen":r] o = pa r {o & gen=True}
- pa ["--no-gen":r] o = pa r {o & gen=False}
+ pa ["--code":r] o = pa r {o & gen=True}
+ pa ["--no-code":r] o = pa r {o & gen=False}
pa [x:r] o = pa r {o & fp=Just x}
readFileOrStdin :: *File (Maybe String) *World -> *(Either String [Char], *File, *World)