Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12bba85

Browse files
committed
Rough and incomplete documentation on augmented assignment, which follows
shortly. Markup also needs checking.
1 parent b0b7e31 commit 12bba85

3 files changed

Lines changed: 70 additions & 4 deletions

File tree

Doc/lib/libdis.tex

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ \subsection{Python Byte Code Instructions}
130130
to position three.
131131
\end{opcodedesc}
132132

133+
\begin{opcodedesc}{ROT_FOUR}{}
134+
Lifts second, third and forth stack item one position up, moves top down to
135+
position four.
136+
\end{opcodedesc}
137+
133138
\begin{opcodedesc}{DUP_TOP}{}
134139
Duplicates the reference on top of the stack.
135140
\end{opcodedesc}
@@ -209,6 +214,55 @@ \subsection{Python Byte Code Instructions}
209214
Implements \code{TOS = TOS1 | TOS}.
210215
\end{opcodedesc}
211216

217+
In-place operations are like binary operations, in that they remove TOS and
218+
TOS1, and push the result back on the stack, but the operation is done
219+
in-place when TOS1 supports it, and the resulting TOS may be (but does not
220+
have to be) the original TOS1.
221+
222+
\begin{opcodedesc}{INPLACE_POWER}{}
223+
Implements in-place \code{TOS = TOS1 ** TOS}.
224+
\end{opcodedesc}
225+
226+
\begin{opcodedesc}{INPLACE_MULTIPLY}{}
227+
Implements in-place \code{TOS = TOS1 * TOS}.
228+
\end{opcodedesc}
229+
230+
\begin{opcodedesc}{INPLACE_DIVIDE}{}
231+
Implements in-place \code{TOS = TOS1 / TOS}.
232+
\end{opcodedesc}
233+
234+
\begin{opcodedesc}{INPLACE_MODULO}{}
235+
Implements in-place \code{TOS = TOS1 \%{} TOS}.
236+
\end{opcodedesc}
237+
238+
\begin{opcodedesc}{INPLACE_ADD}{}
239+
Implements in-place \code{TOS = TOS1 + TOS}.
240+
\end{opcodedesc}
241+
242+
\begin{opcodedesc}{INPLACE_SUBTRACT}{}
243+
Implements in-place \code{TOS = TOS1 - TOS}.
244+
\end{opcodedesc}
245+
246+
\begin{opcodedesc}{INPLACE_LSHIFT}{}
247+
Implements in-place \code{TOS = TOS1 << TOS}.
248+
\end{opcodedesc}
249+
250+
\begin{opcodedesc}{INPLACE_RSHIFT}{}
251+
Implements in-place \code{TOS = TOS1 >> TOS}.
252+
\end{opcodedesc}
253+
254+
\begin{opcodedesc}{INPLACE_AND}{}
255+
Implements in-place \code{TOS = TOS1 \&\ TOS}.
256+
\end{opcodedesc}
257+
258+
\begin{opcodedesc}{INPLACE_XOR}{}
259+
Implements in-place \code{TOS = TOS1 \^\ TOS}.
260+
\end{opcodedesc}
261+
262+
\begin{opcodedesc}{INPLACE_OR}{}
263+
Implements in-place \code{TOS = TOS1 | TOS}.
264+
\end{opcodedesc}
265+
212266
The slice opcodes take up to three parameters.
213267

214268
\begin{opcodedesc}{SLICE+0}{}
@@ -366,6 +420,11 @@ \subsection{Python Byte Code Instructions}
366420
%This opcode is obsolete.
367421
%\end{opcodedesc}
368422

423+
\begin{opcodedesc}{DUP_TOPX}{count}
424+
Duplicate \var{count} items, keeping them in the same order. Due to
425+
implementation limits, \var{count} should be between 1 and 5 inclusive.
426+
\end{opcodedesc}
427+
369428
\begin{opcodedesc}{STORE_ATTR}{namei}
370429
Implements \code{TOS.name = TOS1}, where \var{namei} is the index
371430
of name in \member{co_names}.

Doc/ref/ref2.tex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,14 @@ \section{Delimiters\label{delimiters}}
523523
\begin{verbatim}
524524
( ) [ ] { }
525525
, : . ` = ;
526+
+= -= *= /= %= **=
527+
&= |= ^= >>= <<=
526528
\end{verbatim}
527529

528530
The period can also occur in floating-point and imaginary literals. A
529531
sequence of three periods has a special meaning as an ellipsis in slices.
532+
The second half of the list, the augmented assignment operators, serve
533+
lexically as delimiters, but also perform an operation.
530534

531535
The following printing ASCII characters have special meaning as part
532536
of other tokens or are otherwise significant to the lexical analyzer:

Doc/ref/ref3.tex

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,9 +1054,10 @@ \subsection{Emulating sequence and mapping types\label{sequence-types}}
10541054
and \method{sort()}, like Python standard list objects. Finally,
10551055
sequence types should implement addition (meaning concatenation) and
10561056
multiplication (meaning repetition) by defining the methods
1057-
\method{__add__()}, \method{__radd__()}, \method{__mul__()} and
1058-
\method{__rmul__()} described below; they should not define
1059-
\method{__coerce__()} or other numerical operators.
1057+
\method{__add__()}, \method{__radd__()}, \method{__iadd__()},
1058+
\method{__mul__()}, \method{__rmul__()} and \method{__imul__()} described
1059+
below; they should not define \method{__coerce__()} or other numerical
1060+
operators.
10601061
\withsubitem{(mapping object method)}{
10611062
\ttindex{keys()}
10621063
\ttindex{values()}
@@ -1077,8 +1078,10 @@ \subsection{Emulating sequence and mapping types\label{sequence-types}}
10771078
\ttindex{sort()}
10781079
\ttindex{__add__()}
10791080
\ttindex{__radd__()}
1081+
\ttindex{__iadd__()}
10801082
\ttindex{__mul__()}
1081-
\ttindex{__rmul__()}}
1083+
\ttindex{__rmul__()}
1084+
\ttindex{__imul__()}}
10821085
\withsubitem{(numeric object method)}{\ttindex{__coerce__()}}
10831086

10841087
\begin{methoddesc}[mapping object]{__len__}{self}

0 commit comments

Comments
 (0)