Browse Source

created transformation environmetn

Jeremy Siek 4 years ago
parent
commit
ec59799c87
2 changed files with 20 additions and 36 deletions
  1. 13 36
      book.tex
  2. 7 0
      defs.tex

+ 13 - 36
book.tex

@@ -5,6 +5,7 @@
 \usepackage[T1]{fontenc}
 \usepackage[T1]{fontenc}
 \usepackage[utf8]{inputenc}
 \usepackage[utf8]{inputenc}
 \usepackage{listings}
 \usepackage{listings}
+\usepackage{verbatim}
 \usepackage{amsmath}
 \usepackage{amsmath}
 \usepackage{amsthm}
 \usepackage{amsthm}
 \usepackage{amssymb}
 \usepackage{amssymb}
@@ -99,7 +100,7 @@ Cambridge, Massachusetts\\
 London, England}
 London, England}
 
 
 \begin{copyrightpage}
 \begin{copyrightpage}
-  \textcopyright\ [2021] Jeremy G. Siek.  Available for free viewing
+  \textcopyright\ 2021 Jeremy G. Siek.  Available for free viewing
   or personal downloading under the
   or personal downloading under the
   \href{https://creativecommons.org/licenses/by-nc-nd/2.0/uk/}{CC-BY-NC-ND}
   \href{https://creativecommons.org/licenses/by-nc-nd/2.0/uk/}{CC-BY-NC-ND}
   license.
   license.
@@ -2108,27 +2109,19 @@ in the program below. This is accomplished by introducing a new
 variable, and then using the new variable in place of the complex
 variable, and then using the new variable in place of the complex
 operand, as shown in the output of \code{remove-complex-opera*} on the
 operand, as shown in the output of \code{remove-complex-opera*} on the
 right.
 right.
-\begin{center}
-\begin{tabular}{lll}
-\begin{minipage}{0.4\textwidth}
+\begin{transformation}
 % var_test_19.rkt
 % var_test_19.rkt
 \begin{lstlisting}
 \begin{lstlisting}
 (let ([x (+ 42 (- 10))])
 (let ([x (+ 42 (- 10))])
   (+ x 10))
   (+ x 10))
 \end{lstlisting}
 \end{lstlisting}
-\end{minipage}
-&
-$\Rightarrow$
-&
-\begin{minipage}{0.4\textwidth}
+\compilesto
 \begin{lstlisting}
 \begin{lstlisting}
 (let ([x (let ([tmp.1 (- 10)])
 (let ([x (let ([tmp.1 (- 10)])
             (+ 42 tmp.1))])
             (+ 42 tmp.1))])
    (+ x 10))
    (+ x 10))
 \end{lstlisting}
 \end{lstlisting}
-\end{minipage}
-\end{tabular}
-\end{center}
+\end{transformation}
 
 
 \begin{figure}[tp]
 \begin{figure}[tp]
 \centering
 \centering
@@ -2179,50 +2172,34 @@ Returning to the example program with the expression \code{(+ 42 (-
 \code{rco-atom} function because it is an argument of the \code{+} and
 \code{rco-atom} function because it is an argument of the \code{+} and
 therefore needs to become atomic.  The output of \code{rco-atom}
 therefore needs to become atomic.  The output of \code{rco-atom}
 applied to \code{(- 10)} is as follows.
 applied to \code{(- 10)} is as follows.
-\begin{center}
-\begin{tabular}{lll}
-\begin{minipage}{0.4\textwidth}
+\begin{transformation}
 \begin{lstlisting}
 \begin{lstlisting}
-(- 10)
+  (- 10)
 \end{lstlisting}
 \end{lstlisting}
-\end{minipage}
-&
-$\Rightarrow$
-&
-\begin{minipage}{0.4\textwidth}
+\compilesto
 \begin{lstlisting}
 \begin{lstlisting}
 tmp.1
 tmp.1
 ((tmp.1 . (- 10)))
 ((tmp.1 . (- 10)))
 \end{lstlisting}
 \end{lstlisting}
-\end{minipage}
-\end{tabular}
-\end{center}
+\end{transformation}
 
 
 Take special care of programs such as the following that bind a
 Take special care of programs such as the following that bind a
 variable to an atomic expression. You should leave such variable
 variable to an atomic expression. You should leave such variable
 bindings unchanged, as shown in the program on the right \\
 bindings unchanged, as shown in the program on the right \\
-\begin{center}
-\begin{tabular}{lll}
-\begin{minipage}{0.4\textwidth}
+\begin{transformation}
 % var_test_20.rkt
 % var_test_20.rkt
 \begin{lstlisting}
 \begin{lstlisting}
 (let ([a 42])
 (let ([a 42])
   (let ([b a])
   (let ([b a])
     b))
     b))
 \end{lstlisting}
 \end{lstlisting}
-\end{minipage}
-&
-$\Rightarrow$
-&
-\begin{minipage}{0.4\textwidth}
+\compilesto
 \begin{lstlisting}
 \begin{lstlisting}
 (let ([a 42])
 (let ([a 42])
   (let ([b a])
   (let ([b a])
     b))
     b))
 \end{lstlisting}
 \end{lstlisting}
-\end{minipage}
-\end{tabular} 
-\end{center}
+\end{transformation}
 A careless implementation of \key{rco-exp} and \key{rco-atom} might
 A careless implementation of \key{rco-exp} and \key{rco-atom} might
 produce the following output with unnecessary temporary variables.
 produce the following output with unnecessary temporary variables.
 \begin{center}
 \begin{center}
@@ -2253,7 +2230,7 @@ list of \code{passes} and then run the script to test your compiler.
 \end{lstlisting}
 \end{lstlisting}
 While debugging your compiler, it is often useful to see the
 While debugging your compiler, it is often useful to see the
 intermediate programs that are output from each pass. To print the
 intermediate programs that are output from each pass. To print the
-intermediate programs, place the \lstinline{(debug-level 1)} before the call to
+intermediate programs, place \lstinline{(debug-level 1)} before the call to
 \code{interp-tests} in \code{run-tests.rkt}.
 \code{interp-tests} in \code{run-tests.rkt}.
 \end{exercise}
 \end{exercise}
 
 

+ 7 - 0
defs.tex

@@ -201,3 +201,10 @@
 
 
 \newcommand{\TTKEY}[1]{{\normalfont\tt #1}}
 \newcommand{\TTKEY}[1]{{\normalfont\tt #1}}
 
 
+\newenvironment{transformation}{
+  \newcommand{\compilesto}{%
+    \end{minipage}&$\Rightarrow$&\begin{minipage}{0.4\textwidth}}
+  \begin{center}\begin{tabular}{lll}\begin{minipage}{0.4\textwidth}
+  }{%
+  \end{minipage}\end{tabular}\end{center}%
+}