|
@@ -7789,7 +7789,7 @@ list of \code{passes} and then run the script to test your compiler.
|
|
|
|
|
|
\racket{Recall that the purpose of \code{explicate\_control} is to
|
|
\racket{Recall that the purpose of \code{explicate\_control} is to
|
|
make the order of evaluation explicit in the syntax of the program.
|
|
make the order of evaluation explicit in the syntax of the program.
|
|
- With the addition of \key{if} this get more interesting.}
|
|
|
|
|
|
+ With the addition of \key{if} this gets more interesting.}
|
|
%
|
|
%
|
|
The \code{explicate\_control} pass translates from \LangIf{} to \LangCIf{}.
|
|
The \code{explicate\_control} pass translates from \LangIf{} to \LangCIf{}.
|
|
%
|
|
%
|
|
@@ -7847,8 +7847,9 @@ above example would be as follows.
|
|
\end{lstlisting}
|
|
\end{lstlisting}
|
|
\end{minipage}
|
|
\end{minipage}
|
|
\end{center}
|
|
\end{center}
|
|
-However, if we take context into account we can do better and reduce
|
|
|
|
-the use of \key{cmpq} instructions for accessing the EFLAG register.
|
|
|
|
|
|
+Notice that the three instructions starting with \code{setl} are
|
|
|
|
+redundant: the conditional jump could come immediately after the first
|
|
|
|
+\code{cmpq}.
|
|
|
|
|
|
Our goal will be to compile \key{if} expressions so that the relevant
|
|
Our goal will be to compile \key{if} expressions so that the relevant
|
|
comparison instruction appears directly before the conditional jump.
|
|
comparison instruction appears directly before the conditional jump.
|
|
@@ -7894,7 +7895,7 @@ print(((y + 2) if x == 0 else (y + 10)) \
|
|
\end{center}
|
|
\end{center}
|
|
Unfortunately, this approach duplicates the two branches from the
|
|
Unfortunately, this approach duplicates the two branches from the
|
|
outer \code{if} and a compiler must never duplicate code! After all,
|
|
outer \code{if} and a compiler must never duplicate code! After all,
|
|
-the two branches could have been very large expressions.
|
|
|
|
|
|
+the two branches could be very large expressions.
|
|
|
|
|
|
We need a way to perform the above transformation but without
|
|
We need a way to perform the above transformation but without
|
|
duplicating code. That is, we need a way for different parts of a
|
|
duplicating code. That is, we need a way for different parts of a
|
|
@@ -7908,7 +7909,7 @@ label the code for each branch and insert jumps in all the places that
|
|
need to execute the branch.
|
|
need to execute the branch.
|
|
%
|
|
%
|
|
Likewise, our language \LangCIf{} provides the ability to label a
|
|
Likewise, our language \LangCIf{} provides the ability to label a
|
|
-sequence of code and to jump to a label via \code{goto}.
|
|
|
|
|
|
+sequence of statements and to jump to a label via \code{goto}.
|
|
%
|
|
%
|
|
%% In particular, we use a standard program representation called a
|
|
%% In particular, we use a standard program representation called a
|
|
%% \emph{control flow graph} (CFG), due to Frances Elizabeth
|
|
%% \emph{control flow graph} (CFG), due to Frances Elizabeth
|
|
@@ -7929,7 +7930,7 @@ sequence of code and to jump to a label via \code{goto}.
|
|
{\if\edition\racketEd
|
|
{\if\edition\racketEd
|
|
%
|
|
%
|
|
Recall that in Section~\ref{sec:explicate-control-Lvar} we implement
|
|
Recall that in Section~\ref{sec:explicate-control-Lvar} we implement
|
|
-\code{explicate\_control} for \LangVar{} using two mutually recursive
|
|
|
|
|
|
+\code{explicate\_control} for \LangVar{} using two recursive
|
|
functions, \code{explicate\_tail} and \code{explicate\_assign}. The
|
|
functions, \code{explicate\_tail} and \code{explicate\_assign}. The
|
|
former function translates expressions in tail position whereas the
|
|
former function translates expressions in tail position whereas the
|
|
later function translates expressions on the right-hand-side of a
|
|
later function translates expressions on the right-hand-side of a
|
|
@@ -7937,9 +7938,9 @@ later function translates expressions on the right-hand-side of a
|
|
have a new kind of position to deal with: the predicate position of
|
|
have a new kind of position to deal with: the predicate position of
|
|
the \key{if}. We need another function, \code{explicate\_pred}, that
|
|
the \key{if}. We need another function, \code{explicate\_pred}, that
|
|
decides how to compile an \key{if} by analyzing its predicate. So
|
|
decides how to compile an \key{if} by analyzing its predicate. So
|
|
-\code{explicate\_pred} takes an \LangIf{} expression and two \LangCIf{}
|
|
|
|
-tails for the then-branch and else-branch and outputs a tail. In the
|
|
|
|
-following paragraphs we discuss specific cases in the
|
|
|
|
|
|
+\code{explicate\_pred} takes an \LangIf{} expression and two
|
|
|
|
+\LangCIf{} tails for the then-branch and else-branch and outputs a
|
|
|
|
+tail. In the following paragraphs we discuss specific cases in the
|
|
\code{explicate\_tail}, \code{explicate\_assign}, and
|
|
\code{explicate\_tail}, \code{explicate\_assign}, and
|
|
\code{explicate\_pred} functions.
|
|
\code{explicate\_pred} functions.
|
|
%
|
|
%
|