libdis.tex 20 KB
Newer Older
Fred Drake's avatar
Fred Drake committed
1
\section{\module{dis} ---
2
         Disassembler for Python byte code}
3

4
\declaremodule{standard}{dis}
5
\modulesynopsis{Disassembler for Python byte code.}
6

7

Fred Drake's avatar
Fred Drake committed
8
The \module{dis} module supports the analysis of Python byte code by
9 10 11
disassembling it.  Since there is no Python assembler, this module
defines the Python assembly language.  The Python byte code which
this module takes as an input is defined in the file 
12
\file{Include/opcode.h} and used by the compiler and the interpreter.
13

Fred Drake's avatar
Fred Drake committed
14
Example: Given the function \function{myfunc}:
15

16
\begin{verbatim}
17
def myfunc(alist):
Fred Drake's avatar
Fred Drake committed
18
    return len(alist)
19
\end{verbatim}
20

Fred Drake's avatar
Fred Drake committed
21 22
the following command can be used to get the disassembly of
\function{myfunc()}:
23 24 25

\begin{verbatim}
>>> dis.dis(myfunc)
Michael W. Hudson's avatar
Michael W. Hudson committed
26 27 28
  2           0 LOAD_GLOBAL              0 (len)
              3 LOAD_FAST                0 (alist)
              6 CALL_FUNCTION            1
29
              9 RETURN_VALUE
30 31
\end{verbatim}

Michael W. Hudson's avatar
Michael W. Hudson committed
32 33
(The ``2'' is a line number).

34
The \module{dis} module defines the following functions and constants:
35 36 37

\begin{funcdesc}{dis}{\optional{bytesource}}
Disassemble the \var{bytesource} object. \var{bytesource} can denote
38 39
either a module, a class, a method, a function, or a code object.  
For a module, it disassembles all functions.  For a class,
40 41 42 43 44 45 46 47 48 49 50
it disassembles all methods.  For a single code sequence, it prints
one line per byte code instruction.  If no object is provided, it
disassembles the last traceback.
\end{funcdesc}

\begin{funcdesc}{distb}{\optional{tb}}
Disassembles the top-of-stack function of a traceback, using the last
traceback if none was passed.  The instruction causing the exception
is indicated.
\end{funcdesc}

51
\begin{funcdesc}{disassemble}{code\optional{, lasti}}
52 53
Disassembles a code object, indicating the last instruction if \var{lasti}
was provided.  The output is divided in the following columns:
54

55
\begin{enumerate}
Michael W. Hudson's avatar
Michael W. Hudson committed
56
\item the line number, for the first instruction of each line
Fred Drake's avatar
Fred Drake committed
57
\item the current instruction, indicated as \samp{-->},
58
\item a labelled instruction, indicated with \samp{>>},
59 60 61 62
\item the address of the instruction,
\item the operation code name,
\item operation parameters, and
\item interpretation of the parameters in parentheses.
63
\end{enumerate}
64

65 66 67 68 69
The parameter interpretation recognizes local and global
variable names, constant values, branch targets, and compare
operators.
\end{funcdesc}

70
\begin{funcdesc}{disco}{code\optional{, lasti}}
71 72 73 74 75
A synonym for disassemble.  It is more convenient to type, and kept
for compatibility with earlier Python releases.
\end{funcdesc}

\begin{datadesc}{opname}
76
Sequence of operation names, indexable using the byte code.
77 78
\end{datadesc}

Skip Montanaro's avatar
Skip Montanaro committed
79 80 81 82
\begin{datadesc}{opmap}
Dictionary mapping byte codes to operation names.
\end{datadesc}

83 84 85 86 87 88 89 90
\begin{datadesc}{cmp_op}
Sequence of all compare operation names.
\end{datadesc}

\begin{datadesc}{hasconst}
Sequence of byte codes that have a constant parameter.
\end{datadesc}

91 92 93 94
\begin{datadesc}{hasfree}
Sequence of byte codes that access a free variable.
\end{datadesc}

95
\begin{datadesc}{hasname}
96
Sequence of byte codes that access an attribute by name.
97 98 99 100 101 102 103 104 105 106 107
\end{datadesc}

\begin{datadesc}{hasjrel}
Sequence of byte codes that have a relative jump target.
\end{datadesc}

\begin{datadesc}{hasjabs}
Sequence of byte codes that have an absolute jump target.
\end{datadesc}

\begin{datadesc}{haslocal}
108
Sequence of byte codes that access a local variable.
109 110 111
\end{datadesc}

\begin{datadesc}{hascompare}
112
Sequence of byte codes of Boolean operations.
113 114 115
\end{datadesc}

\subsection{Python Byte Code Instructions}
116
\label{bytecodes}
117 118 119 120

The Python compiler currently generates the following byte code
instructions.

121
\setindexsubitem{(byte code insns)}
122

123
\begin{opcodedesc}{STOP_CODE}{}
124
Indicates end-of-code to the compiler, not used by the interpreter.
125
\end{opcodedesc}
126

127 128 129 130
\begin{opcodedesc}{NOP}{}
Do nothing code.  Used as a placeholder by the bytecode optimizer.
\end{opcodedesc}

131
\begin{opcodedesc}{POP_TOP}{}
132
Removes the top-of-stack (TOS) item.
133
\end{opcodedesc}
134

135
\begin{opcodedesc}{ROT_TWO}{}
136
Swaps the two top-most stack items.
137
\end{opcodedesc}
138

139 140
\begin{opcodedesc}{ROT_THREE}{}
Lifts second and third stack item one position up, moves top down
141
to position three.
142
\end{opcodedesc}
143

144 145 146 147 148
\begin{opcodedesc}{ROT_FOUR}{}
Lifts second, third and forth stack item one position up, moves top down to
position four.
\end{opcodedesc}

149
\begin{opcodedesc}{DUP_TOP}{}
150
Duplicates the reference on top of the stack.
151
\end{opcodedesc}
152 153 154 155

Unary Operations take the top of the stack, apply the operation, and
push the result back on the stack.

156
\begin{opcodedesc}{UNARY_POSITIVE}{}
157
Implements \code{TOS = +TOS}.
158
\end{opcodedesc}
159

160
\begin{opcodedesc}{UNARY_NEGATIVE}{}
161
Implements \code{TOS = -TOS}.
162
\end{opcodedesc}
163

164
\begin{opcodedesc}{UNARY_NOT}{}
165
Implements \code{TOS = not TOS}.
166
\end{opcodedesc}
167

168
\begin{opcodedesc}{UNARY_INVERT}{}
169
Implements \code{TOS = \~{}TOS}.
170
\end{opcodedesc}
171

172 173 174 175
\begin{opcodedesc}{GET_ITER}{}
Implements \code{TOS = iter(TOS)}.
\end{opcodedesc}

176 177 178 179
Binary operations remove the top of the stack (TOS) and the second top-most
stack item (TOS1) from the stack.  They perform the operation, and put the
result back on the stack.

180
\begin{opcodedesc}{BINARY_POWER}{}
181
Implements \code{TOS = TOS1 ** TOS}.
182
\end{opcodedesc}
183

184
\begin{opcodedesc}{BINARY_MULTIPLY}{}
185
Implements \code{TOS = TOS1 * TOS}.
186
\end{opcodedesc}
187

188 189 190 191 192 193 194
\begin{opcodedesc}{BINARY_FLOOR_DIVIDE}{}
Implements \code{TOS = TOS1 // TOS}.
\end{opcodedesc}

\begin{opcodedesc}{BINARY_TRUE_DIVIDE}{}
Implements \code{TOS = TOS1 / TOS} when
\code{from __future__ import division} is in effect.
195
\end{opcodedesc}
196

197
\begin{opcodedesc}{BINARY_MODULO}{}
198
Implements \code{TOS = TOS1 \%{} TOS}.
199
\end{opcodedesc}
200

201
\begin{opcodedesc}{BINARY_ADD}{}
202
Implements \code{TOS = TOS1 + TOS}.
203
\end{opcodedesc}
204

205
\begin{opcodedesc}{BINARY_SUBTRACT}{}
206
Implements \code{TOS = TOS1 - TOS}.
207
\end{opcodedesc}
208

209
\begin{opcodedesc}{BINARY_SUBSCR}{}
210
Implements \code{TOS = TOS1[TOS]}.
211
\end{opcodedesc}
212

213
\begin{opcodedesc}{BINARY_LSHIFT}{}
214
Implements \code{TOS = TOS1 <\code{}< TOS}.
215
\end{opcodedesc}
216

217
\begin{opcodedesc}{BINARY_RSHIFT}{}
218
Implements \code{TOS = TOS1 >\code{}> TOS}.
219
\end{opcodedesc}
220

221
\begin{opcodedesc}{BINARY_AND}{}
222
Implements \code{TOS = TOS1 \&\ TOS}.
223
\end{opcodedesc}
224

225
\begin{opcodedesc}{BINARY_XOR}{}
226
Implements \code{TOS = TOS1 \^\ TOS}.
227
\end{opcodedesc}
228

229
\begin{opcodedesc}{BINARY_OR}{}
230
Implements \code{TOS = TOS1 | TOS}.
231
\end{opcodedesc}
232

233 234 235 236 237 238 239 240 241 242 243 244 245
In-place operations are like binary operations, in that they remove TOS and
TOS1, and push the result back on the stack, but the operation is done
in-place when TOS1 supports it, and the resulting TOS may be (but does not
have to be) the original TOS1.

\begin{opcodedesc}{INPLACE_POWER}{}
Implements in-place \code{TOS = TOS1 ** TOS}.
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_MULTIPLY}{}
Implements in-place \code{TOS = TOS1 * TOS}.
\end{opcodedesc}

246 247 248 249 250 251 252
\begin{opcodedesc}{INPLACE_FLOOR_DIVIDE}{}
Implements in-place \code{TOS = TOS1 // TOS}.
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_TRUE_DIVIDE}{}
Implements in-place \code{TOS = TOS1 / TOS} when
\code{from __future__ import division} is in effect.
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_MODULO}{}
Implements in-place \code{TOS = TOS1 \%{} TOS}.
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_ADD}{}
Implements in-place \code{TOS = TOS1 + TOS}.
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_SUBTRACT}{}
Implements in-place \code{TOS = TOS1 - TOS}.
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_LSHIFT}{}
268
Implements in-place \code{TOS = TOS1 <\code{}< TOS}.
269 270 271
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_RSHIFT}{}
272
Implements in-place \code{TOS = TOS1 >\code{}> TOS}.
273 274 275 276 277 278 279 280 281 282 283 284 285 286
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_AND}{}
Implements in-place \code{TOS = TOS1 \&\ TOS}.
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_XOR}{}
Implements in-place \code{TOS = TOS1 \^\ TOS}.
\end{opcodedesc}

\begin{opcodedesc}{INPLACE_OR}{}
Implements in-place \code{TOS = TOS1 | TOS}.
\end{opcodedesc}

287 288
The slice opcodes take up to three parameters.

289
\begin{opcodedesc}{SLICE+0}{}
290
Implements \code{TOS = TOS[:]}.
291
\end{opcodedesc}
292

293
\begin{opcodedesc}{SLICE+1}{}
294
Implements \code{TOS = TOS1[TOS:]}.
295
\end{opcodedesc}
296

297
\begin{opcodedesc}{SLICE+2}{}
298
Implements \code{TOS = TOS1[:TOS]}.
299
\end{opcodedesc}
300

301
\begin{opcodedesc}{SLICE+3}{}
302
Implements \code{TOS = TOS2[TOS1:TOS]}.
303
\end{opcodedesc}
304 305 306 307

Slice assignment needs even an additional parameter.  As any statement,
they put nothing on the stack.

308
\begin{opcodedesc}{STORE_SLICE+0}{}
309
Implements \code{TOS[:] = TOS1}.
310
\end{opcodedesc}
311

312
\begin{opcodedesc}{STORE_SLICE+1}{}
313
Implements \code{TOS1[TOS:] = TOS2}.
314
\end{opcodedesc}
315

316
\begin{opcodedesc}{STORE_SLICE+2}{}
317
Implements \code{TOS1[:TOS] = TOS2}.
318
\end{opcodedesc}
319

320
\begin{opcodedesc}{STORE_SLICE+3}{}
321
Implements \code{TOS2[TOS1:TOS] = TOS3}.
322
\end{opcodedesc}
323

324
\begin{opcodedesc}{DELETE_SLICE+0}{}
325
Implements \code{del TOS[:]}.
326
\end{opcodedesc}
327

328
\begin{opcodedesc}{DELETE_SLICE+1}{}
329
Implements \code{del TOS1[TOS:]}.
330
\end{opcodedesc}
331

332
\begin{opcodedesc}{DELETE_SLICE+2}{}
333
Implements \code{del TOS1[:TOS]}.
334
\end{opcodedesc}
335

336
\begin{opcodedesc}{DELETE_SLICE+3}{}
337
Implements \code{del TOS2[TOS1:TOS]}.
338
\end{opcodedesc}
339

340
\begin{opcodedesc}{STORE_SUBSCR}{}
341
Implements \code{TOS1[TOS] = TOS2}.
342
\end{opcodedesc}
343

344
\begin{opcodedesc}{DELETE_SUBSCR}{}
345
Implements \code{del TOS1[TOS]}.
346
\end{opcodedesc}
347

348 349
Miscellaneous opcodes.

350
\begin{opcodedesc}{PRINT_EXPR}{}
351 352
Implements the expression statement for the interactive mode.  TOS is
removed from the stack and printed.  In non-interactive mode, an
353 354
expression statement is terminated with \code{POP_STACK}.
\end{opcodedesc}
355

356
\begin{opcodedesc}{BREAK_LOOP}{}
357
Terminates a loop due to a \keyword{break} statement.
358
\end{opcodedesc}
359

360 361 362 363 364 365
\begin{opcodedesc}{CONTINUE_LOOP}{target}
Continues a loop due to a \keyword{continue} statement.  \var{target}
is the address to jump to (which should be a \code{FOR_ITER}
instruction).
\end{opcodedesc}

366 367 368 369
\begin{opcodedesc}{LIST_APPEND}{}
Calls \code{list.append(TOS1, TOS)}.  Used to implement list comprehensions.
\end{opcodedesc}

370
\begin{opcodedesc}{LOAD_LOCALS}{}
371 372 373
Pushes a reference to the locals of the current scope on the stack.
This is used in the code for a class definition: After the class body
is evaluated, the locals are passed to the class definition.
374
\end{opcodedesc}
375

376
\begin{opcodedesc}{RETURN_VALUE}{}
377
Returns with TOS to the caller of the function.
378
\end{opcodedesc}
379

380 381 382 383
\begin{opcodedesc}{YIELD_VALUE}{}
Pops \code{TOS} and yields it from a generator.
\end{opcodedesc}

384
\begin{opcodedesc}{IMPORT_STAR}{}
385
Loads all symbols not starting with \character{_} directly from the module TOS
386
to the local namespace. The module is popped after loading all names.
387 388
This opcode implements \code{from module import *}.
\end{opcodedesc}
389

390
\begin{opcodedesc}{POP_BLOCK}{}
391 392
Removes one block from the block stack.  Per frame, there is a 
stack of blocks, denoting nested loops, try statements, and such.
393
\end{opcodedesc}
394

395
\begin{opcodedesc}{END_FINALLY}{}
396 397 398
Terminates a \keyword{finally} clause.  The interpreter recalls
whether the exception has to be re-raised, or whether the function
returns, and continues with the outer-next block.
399
\end{opcodedesc}
400

401
\begin{opcodedesc}{BUILD_CLASS}{}
402 403
Creates a new class object.  TOS is the methods dictionary, TOS1
the tuple of the names of the base classes, and TOS2 the class name.
404
\end{opcodedesc}
405 406 407 408

All of the following opcodes expect arguments.  An argument is two
bytes, with the more significant byte last.

409
\begin{opcodedesc}{STORE_NAME}{namei}
410
Implements \code{name = TOS}. \var{namei} is the index of \var{name}
Fred Drake's avatar
Fred Drake committed
411
in the attribute \member{co_names} of the code object.
412 413 414
The compiler tries to use \code{STORE_LOCAL} or \code{STORE_GLOBAL}
if possible.
\end{opcodedesc}
415

416
\begin{opcodedesc}{DELETE_NAME}{namei}
417
Implements \code{del name}, where \var{namei} is the index into
Fred Drake's avatar
Fred Drake committed
418
\member{co_names} attribute of the code object.
419
\end{opcodedesc}
420

421
\begin{opcodedesc}{UNPACK_SEQUENCE}{count}
422 423
Unpacks TOS into \var{count} individual values, which are put onto
the stack right-to-left.
424
\end{opcodedesc}
425

426 427 428
%\begin{opcodedesc}{UNPACK_LIST}{count}
%This opcode is obsolete.
%\end{opcodedesc}
429

430
%\begin{opcodedesc}{UNPACK_ARG}{count}
431
%This opcode is obsolete.
432
%\end{opcodedesc}
433

434 435 436 437 438
\begin{opcodedesc}{DUP_TOPX}{count}
Duplicate \var{count} items, keeping them in the same order. Due to
implementation limits, \var{count} should be between 1 and 5 inclusive.
\end{opcodedesc}

439
\begin{opcodedesc}{STORE_ATTR}{namei}
440
Implements \code{TOS.name = TOS1}, where \var{namei} is the index
Fred Drake's avatar
Fred Drake committed
441
of name in \member{co_names}.
442
\end{opcodedesc}
443

444
\begin{opcodedesc}{DELETE_ATTR}{namei}
445
Implements \code{del TOS.name}, using \var{namei} as index into
Fred Drake's avatar
Fred Drake committed
446
\member{co_names}.
447
\end{opcodedesc}
448

449 450 451
\begin{opcodedesc}{STORE_GLOBAL}{namei}
Works as \code{STORE_NAME}, but stores the name as a global.
\end{opcodedesc}
452

453 454 455
\begin{opcodedesc}{DELETE_GLOBAL}{namei}
Works as \code{DELETE_NAME}, but deletes a global name.
\end{opcodedesc}
456

457
%\begin{opcodedesc}{UNPACK_VARARG}{argc}
458
%This opcode is obsolete.
459
%\end{opcodedesc}
460

461
\begin{opcodedesc}{LOAD_CONST}{consti}
Fred Drake's avatar
Fred Drake committed
462
Pushes \samp{co_consts[\var{consti}]} onto the stack.
463
\end{opcodedesc}
464

465
\begin{opcodedesc}{LOAD_NAME}{namei}
Fred Drake's avatar
Fred Drake committed
466
Pushes the value associated with \samp{co_names[\var{namei}]} onto the stack.
467
\end{opcodedesc}
468

469
\begin{opcodedesc}{BUILD_TUPLE}{count}
470 471
Creates a tuple consuming \var{count} items from the stack, and pushes
the resulting tuple onto the stack.
472
\end{opcodedesc}
473

474
\begin{opcodedesc}{BUILD_LIST}{count}
475
Works as \code{BUILD_TUPLE}, but creates a list.
476
\end{opcodedesc}
477

478 479 480 481
\begin{opcodedesc}{BUILD_SET}{count}
Works as \code{BUILD_TUPLE}, but creates a set.
\end{opcodedesc}

482
\begin{opcodedesc}{BUILD_MAP}{zero}
483 484
Pushes a new empty dictionary object onto the stack.  The argument is
ignored and set to zero by the compiler.
485
\end{opcodedesc}
486

487
\begin{opcodedesc}{LOAD_ATTR}{namei}
488
Replaces TOS with \code{getattr(TOS, co_names[\var{namei}])}.
489
\end{opcodedesc}
490

491
\begin{opcodedesc}{COMPARE_OP}{opname}
492
Performs a Boolean operation.  The operation name can be found
493
in \code{cmp_op[\var{opname}]}.
494
\end{opcodedesc}
495

496
\begin{opcodedesc}{IMPORT_NAME}{namei}
497
Imports the module \code{co_names[\var{namei}]}.  The module object is
498
pushed onto the stack.  The current namespace is not affected: for a
499
proper import statement, a subsequent \code{STORE_FAST} instruction
500
modifies the namespace.
501
\end{opcodedesc}
502

503
\begin{opcodedesc}{IMPORT_FROM}{namei}
504 505 506
Loads the attribute \code{co_names[\var{namei}]} from the module found in
TOS. The resulting object is pushed onto the stack, to be subsequently
stored by a \code{STORE_FAST} instruction.
507
\end{opcodedesc}
508

509
\begin{opcodedesc}{JUMP_FORWARD}{delta}
510
Increments byte code counter by \var{delta}.
511
\end{opcodedesc}
512

513
\begin{opcodedesc}{JUMP_IF_TRUE}{delta}
514 515
If TOS is true, increment the byte code counter by \var{delta}.  TOS is
left on the stack.
516
\end{opcodedesc}
517

518
\begin{opcodedesc}{JUMP_IF_FALSE}{delta}
519 520
If TOS is false, increment the byte code counter by \var{delta}.  TOS
is not changed. 
521
\end{opcodedesc}
522

523
\begin{opcodedesc}{JUMP_ABSOLUTE}{target}
524
Set byte code counter to \var{target}.
525
\end{opcodedesc}
526

527 528 529 530 531 532 533
\begin{opcodedesc}{FOR_ITER}{delta}
\code{TOS} is an iterator.  Call its \method{next()} method.  If this
yields a new value, push it on the stack (leaving the iterator below
it).  If the iterator indicates it is exhausted  \code{TOS} is
popped, and the byte code counter is incremented by \var{delta}.
\end{opcodedesc}

534 535 536
%\begin{opcodedesc}{FOR_LOOP}{delta}
%This opcode is obsolete.
%\end{opcodedesc}
537

538
%\begin{opcodedesc}{LOAD_LOCAL}{namei}
539
%This opcode is obsolete.
540
%\end{opcodedesc}
541

542
\begin{opcodedesc}{LOAD_GLOBAL}{namei}
543
Loads the global named \code{co_names[\var{namei}]} onto the stack.
544
\end{opcodedesc}
545

546
%\begin{opcodedesc}{SET_FUNC_ARGS}{argc}
547
%This opcode is obsolete.
548
%\end{opcodedesc}
549

550
\begin{opcodedesc}{SETUP_LOOP}{delta}
551 552
Pushes a block for a loop onto the block stack.  The block spans
from the current instruction with a size of \var{delta} bytes.
553
\end{opcodedesc}
554

555
\begin{opcodedesc}{SETUP_EXCEPT}{delta}
556 557
Pushes a try block from a try-except clause onto the block stack.
\var{delta} points to the first except block.
558
\end{opcodedesc}
559

560
\begin{opcodedesc}{SETUP_FINALLY}{delta}
561 562
Pushes a try block from a try-except clause onto the block stack.
\var{delta} points to the finally block.
563
\end{opcodedesc}
564

565
\begin{opcodedesc}{LOAD_FAST}{var_num}
566
Pushes a reference to the local \code{co_varnames[\var{var_num}]} onto
567
the stack.
568
\end{opcodedesc}
569

570
\begin{opcodedesc}{STORE_FAST}{var_num}
571
Stores TOS into the local \code{co_varnames[\var{var_num}]}.
572
\end{opcodedesc}
573

574
\begin{opcodedesc}{DELETE_FAST}{var_num}
575
Deletes local \code{co_varnames[\var{var_num}]}.
576
\end{opcodedesc}
577

578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
\begin{opcodedesc}{LOAD_CLOSURE}{i}
Pushes a reference to the cell contained in slot \var{i} of the
cell and free variable storage.  The name of the variable is 
\code{co_cellvars[\var{i}]} if \var{i} is less than the length of
\var{co_cellvars}.  Otherwise it is 
\code{co_freevars[\var{i} - len(co_cellvars)]}.
\end{opcodedesc}

\begin{opcodedesc}{LOAD_DEREF}{i}
Loads the cell contained in slot \var{i} of the cell and free variable
storage.  Pushes a reference to the object the cell contains on the
stack. 
\end{opcodedesc}

\begin{opcodedesc}{STORE_DEREF}{i}
Stores TOS into the cell contained in slot \var{i} of the cell and
free variable storage.
\end{opcodedesc}

Fred Drake's avatar
Fred Drake committed
597
\begin{opcodedesc}{SET_LINENO}{lineno}
Michael W. Hudson's avatar
Michael W. Hudson committed
598
This opcode is obsolete.
599
\end{opcodedesc}
600

601
\begin{opcodedesc}{RAISE_VARARGS}{argc}
602
Raises an exception. \var{argc} indicates the number of parameters
603
to the raise statement, ranging from 0 to 3.  The handler will find
604 605
the traceback as TOS2, the parameter as TOS1, and the exception
as TOS.
606
\end{opcodedesc}
607

608
\begin{opcodedesc}{CALL_FUNCTION}{argc}
609 610 611 612 613 614 615
Calls a function.  The low byte of \var{argc} indicates the number of
positional parameters, the high byte the number of keyword parameters.
On the stack, the opcode finds the keyword parameters first.  For each
keyword argument, the value is on top of the key.  Below the keyword
parameters, the positional parameters are on the stack, with the
right-most parameter on top.  Below the parameters, the function object
to call is on the stack.
616
\end{opcodedesc}
617

618
\begin{opcodedesc}{MAKE_FUNCTION}{argc}
619 620 621
Pushes a new function object on the stack.  TOS is the code associated
with the function.  The function object is defined to have \var{argc}
default parameters, which are found below TOS.
622
\end{opcodedesc}
623

624
\begin{opcodedesc}{MAKE_CLOSURE}{argc}
625
Creates a new function object, sets its \var{__closure__} slot, and
626 627 628 629 630 631
pushes it on the stack.  TOS is the code associated with the function.
If the code object has N free variables, the next N items on the stack
are the cells for these variables.  The function also has \var{argc}
default parameters, where are found before the cells.
\end{opcodedesc}

632
\begin{opcodedesc}{BUILD_SLICE}{argc}
633 634 635
Pushes a slice object on the stack.  \var{argc} must be 2 or 3.  If it
is 2, \code{slice(TOS1, TOS)} is pushed; if it is 3,
\code{slice(TOS2, TOS1, TOS)} is pushed.
636 637
See the \code{slice()}\bifuncindex{slice} built-in function for more
information.
638
\end{opcodedesc}
639

640 641 642 643
\begin{opcodedesc}{EXTENDED_ARG}{ext}
Prefixes any opcode which has an argument too big to fit into the
default two bytes.  \var{ext} holds two additional bytes which, taken
together with the subsequent opcode's argument, comprise a four-byte
644
argument, \var{ext} being the two most-significant bytes.
645 646
\end{opcodedesc}

647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
\begin{opcodedesc}{CALL_FUNCTION_VAR}{argc}
Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
The top element on the stack contains the variable argument list, followed
by keyword and positional arguments.
\end{opcodedesc}

\begin{opcodedesc}{CALL_FUNCTION_KW}{argc}
Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
The top element on the stack contains the keyword arguments dictionary, 
followed by explicit keyword and positional arguments.
\end{opcodedesc}

\begin{opcodedesc}{CALL_FUNCTION_VAR_KW}{argc}
Calls a function. \var{argc} is interpreted as in
\code{CALL_FUNCTION}.  The top element on the stack contains the
keyword arguments dictionary, followed by the variable-arguments
tuple, followed by explicit keyword and positional arguments.
\end{opcodedesc}
Skip Montanaro's avatar
Skip Montanaro committed
665 666 667 668 669 670

\begin{opcodedesc}{HAVE_ARGUMENT}{}
This is not really an opcode.  It identifies the dividing line between
opcodes which don't take arguments \code{< HAVE_ARGUMENT} and those which do
\code{>= HAVE_ARGUMENT}.
\end{opcodedesc}