|
@@ -956,11 +956,12 @@ In the next section we see our first example of a compiler.
|
|
\section{Example Compiler: a Partial Evaluator}
|
|
\section{Example Compiler: a Partial Evaluator}
|
|
\label{sec:partial-evaluation}
|
|
\label{sec:partial-evaluation}
|
|
|
|
|
|
-In this section we consider a compiler that translates $R_0$
|
|
|
|
-programs into $R_0$ programs that may be more efficient, that is,
|
|
|
|
-this compiler is an optimizer. Our optimizer will accomplish this by
|
|
|
|
-trying to eagerly compute the parts of the program that do not depend
|
|
|
|
-on any inputs. For example, given the following program
|
|
|
|
|
|
+In this section we consider a compiler that translates $R_0$ programs
|
|
|
|
+into $R_0$ programs that may be more efficient, that is, this compiler
|
|
|
|
+is an optimizer. This optimizer eagerly computes the parts of the
|
|
|
|
+program that do not depend on any inputs, a process known as
|
|
|
|
+\emph{partial evaluation}~\cite{Jones:1993uq}. For example, given the
|
|
|
|
+following program
|
|
\begin{lstlisting}
|
|
\begin{lstlisting}
|
|
(+ (read) (- (+ 5 3)))
|
|
(+ (read) (- (+ 5 3)))
|
|
\end{lstlisting}
|
|
\end{lstlisting}
|
|
@@ -1009,9 +1010,8 @@ functions is the output of partially evaluating the children.
|
|
|
|
|
|
The \texttt{pe-neg} and \texttt{pe-add} functions check whether their
|
|
The \texttt{pe-neg} and \texttt{pe-add} functions check whether their
|
|
arguments are integers and if they are, perform the appropriate
|
|
arguments are integers and if they are, perform the appropriate
|
|
-arithmetic. Otherwise, they use quasiquote to create an AST node for
|
|
|
|
-the operation (either negation or addition) and use comma to splice in
|
|
|
|
-the children.
|
|
|
|
|
|
+arithmetic. Otherwise, they create an AST node for the operation
|
|
|
|
+(either negation or addition).
|
|
|
|
|
|
To gain some confidence that the partial evaluator is correct, we can
|
|
To gain some confidence that the partial evaluator is correct, we can
|
|
test whether it produces programs that get the same result as the
|
|
test whether it produces programs that get the same result as the
|
|
@@ -7837,8 +7837,11 @@ The utility function described in this section can be found in the
|
|
\key{utilities.rkt} file.
|
|
\key{utilities.rkt} file.
|
|
|
|
|
|
The \key{read-program} function takes a file path and parses that file
|
|
The \key{read-program} function takes a file path and parses that file
|
|
-(it must be a Racket program) into an abstract syntax tree (as an
|
|
|
|
-S-expression) with a \key{program} AST at the top.
|
|
|
|
|
|
+(it must be a Racket program) into an abstract syntax tree with a
|
|
|
|
+\key{Program} node at the top.
|
|
|
|
+
|
|
|
|
+The \key{parse-program} function takes an S-expression representation
|
|
|
|
+of an AST and converts it into the struct-based representation.
|
|
|
|
|
|
The \key{assert} function displays the error message \key{msg} if the
|
|
The \key{assert} function displays the error message \key{msg} if the
|
|
Boolean \key{bool} is false.
|
|
Boolean \key{bool} is false.
|