|
179 | 179 | {\if\edition\pythonEd
|
180 | 180 | Library of Congress Cataloging-in-Publication Data\\
|
181 | 181 | \ \\
|
182 |
| -Names: Jeremy G. Siek. \\ |
| 182 | +Names: Siek, Jeremy, author. \\ |
183 | 183 | Title: Essentials of compilation : an incremental approach in Python / Jeremy G. Siek. \\
|
184 | 184 | Description: Cambridge, Massachusetts : The MIT Press, [2023] | Includes
|
185 | 185 | bibliographical references and index. \\
|
@@ -2536,7 +2536,7 @@ \section{The \LangXInt{} Assembly Language}
|
2536 | 2536 | value. There are 16 general-purpose registers in the computer; their
|
2537 | 2537 | names are given in figure~\ref{fig:x86-int-concrete}. A register is
|
2538 | 2538 | written with a percent sign, \key{\%}, followed by its name,
|
2539 |
| -for example \key{\%rax}. |
| 2539 | +for example, \key{\%rax}. |
2540 | 2540 |
|
2541 | 2541 | An immediate value is written using the notation \key{\$}$n$ where $n$
|
2542 | 2542 | is an integer.
|
@@ -7870,8 +7870,9 @@ \section{The \LangIf{} Language}
|
7870 | 7870 | Figure~\ref{fig:interp-Lif} shows the definition of the interpreter
|
7871 | 7871 | for \LangIf{}, which inherits from the interpreter for \LangVar{}
|
7872 | 7872 | (figure~\ref{fig:interp-Lvar}). The constants \TRUE{} and \FALSE{}
|
7873 |
| -evaluate to the corresponding Boolean values, which is |
7874 |
| -inherited from the interpreter for \LangInt{} (figure~\ref{fig:interp-Lint-class}). |
| 7873 | +evaluate to the corresponding Boolean values, behavior that is |
| 7874 | +inherited from the interpreter for \LangInt{} |
| 7875 | +(figure~\ref{fig:interp-Lint-class}). |
7875 | 7876 | The conditional expression $\CIF{e_1}{e_2}{\itm{e_3}}$ evaluates
|
7876 | 7877 | expression $e_1$ and then either evaluates $e_2$ or $e_3$, depending
|
7877 | 7878 | on whether $e_1$ produced \TRUE{} or \FALSE{}. The logical operations
|
@@ -10835,7 +10836,7 @@ \subsection{Remove Jumps}
|
10835 | 10836 | \section{Further Reading}
|
10836 | 10837 | \label{sec:cond-further-reading}
|
10837 | 10838 |
|
10838 |
| -The algorithm for the \code{explicate\_control} pass is based on the |
| 10839 | +The algorithm for \code{explicate\_control} is based on the |
10839 | 10840 | \code{expose-basic-blocks} pass in the course notes of
|
10840 | 10841 | \citet{Dybvig:2010aa}.
|
10841 | 10842 | %
|
@@ -12911,7 +12912,7 @@ \section{Expose Allocation}
|
12911 | 12912 | the \code{expose\_allocation} pass before
|
12912 | 12913 | \code{remove\_complex\_operands} because it generates code that
|
12913 | 12914 | contains complex operands. However, with some care it can also be
|
12914 |
| -placed before \code{remove\_complex\_operands} which would simplify |
| 12915 | +placed before \code{remove\_complex\_operands}, which would simplify |
12915 | 12916 | tuple creation by removing the need to assign the initializing
|
12916 | 12917 | expressions to temporary variables (see below).
|
12917 | 12918 |
|
@@ -14289,7 +14290,7 @@ \section{Challenge: Arrays}
|
14289 | 14290 | {\if\edition\pythonEd\pythonColor
|
14290 | 14291 | %
|
14291 | 14292 | The type checker for \LangArray{} is defined in
|
14292 |
| -figure~\ref{fig:type-check-Lvecof} and |
| 14293 | +figures~\ref{fig:type-check-Lvecof} and |
14293 | 14294 | \ref{fig:type-check-Lvecof-part2}. The result type of a list literal
|
14294 | 14295 | is \code{list[T]}, where \code{T} is the type of the initializing
|
14295 | 14296 | expressions. The type checking of the \code{len} function and the
|
@@ -14586,7 +14587,7 @@ \subsection{Overload Resolution}
|
14586 | 14587 | Translate the reading of an array element to
|
14587 | 14588 | \racket{\code{vectorof-ref}}\python{\code{array\_load}}
|
14588 | 14589 | and the writing of an array element to
|
14589 |
| -\racket{\code{vectorof-set!}}\python{\code{array\_store}} |
| 14590 | +\racket{\code{vectorof-set!}}\python{\code{array\_store}}. |
14590 | 14591 | Translate calls to \racket{\code{vector-length}}\python{\code{len}}
|
14591 | 14592 | into \racket{\code{vectorof-length}}\python{\code{array\_len}}.
|
14592 | 14593 | When these operators are applied to tuples, leave them as is.
|
@@ -15205,10 +15206,10 @@ \section{The \LangFun{} Language}
|
15205 | 15206 | \code{env} with the parameters of the function. We then type check
|
15206 | 15207 | the body of the function and obtain the actual return type
|
15207 | 15208 | \code{rt}, which is either the type of the expression in a
|
15208 |
| - \code{return} statement, or the \code{VoidType} if control reaches |
| 15209 | + \code{return} statement or the \code{VoidType} if control reaches |
15209 | 15210 | the end of the function without a \code{return} statement. (If
|
15210 | 15211 | there are multiple \code{return} statements, the types of their
|
15211 |
| - expressions must agree.) Finally we check that the actual return |
| 15212 | + expressions must agree.) Finally, we check that the actual return |
15212 | 15213 | type \code{rt} is equal to the declared return type \code{returns}.}
|
15213 | 15214 | %
|
15214 | 15215 | To check a function \racket{application}\python{call}, we match
|
@@ -17888,12 +17889,16 @@ \subsection{An Example Translation}
|
17888 | 17889 | \section{Expose Allocation}
|
17889 | 17890 | \label{sec:expose-allocation-r5}
|
17890 | 17891 |
|
17891 |
| -Compile the $\CLOSURE{\itm{arity}}{\Exp^{*}}$ form into code |
17892 |
| -that allocates and initializes a tuple, similar to the translation of |
17893 |
| -the tuple creation in section~\ref{sec:expose-allocation}. |
17894 |
| -The only difference is replacing the use of |
17895 |
| -\ALLOC{\itm{len}}{\itm{type}} with |
17896 |
| -\ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}}. |
| 17892 | +Compile the $\CLOSURE{\itm{arity}}{\Exp^{*}}$ form into code that |
| 17893 | +allocates and initializes a tuple, similar to the translation of the |
| 17894 | +tuple creation in section~\ref{sec:expose-allocation}. The main |
| 17895 | +difference is replacing the use of \ALLOC{\itm{len}}{\itm{type}} with |
| 17896 | +\ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}}. The result type of |
| 17897 | +the translation of $\CLOSURE{\itm{arity}}{\Exp^{*}}$ should be a tuple |
| 17898 | +type, but only a single element tuple type. The types of the tuple |
| 17899 | +elements that correspond to the free variables of the closure should |
| 17900 | +not appear in the tuple type. The new AST class \code{UncheckedCast} |
| 17901 | +can be used to adjust the result type. |
17897 | 17902 |
|
17898 | 17903 |
|
17899 | 17904 | \section{Explicate Control and \LangCLam{}}
|
@@ -17929,6 +17934,7 @@ \section{Explicate Control and \LangCLam{}}
|
17929 | 17934 | \Exp &::=& \key{Uninitialized}\LP \Type \RP
|
17930 | 17935 | \MID \key{AllocateClosure}\LP\itm{len},\Type, \itm{arity}\RP \\
|
17931 | 17936 | &\MID& \ARITY{\Atm}
|
| 17937 | + \MID \key{UncheckedCast}\LP\Exp,\Type\RP |
17932 | 17938 | \end{array}
|
17933 | 17939 | }
|
17934 | 17940 |
|
|
0 commit comments