| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> |
| 5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> |
| 6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> |
| 7 | <link rel="first" href="lib.html" title='Python Library Reference' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="prev" href="module-dis.html" /> |
| 13 | <link rel="parent" href="module-dis.html" /> |
| 14 | <link rel="next" href="module-pickletools.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>18.10.1 Python Byte Code Instructions</title> |
| 17 | </head> |
| 18 | <body> |
| 19 | <DIV CLASS="navigation"> |
| 20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> |
| 21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 22 | <tr> |
| 23 | <td class='online-navigation'><a rel="prev" title="18.10 dis " |
| 24 | href="module-dis.html"><img src='../icons/previous.png' |
| 25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 26 | <td class='online-navigation'><a rel="parent" title="18.10 dis " |
| 27 | href="module-dis.html"><img src='../icons/up.png' |
| 28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 29 | <td class='online-navigation'><a rel="next" title="18.11 pickletools " |
| 30 | href="module-pickletools.html"><img src='../icons/next.png' |
| 31 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 32 | <td align="center" width="100%">Python Library Reference</td> |
| 33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 34 | href="contents.html"><img src='../icons/contents.png' |
| 35 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 37 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 38 | <td class='online-navigation'><a rel="index" title="Index" |
| 39 | href="genindex.html"><img src='../icons/index.png' |
| 40 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 41 | </tr></table> |
| 42 | <div class='online-navigation'> |
| 43 | <b class="navlabel">Previous:</b> |
| 44 | <a class="sectref" rel="prev" href="module-dis.html">18.10 dis </A> |
| 45 | <b class="navlabel">Up:</b> |
| 46 | <a class="sectref" rel="parent" href="module-dis.html">18.10 dis </A> |
| 47 | <b class="navlabel">Next:</b> |
| 48 | <a class="sectref" rel="next" href="module-pickletools.html">18.11 pickletools </A> |
| 49 | </div> |
| 50 | <hr /></div> |
| 51 | </DIV> |
| 52 | <!--End of Navigation Panel--> |
| 53 | |
| 54 | <H2><A NAME="SECTION00201010000000000000000"></A> |
| 55 | <A NAME="bytecodes"></A> |
| 56 | <BR> |
| 57 | 18.10.1 Python Byte Code Instructions |
| 58 | </H2> |
| 59 | |
| 60 | <P> |
| 61 | The Python compiler currently generates the following byte code |
| 62 | instructions. |
| 63 | |
| 64 | <P> |
| 65 | |
| 66 | <P> |
| 67 | <dl><dt><b><tt class="opcode">STOP_CODE</tt></b></dt> |
| 68 | <dd> |
| 69 | Indicates end-of-code to the compiler, not used by the interpreter. |
| 70 | </dt></dl> |
| 71 | |
| 72 | <P> |
| 73 | <dl><dt><b><tt class="opcode">NOP</tt></b></dt> |
| 74 | <dd> |
| 75 | Do nothing code. Used as a placeholder by the bytecode optimizer. |
| 76 | </dt></dl> |
| 77 | |
| 78 | <P> |
| 79 | <dl><dt><b><tt class="opcode">POP_TOP</tt></b></dt> |
| 80 | <dd> |
| 81 | Removes the top-of-stack (TOS) item. |
| 82 | </dt></dl> |
| 83 | |
| 84 | <P> |
| 85 | <dl><dt><b><tt class="opcode">ROT_TWO</tt></b></dt> |
| 86 | <dd> |
| 87 | Swaps the two top-most stack items. |
| 88 | </dt></dl> |
| 89 | |
| 90 | <P> |
| 91 | <dl><dt><b><tt class="opcode">ROT_THREE</tt></b></dt> |
| 92 | <dd> |
| 93 | Lifts second and third stack item one position up, moves top down |
| 94 | to position three. |
| 95 | </dt></dl> |
| 96 | |
| 97 | <P> |
| 98 | <dl><dt><b><tt class="opcode">ROT_FOUR</tt></b></dt> |
| 99 | <dd> |
| 100 | Lifts second, third and forth stack item one position up, moves top down to |
| 101 | position four. |
| 102 | </dt></dl> |
| 103 | |
| 104 | <P> |
| 105 | <dl><dt><b><tt class="opcode">DUP_TOP</tt></b></dt> |
| 106 | <dd> |
| 107 | Duplicates the reference on top of the stack. |
| 108 | </dt></dl> |
| 109 | |
| 110 | <P> |
| 111 | Unary Operations take the top of the stack, apply the operation, and |
| 112 | push the result back on the stack. |
| 113 | |
| 114 | <P> |
| 115 | <dl><dt><b><tt class="opcode">UNARY_POSITIVE</tt></b></dt> |
| 116 | <dd> |
| 117 | Implements <code>TOS = +TOS</code>. |
| 118 | </dt></dl> |
| 119 | |
| 120 | <P> |
| 121 | <dl><dt><b><tt class="opcode">UNARY_NEGATIVE</tt></b></dt> |
| 122 | <dd> |
| 123 | Implements <code>TOS = -TOS</code>. |
| 124 | </dt></dl> |
| 125 | |
| 126 | <P> |
| 127 | <dl><dt><b><tt class="opcode">UNARY_NOT</tt></b></dt> |
| 128 | <dd> |
| 129 | Implements <code>TOS = not TOS</code>. |
| 130 | </dt></dl> |
| 131 | |
| 132 | <P> |
| 133 | <dl><dt><b><tt class="opcode">UNARY_CONVERT</tt></b></dt> |
| 134 | <dd> |
| 135 | Implements <code>TOS = `TOS`</code>. |
| 136 | </dt></dl> |
| 137 | |
| 138 | <P> |
| 139 | <dl><dt><b><tt class="opcode">UNARY_INVERT</tt></b></dt> |
| 140 | <dd> |
| 141 | Implements <code>TOS = ~TOS</code>. |
| 142 | </dt></dl> |
| 143 | |
| 144 | <P> |
| 145 | <dl><dt><b><tt class="opcode">GET_ITER</tt></b></dt> |
| 146 | <dd> |
| 147 | Implements <code>TOS = iter(TOS)</code>. |
| 148 | </dt></dl> |
| 149 | |
| 150 | <P> |
| 151 | Binary operations remove the top of the stack (TOS) and the second top-most |
| 152 | stack item (TOS1) from the stack. They perform the operation, and put the |
| 153 | result back on the stack. |
| 154 | |
| 155 | <P> |
| 156 | <dl><dt><b><tt class="opcode">BINARY_POWER</tt></b></dt> |
| 157 | <dd> |
| 158 | Implements <code>TOS = TOS1 ** TOS</code>. |
| 159 | </dt></dl> |
| 160 | |
| 161 | <P> |
| 162 | <dl><dt><b><tt class="opcode">BINARY_MULTIPLY</tt></b></dt> |
| 163 | <dd> |
| 164 | Implements <code>TOS = TOS1 * TOS</code>. |
| 165 | </dt></dl> |
| 166 | |
| 167 | <P> |
| 168 | <dl><dt><b><tt class="opcode">BINARY_DIVIDE</tt></b></dt> |
| 169 | <dd> |
| 170 | Implements <code>TOS = TOS1 / TOS</code> when |
| 171 | <code>from __future__ import division</code> is not in effect. |
| 172 | </dt></dl> |
| 173 | |
| 174 | <P> |
| 175 | <dl><dt><b><tt class="opcode">BINARY_FLOOR_DIVIDE</tt></b></dt> |
| 176 | <dd> |
| 177 | Implements <code>TOS = TOS1 // TOS</code>. |
| 178 | </dt></dl> |
| 179 | |
| 180 | <P> |
| 181 | <dl><dt><b><tt class="opcode">BINARY_TRUE_DIVIDE</tt></b></dt> |
| 182 | <dd> |
| 183 | Implements <code>TOS = TOS1 / TOS</code> when |
| 184 | <code>from __future__ import division</code> is in effect. |
| 185 | </dt></dl> |
| 186 | |
| 187 | <P> |
| 188 | <dl><dt><b><tt class="opcode">BINARY_MODULO</tt></b></dt> |
| 189 | <dd> |
| 190 | Implements <code>TOS = TOS1 % TOS</code>. |
| 191 | </dt></dl> |
| 192 | |
| 193 | <P> |
| 194 | <dl><dt><b><tt class="opcode">BINARY_ADD</tt></b></dt> |
| 195 | <dd> |
| 196 | Implements <code>TOS = TOS1 + TOS</code>. |
| 197 | </dt></dl> |
| 198 | |
| 199 | <P> |
| 200 | <dl><dt><b><tt class="opcode">BINARY_SUBTRACT</tt></b></dt> |
| 201 | <dd> |
| 202 | Implements <code>TOS = TOS1 - TOS</code>. |
| 203 | </dt></dl> |
| 204 | |
| 205 | <P> |
| 206 | <dl><dt><b><tt class="opcode">BINARY_SUBSCR</tt></b></dt> |
| 207 | <dd> |
| 208 | Implements <code>TOS = TOS1[TOS]</code>. |
| 209 | </dt></dl> |
| 210 | |
| 211 | <P> |
| 212 | <dl><dt><b><tt class="opcode">BINARY_LSHIFT</tt></b></dt> |
| 213 | <dd> |
| 214 | Implements <code>TOS = TOS1 <<code></code>< TOS</code>. |
| 215 | </dt></dl> |
| 216 | |
| 217 | <P> |
| 218 | <dl><dt><b><tt class="opcode">BINARY_RSHIFT</tt></b></dt> |
| 219 | <dd> |
| 220 | Implements <code>TOS = TOS1 ><code></code>> TOS</code>. |
| 221 | </dt></dl> |
| 222 | |
| 223 | <P> |
| 224 | <dl><dt><b><tt class="opcode">BINARY_AND</tt></b></dt> |
| 225 | <dd> |
| 226 | Implements <code>TOS = TOS1 & TOS</code>. |
| 227 | </dt></dl> |
| 228 | |
| 229 | <P> |
| 230 | <dl><dt><b><tt class="opcode">BINARY_XOR</tt></b></dt> |
| 231 | <dd> |
| 232 | Implements <code>TOS = TOS1 ^ TOS</code>. |
| 233 | </dt></dl> |
| 234 | |
| 235 | <P> |
| 236 | <dl><dt><b><tt class="opcode">BINARY_OR</tt></b></dt> |
| 237 | <dd> |
| 238 | Implements <code>TOS = TOS1 | TOS</code>. |
| 239 | </dt></dl> |
| 240 | |
| 241 | <P> |
| 242 | In-place operations are like binary operations, in that they remove TOS and |
| 243 | TOS1, and push the result back on the stack, but the operation is done |
| 244 | in-place when TOS1 supports it, and the resulting TOS may be (but does not |
| 245 | have to be) the original TOS1. |
| 246 | |
| 247 | <P> |
| 248 | <dl><dt><b><tt class="opcode">INPLACE_POWER</tt></b></dt> |
| 249 | <dd> |
| 250 | Implements in-place <code>TOS = TOS1 ** TOS</code>. |
| 251 | </dt></dl> |
| 252 | |
| 253 | <P> |
| 254 | <dl><dt><b><tt class="opcode">INPLACE_MULTIPLY</tt></b></dt> |
| 255 | <dd> |
| 256 | Implements in-place <code>TOS = TOS1 * TOS</code>. |
| 257 | </dt></dl> |
| 258 | |
| 259 | <P> |
| 260 | <dl><dt><b><tt class="opcode">INPLACE_DIVIDE</tt></b></dt> |
| 261 | <dd> |
| 262 | Implements in-place <code>TOS = TOS1 / TOS</code> when |
| 263 | <code>from __future__ import division</code> is not in effect. |
| 264 | </dt></dl> |
| 265 | |
| 266 | <P> |
| 267 | <dl><dt><b><tt class="opcode">INPLACE_FLOOR_DIVIDE</tt></b></dt> |
| 268 | <dd> |
| 269 | Implements in-place <code>TOS = TOS1 // TOS</code>. |
| 270 | </dt></dl> |
| 271 | |
| 272 | <P> |
| 273 | <dl><dt><b><tt class="opcode">INPLACE_TRUE_DIVIDE</tt></b></dt> |
| 274 | <dd> |
| 275 | Implements in-place <code>TOS = TOS1 / TOS</code> when |
| 276 | <code>from __future__ import division</code> is in effect. |
| 277 | </dt></dl> |
| 278 | |
| 279 | <P> |
| 280 | <dl><dt><b><tt class="opcode">INPLACE_MODULO</tt></b></dt> |
| 281 | <dd> |
| 282 | Implements in-place <code>TOS = TOS1 % TOS</code>. |
| 283 | </dt></dl> |
| 284 | |
| 285 | <P> |
| 286 | <dl><dt><b><tt class="opcode">INPLACE_ADD</tt></b></dt> |
| 287 | <dd> |
| 288 | Implements in-place <code>TOS = TOS1 + TOS</code>. |
| 289 | </dt></dl> |
| 290 | |
| 291 | <P> |
| 292 | <dl><dt><b><tt class="opcode">INPLACE_SUBTRACT</tt></b></dt> |
| 293 | <dd> |
| 294 | Implements in-place <code>TOS = TOS1 - TOS</code>. |
| 295 | </dt></dl> |
| 296 | |
| 297 | <P> |
| 298 | <dl><dt><b><tt class="opcode">INPLACE_LSHIFT</tt></b></dt> |
| 299 | <dd> |
| 300 | Implements in-place <code>TOS = TOS1 <<code></code>< TOS</code>. |
| 301 | </dt></dl> |
| 302 | |
| 303 | <P> |
| 304 | <dl><dt><b><tt class="opcode">INPLACE_RSHIFT</tt></b></dt> |
| 305 | <dd> |
| 306 | Implements in-place <code>TOS = TOS1 ><code></code>> TOS</code>. |
| 307 | </dt></dl> |
| 308 | |
| 309 | <P> |
| 310 | <dl><dt><b><tt class="opcode">INPLACE_AND</tt></b></dt> |
| 311 | <dd> |
| 312 | Implements in-place <code>TOS = TOS1 & TOS</code>. |
| 313 | </dt></dl> |
| 314 | |
| 315 | <P> |
| 316 | <dl><dt><b><tt class="opcode">INPLACE_XOR</tt></b></dt> |
| 317 | <dd> |
| 318 | Implements in-place <code>TOS = TOS1 ^ TOS</code>. |
| 319 | </dt></dl> |
| 320 | |
| 321 | <P> |
| 322 | <dl><dt><b><tt class="opcode">INPLACE_OR</tt></b></dt> |
| 323 | <dd> |
| 324 | Implements in-place <code>TOS = TOS1 | TOS</code>. |
| 325 | </dt></dl> |
| 326 | |
| 327 | <P> |
| 328 | The slice opcodes take up to three parameters. |
| 329 | |
| 330 | <P> |
| 331 | <dl><dt><b><tt class="opcode">SLICE+0</tt></b></dt> |
| 332 | <dd> |
| 333 | Implements <code>TOS = TOS[:]</code>. |
| 334 | </dt></dl> |
| 335 | |
| 336 | <P> |
| 337 | <dl><dt><b><tt class="opcode">SLICE+1</tt></b></dt> |
| 338 | <dd> |
| 339 | Implements <code>TOS = TOS1[TOS:]</code>. |
| 340 | </dt></dl> |
| 341 | |
| 342 | <P> |
| 343 | <dl><dt><b><tt class="opcode">SLICE+2</tt></b></dt> |
| 344 | <dd> |
| 345 | Implements <code>TOS = TOS1[:TOS]</code>. |
| 346 | </dt></dl> |
| 347 | |
| 348 | <P> |
| 349 | <dl><dt><b><tt class="opcode">SLICE+3</tt></b></dt> |
| 350 | <dd> |
| 351 | Implements <code>TOS = TOS2[TOS1:TOS]</code>. |
| 352 | </dt></dl> |
| 353 | |
| 354 | <P> |
| 355 | Slice assignment needs even an additional parameter. As any statement, |
| 356 | they put nothing on the stack. |
| 357 | |
| 358 | <P> |
| 359 | <dl><dt><b><tt class="opcode">STORE_SLICE+0</tt></b></dt> |
| 360 | <dd> |
| 361 | Implements <code>TOS[:] = TOS1</code>. |
| 362 | </dt></dl> |
| 363 | |
| 364 | <P> |
| 365 | <dl><dt><b><tt class="opcode">STORE_SLICE+1</tt></b></dt> |
| 366 | <dd> |
| 367 | Implements <code>TOS1[TOS:] = TOS2</code>. |
| 368 | </dt></dl> |
| 369 | |
| 370 | <P> |
| 371 | <dl><dt><b><tt class="opcode">STORE_SLICE+2</tt></b></dt> |
| 372 | <dd> |
| 373 | Implements <code>TOS1[:TOS] = TOS2</code>. |
| 374 | </dt></dl> |
| 375 | |
| 376 | <P> |
| 377 | <dl><dt><b><tt class="opcode">STORE_SLICE+3</tt></b></dt> |
| 378 | <dd> |
| 379 | Implements <code>TOS2[TOS1:TOS] = TOS3</code>. |
| 380 | </dt></dl> |
| 381 | |
| 382 | <P> |
| 383 | <dl><dt><b><tt class="opcode">DELETE_SLICE+0</tt></b></dt> |
| 384 | <dd> |
| 385 | Implements <code>del TOS[:]</code>. |
| 386 | </dt></dl> |
| 387 | |
| 388 | <P> |
| 389 | <dl><dt><b><tt class="opcode">DELETE_SLICE+1</tt></b></dt> |
| 390 | <dd> |
| 391 | Implements <code>del TOS1[TOS:]</code>. |
| 392 | </dt></dl> |
| 393 | |
| 394 | <P> |
| 395 | <dl><dt><b><tt class="opcode">DELETE_SLICE+2</tt></b></dt> |
| 396 | <dd> |
| 397 | Implements <code>del TOS1[:TOS]</code>. |
| 398 | </dt></dl> |
| 399 | |
| 400 | <P> |
| 401 | <dl><dt><b><tt class="opcode">DELETE_SLICE+3</tt></b></dt> |
| 402 | <dd> |
| 403 | Implements <code>del TOS2[TOS1:TOS]</code>. |
| 404 | </dt></dl> |
| 405 | |
| 406 | <P> |
| 407 | <dl><dt><b><tt class="opcode">STORE_SUBSCR</tt></b></dt> |
| 408 | <dd> |
| 409 | Implements <code>TOS1[TOS] = TOS2</code>. |
| 410 | </dt></dl> |
| 411 | |
| 412 | <P> |
| 413 | <dl><dt><b><tt class="opcode">DELETE_SUBSCR</tt></b></dt> |
| 414 | <dd> |
| 415 | Implements <code>del TOS1[TOS]</code>. |
| 416 | </dt></dl> |
| 417 | |
| 418 | <P> |
| 419 | Miscellaneous opcodes. |
| 420 | |
| 421 | <P> |
| 422 | <dl><dt><b><tt class="opcode">PRINT_EXPR</tt></b></dt> |
| 423 | <dd> |
| 424 | Implements the expression statement for the interactive mode. TOS is |
| 425 | removed from the stack and printed. In non-interactive mode, an |
| 426 | expression statement is terminated with <code>POP_STACK</code>. |
| 427 | </dt></dl> |
| 428 | |
| 429 | <P> |
| 430 | <dl><dt><b><tt class="opcode">PRINT_ITEM</tt></b></dt> |
| 431 | <dd> |
| 432 | Prints TOS to the file-like object bound to <code>sys.stdout</code>. There |
| 433 | is one such instruction for each item in the <tt class="keyword">print</tt> statement. |
| 434 | </dt></dl> |
| 435 | |
| 436 | <P> |
| 437 | <dl><dt><b><tt class="opcode">PRINT_ITEM_TO</tt></b></dt> |
| 438 | <dd> |
| 439 | Like <code>PRINT_ITEM</code>, but prints the item second from TOS to the |
| 440 | file-like object at TOS. This is used by the extended print statement. |
| 441 | </dt></dl> |
| 442 | |
| 443 | <P> |
| 444 | <dl><dt><b><tt class="opcode">PRINT_NEWLINE</tt></b></dt> |
| 445 | <dd> |
| 446 | Prints a new line on <code>sys.stdout</code>. This is generated as the |
| 447 | last operation of a <tt class="keyword">print</tt> statement, unless the statement |
| 448 | ends with a comma. |
| 449 | </dt></dl> |
| 450 | |
| 451 | <P> |
| 452 | <dl><dt><b><tt class="opcode">PRINT_NEWLINE_TO</tt></b></dt> |
| 453 | <dd> |
| 454 | Like <code>PRINT_NEWLINE</code>, but prints the new line on the file-like |
| 455 | object on the TOS. This is used by the extended print statement. |
| 456 | </dt></dl> |
| 457 | |
| 458 | <P> |
| 459 | <dl><dt><b><tt class="opcode">BREAK_LOOP</tt></b></dt> |
| 460 | <dd> |
| 461 | Terminates a loop due to a <tt class="keyword">break</tt> statement. |
| 462 | </dt></dl> |
| 463 | |
| 464 | <P> |
| 465 | <dl><dt><b><tt class="opcode">CONTINUE_LOOP</tt></b> <var>target</var></dt> |
| 466 | <dd> |
| 467 | Continues a loop due to a <tt class="keyword">continue</tt> statement. <var>target</var> |
| 468 | is the address to jump to (which should be a <code>FOR_ITER</code> |
| 469 | instruction). |
| 470 | </dt></dl> |
| 471 | |
| 472 | <P> |
| 473 | <dl><dt><b><tt class="opcode">LIST_APPEND</tt></b></dt> |
| 474 | <dd> |
| 475 | Calls <code>list.append(TOS1, TOS)</code>. Used to implement list comprehensions. |
| 476 | </dt></dl> |
| 477 | |
| 478 | <P> |
| 479 | <dl><dt><b><tt class="opcode">LOAD_LOCALS</tt></b></dt> |
| 480 | <dd> |
| 481 | Pushes a reference to the locals of the current scope on the stack. |
| 482 | This is used in the code for a class definition: After the class body |
| 483 | is evaluated, the locals are passed to the class definition. |
| 484 | </dt></dl> |
| 485 | |
| 486 | <P> |
| 487 | <dl><dt><b><tt class="opcode">RETURN_VALUE</tt></b></dt> |
| 488 | <dd> |
| 489 | Returns with TOS to the caller of the function. |
| 490 | </dt></dl> |
| 491 | |
| 492 | <P> |
| 493 | <dl><dt><b><tt class="opcode">YIELD_VALUE</tt></b></dt> |
| 494 | <dd> |
| 495 | Pops <code>TOS</code> and yields it from a generator. |
| 496 | </dt></dl> |
| 497 | |
| 498 | <P> |
| 499 | <dl><dt><b><tt class="opcode">IMPORT_STAR</tt></b></dt> |
| 500 | <dd> |
| 501 | Loads all symbols not starting with "<tt class="character">_</tt>" directly from the module TOS |
| 502 | to the local namespace. The module is popped after loading all names. |
| 503 | This opcode implements <code>from module import *</code>. |
| 504 | </dt></dl> |
| 505 | |
| 506 | <P> |
| 507 | <dl><dt><b><tt class="opcode">EXEC_STMT</tt></b></dt> |
| 508 | <dd> |
| 509 | Implements <code>exec TOS2,TOS1,TOS</code>. The compiler fills |
| 510 | missing optional parameters with <code>None</code>. |
| 511 | </dt></dl> |
| 512 | |
| 513 | <P> |
| 514 | <dl><dt><b><tt class="opcode">POP_BLOCK</tt></b></dt> |
| 515 | <dd> |
| 516 | Removes one block from the block stack. Per frame, there is a |
| 517 | stack of blocks, denoting nested loops, try statements, and such. |
| 518 | </dt></dl> |
| 519 | |
| 520 | <P> |
| 521 | <dl><dt><b><tt class="opcode">END_FINALLY</tt></b></dt> |
| 522 | <dd> |
| 523 | Terminates a <tt class="keyword">finally</tt> clause. The interpreter recalls |
| 524 | whether the exception has to be re-raised, or whether the function |
| 525 | returns, and continues with the outer-next block. |
| 526 | </dt></dl> |
| 527 | |
| 528 | <P> |
| 529 | <dl><dt><b><tt class="opcode">BUILD_CLASS</tt></b></dt> |
| 530 | <dd> |
| 531 | Creates a new class object. TOS is the methods dictionary, TOS1 |
| 532 | the tuple of the names of the base classes, and TOS2 the class name. |
| 533 | </dt></dl> |
| 534 | |
| 535 | <P> |
| 536 | All of the following opcodes expect arguments. An argument is two |
| 537 | bytes, with the more significant byte last. |
| 538 | |
| 539 | <P> |
| 540 | <dl><dt><b><tt class="opcode">STORE_NAME</tt></b> <var>namei</var></dt> |
| 541 | <dd> |
| 542 | Implements <code>name = TOS</code>. <var>namei</var> is the index of <var>name</var> |
| 543 | in the attribute <tt class="member">co_names</tt> of the code object. |
| 544 | The compiler tries to use <code>STORE_LOCAL</code> or <code>STORE_GLOBAL</code> |
| 545 | if possible. |
| 546 | </dt></dl> |
| 547 | |
| 548 | <P> |
| 549 | <dl><dt><b><tt class="opcode">DELETE_NAME</tt></b> <var>namei</var></dt> |
| 550 | <dd> |
| 551 | Implements <code>del name</code>, where <var>namei</var> is the index into |
| 552 | <tt class="member">co_names</tt> attribute of the code object. |
| 553 | </dt></dl> |
| 554 | |
| 555 | <P> |
| 556 | <dl><dt><b><tt class="opcode">UNPACK_SEQUENCE</tt></b> <var>count</var></dt> |
| 557 | <dd> |
| 558 | Unpacks TOS into <var>count</var> individual values, which are put onto |
| 559 | the stack right-to-left. |
| 560 | </dt></dl> |
| 561 | |
| 562 | <P> |
| 563 | <dl><dt><b><tt class="opcode">DUP_TOPX</tt></b> <var>count</var></dt> |
| 564 | <dd> |
| 565 | Duplicate <var>count</var> items, keeping them in the same order. Due to |
| 566 | implementation limits, <var>count</var> should be between 1 and 5 inclusive. |
| 567 | </dt></dl> |
| 568 | |
| 569 | <P> |
| 570 | <dl><dt><b><tt class="opcode">STORE_ATTR</tt></b> <var>namei</var></dt> |
| 571 | <dd> |
| 572 | Implements <code>TOS.name = TOS1</code>, where <var>namei</var> is the index |
| 573 | of name in <tt class="member">co_names</tt>. |
| 574 | </dt></dl> |
| 575 | |
| 576 | <P> |
| 577 | <dl><dt><b><tt class="opcode">DELETE_ATTR</tt></b> <var>namei</var></dt> |
| 578 | <dd> |
| 579 | Implements <code>del TOS.name</code>, using <var>namei</var> as index into |
| 580 | <tt class="member">co_names</tt>. |
| 581 | </dt></dl> |
| 582 | |
| 583 | <P> |
| 584 | <dl><dt><b><tt class="opcode">STORE_GLOBAL</tt></b> <var>namei</var></dt> |
| 585 | <dd> |
| 586 | Works as <code>STORE_NAME</code>, but stores the name as a global. |
| 587 | </dt></dl> |
| 588 | |
| 589 | <P> |
| 590 | <dl><dt><b><tt class="opcode">DELETE_GLOBAL</tt></b> <var>namei</var></dt> |
| 591 | <dd> |
| 592 | Works as <code>DELETE_NAME</code>, but deletes a global name. |
| 593 | </dt></dl> |
| 594 | |
| 595 | <P> |
| 596 | <dl><dt><b><tt class="opcode">LOAD_CONST</tt></b> <var>consti</var></dt> |
| 597 | <dd> |
| 598 | Pushes "<tt class="samp">co_consts[<var>consti</var>]</tt>" onto the stack. |
| 599 | </dt></dl> |
| 600 | |
| 601 | <P> |
| 602 | <dl><dt><b><tt class="opcode">LOAD_NAME</tt></b> <var>namei</var></dt> |
| 603 | <dd> |
| 604 | Pushes the value associated with "<tt class="samp">co_names[<var>namei</var>]</tt>" onto the stack. |
| 605 | </dt></dl> |
| 606 | |
| 607 | <P> |
| 608 | <dl><dt><b><tt class="opcode">BUILD_TUPLE</tt></b> <var>count</var></dt> |
| 609 | <dd> |
| 610 | Creates a tuple consuming <var>count</var> items from the stack, and pushes |
| 611 | the resulting tuple onto the stack. |
| 612 | </dt></dl> |
| 613 | |
| 614 | <P> |
| 615 | <dl><dt><b><tt class="opcode">BUILD_LIST</tt></b> <var>count</var></dt> |
| 616 | <dd> |
| 617 | Works as <code>BUILD_TUPLE</code>, but creates a list. |
| 618 | </dt></dl> |
| 619 | |
| 620 | <P> |
| 621 | <dl><dt><b><tt class="opcode">BUILD_MAP</tt></b> <var>zero</var></dt> |
| 622 | <dd> |
| 623 | Pushes a new empty dictionary object onto the stack. The argument is |
| 624 | ignored and set to zero by the compiler. |
| 625 | </dt></dl> |
| 626 | |
| 627 | <P> |
| 628 | <dl><dt><b><tt class="opcode">LOAD_ATTR</tt></b> <var>namei</var></dt> |
| 629 | <dd> |
| 630 | Replaces TOS with <code>getattr(TOS, co_names[<var>namei</var>])</code>. |
| 631 | </dt></dl> |
| 632 | |
| 633 | <P> |
| 634 | <dl><dt><b><tt class="opcode">COMPARE_OP</tt></b> <var>opname</var></dt> |
| 635 | <dd> |
| 636 | Performs a Boolean operation. The operation name can be found |
| 637 | in <code>cmp_op[<var>opname</var>]</code>. |
| 638 | </dt></dl> |
| 639 | |
| 640 | <P> |
| 641 | <dl><dt><b><tt class="opcode">IMPORT_NAME</tt></b> <var>namei</var></dt> |
| 642 | <dd> |
| 643 | Imports the module <code>co_names[<var>namei</var>]</code>. The module object is |
| 644 | pushed onto the stack. The current namespace is not affected: for a |
| 645 | proper import statement, a subsequent <code>STORE_FAST</code> instruction |
| 646 | modifies the namespace. |
| 647 | </dt></dl> |
| 648 | |
| 649 | <P> |
| 650 | <dl><dt><b><tt class="opcode">IMPORT_FROM</tt></b> <var>namei</var></dt> |
| 651 | <dd> |
| 652 | Loads the attribute <code>co_names[<var>namei</var>]</code> from the module found in |
| 653 | TOS. The resulting object is pushed onto the stack, to be subsequently |
| 654 | stored by a <code>STORE_FAST</code> instruction. |
| 655 | </dt></dl> |
| 656 | |
| 657 | <P> |
| 658 | <dl><dt><b><tt class="opcode">JUMP_FORWARD</tt></b> <var>delta</var></dt> |
| 659 | <dd> |
| 660 | Increments byte code counter by <var>delta</var>. |
| 661 | </dt></dl> |
| 662 | |
| 663 | <P> |
| 664 | <dl><dt><b><tt class="opcode">JUMP_IF_TRUE</tt></b> <var>delta</var></dt> |
| 665 | <dd> |
| 666 | If TOS is true, increment the byte code counter by <var>delta</var>. TOS is |
| 667 | left on the stack. |
| 668 | </dt></dl> |
| 669 | |
| 670 | <P> |
| 671 | <dl><dt><b><tt class="opcode">JUMP_IF_FALSE</tt></b> <var>delta</var></dt> |
| 672 | <dd> |
| 673 | If TOS is false, increment the byte code counter by <var>delta</var>. TOS |
| 674 | is not changed. |
| 675 | </dt></dl> |
| 676 | |
| 677 | <P> |
| 678 | <dl><dt><b><tt class="opcode">JUMP_ABSOLUTE</tt></b> <var>target</var></dt> |
| 679 | <dd> |
| 680 | Set byte code counter to <var>target</var>. |
| 681 | </dt></dl> |
| 682 | |
| 683 | <P> |
| 684 | <dl><dt><b><tt class="opcode">FOR_ITER</tt></b> <var>delta</var></dt> |
| 685 | <dd> |
| 686 | <code>TOS</code> is an iterator. Call its <tt class="method">next()</tt> method. If this |
| 687 | yields a new value, push it on the stack (leaving the iterator below |
| 688 | it). If the iterator indicates it is exhausted <code>TOS</code> is |
| 689 | popped, and the byte code counter is incremented by <var>delta</var>. |
| 690 | </dt></dl> |
| 691 | |
| 692 | <P> |
| 693 | <dl><dt><b><tt class="opcode">LOAD_GLOBAL</tt></b> <var>namei</var></dt> |
| 694 | <dd> |
| 695 | Loads the global named <code>co_names[<var>namei</var>]</code> onto the stack. |
| 696 | </dt></dl> |
| 697 | |
| 698 | <P> |
| 699 | <dl><dt><b><tt class="opcode">SETUP_LOOP</tt></b> <var>delta</var></dt> |
| 700 | <dd> |
| 701 | Pushes a block for a loop onto the block stack. The block spans |
| 702 | from the current instruction with a size of <var>delta</var> bytes. |
| 703 | </dt></dl> |
| 704 | |
| 705 | <P> |
| 706 | <dl><dt><b><tt class="opcode">SETUP_EXCEPT</tt></b> <var>delta</var></dt> |
| 707 | <dd> |
| 708 | Pushes a try block from a try-except clause onto the block stack. |
| 709 | <var>delta</var> points to the first except block. |
| 710 | </dt></dl> |
| 711 | |
| 712 | <P> |
| 713 | <dl><dt><b><tt class="opcode">SETUP_FINALLY</tt></b> <var>delta</var></dt> |
| 714 | <dd> |
| 715 | Pushes a try block from a try-except clause onto the block stack. |
| 716 | <var>delta</var> points to the finally block. |
| 717 | </dt></dl> |
| 718 | |
| 719 | <P> |
| 720 | <dl><dt><b><tt class="opcode">LOAD_FAST</tt></b> <var>var_num</var></dt> |
| 721 | <dd> |
| 722 | Pushes a reference to the local <code>co_varnames[<var>var_num</var>]</code> onto |
| 723 | the stack. |
| 724 | </dt></dl> |
| 725 | |
| 726 | <P> |
| 727 | <dl><dt><b><tt class="opcode">STORE_FAST</tt></b> <var>var_num</var></dt> |
| 728 | <dd> |
| 729 | Stores TOS into the local <code>co_varnames[<var>var_num</var>]</code>. |
| 730 | </dt></dl> |
| 731 | |
| 732 | <P> |
| 733 | <dl><dt><b><tt class="opcode">DELETE_FAST</tt></b> <var>var_num</var></dt> |
| 734 | <dd> |
| 735 | Deletes local <code>co_varnames[<var>var_num</var>]</code>. |
| 736 | </dt></dl> |
| 737 | |
| 738 | <P> |
| 739 | <dl><dt><b><tt class="opcode">LOAD_CLOSURE</tt></b> <var>i</var></dt> |
| 740 | <dd> |
| 741 | Pushes a reference to the cell contained in slot <var>i</var> of the |
| 742 | cell and free variable storage. The name of the variable is |
| 743 | <code>co_cellvars[<var>i</var>]</code> if <var>i</var> is less than the length of |
| 744 | <var>co_cellvars</var>. Otherwise it is |
| 745 | <code>co_freevars[<var>i</var> - len(co_cellvars)]</code>. |
| 746 | </dt></dl> |
| 747 | |
| 748 | <P> |
| 749 | <dl><dt><b><tt class="opcode">LOAD_DEREF</tt></b> <var>i</var></dt> |
| 750 | <dd> |
| 751 | Loads the cell contained in slot <var>i</var> of the cell and free variable |
| 752 | storage. Pushes a reference to the object the cell contains on the |
| 753 | stack. |
| 754 | </dt></dl> |
| 755 | |
| 756 | <P> |
| 757 | <dl><dt><b><tt class="opcode">STORE_DEREF</tt></b> <var>i</var></dt> |
| 758 | <dd> |
| 759 | Stores TOS into the cell contained in slot <var>i</var> of the cell and |
| 760 | free variable storage. |
| 761 | </dt></dl> |
| 762 | |
| 763 | <P> |
| 764 | <dl><dt><b><tt class="opcode">SET_LINENO</tt></b> <var>lineno</var></dt> |
| 765 | <dd> |
| 766 | This opcode is obsolete. |
| 767 | </dt></dl> |
| 768 | |
| 769 | <P> |
| 770 | <dl><dt><b><tt class="opcode">RAISE_VARARGS</tt></b> <var>argc</var></dt> |
| 771 | <dd> |
| 772 | Raises an exception. <var>argc</var> indicates the number of parameters |
| 773 | to the raise statement, ranging from 0 to 3. The handler will find |
| 774 | the traceback as TOS2, the parameter as TOS1, and the exception |
| 775 | as TOS. |
| 776 | </dt></dl> |
| 777 | |
| 778 | <P> |
| 779 | <dl><dt><b><tt class="opcode">CALL_FUNCTION</tt></b> <var>argc</var></dt> |
| 780 | <dd> |
| 781 | Calls a function. The low byte of <var>argc</var> indicates the number of |
| 782 | positional parameters, the high byte the number of keyword parameters. |
| 783 | On the stack, the opcode finds the keyword parameters first. For each |
| 784 | keyword argument, the value is on top of the key. Below the keyword |
| 785 | parameters, the positional parameters are on the stack, with the |
| 786 | right-most parameter on top. Below the parameters, the function object |
| 787 | to call is on the stack. |
| 788 | </dt></dl> |
| 789 | |
| 790 | <P> |
| 791 | <dl><dt><b><tt class="opcode">MAKE_FUNCTION</tt></b> <var>argc</var></dt> |
| 792 | <dd> |
| 793 | Pushes a new function object on the stack. TOS is the code associated |
| 794 | with the function. The function object is defined to have <var>argc</var> |
| 795 | default parameters, which are found below TOS. |
| 796 | </dt></dl> |
| 797 | |
| 798 | <P> |
| 799 | <dl><dt><b><tt class="opcode">MAKE_CLOSURE</tt></b> <var>argc</var></dt> |
| 800 | <dd> |
| 801 | Creates a new function object, sets its <var>func_closure</var> slot, and |
| 802 | pushes it on the stack. TOS is the code associated with the function. |
| 803 | If the code object has N free variables, the next N items on the stack |
| 804 | are the cells for these variables. The function also has <var>argc</var> |
| 805 | default parameters, where are found before the cells. |
| 806 | </dt></dl> |
| 807 | |
| 808 | <P> |
| 809 | <dl><dt><b><tt class="opcode">BUILD_SLICE</tt></b> <var>argc</var></dt> |
| 810 | <dd> |
| 811 | Pushes a slice object on the stack. <var>argc</var> must be 2 or 3. If it |
| 812 | is 2, <code>slice(TOS1, TOS)</code> is pushed; if it is 3, |
| 813 | <code>slice(TOS2, TOS1, TOS)</code> is pushed. |
| 814 | See the <code>slice()</code><a id='l2h-5014' xml:id='l2h-5014'></a> built-in function for more |
| 815 | information. |
| 816 | </dt></dl> |
| 817 | |
| 818 | <P> |
| 819 | <dl><dt><b><tt class="opcode">EXTENDED_ARG</tt></b> <var>ext</var></dt> |
| 820 | <dd> |
| 821 | Prefixes any opcode which has an argument too big to fit into the |
| 822 | default two bytes. <var>ext</var> holds two additional bytes which, taken |
| 823 | together with the subsequent opcode's argument, comprise a four-byte |
| 824 | argument, <var>ext</var> being the two most-significant bytes. |
| 825 | </dt></dl> |
| 826 | |
| 827 | <P> |
| 828 | <dl><dt><b><tt class="opcode">CALL_FUNCTION_VAR</tt></b> <var>argc</var></dt> |
| 829 | <dd> |
| 830 | Calls a function. <var>argc</var> is interpreted as in <code>CALL_FUNCTION</code>. |
| 831 | The top element on the stack contains the variable argument list, followed |
| 832 | by keyword and positional arguments. |
| 833 | </dt></dl> |
| 834 | |
| 835 | <P> |
| 836 | <dl><dt><b><tt class="opcode">CALL_FUNCTION_KW</tt></b> <var>argc</var></dt> |
| 837 | <dd> |
| 838 | Calls a function. <var>argc</var> is interpreted as in <code>CALL_FUNCTION</code>. |
| 839 | The top element on the stack contains the keyword arguments dictionary, |
| 840 | followed by explicit keyword and positional arguments. |
| 841 | </dt></dl> |
| 842 | |
| 843 | <P> |
| 844 | <dl><dt><b><tt class="opcode">CALL_FUNCTION_VAR_KW</tt></b> <var>argc</var></dt> |
| 845 | <dd> |
| 846 | Calls a function. <var>argc</var> is interpreted as in |
| 847 | <code>CALL_FUNCTION</code>. The top element on the stack contains the |
| 848 | keyword arguments dictionary, followed by the variable-arguments |
| 849 | tuple, followed by explicit keyword and positional arguments. |
| 850 | </dt></dl> |
| 851 | |
| 852 | <DIV CLASS="navigation"> |
| 853 | <div class='online-navigation'> |
| 854 | <p></p><hr /> |
| 855 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 856 | <tr> |
| 857 | <td class='online-navigation'><a rel="prev" title="18.10 dis " |
| 858 | href="module-dis.html"><img src='../icons/previous.png' |
| 859 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 860 | <td class='online-navigation'><a rel="parent" title="18.10 dis " |
| 861 | href="module-dis.html"><img src='../icons/up.png' |
| 862 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 863 | <td class='online-navigation'><a rel="next" title="18.11 pickletools " |
| 864 | href="module-pickletools.html"><img src='../icons/next.png' |
| 865 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 866 | <td align="center" width="100%">Python Library Reference</td> |
| 867 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 868 | href="contents.html"><img src='../icons/contents.png' |
| 869 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 870 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 871 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 872 | <td class='online-navigation'><a rel="index" title="Index" |
| 873 | href="genindex.html"><img src='../icons/index.png' |
| 874 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 875 | </tr></table> |
| 876 | <div class='online-navigation'> |
| 877 | <b class="navlabel">Previous:</b> |
| 878 | <a class="sectref" rel="prev" href="module-dis.html">18.10 dis </A> |
| 879 | <b class="navlabel">Up:</b> |
| 880 | <a class="sectref" rel="parent" href="module-dis.html">18.10 dis </A> |
| 881 | <b class="navlabel">Next:</b> |
| 882 | <a class="sectref" rel="next" href="module-pickletools.html">18.11 pickletools </A> |
| 883 | </div> |
| 884 | </div> |
| 885 | <hr /> |
| 886 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 887 | </DIV> |
| 888 | <!--End of Navigation Panel--> |
| 889 | <ADDRESS> |
| 890 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 891 | </ADDRESS> |
| 892 | </BODY> |
| 893 | </HTML> |