浏览代码

added 'is' to select instructions for tuples

Jeremy G. Siek 2 年之前
父节点
当前提交
5686a0618b
共有 2 个文件被更改,包括 27 次插入3 次删除
  1. 26 3
      book.tex
  2. 1 0
      defs.tex

+ 26 - 3
book.tex

@@ -33,8 +33,8 @@
 % would like a command for: \if\edition\racketEd\color{olive}
 % and : \fi\color{black}
 
-\newcommand{\pythonColor}[0]{\color{purple}}
-%\newcommand{\pythonColor}[0]{}
+%\newcommand{\pythonColor}[0]{\color{purple}}
+\newcommand{\pythonColor}[0]{}
 
 % material that is specific to the Python edition of the book
 \newcommand{\python}[1]{{\if\edition\pythonEd\pythonColor #1\fi}}
@@ -13245,7 +13245,8 @@ section.
 
 In this pass we generate x86 code for most of the new operations that
 are needed to compile tuples, including \code{Allocate},
-\code{Collect}, and accessing tuple elements.
+\code{Collect}, accessing tuple elements, and the \code{Is}
+comparison.
 %
 We compile \code{GlobalValue} to \code{Global} because the latter has a
 different concrete syntax (see figures~\ref{fig:x86-2-concrete} and
@@ -13400,6 +13401,28 @@ available for use by the register allocator.
 \end{lstlisting}
 \fi}
 
+{\if\edition\pythonEd\pythonColor    
+The \code{is} comparison is compiled similarly to the other comparison
+operators, using the \code{cmpq} instruction. Because the value of a
+tuple is its address, we can translate \code{is} into a simple check
+for equality using the \code{e} condition code. \\
+\begin{tabular}{lll}
+\begin{minipage}{0.4\textwidth}
+$\CASSIGN{\Var}{ \LP\CIS{\Atm_1}{\Atm_2} \RP }$ 
+\end{minipage}
+&
+$\Rightarrow$
+&
+\begin{minipage}{0.4\textwidth}
+\begin{lstlisting}
+cmpq |$\Arg_2$|, |$\Arg_1$|
+sete %al
+movzbq %al, |$\Var$|
+\end{lstlisting}
+\end{minipage}
+\end{tabular}
+\fi}
+
 
 \newcommand{\GrammarXGlobal}{
 \begin{array}{lcl}

+ 1 - 0
defs.tex

@@ -226,6 +226,7 @@
 \newcommand{\EQNAME}{\key{Eq}}
 \newcommand{\NOTEQNAME}{\key{NotEq}}
 \newcommand{\CEQ}[2]{#1~\code{==}~#2}
+\newcommand{\CIS}[2]{#1~\code{is}~#2}
 \newcommand{\CGET}[2]{#1 \LS #2 \RS}
 \newcommand{\GET}[2]{\key{Subscript}\LP #1 \code{,} #2 \code{,} \code{Load()} \RP}
 \newcommand{\CLEN}[1]{\code{len}\LP #1 \RP}