Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 1 | :mod:`dis` --- Disassembler for Python bytecode |
| 2 | =============================================== |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 3 | |
| 4 | .. module:: dis |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 5 | :synopsis: Disassembler for Python bytecode. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 6 | |
Éric Araujo | 29a0b57 | 2011-08-19 02:14:03 +0200 | [diff] [blame] | 7 | **Source code:** :source:`Lib/dis.py` |
| 8 | |
| 9 | -------------- |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 10 | |
Brett Cannon | 8c4fa11 | 2010-07-21 09:52:10 +0000 | [diff] [blame] | 11 | The :mod:`dis` module supports the analysis of CPython :term:`bytecode` by |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 12 | disassembling it. The CPython bytecode which this module takes as an input is |
| 13 | defined in the file :file:`Include/opcode.h` and used by the compiler and the |
| 14 | interpreter. |
Brett Cannon | 8c4fa11 | 2010-07-21 09:52:10 +0000 | [diff] [blame] | 15 | |
| 16 | .. impl-detail:: |
| 17 | |
| 18 | Bytecode is an implementation detail of the CPython interpreter! No |
| 19 | guarantees are made that bytecode will not be added, removed, or changed |
| 20 | between versions of Python. Use of this module should not be considered to |
| 21 | work across Python VMs or Python releases. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 22 | |
| 23 | Example: Given the function :func:`myfunc`:: |
| 24 | |
| 25 | def myfunc(alist): |
| 26 | return len(alist) |
| 27 | |
| 28 | the following command can be used to get the disassembly of :func:`myfunc`:: |
| 29 | |
| 30 | >>> dis.dis(myfunc) |
| 31 | 2 0 LOAD_GLOBAL 0 (len) |
| 32 | 3 LOAD_FAST 0 (alist) |
| 33 | 6 CALL_FUNCTION 1 |
| 34 | 9 RETURN_VALUE |
| 35 | |
| 36 | (The "2" is a line number). |
| 37 | |
| 38 | The :mod:`dis` module defines the following functions and constants: |
| 39 | |
| 40 | |
| 41 | .. function:: dis([bytesource]) |
| 42 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 43 | Disassemble the *bytesource* object. *bytesource* can denote either a module, |
| 44 | a class, a method, a function, or a code object. For a module, it |
| 45 | disassembles all functions. For a class, it disassembles all methods. For a |
| 46 | single code sequence, it prints one line per bytecode instruction. If no |
| 47 | object is provided, it disassembles the last traceback. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 48 | |
| 49 | |
| 50 | .. function:: distb([tb]) |
| 51 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 52 | Disassembles the top-of-stack function of a traceback, using the last |
| 53 | traceback if none was passed. The instruction causing the exception is |
| 54 | indicated. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 55 | |
| 56 | |
| 57 | .. function:: disassemble(code[, lasti]) |
| 58 | |
| 59 | Disassembles a code object, indicating the last instruction if *lasti* was |
| 60 | provided. The output is divided in the following columns: |
| 61 | |
| 62 | #. the line number, for the first instruction of each line |
| 63 | #. the current instruction, indicated as ``-->``, |
| 64 | #. a labelled instruction, indicated with ``>>``, |
| 65 | #. the address of the instruction, |
| 66 | #. the operation code name, |
| 67 | #. operation parameters, and |
| 68 | #. interpretation of the parameters in parentheses. |
| 69 | |
| 70 | The parameter interpretation recognizes local and global variable names, |
| 71 | constant values, branch targets, and compare operators. |
| 72 | |
| 73 | |
| 74 | .. function:: disco(code[, lasti]) |
| 75 | |
Georg Brandl | 775c307 | 2009-01-01 12:09:40 +0000 | [diff] [blame] | 76 | A synonym for :func:`disassemble`. It is more convenient to type, and kept |
| 77 | for compatibility with earlier Python releases. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 78 | |
| 79 | |
Georg Brandl | 775c307 | 2009-01-01 12:09:40 +0000 | [diff] [blame] | 80 | .. function:: findlinestarts(code) |
| 81 | |
| 82 | This generator function uses the ``co_firstlineno`` and ``co_lnotab`` |
| 83 | attributes of the code object *code* to find the offsets which are starts of |
| 84 | lines in the source code. They are generated as ``(offset, lineno)`` pairs. |
| 85 | |
| 86 | |
| 87 | .. function:: findlabels(code) |
| 88 | |
| 89 | Detect all offsets in the code object *code* which are jump targets, and |
| 90 | return a list of these offsets. |
Georg Brandl | c62ef8b | 2009-01-03 20:55:06 +0000 | [diff] [blame] | 91 | |
| 92 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 93 | .. data:: opname |
| 94 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 95 | Sequence of operation names, indexable using the bytecode. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 96 | |
| 97 | |
| 98 | .. data:: opmap |
| 99 | |
Georg Brandl | b8d0e36 | 2010-11-26 07:53:50 +0000 | [diff] [blame] | 100 | Dictionary mapping operation names to bytecodes. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 101 | |
| 102 | |
| 103 | .. data:: cmp_op |
| 104 | |
| 105 | Sequence of all compare operation names. |
| 106 | |
| 107 | |
| 108 | .. data:: hasconst |
| 109 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 110 | Sequence of bytecodes that have a constant parameter. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 111 | |
| 112 | |
| 113 | .. data:: hasfree |
| 114 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 115 | Sequence of bytecodes that access a free variable. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 116 | |
| 117 | |
| 118 | .. data:: hasname |
| 119 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 120 | Sequence of bytecodes that access an attribute by name. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 121 | |
| 122 | |
| 123 | .. data:: hasjrel |
| 124 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 125 | Sequence of bytecodes that have a relative jump target. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 126 | |
| 127 | |
| 128 | .. data:: hasjabs |
| 129 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 130 | Sequence of bytecodes that have an absolute jump target. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 131 | |
| 132 | |
| 133 | .. data:: haslocal |
| 134 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 135 | Sequence of bytecodes that access a local variable. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 136 | |
| 137 | |
| 138 | .. data:: hascompare |
| 139 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 140 | Sequence of bytecodes of Boolean operations. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 141 | |
| 142 | |
| 143 | .. _bytecodes: |
| 144 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 145 | Python Bytecode Instructions |
| 146 | ---------------------------- |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 147 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 148 | The Python compiler currently generates the following bytecode instructions. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 149 | |
| 150 | |
| 151 | .. opcode:: STOP_CODE () |
| 152 | |
| 153 | Indicates end-of-code to the compiler, not used by the interpreter. |
| 154 | |
| 155 | |
| 156 | .. opcode:: NOP () |
| 157 | |
| 158 | Do nothing code. Used as a placeholder by the bytecode optimizer. |
| 159 | |
| 160 | |
| 161 | .. opcode:: POP_TOP () |
| 162 | |
| 163 | Removes the top-of-stack (TOS) item. |
| 164 | |
| 165 | |
| 166 | .. opcode:: ROT_TWO () |
| 167 | |
| 168 | Swaps the two top-most stack items. |
| 169 | |
| 170 | |
| 171 | .. opcode:: ROT_THREE () |
| 172 | |
| 173 | Lifts second and third stack item one position up, moves top down to position |
| 174 | three. |
| 175 | |
| 176 | |
| 177 | .. opcode:: ROT_FOUR () |
| 178 | |
| 179 | Lifts second, third and forth stack item one position up, moves top down to |
| 180 | position four. |
| 181 | |
| 182 | |
| 183 | .. opcode:: DUP_TOP () |
| 184 | |
| 185 | Duplicates the reference on top of the stack. |
| 186 | |
| 187 | Unary Operations take the top of the stack, apply the operation, and push the |
| 188 | result back on the stack. |
| 189 | |
| 190 | |
| 191 | .. opcode:: UNARY_POSITIVE () |
| 192 | |
| 193 | Implements ``TOS = +TOS``. |
| 194 | |
| 195 | |
| 196 | .. opcode:: UNARY_NEGATIVE () |
| 197 | |
| 198 | Implements ``TOS = -TOS``. |
| 199 | |
| 200 | |
| 201 | .. opcode:: UNARY_NOT () |
| 202 | |
| 203 | Implements ``TOS = not TOS``. |
| 204 | |
| 205 | |
| 206 | .. opcode:: UNARY_CONVERT () |
| 207 | |
| 208 | Implements ``TOS = `TOS```. |
| 209 | |
| 210 | |
| 211 | .. opcode:: UNARY_INVERT () |
| 212 | |
| 213 | Implements ``TOS = ~TOS``. |
| 214 | |
| 215 | |
| 216 | .. opcode:: GET_ITER () |
| 217 | |
| 218 | Implements ``TOS = iter(TOS)``. |
| 219 | |
| 220 | Binary operations remove the top of the stack (TOS) and the second top-most |
| 221 | stack item (TOS1) from the stack. They perform the operation, and put the |
| 222 | result back on the stack. |
| 223 | |
| 224 | |
| 225 | .. opcode:: BINARY_POWER () |
| 226 | |
| 227 | Implements ``TOS = TOS1 ** TOS``. |
| 228 | |
| 229 | |
| 230 | .. opcode:: BINARY_MULTIPLY () |
| 231 | |
| 232 | Implements ``TOS = TOS1 * TOS``. |
| 233 | |
| 234 | |
| 235 | .. opcode:: BINARY_DIVIDE () |
| 236 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 237 | Implements ``TOS = TOS1 / TOS`` when ``from __future__ import division`` is |
| 238 | not in effect. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 239 | |
| 240 | |
| 241 | .. opcode:: BINARY_FLOOR_DIVIDE () |
| 242 | |
| 243 | Implements ``TOS = TOS1 // TOS``. |
| 244 | |
| 245 | |
| 246 | .. opcode:: BINARY_TRUE_DIVIDE () |
| 247 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 248 | Implements ``TOS = TOS1 / TOS`` when ``from __future__ import division`` is |
| 249 | in effect. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 250 | |
| 251 | |
| 252 | .. opcode:: BINARY_MODULO () |
| 253 | |
| 254 | Implements ``TOS = TOS1 % TOS``. |
| 255 | |
| 256 | |
| 257 | .. opcode:: BINARY_ADD () |
| 258 | |
| 259 | Implements ``TOS = TOS1 + TOS``. |
| 260 | |
| 261 | |
| 262 | .. opcode:: BINARY_SUBTRACT () |
| 263 | |
| 264 | Implements ``TOS = TOS1 - TOS``. |
| 265 | |
| 266 | |
| 267 | .. opcode:: BINARY_SUBSCR () |
| 268 | |
| 269 | Implements ``TOS = TOS1[TOS]``. |
| 270 | |
| 271 | |
| 272 | .. opcode:: BINARY_LSHIFT () |
| 273 | |
| 274 | Implements ``TOS = TOS1 << TOS``. |
| 275 | |
| 276 | |
| 277 | .. opcode:: BINARY_RSHIFT () |
| 278 | |
| 279 | Implements ``TOS = TOS1 >> TOS``. |
| 280 | |
| 281 | |
| 282 | .. opcode:: BINARY_AND () |
| 283 | |
| 284 | Implements ``TOS = TOS1 & TOS``. |
| 285 | |
| 286 | |
| 287 | .. opcode:: BINARY_XOR () |
| 288 | |
| 289 | Implements ``TOS = TOS1 ^ TOS``. |
| 290 | |
| 291 | |
| 292 | .. opcode:: BINARY_OR () |
| 293 | |
| 294 | Implements ``TOS = TOS1 | TOS``. |
| 295 | |
| 296 | In-place operations are like binary operations, in that they remove TOS and |
| 297 | TOS1, and push the result back on the stack, but the operation is done in-place |
| 298 | when TOS1 supports it, and the resulting TOS may be (but does not have to be) |
| 299 | the original TOS1. |
| 300 | |
| 301 | |
| 302 | .. opcode:: INPLACE_POWER () |
| 303 | |
| 304 | Implements in-place ``TOS = TOS1 ** TOS``. |
| 305 | |
| 306 | |
| 307 | .. opcode:: INPLACE_MULTIPLY () |
| 308 | |
| 309 | Implements in-place ``TOS = TOS1 * TOS``. |
| 310 | |
| 311 | |
| 312 | .. opcode:: INPLACE_DIVIDE () |
| 313 | |
| 314 | Implements in-place ``TOS = TOS1 / TOS`` when ``from __future__ import |
| 315 | division`` is not in effect. |
| 316 | |
| 317 | |
| 318 | .. opcode:: INPLACE_FLOOR_DIVIDE () |
| 319 | |
| 320 | Implements in-place ``TOS = TOS1 // TOS``. |
| 321 | |
| 322 | |
| 323 | .. opcode:: INPLACE_TRUE_DIVIDE () |
| 324 | |
| 325 | Implements in-place ``TOS = TOS1 / TOS`` when ``from __future__ import |
| 326 | division`` is in effect. |
| 327 | |
| 328 | |
| 329 | .. opcode:: INPLACE_MODULO () |
| 330 | |
| 331 | Implements in-place ``TOS = TOS1 % TOS``. |
| 332 | |
| 333 | |
| 334 | .. opcode:: INPLACE_ADD () |
| 335 | |
| 336 | Implements in-place ``TOS = TOS1 + TOS``. |
| 337 | |
| 338 | |
| 339 | .. opcode:: INPLACE_SUBTRACT () |
| 340 | |
| 341 | Implements in-place ``TOS = TOS1 - TOS``. |
| 342 | |
| 343 | |
| 344 | .. opcode:: INPLACE_LSHIFT () |
| 345 | |
| 346 | Implements in-place ``TOS = TOS1 << TOS``. |
| 347 | |
| 348 | |
| 349 | .. opcode:: INPLACE_RSHIFT () |
| 350 | |
| 351 | Implements in-place ``TOS = TOS1 >> TOS``. |
| 352 | |
| 353 | |
| 354 | .. opcode:: INPLACE_AND () |
| 355 | |
| 356 | Implements in-place ``TOS = TOS1 & TOS``. |
| 357 | |
| 358 | |
| 359 | .. opcode:: INPLACE_XOR () |
| 360 | |
| 361 | Implements in-place ``TOS = TOS1 ^ TOS``. |
| 362 | |
| 363 | |
| 364 | .. opcode:: INPLACE_OR () |
| 365 | |
| 366 | Implements in-place ``TOS = TOS1 | TOS``. |
| 367 | |
| 368 | The slice opcodes take up to three parameters. |
| 369 | |
| 370 | |
| 371 | .. opcode:: SLICE+0 () |
| 372 | |
| 373 | Implements ``TOS = TOS[:]``. |
| 374 | |
| 375 | |
| 376 | .. opcode:: SLICE+1 () |
| 377 | |
| 378 | Implements ``TOS = TOS1[TOS:]``. |
| 379 | |
| 380 | |
| 381 | .. opcode:: SLICE+2 () |
| 382 | |
| 383 | Implements ``TOS = TOS1[:TOS]``. |
| 384 | |
| 385 | |
| 386 | .. opcode:: SLICE+3 () |
| 387 | |
| 388 | Implements ``TOS = TOS2[TOS1:TOS]``. |
| 389 | |
| 390 | Slice assignment needs even an additional parameter. As any statement, they put |
| 391 | nothing on the stack. |
| 392 | |
| 393 | |
| 394 | .. opcode:: STORE_SLICE+0 () |
| 395 | |
| 396 | Implements ``TOS[:] = TOS1``. |
| 397 | |
| 398 | |
| 399 | .. opcode:: STORE_SLICE+1 () |
| 400 | |
| 401 | Implements ``TOS1[TOS:] = TOS2``. |
| 402 | |
| 403 | |
| 404 | .. opcode:: STORE_SLICE+2 () |
| 405 | |
| 406 | Implements ``TOS1[:TOS] = TOS2``. |
| 407 | |
| 408 | |
| 409 | .. opcode:: STORE_SLICE+3 () |
| 410 | |
| 411 | Implements ``TOS2[TOS1:TOS] = TOS3``. |
| 412 | |
| 413 | |
| 414 | .. opcode:: DELETE_SLICE+0 () |
| 415 | |
| 416 | Implements ``del TOS[:]``. |
| 417 | |
| 418 | |
| 419 | .. opcode:: DELETE_SLICE+1 () |
| 420 | |
| 421 | Implements ``del TOS1[TOS:]``. |
| 422 | |
| 423 | |
| 424 | .. opcode:: DELETE_SLICE+2 () |
| 425 | |
| 426 | Implements ``del TOS1[:TOS]``. |
| 427 | |
| 428 | |
| 429 | .. opcode:: DELETE_SLICE+3 () |
| 430 | |
| 431 | Implements ``del TOS2[TOS1:TOS]``. |
| 432 | |
| 433 | |
| 434 | .. opcode:: STORE_SUBSCR () |
| 435 | |
| 436 | Implements ``TOS1[TOS] = TOS2``. |
| 437 | |
| 438 | |
| 439 | .. opcode:: DELETE_SUBSCR () |
| 440 | |
| 441 | Implements ``del TOS1[TOS]``. |
| 442 | |
| 443 | Miscellaneous opcodes. |
| 444 | |
| 445 | |
| 446 | .. opcode:: PRINT_EXPR () |
| 447 | |
| 448 | Implements the expression statement for the interactive mode. TOS is removed |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 449 | from the stack and printed. In non-interactive mode, an expression statement |
| 450 | is terminated with :opcode:`POP_TOP`. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 451 | |
| 452 | |
| 453 | .. opcode:: PRINT_ITEM () |
| 454 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 455 | Prints TOS to the file-like object bound to ``sys.stdout``. There is one |
| 456 | such instruction for each item in the :keyword:`print` statement. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 457 | |
| 458 | |
| 459 | .. opcode:: PRINT_ITEM_TO () |
| 460 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 461 | Like ``PRINT_ITEM``, but prints the item second from TOS to the file-like |
| 462 | object at TOS. This is used by the extended print statement. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 463 | |
| 464 | |
| 465 | .. opcode:: PRINT_NEWLINE () |
| 466 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 467 | Prints a new line on ``sys.stdout``. This is generated as the last operation |
| 468 | of a :keyword:`print` statement, unless the statement ends with a comma. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 469 | |
| 470 | |
| 471 | .. opcode:: PRINT_NEWLINE_TO () |
| 472 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 473 | Like ``PRINT_NEWLINE``, but prints the new line on the file-like object on |
| 474 | the TOS. This is used by the extended print statement. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 475 | |
| 476 | |
| 477 | .. opcode:: BREAK_LOOP () |
| 478 | |
| 479 | Terminates a loop due to a :keyword:`break` statement. |
| 480 | |
| 481 | |
| 482 | .. opcode:: CONTINUE_LOOP (target) |
| 483 | |
| 484 | Continues a loop due to a :keyword:`continue` statement. *target* is the |
Serhiy Storchaka | 04eee63 | 2014-11-11 10:02:57 +0200 | [diff] [blame] | 485 | address to jump to (which should be a :opcode:`FOR_ITER` instruction). |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 486 | |
| 487 | |
Antoine Pitrou | d0c3515 | 2008-12-17 00:38:28 +0000 | [diff] [blame] | 488 | .. opcode:: LIST_APPEND (i) |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 489 | |
Antoine Pitrou | d0c3515 | 2008-12-17 00:38:28 +0000 | [diff] [blame] | 490 | Calls ``list.append(TOS[-i], TOS)``. Used to implement list comprehensions. |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 491 | While the appended value is popped off, the list object remains on the stack |
| 492 | so that it is available for further iterations of the loop. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 493 | |
| 494 | |
| 495 | .. opcode:: LOAD_LOCALS () |
| 496 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 497 | Pushes a reference to the locals of the current scope on the stack. This is |
| 498 | used in the code for a class definition: After the class body is evaluated, |
| 499 | the locals are passed to the class definition. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 500 | |
| 501 | |
| 502 | .. opcode:: RETURN_VALUE () |
| 503 | |
| 504 | Returns with TOS to the caller of the function. |
| 505 | |
| 506 | |
| 507 | .. opcode:: YIELD_VALUE () |
| 508 | |
Georg Brandl | cf3fb25 | 2007-10-21 10:52:38 +0000 | [diff] [blame] | 509 | Pops ``TOS`` and yields it from a :term:`generator`. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 510 | |
| 511 | |
| 512 | .. opcode:: IMPORT_STAR () |
| 513 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 514 | Loads all symbols not starting with ``'_'`` directly from the module TOS to |
| 515 | the local namespace. The module is popped after loading all names. This |
| 516 | opcode implements ``from module import *``. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 517 | |
| 518 | |
| 519 | .. opcode:: EXEC_STMT () |
| 520 | |
| 521 | Implements ``exec TOS2,TOS1,TOS``. The compiler fills missing optional |
| 522 | parameters with ``None``. |
| 523 | |
| 524 | |
| 525 | .. opcode:: POP_BLOCK () |
| 526 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 527 | Removes one block from the block stack. Per frame, there is a stack of |
| 528 | blocks, denoting nested loops, try statements, and such. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 529 | |
| 530 | |
| 531 | .. opcode:: END_FINALLY () |
| 532 | |
| 533 | Terminates a :keyword:`finally` clause. The interpreter recalls whether the |
| 534 | exception has to be re-raised, or whether the function returns, and continues |
| 535 | with the outer-next block. |
| 536 | |
| 537 | |
| 538 | .. opcode:: BUILD_CLASS () |
| 539 | |
| 540 | Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of |
| 541 | the names of the base classes, and TOS2 the class name. |
| 542 | |
Georg Brandl | 4debd55 | 2007-08-23 17:54:11 +0000 | [diff] [blame] | 543 | |
Benjamin Peterson | 1880d8b | 2009-05-25 13:13:44 +0000 | [diff] [blame] | 544 | .. opcode:: SETUP_WITH (delta) |
| 545 | |
| 546 | This opcode performs several operations before a with block starts. First, |
| 547 | it loads :meth:`~object.__exit__` from the context manager and pushes it onto |
| 548 | the stack for later use by :opcode:`WITH_CLEANUP`. Then, |
| 549 | :meth:`~object.__enter__` is called, and a finally block pointing to *delta* |
| 550 | is pushed. Finally, the result of calling the enter method is pushed onto |
| 551 | the stack. The next opcode will either ignore it (:opcode:`POP_TOP`), or |
| 552 | store it in (a) variable(s) (:opcode:`STORE_FAST`, :opcode:`STORE_NAME`, or |
| 553 | :opcode:`UNPACK_SEQUENCE`). |
| 554 | |
| 555 | |
Georg Brandl | 4debd55 | 2007-08-23 17:54:11 +0000 | [diff] [blame] | 556 | .. opcode:: WITH_CLEANUP () |
| 557 | |
Nick Coghlan | 7af53be | 2008-03-07 14:13:28 +0000 | [diff] [blame] | 558 | Cleans up the stack when a :keyword:`with` statement block exits. On top of |
| 559 | the stack are 1--3 values indicating how/why the finally clause was entered: |
Georg Brandl | 4debd55 | 2007-08-23 17:54:11 +0000 | [diff] [blame] | 560 | |
Nick Coghlan | 7af53be | 2008-03-07 14:13:28 +0000 | [diff] [blame] | 561 | * TOP = ``None`` |
| 562 | * (TOP, SECOND) = (``WHY_{RETURN,CONTINUE}``), retval |
| 563 | * TOP = ``WHY_*``; no retval below it |
| 564 | * (TOP, SECOND, THIRD) = exc_info() |
Georg Brandl | 4debd55 | 2007-08-23 17:54:11 +0000 | [diff] [blame] | 565 | |
Nick Coghlan | 7af53be | 2008-03-07 14:13:28 +0000 | [diff] [blame] | 566 | Under them is EXIT, the context manager's :meth:`__exit__` bound method. |
Georg Brandl | 4debd55 | 2007-08-23 17:54:11 +0000 | [diff] [blame] | 567 | |
Nick Coghlan | 7af53be | 2008-03-07 14:13:28 +0000 | [diff] [blame] | 568 | In the last case, ``EXIT(TOP, SECOND, THIRD)`` is called, otherwise |
| 569 | ``EXIT(None, None, None)``. |
| 570 | |
| 571 | EXIT is removed from the stack, leaving the values above it in the same |
| 572 | order. In addition, if the stack represents an exception, *and* the function |
| 573 | call returns a 'true' value, this information is "zapped", to prevent |
| 574 | ``END_FINALLY`` from re-raising the exception. (But non-local gotos should |
| 575 | still be resumed.) |
Georg Brandl | 4debd55 | 2007-08-23 17:54:11 +0000 | [diff] [blame] | 576 | |
Georg Brandl | ff27e0c | 2007-10-20 13:22:53 +0000 | [diff] [blame] | 577 | .. XXX explain the WHY stuff! |
| 578 | |
Georg Brandl | 4debd55 | 2007-08-23 17:54:11 +0000 | [diff] [blame] | 579 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 580 | All of the following opcodes expect arguments. An argument is two bytes, with |
| 581 | the more significant byte last. |
| 582 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 583 | .. opcode:: STORE_NAME (namei) |
| 584 | |
| 585 | Implements ``name = TOS``. *namei* is the index of *name* in the attribute |
Georg Brandl | 5972493 | 2008-02-23 15:43:48 +0000 | [diff] [blame] | 586 | :attr:`co_names` of the code object. The compiler tries to use ``STORE_FAST`` |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 587 | or ``STORE_GLOBAL`` if possible. |
| 588 | |
| 589 | |
| 590 | .. opcode:: DELETE_NAME (namei) |
| 591 | |
| 592 | Implements ``del name``, where *namei* is the index into :attr:`co_names` |
| 593 | attribute of the code object. |
| 594 | |
| 595 | |
| 596 | .. opcode:: UNPACK_SEQUENCE (count) |
| 597 | |
| 598 | Unpacks TOS into *count* individual values, which are put onto the stack |
| 599 | right-to-left. |
| 600 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 601 | |
| 602 | .. opcode:: DUP_TOPX (count) |
| 603 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 604 | Duplicate *count* items, keeping them in the same order. Due to |
| 605 | implementation limits, *count* should be between 1 and 5 inclusive. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 606 | |
| 607 | |
| 608 | .. opcode:: STORE_ATTR (namei) |
| 609 | |
| 610 | Implements ``TOS.name = TOS1``, where *namei* is the index of name in |
| 611 | :attr:`co_names`. |
| 612 | |
| 613 | |
| 614 | .. opcode:: DELETE_ATTR (namei) |
| 615 | |
| 616 | Implements ``del TOS.name``, using *namei* as index into :attr:`co_names`. |
| 617 | |
| 618 | |
| 619 | .. opcode:: STORE_GLOBAL (namei) |
| 620 | |
| 621 | Works as ``STORE_NAME``, but stores the name as a global. |
| 622 | |
| 623 | |
| 624 | .. opcode:: DELETE_GLOBAL (namei) |
| 625 | |
| 626 | Works as ``DELETE_NAME``, but deletes a global name. |
| 627 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 628 | |
| 629 | .. opcode:: LOAD_CONST (consti) |
| 630 | |
| 631 | Pushes ``co_consts[consti]`` onto the stack. |
| 632 | |
| 633 | |
| 634 | .. opcode:: LOAD_NAME (namei) |
| 635 | |
| 636 | Pushes the value associated with ``co_names[namei]`` onto the stack. |
| 637 | |
| 638 | |
| 639 | .. opcode:: BUILD_TUPLE (count) |
| 640 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 641 | Creates a tuple consuming *count* items from the stack, and pushes the |
| 642 | resulting tuple onto the stack. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 643 | |
| 644 | |
| 645 | .. opcode:: BUILD_LIST (count) |
| 646 | |
| 647 | Works as ``BUILD_TUPLE``, but creates a list. |
| 648 | |
| 649 | |
Raymond Hettinger | bed4dd4 | 2008-01-11 23:25:18 +0000 | [diff] [blame] | 650 | .. opcode:: BUILD_MAP (count) |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 651 | |
Raymond Hettinger | bed4dd4 | 2008-01-11 23:25:18 +0000 | [diff] [blame] | 652 | Pushes a new dictionary object onto the stack. The dictionary is pre-sized |
| 653 | to hold *count* entries. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 654 | |
| 655 | |
| 656 | .. opcode:: LOAD_ATTR (namei) |
| 657 | |
| 658 | Replaces TOS with ``getattr(TOS, co_names[namei])``. |
| 659 | |
| 660 | |
| 661 | .. opcode:: COMPARE_OP (opname) |
| 662 | |
| 663 | Performs a Boolean operation. The operation name can be found in |
| 664 | ``cmp_op[opname]``. |
| 665 | |
| 666 | |
| 667 | .. opcode:: IMPORT_NAME (namei) |
| 668 | |
Georg Brandl | 2fb8a53 | 2008-04-19 16:59:16 +0000 | [diff] [blame] | 669 | Imports the module ``co_names[namei]``. TOS and TOS1 are popped and provide |
| 670 | the *fromlist* and *level* arguments of :func:`__import__`. The module |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 671 | object is pushed onto the stack. The current namespace is not affected: for |
| 672 | a proper import statement, a subsequent ``STORE_FAST`` instruction modifies |
| 673 | the namespace. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 674 | |
| 675 | |
| 676 | .. opcode:: IMPORT_FROM (namei) |
| 677 | |
| 678 | Loads the attribute ``co_names[namei]`` from the module found in TOS. The |
| 679 | resulting object is pushed onto the stack, to be subsequently stored by a |
| 680 | ``STORE_FAST`` instruction. |
| 681 | |
| 682 | |
| 683 | .. opcode:: JUMP_FORWARD (delta) |
| 684 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 685 | Increments bytecode counter by *delta*. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 686 | |
| 687 | |
Jeffrey Yasskin | 68d6852 | 2009-02-28 19:03:21 +0000 | [diff] [blame] | 688 | .. opcode:: POP_JUMP_IF_TRUE (target) |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 689 | |
Jeffrey Yasskin | 68d6852 | 2009-02-28 19:03:21 +0000 | [diff] [blame] | 690 | If TOS is true, sets the bytecode counter to *target*. TOS is popped. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 691 | |
| 692 | |
Jeffrey Yasskin | 68d6852 | 2009-02-28 19:03:21 +0000 | [diff] [blame] | 693 | .. opcode:: POP_JUMP_IF_FALSE (target) |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 694 | |
Jeffrey Yasskin | 68d6852 | 2009-02-28 19:03:21 +0000 | [diff] [blame] | 695 | If TOS is false, sets the bytecode counter to *target*. TOS is popped. |
| 696 | |
| 697 | |
| 698 | .. opcode:: JUMP_IF_TRUE_OR_POP (target) |
| 699 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 700 | If TOS is true, sets the bytecode counter to *target* and leaves TOS on the |
| 701 | stack. Otherwise (TOS is false), TOS is popped. |
Jeffrey Yasskin | 68d6852 | 2009-02-28 19:03:21 +0000 | [diff] [blame] | 702 | |
| 703 | |
| 704 | .. opcode:: JUMP_IF_FALSE_OR_POP (target) |
| 705 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 706 | If TOS is false, sets the bytecode counter to *target* and leaves TOS on the |
| 707 | stack. Otherwise (TOS is true), TOS is popped. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 708 | |
| 709 | |
| 710 | .. opcode:: JUMP_ABSOLUTE (target) |
| 711 | |
Georg Brandl | 63fa168 | 2007-10-21 10:24:20 +0000 | [diff] [blame] | 712 | Set bytecode counter to *target*. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 713 | |
| 714 | |
| 715 | .. opcode:: FOR_ITER (delta) |
| 716 | |
Georg Brandl | 9fa61bb | 2009-07-26 14:19:57 +0000 | [diff] [blame] | 717 | ``TOS`` is an :term:`iterator`. Call its :meth:`!next` method. If this |
Georg Brandl | e7a0990 | 2007-10-21 12:10:28 +0000 | [diff] [blame] | 718 | yields a new value, push it on the stack (leaving the iterator below it). If |
| 719 | the iterator indicates it is exhausted ``TOS`` is popped, and the bytecode |
| 720 | counter is incremented by *delta*. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 721 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 722 | |
| 723 | .. opcode:: LOAD_GLOBAL (namei) |
| 724 | |
| 725 | Loads the global named ``co_names[namei]`` onto the stack. |
| 726 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 727 | |
| 728 | .. opcode:: SETUP_LOOP (delta) |
| 729 | |
| 730 | Pushes a block for a loop onto the block stack. The block spans from the |
| 731 | current instruction with a size of *delta* bytes. |
| 732 | |
| 733 | |
| 734 | .. opcode:: SETUP_EXCEPT (delta) |
| 735 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 736 | Pushes a try block from a try-except clause onto the block stack. *delta* |
| 737 | points to the first except block. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 738 | |
| 739 | |
| 740 | .. opcode:: SETUP_FINALLY (delta) |
| 741 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 742 | Pushes a try block from a try-except clause onto the block stack. *delta* |
| 743 | points to the finally block. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 744 | |
Raymond Hettinger | bed4dd4 | 2008-01-11 23:25:18 +0000 | [diff] [blame] | 745 | .. opcode:: STORE_MAP () |
| 746 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 747 | Store a key and value pair in a dictionary. Pops the key and value while |
| 748 | leaving the dictionary on the stack. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 749 | |
| 750 | .. opcode:: LOAD_FAST (var_num) |
| 751 | |
| 752 | Pushes a reference to the local ``co_varnames[var_num]`` onto the stack. |
| 753 | |
| 754 | |
| 755 | .. opcode:: STORE_FAST (var_num) |
| 756 | |
| 757 | Stores TOS into the local ``co_varnames[var_num]``. |
| 758 | |
| 759 | |
| 760 | .. opcode:: DELETE_FAST (var_num) |
| 761 | |
| 762 | Deletes local ``co_varnames[var_num]``. |
| 763 | |
| 764 | |
| 765 | .. opcode:: LOAD_CLOSURE (i) |
| 766 | |
| 767 | Pushes a reference to the cell contained in slot *i* of the cell and free |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 768 | variable storage. The name of the variable is ``co_cellvars[i]`` if *i* is |
| 769 | less than the length of *co_cellvars*. Otherwise it is ``co_freevars[i - |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 770 | len(co_cellvars)]``. |
| 771 | |
| 772 | |
| 773 | .. opcode:: LOAD_DEREF (i) |
| 774 | |
| 775 | Loads the cell contained in slot *i* of the cell and free variable storage. |
| 776 | Pushes a reference to the object the cell contains on the stack. |
| 777 | |
| 778 | |
| 779 | .. opcode:: STORE_DEREF (i) |
| 780 | |
| 781 | Stores TOS into the cell contained in slot *i* of the cell and free variable |
| 782 | storage. |
| 783 | |
| 784 | |
| 785 | .. opcode:: SET_LINENO (lineno) |
| 786 | |
| 787 | This opcode is obsolete. |
| 788 | |
| 789 | |
| 790 | .. opcode:: RAISE_VARARGS (argc) |
| 791 | |
| 792 | Raises an exception. *argc* indicates the number of parameters to the raise |
| 793 | statement, ranging from 0 to 3. The handler will find the traceback as TOS2, |
| 794 | the parameter as TOS1, and the exception as TOS. |
| 795 | |
| 796 | |
| 797 | .. opcode:: CALL_FUNCTION (argc) |
| 798 | |
| 799 | Calls a function. The low byte of *argc* indicates the number of positional |
| 800 | parameters, the high byte the number of keyword parameters. On the stack, the |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 801 | opcode finds the keyword parameters first. For each keyword argument, the |
| 802 | value is on top of the key. Below the keyword parameters, the positional |
| 803 | parameters are on the stack, with the right-most parameter on top. Below the |
| 804 | parameters, the function object to call is on the stack. Pops all function |
| 805 | arguments, and the function itself off the stack, and pushes the return |
| 806 | value. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 807 | |
| 808 | |
| 809 | .. opcode:: MAKE_FUNCTION (argc) |
| 810 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 811 | Pushes a new function object on the stack. TOS is the code associated with |
| 812 | the function. The function object is defined to have *argc* default |
| 813 | parameters, which are found below TOS. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 814 | |
| 815 | |
| 816 | .. opcode:: MAKE_CLOSURE (argc) |
| 817 | |
| 818 | Creates a new function object, sets its *func_closure* slot, and pushes it on |
Georg Brandl | 4debd55 | 2007-08-23 17:54:11 +0000 | [diff] [blame] | 819 | the stack. TOS is the code associated with the function, TOS1 the tuple |
| 820 | containing cells for the closure's free variables. The function also has |
| 821 | *argc* default parameters, which are found below the cells. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 822 | |
| 823 | |
| 824 | .. opcode:: BUILD_SLICE (argc) |
| 825 | |
| 826 | .. index:: builtin: slice |
| 827 | |
| 828 | Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2, |
| 829 | ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is |
Georg Brandl | b19be57 | 2007-12-29 10:57:00 +0000 | [diff] [blame] | 830 | pushed. See the :func:`slice` built-in function for more information. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 831 | |
| 832 | |
| 833 | .. opcode:: EXTENDED_ARG (ext) |
| 834 | |
| 835 | Prefixes any opcode which has an argument too big to fit into the default two |
| 836 | bytes. *ext* holds two additional bytes which, taken together with the |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 837 | subsequent opcode's argument, comprise a four-byte argument, *ext* being the |
| 838 | two most-significant bytes. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 839 | |
| 840 | |
| 841 | .. opcode:: CALL_FUNCTION_VAR (argc) |
| 842 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 843 | Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The |
| 844 | top element on the stack contains the variable argument list, followed by |
| 845 | keyword and positional arguments. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 846 | |
| 847 | |
| 848 | .. opcode:: CALL_FUNCTION_KW (argc) |
| 849 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 850 | Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The |
| 851 | top element on the stack contains the keyword arguments dictionary, followed |
| 852 | by explicit keyword and positional arguments. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 853 | |
| 854 | |
| 855 | .. opcode:: CALL_FUNCTION_VAR_KW (argc) |
| 856 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 857 | Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The |
| 858 | top element on the stack contains the keyword arguments dictionary, followed |
| 859 | by the variable-arguments tuple, followed by explicit keyword and positional |
| 860 | arguments. |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 861 | |
| 862 | |
| 863 | .. opcode:: HAVE_ARGUMENT () |
| 864 | |
Benjamin Peterson | b198ad9 | 2015-03-02 09:34:31 -0500 | [diff] [blame] | 865 | This is not really an opcode. It identifies the dividing line between |
| 866 | opcodes which don't take arguments ``< HAVE_ARGUMENT`` and those which do |
| 867 | ``>= HAVE_ARGUMENT``. |