|
@@ -179,7 +179,7 @@ LC ebook record available at https://lccn.loc.gov/2022015400\\
|
|
{\if\edition\pythonEd
|
|
{\if\edition\pythonEd
|
|
Library of Congress Cataloging-in-Publication Data\\
|
|
Library of Congress Cataloging-in-Publication Data\\
|
|
\ \\
|
|
\ \\
|
|
-Names: Jeremy G. Siek. \\
|
|
|
|
|
|
+Names: Siek, Jeremy, author. \\
|
|
Title: Essentials of compilation : an incremental approach in Python / Jeremy G. Siek. \\
|
|
Title: Essentials of compilation : an incremental approach in Python / Jeremy G. Siek. \\
|
|
Description: Cambridge, Massachusetts : The MIT Press, [2023] | Includes
|
|
Description: Cambridge, Massachusetts : The MIT Press, [2023] | Includes
|
|
bibliographical references and index. \\
|
|
bibliographical references and index. \\
|
|
@@ -2536,7 +2536,7 @@ A register is a special kind of variable that holds a 64-bit
|
|
value. There are 16 general-purpose registers in the computer; their
|
|
value. There are 16 general-purpose registers in the computer; their
|
|
names are given in figure~\ref{fig:x86-int-concrete}. A register is
|
|
names are given in figure~\ref{fig:x86-int-concrete}. A register is
|
|
written with a percent sign, \key{\%}, followed by its name,
|
|
written with a percent sign, \key{\%}, followed by its name,
|
|
-for example \key{\%rax}.
|
|
|
|
|
|
+for example, \key{\%rax}.
|
|
|
|
|
|
An immediate value is written using the notation \key{\$}$n$ where $n$
|
|
An immediate value is written using the notation \key{\$}$n$ where $n$
|
|
is an integer.
|
|
is an integer.
|
|
@@ -7870,8 +7870,9 @@ operators to include
|
|
Figure~\ref{fig:interp-Lif} shows the definition of the interpreter
|
|
Figure~\ref{fig:interp-Lif} shows the definition of the interpreter
|
|
for \LangIf{}, which inherits from the interpreter for \LangVar{}
|
|
for \LangIf{}, which inherits from the interpreter for \LangVar{}
|
|
(figure~\ref{fig:interp-Lvar}). The constants \TRUE{} and \FALSE{}
|
|
(figure~\ref{fig:interp-Lvar}). The constants \TRUE{} and \FALSE{}
|
|
-evaluate to the corresponding Boolean values, which is
|
|
|
|
-inherited from the interpreter for \LangInt{} (figure~\ref{fig:interp-Lint-class}).
|
|
|
|
|
|
+evaluate to the corresponding Boolean values, behavior that is
|
|
|
|
+inherited from the interpreter for \LangInt{}
|
|
|
|
+(figure~\ref{fig:interp-Lint-class}).
|
|
The conditional expression $\CIF{e_1}{e_2}{\itm{e_3}}$ evaluates
|
|
The conditional expression $\CIF{e_1}{e_2}{\itm{e_3}}$ evaluates
|
|
expression $e_1$ and then either evaluates $e_2$ or $e_3$, depending
|
|
expression $e_1$ and then either evaluates $e_2$ or $e_3$, depending
|
|
on whether $e_1$ produced \TRUE{} or \FALSE{}. The logical operations
|
|
on whether $e_1$ produced \TRUE{} or \FALSE{}. The logical operations
|
|
@@ -10835,7 +10836,7 @@ blocks on several test programs.
|
|
\section{Further Reading}
|
|
\section{Further Reading}
|
|
\label{sec:cond-further-reading}
|
|
\label{sec:cond-further-reading}
|
|
|
|
|
|
-The algorithm for the \code{explicate\_control} pass is based on the
|
|
|
|
|
|
+The algorithm for \code{explicate\_control} is based on the
|
|
\code{expose-basic-blocks} pass in the course notes of
|
|
\code{expose-basic-blocks} pass in the course notes of
|
|
\citet{Dybvig:2010aa}.
|
|
\citet{Dybvig:2010aa}.
|
|
%
|
|
%
|
|
@@ -12911,7 +12912,7 @@ appropriate amount of memory and initializing it. We choose to place
|
|
the \code{expose\_allocation} pass before
|
|
the \code{expose\_allocation} pass before
|
|
\code{remove\_complex\_operands} because it generates code that
|
|
\code{remove\_complex\_operands} because it generates code that
|
|
contains complex operands. However, with some care it can also be
|
|
contains complex operands. However, with some care it can also be
|
|
-placed before \code{remove\_complex\_operands} which would simplify
|
|
|
|
|
|
+placed before \code{remove\_complex\_operands}, which would simplify
|
|
tuple creation by removing the need to assign the initializing
|
|
tuple creation by removing the need to assign the initializing
|
|
expressions to temporary variables (see below).
|
|
expressions to temporary variables (see below).
|
|
|
|
|
|
@@ -14289,7 +14290,7 @@ multiplication: it takes two integers and returns an integer.
|
|
{\if\edition\pythonEd\pythonColor
|
|
{\if\edition\pythonEd\pythonColor
|
|
%
|
|
%
|
|
The type checker for \LangArray{} is defined in
|
|
The type checker for \LangArray{} is defined in
|
|
-figure~\ref{fig:type-check-Lvecof} and
|
|
|
|
|
|
+figures~\ref{fig:type-check-Lvecof} and
|
|
\ref{fig:type-check-Lvecof-part2}. The result type of a list literal
|
|
\ref{fig:type-check-Lvecof-part2}. The result type of a list literal
|
|
is \code{list[T]}, where \code{T} is the type of the initializing
|
|
is \code{list[T]}, where \code{T} is the type of the initializing
|
|
expressions. The type checking of the \code{len} function and the
|
|
expressions. The type checking of the \code{len} function and the
|
|
@@ -14586,7 +14587,7 @@ Implement a new pass named \code{resolve}.
|
|
Translate the reading of an array element to
|
|
Translate the reading of an array element to
|
|
\racket{\code{vectorof-ref}}\python{\code{array\_load}}
|
|
\racket{\code{vectorof-ref}}\python{\code{array\_load}}
|
|
and the writing of an array element to
|
|
and the writing of an array element to
|
|
-\racket{\code{vectorof-set!}}\python{\code{array\_store}}
|
|
|
|
|
|
+\racket{\code{vectorof-set!}}\python{\code{array\_store}}.
|
|
Translate calls to \racket{\code{vector-length}}\python{\code{len}}
|
|
Translate calls to \racket{\code{vector-length}}\python{\code{len}}
|
|
into \racket{\code{vectorof-length}}\python{\code{array\_len}}.
|
|
into \racket{\code{vectorof-length}}\python{\code{array\_len}}.
|
|
When these operators are applied to tuples, leave them as is.
|
|
When these operators are applied to tuples, leave them as is.
|
|
@@ -15205,10 +15206,10 @@ the program using this mapping.
|
|
\code{env} with the parameters of the function. We then type check
|
|
\code{env} with the parameters of the function. We then type check
|
|
the body of the function and obtain the actual return type
|
|
the body of the function and obtain the actual return type
|
|
\code{rt}, which is either the type of the expression in a
|
|
\code{rt}, which is either the type of the expression in a
|
|
- \code{return} statement, or the \code{VoidType} if control reaches
|
|
|
|
|
|
+ \code{return} statement or the \code{VoidType} if control reaches
|
|
the end of the function without a \code{return} statement. (If
|
|
the end of the function without a \code{return} statement. (If
|
|
there are multiple \code{return} statements, the types of their
|
|
there are multiple \code{return} statements, the types of their
|
|
- expressions must agree.) Finally we check that the actual return
|
|
|
|
|
|
+ expressions must agree.) Finally, we check that the actual return
|
|
type \code{rt} is equal to the declared return type \code{returns}.}
|
|
type \code{rt} is equal to the declared return type \code{returns}.}
|
|
%
|
|
%
|
|
To check a function \racket{application}\python{call}, we match
|
|
To check a function \racket{application}\python{call}, we match
|
|
@@ -17888,12 +17889,16 @@ your previously created test programs.
|
|
\section{Expose Allocation}
|
|
\section{Expose Allocation}
|
|
\label{sec:expose-allocation-r5}
|
|
\label{sec:expose-allocation-r5}
|
|
|
|
|
|
-Compile the $\CLOSURE{\itm{arity}}{\Exp^{*}}$ form into code
|
|
|
|
-that allocates and initializes a tuple, similar to the translation of
|
|
|
|
-the tuple creation in section~\ref{sec:expose-allocation}.
|
|
|
|
-The only difference is replacing the use of
|
|
|
|
-\ALLOC{\itm{len}}{\itm{type}} with
|
|
|
|
-\ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}}.
|
|
|
|
|
|
+Compile the $\CLOSURE{\itm{arity}}{\Exp^{*}}$ form into code that
|
|
|
|
+allocates and initializes a tuple, similar to the translation of the
|
|
|
|
+tuple creation in section~\ref{sec:expose-allocation}. The main
|
|
|
|
+difference is replacing the use of \ALLOC{\itm{len}}{\itm{type}} with
|
|
|
|
+\ALLOCCLOS{\itm{len}}{\itm{type}}{\itm{arity}}. The result type of
|
|
|
|
+the translation of $\CLOSURE{\itm{arity}}{\Exp^{*}}$ should be a tuple
|
|
|
|
+type, but only a single element tuple type. The types of the tuple
|
|
|
|
+elements that correspond to the free variables of the closure should
|
|
|
|
+not appear in the tuple type. The new AST class \code{UncheckedCast}
|
|
|
|
+can be used to adjust the result type.
|
|
|
|
|
|
|
|
|
|
\section{Explicate Control and \LangCLam{}}
|
|
\section{Explicate Control and \LangCLam{}}
|
|
@@ -17929,6 +17934,7 @@ figure~\ref{fig:Clam-syntax}.
|
|
\Exp &::=& \key{Uninitialized}\LP \Type \RP
|
|
\Exp &::=& \key{Uninitialized}\LP \Type \RP
|
|
\MID \key{AllocateClosure}\LP\itm{len},\Type, \itm{arity}\RP \\
|
|
\MID \key{AllocateClosure}\LP\itm{len},\Type, \itm{arity}\RP \\
|
|
&\MID& \ARITY{\Atm}
|
|
&\MID& \ARITY{\Atm}
|
|
|
|
+ \MID \key{UncheckedCast}\LP\Exp,\Type\RP
|
|
\end{array}
|
|
\end{array}
|
|
}
|
|
}
|
|
|
|
|