|
@@ -22131,10 +22131,11 @@ needed to compile \LangPoly{}.
|
|
|
|
|
|
We provide interpreters for each of the source languages \LangInt{},
|
|
|
\LangVar{}, $\ldots$ in the files \code{interp\_Lint.rkt},
|
|
|
-\code{interp-Lvar.rkt}, etc. The interpreters for the intermediate
|
|
|
-languages \LangCVar{} and \LangCIf{} are in \code{interp-Cvar.rkt} and
|
|
|
-\code{interp-C1.rkt}. The interpreters for \LangCVec{}, \LangCFun{}, pseudo-x86,
|
|
|
-and x86 are in the \key{interp.rkt} file.
|
|
|
+\code{interp-Lvar.rkt}, and so on. The interpreters for the
|
|
|
+intermediate languages \LangCVar{} and \LangCIf{} are in
|
|
|
+\code{interp-Cvar.rkt} and \code{interp-C1.rkt}. The interpreters for
|
|
|
+\LangCVec{}, \LangCFun{}, pseudo-x86, and x86 are in the
|
|
|
+\key{interp.rkt} file.
|
|
|
|
|
|
\section{Utility Functions}
|
|
|
\label{appendix:utilities}
|
|
@@ -22149,55 +22150,55 @@ interpreters on each of the specified tests to check whether each pass
|
|
|
is correct. The \key{interp-tests} function has the following
|
|
|
parameters:
|
|
|
\begin{description}
|
|
|
-\item[name (a string)] a name to identify the compiler,
|
|
|
-\item[typechecker] a function of exactly one argument that either
|
|
|
+\item[name (a string)] A name to identify the compiler,
|
|
|
+\item[typechecker] A function of exactly one argument that either
|
|
|
raises an error using the \code{error} function when it encounters a
|
|
|
- type error, or returns \code{\#f} when it encounters a type
|
|
|
+ type error or returns \code{\#f} when it encounters a type
|
|
|
error. If there is no type error, the type checker returns the
|
|
|
program.
|
|
|
|
|
|
-\item[passes] a list with one entry per pass. An entry is a list with
|
|
|
- four things:
|
|
|
+\item[passes] A list with one entry per pass. An entry is a list
|
|
|
+ consisting of four things:
|
|
|
\begin{enumerate}
|
|
|
- \item a string giving the name of the pass,
|
|
|
+ \item a string giving the name of the pass;
|
|
|
\item the function that implements the pass (a translator from AST
|
|
|
- to AST),
|
|
|
+ to AST);
|
|
|
\item a function that implements the interpreter (a function from
|
|
|
- AST to result value) for the output language,
|
|
|
- \item and a type checker for the output language. Type checkers for
|
|
|
- the $R$ and $C$ languages are provided in the support code. For
|
|
|
- example, the type checkers for \LangVar{} and \LangCVar{} are in
|
|
|
+ AST to result value) for the output language; and,
|
|
|
+ \item a type checker for the output language. Type checkers for
|
|
|
+ all the $\Lang{}$ and $\CLang{}$ languages are provided in the support code.
|
|
|
+ For example, the type checkers for \LangVar{} and \LangCVar{} are in
|
|
|
\code{type-check-Lvar.rkt} and \code{type-check-Cvar.rkt}. The
|
|
|
type checker entry is optional. The support code does not provide
|
|
|
type checkers for the x86 languages.
|
|
|
\end{enumerate}
|
|
|
|
|
|
-\item[source-interp] an interpreter for the source language. The
|
|
|
- interpreters from Appendix~\ref{appendix:interp} make a good choice.
|
|
|
+\item[source-interp] An interpreter for the source language. The
|
|
|
+ interpreters from appendix~\ref{appendix:interp} make a good choice.
|
|
|
|
|
|
-\item[test-family (a string)] for example, \code{"var"}, \code{"cond"}, etc.
|
|
|
-\item[tests] a list of test numbers that specifies which tests to
|
|
|
- run. (see below)
|
|
|
+\item[test-family (a string)] For example, \code{"var"} or \code{"cond"}.
|
|
|
+\item[tests] A list of test numbers that specifies which tests to
|
|
|
+ run (explained next).
|
|
|
\end{description}
|
|
|
%
|
|
|
The \key{interp-tests} function assumes that the subdirectory
|
|
|
\key{tests} has a collection of Racket programs whose names all start
|
|
|
with the family name, followed by an underscore and then the test
|
|
|
-number, ending with the file extension \key{.rkt}. Also, for each test
|
|
|
+number, and ending with the file extension \key{.rkt}. Also, for each test
|
|
|
program that calls \code{read} one or more times, there is a file with
|
|
|
-the same name except that the file extension is \key{.in} that
|
|
|
+the same name except that the file extension is \key{.in}, which
|
|
|
provides the input for the Racket program. If the test program is
|
|
|
expected to fail type checking, then there should be an empty file of
|
|
|
-the same name but with extension \key{.tyerr}.
|
|
|
+the same name with extension \key{.tyerr}.
|
|
|
|
|
|
|
|
|
\paragraph{\code{compiler-tests}}
|
|
|
|
|
|
-runs the compiler passes to generate x86 (a \key{.s} file) and then
|
|
|
+Runs the compiler passes to generate x86 (a \key{.s} file) and then
|
|
|
runs the GNU C compiler (gcc) to generate machine code. It runs the
|
|
|
machine code and checks that the output is $42$. The parameters to the
|
|
|
\code{compiler-tests} function are similar to those of the
|
|
|
-\code{interp-tests} function, and consist of
|
|
|
+\code{interp-tests} function, and they consist of
|
|
|
\begin{itemize}
|
|
|
\item a compiler name (a string),
|
|
|
\item a type checker,
|
|
@@ -22209,32 +22210,32 @@ machine code and checks that the output is $42$. The parameters to the
|
|
|
|
|
|
\paragraph{\code{compile-file}}
|
|
|
|
|
|
-takes a description of the compiler passes (see the comment for
|
|
|
+Takes a description of the compiler passes (see the comment for
|
|
|
\key{interp-tests}) and returns a function that, given a program file
|
|
|
-name (a string ending in \key{.rkt}), applies all of the passes and
|
|
|
+name (a string ending in \key{.rkt}), applies all the passes and
|
|
|
writes the output to a file whose name is the same as the program file
|
|
|
-name but with \key{.rkt} replaced with \key{.s}.
|
|
|
+name with extension \key{.rkt} replaced by \key{.s}.
|
|
|
|
|
|
|
|
|
\paragraph{\code{read-program}}
|
|
|
|
|
|
-takes a file path and parses that file (it must be a Racket program)
|
|
|
+Takes a file path and parses that file (it must be a Racket program)
|
|
|
into an abstract syntax tree.
|
|
|
|
|
|
\paragraph{\code{parse-program}}
|
|
|
|
|
|
-takes an S-expression representation of an abstract syntax tree and converts it into
|
|
|
-the struct-based representation.
|
|
|
+Takes an S-expression representation of an abstract syntax tree and
|
|
|
+converts it into the struct-based representation.
|
|
|
|
|
|
\paragraph{\code{assert}}
|
|
|
|
|
|
-takes two parameters, a string (\code{msg}) and Boolean (\code{bool}),
|
|
|
+Takes two parameters, a string (\code{msg}) and Boolean (\code{bool}),
|
|
|
and displays the message \key{msg} if the Boolean \key{bool} is false.
|
|
|
|
|
|
\paragraph{\code{lookup}}
|
|
|
|
|
|
% remove discussion of lookup? -Jeremy
|
|
|
-takes a key and an alist, and returns the first value that is
|
|
|
+takes a key and an alist and returns the first value that is
|
|
|
associated with the given key, if there is one. If not, an error is
|
|
|
triggered. The alist may contain both immutable pairs (built with
|
|
|
\key{cons}) and mutable pairs (built with \key{mcons}).
|
|
@@ -22243,7 +22244,7 @@ triggered. The alist may contain both immutable pairs (built with
|
|
|
|
|
|
\fi %\racketEd
|
|
|
|
|
|
-\section{x86 Instruction Set Quick-Reference}
|
|
|
+\section{x86 Instruction Set Quick Reference}
|
|
|
\label{sec:x86-quick-reference}
|
|
|
\index{subject}{x86}
|
|
|
|
|
@@ -22252,7 +22253,7 @@ do. We write $A \to B$ to mean that the value of $A$ is written into
|
|
|
location $B$. Address offsets are given in bytes. The instruction
|
|
|
arguments $A, B, C$ can be immediate constants (such as \code{\$4}),
|
|
|
registers (such as \code{\%rax}), or memory references (such as
|
|
|
-\code{-4(\%ebp)}). Most x86 instructions only allow at most one memory
|
|
|
+\code{-4(\%ebp)}). Most x86 instructions allow at most one memory
|
|
|
reference per instruction. Other operands must be immediates or
|
|
|
registers.
|
|
|
|
|
@@ -22271,13 +22272,13 @@ registers.
|
|
|
\texttt{popq} $A$ & $*\mathtt{rsp} \to A; \mathtt{rsp} + 8 \to \mathtt{rsp}$ \\
|
|
|
\texttt{pushq} $A$ & $\texttt{rsp} - 8 \to \texttt{rsp}; A \to *\texttt{rsp}$\\
|
|
|
\texttt{leaq} $A$,$B$ & $A \to B$ ($B$ must be a register) \\
|
|
|
-\texttt{cmpq} $A$, $B$ & compare $A$ and $B$ and set the flag register ($B$ must not
|
|
|
+\texttt{cmpq} $A$, $B$ & Compare $A$ and $B$ and set the flag register ($B$ must not
|
|
|
be an immediate) \\
|
|
|
\texttt{je} $L$ & \multirow{5}{3.7in}{Jump to label $L$ if the flag register
|
|
|
- matches the condition code of the instruction, otherwise go to the
|
|
|
- next instructions. The condition codes are \key{e} for ``equal'',
|
|
|
- \key{l} for ``less'', \key{le} for ``less or equal'', \key{g}
|
|
|
- for ``greater'', and \key{ge} for ``greater or equal''.} \\
|
|
|
+ matches the condition code of the instruction; otherwise go to the
|
|
|
+ next instructions. The condition codes are \key{e} for \emph{equal},
|
|
|
+ \key{l} for \emph{less}, \key{le} for \emph{less or equal}, \key{g}
|
|
|
+ for \emph{greater}, and \key{ge} for \emph{greater or equal}.} \\
|
|
|
\texttt{jl} $L$ & \\
|
|
|
\texttt{jle} $L$ & \\
|
|
|
\texttt{jg} $L$ & \\
|
|
@@ -22286,7 +22287,7 @@ registers.
|
|
|
\texttt{movq} $A$, $B$ & $A \to B$ \\
|
|
|
\texttt{movzbq} $A$, $B$ &
|
|
|
\multirow{3}{3.7in}{$A \to B$, \text{where } $A$ is a single-byte register
|
|
|
- (e.g., \texttt{al} or \texttt{cl}), $B$ is a 8-byte register,
|
|
|
+ (e.g., \texttt{al} or \texttt{cl}), $B$ is an 8-byte register,
|
|
|
and the extra bytes of $B$ are set to zero.} \\
|
|
|
& \\
|
|
|
& \\
|
|
@@ -22296,7 +22297,7 @@ registers.
|
|
|
\texttt{salq} $A$, $B$ & $B$ \texttt{<<} $A \to B$ (arithmetic shift left, where $A$ is a constant)\\
|
|
|
\texttt{sarq} $A$, $B$ & $B$ \texttt{>>} $A \to B$ (arithmetic shift right, where $A$ is a constant)\\
|
|
|
\texttt{sete} $A$ & \multirow{5}{3.7in}{If the flag matches the condition code,
|
|
|
- then $1 \to A$, else $0 \to A$. Refer to \texttt{je} above for the
|
|
|
+ then $1 \to A$; else $0 \to A$. Refer to \texttt{je} for the
|
|
|
description of the condition codes. $A$ must be a single byte register
|
|
|
(e.g., \texttt{al} or \texttt{cl}).} \\
|
|
|
\texttt{setl} $A$ & \\
|
|
@@ -22305,7 +22306,7 @@ registers.
|
|
|
\texttt{setge} $A$ &
|
|
|
\end{tabular}
|
|
|
\vspace{5pt}
|
|
|
- \caption{Quick-reference for the x86 instructions used in this book.}
|
|
|
+ \caption{Quick reference for the x86 instructions used in this book.}
|
|
|
\label{tab:x86-instr}
|
|
|
\end{table}
|
|
|
|