Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiek committed Aug 11, 2020
1 parent da2143e commit 523f9a8
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions book.tex
Expand Up @@ -1677,19 +1677,19 @@ \section{Uniquify Variables}
\end{minipage}
\end{tabular}

We recommend implementing \code{uniquify} as a structurally recursive
function that mostly copies the input program. However, when
encountering a \key{let}, it should generate a unique name for the
variable (the Racket function \code{gensym} is handy for this) and
associate the old name with the new unique name in an association
list. The \code{uniquify} function will need to access this
association list when it gets to a variable reference, so we add
another parameter to \code{uniquify} for the association list. It is
quite common for a compiler pass to need a map to store extra
information about variables. Such maps are traditionally called
\emph{symbol tables}.

The skeleton of the \code{uniquify} function is shown in
We recommend implementing \code{uniquify} using an auxiliary function
\code{uniquify-exp} that is structurally recursive function and mostly
just copies the input program. However, when encountering a \key{let},
it should generate a unique name for the variable (the Racket function
\code{gensym} is handy for this) and associate the old name with the
new unique name in an association list. The \code{uniquify-exp}
function will need to access this association list when it gets to a
variable reference, so we add another parameter to \code{uniquify-exp}
for the association list. It is quite common for a compiler pass to
need a map to store extra information about variables. Such maps are
traditionally called \emph{symbol tables}.

The skeleton of the \code{uniquify-exp} function is shown in
Figure~\ref{fig:uniquify-s0}. The function is curried so that it is
convenient to partially apply it to an association list and then apply
it to different expressions, as in the last clause for primitive
Expand All @@ -1707,22 +1707,21 @@ \section{Uniquify Variables}

\begin{figure}[tbp]
\begin{lstlisting}
(define (uniquify-exp alist)
(define (uniquify-exp symtab)
(lambda (e)
(match e
[(? symbol?) ___]
[(? integer?) e]
[`(let ([,x ,e]) ,body) ___]
[`(,op ,es ...)
`(,op ,@(for/list ([e es]) ((uniquify-exp alist) e)))]
`(,op ,@(for/list ([e es]) ((uniquify-exp symtab) e)))]
)))

(define (uniquify alist)
(lambda (e)
(match e
[`(program ,info ,e)
`(program ,info ,((uniquify-exp alist) e))]
)))
(define (uniquify p)
(match p
[`(program ,info ,e)
`(program ,info ,((uniquify-exp '()) e))]
)))
\end{lstlisting}
\caption{Skeleton for the \key{uniquify} pass.}
\label{fig:uniquify-s0}
Expand All @@ -1741,7 +1740,9 @@ \section{Uniquify Variables}
except for a different integer at the end of the name, followed by the
ending \key{.rkt}. Use the \key{interp-tests} function
(Appendix~\ref{appendix:utilities}) from \key{utilities.rkt} to test
your \key{uniquify} pass on the example programs.
your \key{uniquify} pass on the example programs. See the
\key{run-tests.rkt} script in the student support code for an example
of how to use \key{interp-tests}.

\end{exercise}

Expand Down Expand Up @@ -2219,10 +2220,10 @@ \section{Print x86}
the example programs that you created for the previous passes. Use the
\key{compiler-tests} function (Appendix~\ref{appendix:utilities}) from
\key{utilities.rkt} to test your complete compiler on the example
programs.
% The following is specific to P423/P523. -Jeremy
%Mac support is optional, but your compiler has to output
%valid code for Unix machines.
programs. See the \key{run-tests.rkt} script in the student support
code for an example of how to use \key{compiler-tests}. Also, remember
to compile the provided \key{runtime.c} file to \key{runtime.o} using
\key{gcc}.
\end{exercise}


Expand Down Expand Up @@ -7718,7 +7719,7 @@ \section{x86 Instruction Set Quick-Reference}
%% LocalWords: quasiquotes pe nullary unary rcl env lookup gcc rax
%% LocalWords: addq movq callq rsp rbp rbx rcx rdx rsi rdi subq nx
%% LocalWords: negq pushq popq retq globl Kernighan uniquify lll ve
%% LocalWords: allocator gensym alist subdirectory scm rkt tmp lhs
%% LocalWords: allocator gensym env subdirectory scm rkt tmp lhs
%% LocalWords: runtime Liveness liveness undirected Balakrishnan je
%% LocalWords: Rosen DSATUR SDO Gebremedhin Omari morekeywords cnd
%% LocalWords: fullflexible vertices Booleans Listof Pairof thn els
Expand Down

0 comments on commit 523f9a8

Please sign in to comment.