\section*{Components} \begin{frame} \frametitle{Towards Attributed Trees as Components (1)} \begin{center} \begin{tikzpicture} [ nd/.style={circle, minimum size=9mm, very thick, draw=blue!50!black!50, top color=white, bottom color=blue!50!black!20,font=\scriptsize} , tr/.style={isosceles triangle,rotate=90, minimum size=12mm, very thick, draw=blue!50!black!50, top color=white, bottom color=blue!50!black!20,font=\footnotesize} , attr/.style={rectangle, minimum size=4mm, node distance=6mm, very thick, draw=black!50, top color=white, bottom color=black!20,font=\scriptsize} , inh/.style={attr} , syn/.style={attr} , leftfirst/.style={xshift=-4mm} , rightfirst/.style={xshift=4mm} , arr/.style={->,dashed, very thick} ] \node[nd](n1){|let|} [sibling distance=35mm, level distance=12mm] child { node[nd](n2){|cons|} [sibling distance=25mm] child { node[nd](n4){|decl|} child { node[nd](n5){|val|} } } child { [sibling distance=32mm] node[tr, xshift=-3mm](n6){|Decls|} } } child { [sibling distance=20mm] node[tr, xshift=-3mm](n3){|Expr|} }; \node[right of=n3,xshift=-4mm](nx){}; \begin{pgfonlayer}{background} \node[rectangle,fit=(n1)(nx)(n5), draw=black!50, fill=white]{}; \end{pgfonlayer} \node[above of=n1,xshift=-20mm,yshift=-4mm, draw=black, fill=white, font=\scriptsize](i1){ \begin{tabular}{l} |visit gather| \\ |syn gathEnv| \\ \end{tabular} }; \node[above of=n1,xshift=17mm,yshift=0mm, draw=black, fill=white, font=\scriptsize](i2){ \begin{tabular}{l} |visit distribute| \\ |inh finEnv| \\ |syn errs| \end{tabular} }; \pause \node[nd, above of=n1, xshift=-60mm, yshift=10mm](n20){|node|} child { node(target){}; } child { node{}; }; \draw[-](n20) to (n1); \draw[-](n20) to (target); \pause \node[below of=target, xshift=20mm]{\scriptsize{ \texths \begin{code} sem :: RealTree loc.c = ... child comp :: Comp = loc.c comp.finEnv = [] \end{code} }}; \end{tikzpicture} \end{center} \end{frame} \begin{frame} \frametitle{Show stoppers} \begin{enumerate} \item Verbose AST \begin{itemize} \item Expressions, declarations: too fine grained \item Essence of name analysis: binding sites, use sites, scoping \end{itemize} \item Interfacing only with root insufficient \begin{itemize} \item Access to the values found for identifiers \item Access to the error messages at one particular node \end{itemize} \item Extend a component? \begin{itemize} \item Mismatch between offered and needed functionality \item Opening up the component, without affecting the original \item Overriding attributes, adding new attributes \end{itemize} \item Intuitiveness and predictability of code? \begin{itemize} \item Delegation of work: finished when results are needed? \item Functional code (side effect free/order independent) \end{itemize} \end{enumerate} \end{frame} \section*{More abstract AST} \begin{frame} \frametitle{Coarser AST} \begin{tikzpicture} [ nd/.style={circle, minimum size=9mm, very thick, draw=blue!50!black!50, top color=white, bottom color=blue!50!black!20,font=\scriptsize} , nd2/.style={circle, minimum size=9mm, very thick, draw=red!50!black!50, top color=white, bottom color=red!50!black!20,font=\scriptsize} , attr/.style={rectangle, minimum size=4mm, node distance=6mm, very thick, draw=black!50, top color=white, bottom color=black!20,font=\scriptsize} , inh/.style={attr} , syn/.style={attr} , leftfirst/.style={xshift=-4mm} , rightfirst/.style={xshift=4mm} , arr/.style={->,dashed, very thick} ] \node[nd](n1){|let|} [sibling distance=60mm, level distance=12mm] child { node[nd](n2){|cons|} [sibling distance=32mm] child { node[nd](n4){|x=|} child { node[nd](n5){|val|} } } child { [sibling distance=32mm] node[nd](n6){|cons|} child { node[nd](n7){|f=|} child { node[nd](n8){|\x|} child { node[nd](n9){|x|} } } } child { node[nd](n10){|nil|} } } } child { [sibling distance=20mm] node[nd](n3){|app|} child { node[nd](n11){|f|} } child { node[nd](n12){|x|} } }; \pause \node[nd2,above of=n1](r1){|sc|} [level distance=12mm] child { node[nd2](r2){|split|} [sibling distance=50mm] child { node[nd2](r3){|split|} [sibling distance=30mm] child { node[nd2](r4){|def x|} } child { node[nd2](r5){|split|} child { node[nd2](r6){|def f|} } child { node[nd2](r7){|sc|} child { node[nd2](r8){|split|} child { node[nd2](r12){|def x|} } child { node[nd2](r13){|use x|} } } } } } child { node[nd2](r9){|split|} [sibling distance=25mm] child { node[nd2](r10){|use f|} } child { node[nd2](r11){|use x|} } } }; \end{tikzpicture} \end{frame} \begin{frame} \frametitle{Coarser AST} \begin{center} \begin{tikzpicture} [ nd/.style={circle, minimum size=9mm, very thick, draw=blue!50!black!50, top color=white, bottom color=blue!50!black!20,font=\scriptsize} , nd2/.style={circle, minimum size=9mm, very thick, draw=red!50!black!50, top color=white, bottom color=red!50!black!20,font=\scriptsize} , attr/.style={rectangle, minimum size=4mm, node distance=6mm, very thick, draw=black!50, top color=white, bottom color=black!20,font=\scriptsize} , inh/.style={attr} , syn/.style={attr} , leftfirst/.style={xshift=-4mm} , rightfirst/.style={xshift=4mm} , arr/.style={->,dashed, very thick} ] \node[nd2](r1){|sc|} child { node[nd2](r2){|split|} [sibling distance=30mm] child { node[nd2](r3){|def x|} } child { node[nd2](r4){|use x|} } }; \end{tikzpicture} \end{center} \end{frame} \begin{frame} \frametitle{More Abstract Code} \scriptsize{ \begin{code} itf Name alpha ^^ visit gather ^^ syn gathEnv huse {++} {[]} :: [(String, alpha)] ^^ visit distribute ^^ inh finEnv :: [(String, alpha)] ^^ syn errors huse {++} {[]}:: [String] sem_Name_Scope b = sem :: Name alpha child body :: Name alpha = b body.finEnv = (lhs.finEnv \\ (map fst body.gathEnv)) ++ body.gathEnv sem_Name_Split l r = sem :: Name alpha child left :: Name alpha = l child right :: Name alpha = r sem_Name_Def x v = sem :: Name alpha lhs.gathEnv = [(x,v)] lhs.errors = if length (filter ((== x) . fst) lhs.finEnv) > 1 then ["dup: " ++ x] else [] sem_Name_Use x = sem :: Name alpha loc.mbVal = lookup x lhs.finEnv lhs.errors = if isNothing loc.mbVal then ["missing: " ++ x] else [] loc.val = maybe undefined id loc.mbVal -- how to access this?? \end{code}} \end{frame} \begin{frame} \frametitle{Instantiation of the component} \small{ \begin{code} itf Expr syn nmTree :: T_Name st Ty sem_Expr_Lam x b = sem :: Expr child body :: Expr = b loc.ty = ... lhs.nmTree = sem_Name_Scope $ sem_Name_Split (sem_Name_Def x loc.ty) $ body.nmTree sem_Expr_Var x = sem :: Expr lhs.nmTree = sem_Name_Use x sem_Root_Root b = sem :: Root child body :: Expr = b child name :: Name Ty = body.nmTree lhs.errors = name.errors \end{code}} \end{frame} \section*{Interface to Subtrees} \begin{frame} \frametitle{Towards Attributed Trees as Components (2)} \begin{center} \begin{tikzpicture} [ nd/.style={circle, minimum size=9mm, very thick, draw=blue!50!black!50, top color=white, bottom color=blue!50!black!20,font=\scriptsize} , nd2/.style={circle, minimum size=9mm, very thick, draw=red!50!black!50, top color=white, bottom color=red!50!black!20,font=\scriptsize} , nd3/.style={circle, minimum size=6mm, very thick, draw=green!50!black!50, top color=white, bottom color=green!50!black!20,font=\scriptsize} , attr/.style={rectangle, minimum size=2mm, node distance=4mm, very thick, draw=black!50, top color=white, bottom color=black!20,font=\scriptsize} , inh/.style={attr} , syn/.style={attr} , leftfirst/.style={xshift=-4mm} , rightfirst/.style={xshift=4mm} , arr/.style={->,dashed, very thick} ] \node[nd2](r1){|sc|} child { node[nd2](r2){|split|} [sibling distance=30mm] child { node[nd2](r3){|def x|} } child { node[nd2](r4){|use x|} } }; \begin{pgfonlayer}{background} \node[rectangle,fit=(r1)(r2)(r3)(r4), draw=black!50, fill=white]{}; \end{pgfonlayer} \node[nd3,left of=r3,xshift=5mm](r5){}; \node[nd3,right of=r4,xshift=-5mm](r6){}; \node[above of=r1,yshift=4mm, draw=black, fill=white, font=\scriptsize](i1){ \texths \begin{code} itf Name visit gather syn gathEnv visit distribute inh finEnv \end{code} }; \node[left of=r5,xshift=-2mm, draw=black, fill=white, font=\scriptsize](i2) { \texths \begin{code} itf NameDef visit supply syn nm syn value visit outcome inh errors \end{code} }; \node[right of=r6,xshift=2mm, draw=black, fill=white, font=\scriptsize](i2) { \texths \begin{code} itf NameUse visit supply syn nm visit outcome inh value inh errors \end{code} }; \end{tikzpicture} \end{center} \end{frame} \begin{frame} \frametitle{Instantiation and Exchange} \begin{center} \begin{tikzpicture} [ nd/.style={circle, minimum size=9mm, very thick, draw=blue!50!black!50, top color=white, bottom color=blue!50!black!20,font=\scriptsize} , nd2/.style={circle, minimum size=9mm, very thick, draw=red!50!black!50, top color=white, bottom color=red!50!black!20,font=\scriptsize} , nd3/.style={circle, minimum size=6mm, very thick, draw=green!50!black!50, top color=white, bottom color=green!50!black!20,font=\scriptsize} , attr/.style={rectangle, minimum size=4mm, node distance=6mm, very thick, draw=black!50, top color=white, bottom color=black!20,font=\scriptsize} , inh/.style={attr} , syn/.style={attr} , leftfirst/.style={xshift=-4mm} , rightfirst/.style={xshift=4mm} , arr/.style={->,dashed, very thick} ] \node[nd](n1){|root|} [sibling distance=50mm] child { node[nd](n2){|app|} [sibling distance=10mm, level distance=25mm] child { node{} } child { node[nd](n3){|var|} } } child { node[nd2](n7){|sc|} [level distance=10mm] child { node[nd2](n4){|split|} [sibling distance=10mm] child { node[nd2](n5){|use|} } child { node{} } } }; \pause \node[nd3, right of=n3, xshift=-5mm](n6){}; \draw[-](n6) to (n5); \node[attr,below of=n6](a4){}; \node[attr,above of=n6](a3){}; \node[attr,right of=a3](a5){}; \node[above of=a5,xshift=5mm,yshift=-5mm]{|<- value,errors|}; \node[right of=a4]{|nm ->|}; \end{tikzpicture} \end{center} \end{frame} \begin{frame} \frametitle{Nested AG Code} \scriptsize{ \begin{code} itf NameUse alpha visit supply syn nm :: String visit outcome inh value :: alpha inh errors :: [String] sem_Name_Use extTree = sem :: Name alpha child ext :: NameUse alpha = extTree loc.mbVal = lookup ext.nm lhs.finEnv ext.value = maybe undefined id loc.mbVal ext.errors = if isNothing loc.mbVal then ["missing: " ++ ext.nm] sem_Expr_Var nm = sem :: Expr lhs.nmTree = sem_Name_Use $ sem :: NameUse Type -- nested sem lhs.nm = nm loc.errors = lhs.errors loc.value = lhs.value ... = loc.errors -- local attributes ... = loc.value -- shared with nested sem \end{code}} \end{frame} \begin{frame} \frametitle{Referentially transparent?} \begin{itemize} \item Unable to guarantee that nested sem is executed exactly once \item We can guarantee referential transparency \begin{itemize} \item Requirement: code is ``orderable'' \item Then: ``an expression for an attribute can be replaced with its value, without affecting the program'' \end{itemize} \item Referential transparency is important! \end{itemize} \end{frame}