|
@@ -8611,8 +8611,41 @@ $\Rightarrow$
|
|
|
\label{fig:lexical-functions-example}
|
|
|
\end{figure}
|
|
|
|
|
|
+\begin{exercise}\normalfont
|
|
|
+Expand your compiler to handle $R_5$ as outlined in this chapter.
|
|
|
+Create 5 new programs that use \key{lambda} functions and make use of
|
|
|
+lexical scoping. Test your compiler on these new programs and all of
|
|
|
+your previously created test programs.
|
|
|
+\end{exercise}
|
|
|
|
|
|
|
|
|
+\section{Expose Allocation}
|
|
|
+\label{sec:expose-allocation-r5}
|
|
|
+
|
|
|
+Compile the $\CLOSURE{\itm{arity}}{\LP\Exp\ldots\RP}$ form into code
|
|
|
+that allocates and initializes a vector, similar to the translation of
|
|
|
+the \code{vector} operator in Section~\ref{sec:expose-allocation}.
|
|
|
+The only difference is replacing the use of
|
|
|
+\ALLOC{\itm{len}}{\itm{type}} with
|
|
|
+\ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}}.
|
|
|
+
|
|
|
+
|
|
|
+\section{Select Instructions}
|
|
|
+\label{sec:select-instructions-R5}
|
|
|
+
|
|
|
+Compile the \ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}} form
|
|
|
+similar to the \ALLOC{\itm{len}}{\itm{type}} form
|
|
|
+(Section~\ref{sec:select-instructions-gc}). The only difference is
|
|
|
+that you should place the \itm{arity} in the tag that is stored at
|
|
|
+position $0$ of the vector. Recall that in
|
|
|
+Section~\ref{sec:select-instructions-gc} we used the first $56$ bits
|
|
|
+of the 64-bit tag, but that the rest were unused. So the arity goes
|
|
|
+into the tag in bit positions $57$ through $63$.
|
|
|
+
|
|
|
+Compile the \code{procedure-arity} operator into a sequence of
|
|
|
+instructions that access the tag from position $0$ of the vector and
|
|
|
+shift it by $57$ bits to the right.
|
|
|
+
|
|
|
\begin{figure}[p]
|
|
|
\begin{tikzpicture}[baseline=(current bounding box.center)]
|
|
|
\node (R4) at (0,2) {\large $R_4$};
|
|
@@ -8638,19 +8671,19 @@ $\Rightarrow$
|
|
|
\path[->,bend left=15] (R4-2) edge [above] node
|
|
|
{\ttfamily\footnotesize uniquify} (R4-3);
|
|
|
\path[->,bend left=15] (R4-3) edge [right] node
|
|
|
- {\ttfamily\footnotesize reveal-functions} (F1-1);
|
|
|
+ {\ttfamily\footnotesize\color{red} reveal-functions} (F1-1);
|
|
|
\path[->,bend left=15] (F1-1) edge [below] node
|
|
|
{\ttfamily\footnotesize\color{red} convert-to-clos.} (F1-2);
|
|
|
\path[->,bend right=15] (F1-2) edge [above] node
|
|
|
{\ttfamily\footnotesize limit-fun.} (F1-3);
|
|
|
\path[->,bend right=15] (F1-3) edge [above] node
|
|
|
- {\ttfamily\footnotesize expose-alloc.} (F1-4);
|
|
|
+ {\ttfamily\footnotesize\color{red} expose-alloc.} (F1-4);
|
|
|
\path[->,bend right=15] (F1-4) edge [above] node
|
|
|
{\ttfamily\footnotesize remove-complex.} (F1-5);
|
|
|
\path[->,bend right=15] (F1-5) edge [right] node
|
|
|
{\ttfamily\footnotesize explicate-control} (C3-2);
|
|
|
\path[->,bend left=15] (C3-2) edge [left] node
|
|
|
- {\ttfamily\footnotesize select-instr.} (x86-2);
|
|
|
+ {\ttfamily\footnotesize\color{red} select-instr.} (x86-2);
|
|
|
\path[->,bend right=15] (x86-2) edge [left] node
|
|
|
{\ttfamily\footnotesize uncover-live} (x86-2-1);
|
|
|
\path[->,bend right=15] (x86-2-1) edge [below] node
|
|
@@ -8670,44 +8703,8 @@ $\Rightarrow$
|
|
|
Figure~\ref{fig:R5-passes} provides an overview of all the passes needed
|
|
|
for the compilation of $R_5$.
|
|
|
|
|
|
-\begin{exercise}\normalfont
|
|
|
-Expand your compiler to handle $R_5$ as outlined in this chapter.
|
|
|
-Create 5 new programs that use \key{lambda} functions and make use of
|
|
|
-lexical scoping. Test your compiler on these new programs and all of
|
|
|
-your previously created test programs.
|
|
|
-\end{exercise}
|
|
|
-
|
|
|
\clearpage
|
|
|
|
|
|
-
|
|
|
-\section{Expose Allocation}
|
|
|
-\label{sec:expose-allocation-r5}
|
|
|
-
|
|
|
-Compile the $\CLOSURE{\itm{arity}}{\LP\Exp\ldots\RP}$ form into code
|
|
|
-that allocates and initializes a vector, similar to the translation of
|
|
|
-the \code{vector} operator in Section~\ref{sec:expose-allocation}.
|
|
|
-The only difference is replacing the use of
|
|
|
-\ALLOC{\itm{len}}{\itm{type}} with
|
|
|
-\ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}}.
|
|
|
-
|
|
|
-
|
|
|
-\section{Select Instructions}
|
|
|
-\label{sec:select-instructions-R5}
|
|
|
-
|
|
|
-Compile the \ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}} form
|
|
|
-similar to the \ALLOC{\itm{len}}{\itm{type}} form
|
|
|
-(Section~\ref{sec:select-instructions-gc}). The only difference is
|
|
|
-that you should place the \itm{arity} in the tag that is stored at
|
|
|
-position $0$ of the vector. Recall that in
|
|
|
-Section~\ref{sec:select-instructions-gc} we used the first $56$ bits
|
|
|
-of the 64-bit tag, but that the rest were unused. So the arity goes
|
|
|
-into the tag in bit positions $57$ through $63$.
|
|
|
-
|
|
|
-Compile the \code{procedure-arity} operator into a sequence of
|
|
|
-instructions that access the tag from position $0$ of the vector and
|
|
|
-shift it by $57$ bits to the right.
|
|
|
-
|
|
|
-
|
|
|
\section{Challenge: Optimize Closures}
|
|
|
\label{sec:optimize-closures}
|
|
|
|