source: vendor/python/2.5/Doc/lib/libdis.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 21.2 KB
Line 
1\section{\module{dis} ---
2 Disassembler for Python byte code}
3
4\declaremodule{standard}{dis}
5\modulesynopsis{Disassembler for Python byte code.}
6
7
8The \module{dis} module supports the analysis of Python byte code by
9disassembling it. Since there is no Python assembler, this module
10defines the Python assembly language. The Python byte code which
11this module takes as an input is defined in the file
12\file{Include/opcode.h} and used by the compiler and the interpreter.
13
14Example: Given the function \function{myfunc}:
15
16\begin{verbatim}
17def myfunc(alist):
18 return len(alist)
19\end{verbatim}
20
21the following command can be used to get the disassembly of
22\function{myfunc()}:
23
24\begin{verbatim}
25>>> dis.dis(myfunc)
26 2 0 LOAD_GLOBAL 0 (len)
27 3 LOAD_FAST 0 (alist)
28 6 CALL_FUNCTION 1
29 9 RETURN_VALUE
30\end{verbatim}
31
32(The ``2'' is a line number).
33
34The \module{dis} module defines the following functions and constants:
35
36\begin{funcdesc}{dis}{\optional{bytesource}}
37Disassemble the \var{bytesource} object. \var{bytesource} can denote
38either a module, a class, a method, a function, or a code object.
39For a module, it disassembles all functions. For a class,
40it disassembles all methods. For a single code sequence, it prints
41one line per byte code instruction. If no object is provided, it
42disassembles the last traceback.
43\end{funcdesc}
44
45\begin{funcdesc}{distb}{\optional{tb}}
46Disassembles the top-of-stack function of a traceback, using the last
47traceback if none was passed. The instruction causing the exception
48is indicated.
49\end{funcdesc}
50
51\begin{funcdesc}{disassemble}{code\optional{, lasti}}
52Disassembles a code object, indicating the last instruction if \var{lasti}
53was provided. The output is divided in the following columns:
54
55\begin{enumerate}
56\item the line number, for the first instruction of each line
57\item the current instruction, indicated as \samp{-->},
58\item a labelled instruction, indicated with \samp{>>},
59\item the address of the instruction,
60\item the operation code name,
61\item operation parameters, and
62\item interpretation of the parameters in parentheses.
63\end{enumerate}
64
65The parameter interpretation recognizes local and global
66variable names, constant values, branch targets, and compare
67operators.
68\end{funcdesc}
69
70\begin{funcdesc}{disco}{code\optional{, lasti}}
71A synonym for disassemble. It is more convenient to type, and kept
72for compatibility with earlier Python releases.
73\end{funcdesc}
74
75\begin{datadesc}{opname}
76Sequence of operation names, indexable using the byte code.
77\end{datadesc}
78
79\begin{datadesc}{opmap}
80Dictionary mapping byte codes to operation names.
81\end{datadesc}
82
83\begin{datadesc}{cmp_op}
84Sequence of all compare operation names.
85\end{datadesc}
86
87\begin{datadesc}{hasconst}
88Sequence of byte codes that have a constant parameter.
89\end{datadesc}
90
91\begin{datadesc}{hasfree}
92Sequence of byte codes that access a free variable.
93\end{datadesc}
94
95\begin{datadesc}{hasname}
96Sequence of byte codes that access an attribute by name.
97\end{datadesc}
98
99\begin{datadesc}{hasjrel}
100Sequence of byte codes that have a relative jump target.
101\end{datadesc}
102
103\begin{datadesc}{hasjabs}
104Sequence of byte codes that have an absolute jump target.
105\end{datadesc}
106
107\begin{datadesc}{haslocal}
108Sequence of byte codes that access a local variable.
109\end{datadesc}
110
111\begin{datadesc}{hascompare}
112Sequence of byte codes of Boolean operations.
113\end{datadesc}
114
115\subsection{Python Byte Code Instructions}
116\label{bytecodes}
117
118The Python compiler currently generates the following byte code
119instructions.
120
121\setindexsubitem{(byte code insns)}
122
123\begin{opcodedesc}{STOP_CODE}{}
124Indicates end-of-code to the compiler, not used by the interpreter.
125\end{opcodedesc}
126
127\begin{opcodedesc}{NOP}{}
128Do nothing code. Used as a placeholder by the bytecode optimizer.
129\end{opcodedesc}
130
131\begin{opcodedesc}{POP_TOP}{}
132Removes the top-of-stack (TOS) item.
133\end{opcodedesc}
134
135\begin{opcodedesc}{ROT_TWO}{}
136Swaps the two top-most stack items.
137\end{opcodedesc}
138
139\begin{opcodedesc}{ROT_THREE}{}
140Lifts second and third stack item one position up, moves top down
141to position three.
142\end{opcodedesc}
143
144\begin{opcodedesc}{ROT_FOUR}{}
145Lifts second, third and forth stack item one position up, moves top down to
146position four.
147\end{opcodedesc}
148
149\begin{opcodedesc}{DUP_TOP}{}
150Duplicates the reference on top of the stack.
151\end{opcodedesc}
152
153Unary Operations take the top of the stack, apply the operation, and
154push the result back on the stack.
155
156\begin{opcodedesc}{UNARY_POSITIVE}{}
157Implements \code{TOS = +TOS}.
158\end{opcodedesc}
159
160\begin{opcodedesc}{UNARY_NEGATIVE}{}
161Implements \code{TOS = -TOS}.
162\end{opcodedesc}
163
164\begin{opcodedesc}{UNARY_NOT}{}
165Implements \code{TOS = not TOS}.
166\end{opcodedesc}
167
168\begin{opcodedesc}{UNARY_CONVERT}{}
169Implements \code{TOS = `TOS`}.
170\end{opcodedesc}
171
172\begin{opcodedesc}{UNARY_INVERT}{}
173Implements \code{TOS = \~{}TOS}.
174\end{opcodedesc}
175
176\begin{opcodedesc}{GET_ITER}{}
177Implements \code{TOS = iter(TOS)}.
178\end{opcodedesc}
179
180Binary operations remove the top of the stack (TOS) and the second top-most
181stack item (TOS1) from the stack. They perform the operation, and put the
182result back on the stack.
183
184\begin{opcodedesc}{BINARY_POWER}{}
185Implements \code{TOS = TOS1 ** TOS}.
186\end{opcodedesc}
187
188\begin{opcodedesc}{BINARY_MULTIPLY}{}
189Implements \code{TOS = TOS1 * TOS}.
190\end{opcodedesc}
191
192\begin{opcodedesc}{BINARY_DIVIDE}{}
193Implements \code{TOS = TOS1 / TOS} when
194\code{from __future__ import division} is not in effect.
195\end{opcodedesc}
196
197\begin{opcodedesc}{BINARY_FLOOR_DIVIDE}{}
198Implements \code{TOS = TOS1 // TOS}.
199\end{opcodedesc}
200
201\begin{opcodedesc}{BINARY_TRUE_DIVIDE}{}
202Implements \code{TOS = TOS1 / TOS} when
203\code{from __future__ import division} is in effect.
204\end{opcodedesc}
205
206\begin{opcodedesc}{BINARY_MODULO}{}
207Implements \code{TOS = TOS1 \%{} TOS}.
208\end{opcodedesc}
209
210\begin{opcodedesc}{BINARY_ADD}{}
211Implements \code{TOS = TOS1 + TOS}.
212\end{opcodedesc}
213
214\begin{opcodedesc}{BINARY_SUBTRACT}{}
215Implements \code{TOS = TOS1 - TOS}.
216\end{opcodedesc}
217
218\begin{opcodedesc}{BINARY_SUBSCR}{}
219Implements \code{TOS = TOS1[TOS]}.
220\end{opcodedesc}
221
222\begin{opcodedesc}{BINARY_LSHIFT}{}
223Implements \code{TOS = TOS1 <\code{}< TOS}.
224\end{opcodedesc}
225
226\begin{opcodedesc}{BINARY_RSHIFT}{}
227Implements \code{TOS = TOS1 >\code{}> TOS}.
228\end{opcodedesc}
229
230\begin{opcodedesc}{BINARY_AND}{}
231Implements \code{TOS = TOS1 \&\ TOS}.
232\end{opcodedesc}
233
234\begin{opcodedesc}{BINARY_XOR}{}
235Implements \code{TOS = TOS1 \^\ TOS}.
236\end{opcodedesc}
237
238\begin{opcodedesc}{BINARY_OR}{}
239Implements \code{TOS = TOS1 | TOS}.
240\end{opcodedesc}
241
242In-place operations are like binary operations, in that they remove TOS and
243TOS1, and push the result back on the stack, but the operation is done
244in-place when TOS1 supports it, and the resulting TOS may be (but does not
245have to be) the original TOS1.
246
247\begin{opcodedesc}{INPLACE_POWER}{}
248Implements in-place \code{TOS = TOS1 ** TOS}.
249\end{opcodedesc}
250
251\begin{opcodedesc}{INPLACE_MULTIPLY}{}
252Implements in-place \code{TOS = TOS1 * TOS}.
253\end{opcodedesc}
254
255\begin{opcodedesc}{INPLACE_DIVIDE}{}
256Implements in-place \code{TOS = TOS1 / TOS} when
257\code{from __future__ import division} is not in effect.
258\end{opcodedesc}
259
260\begin{opcodedesc}{INPLACE_FLOOR_DIVIDE}{}
261Implements in-place \code{TOS = TOS1 // TOS}.
262\end{opcodedesc}
263
264\begin{opcodedesc}{INPLACE_TRUE_DIVIDE}{}
265Implements in-place \code{TOS = TOS1 / TOS} when
266\code{from __future__ import division} is in effect.
267\end{opcodedesc}
268
269\begin{opcodedesc}{INPLACE_MODULO}{}
270Implements in-place \code{TOS = TOS1 \%{} TOS}.
271\end{opcodedesc}
272
273\begin{opcodedesc}{INPLACE_ADD}{}
274Implements in-place \code{TOS = TOS1 + TOS}.
275\end{opcodedesc}
276
277\begin{opcodedesc}{INPLACE_SUBTRACT}{}
278Implements in-place \code{TOS = TOS1 - TOS}.
279\end{opcodedesc}
280
281\begin{opcodedesc}{INPLACE_LSHIFT}{}
282Implements in-place \code{TOS = TOS1 <\code{}< TOS}.
283\end{opcodedesc}
284
285\begin{opcodedesc}{INPLACE_RSHIFT}{}
286Implements in-place \code{TOS = TOS1 >\code{}> TOS}.
287\end{opcodedesc}
288
289\begin{opcodedesc}{INPLACE_AND}{}
290Implements in-place \code{TOS = TOS1 \&\ TOS}.
291\end{opcodedesc}
292
293\begin{opcodedesc}{INPLACE_XOR}{}
294Implements in-place \code{TOS = TOS1 \^\ TOS}.
295\end{opcodedesc}
296
297\begin{opcodedesc}{INPLACE_OR}{}
298Implements in-place \code{TOS = TOS1 | TOS}.
299\end{opcodedesc}
300
301The slice opcodes take up to three parameters.
302
303\begin{opcodedesc}{SLICE+0}{}
304Implements \code{TOS = TOS[:]}.
305\end{opcodedesc}
306
307\begin{opcodedesc}{SLICE+1}{}
308Implements \code{TOS = TOS1[TOS:]}.
309\end{opcodedesc}
310
311\begin{opcodedesc}{SLICE+2}{}
312Implements \code{TOS = TOS1[:TOS]}.
313\end{opcodedesc}
314
315\begin{opcodedesc}{SLICE+3}{}
316Implements \code{TOS = TOS2[TOS1:TOS]}.
317\end{opcodedesc}
318
319Slice assignment needs even an additional parameter. As any statement,
320they put nothing on the stack.
321
322\begin{opcodedesc}{STORE_SLICE+0}{}
323Implements \code{TOS[:] = TOS1}.
324\end{opcodedesc}
325
326\begin{opcodedesc}{STORE_SLICE+1}{}
327Implements \code{TOS1[TOS:] = TOS2}.
328\end{opcodedesc}
329
330\begin{opcodedesc}{STORE_SLICE+2}{}
331Implements \code{TOS1[:TOS] = TOS2}.
332\end{opcodedesc}
333
334\begin{opcodedesc}{STORE_SLICE+3}{}
335Implements \code{TOS2[TOS1:TOS] = TOS3}.
336\end{opcodedesc}
337
338\begin{opcodedesc}{DELETE_SLICE+0}{}
339Implements \code{del TOS[:]}.
340\end{opcodedesc}
341
342\begin{opcodedesc}{DELETE_SLICE+1}{}
343Implements \code{del TOS1[TOS:]}.
344\end{opcodedesc}
345
346\begin{opcodedesc}{DELETE_SLICE+2}{}
347Implements \code{del TOS1[:TOS]}.
348\end{opcodedesc}
349
350\begin{opcodedesc}{DELETE_SLICE+3}{}
351Implements \code{del TOS2[TOS1:TOS]}.
352\end{opcodedesc}
353
354\begin{opcodedesc}{STORE_SUBSCR}{}
355Implements \code{TOS1[TOS] = TOS2}.
356\end{opcodedesc}
357
358\begin{opcodedesc}{DELETE_SUBSCR}{}
359Implements \code{del TOS1[TOS]}.
360\end{opcodedesc}
361
362Miscellaneous opcodes.
363
364\begin{opcodedesc}{PRINT_EXPR}{}
365Implements the expression statement for the interactive mode. TOS is
366removed from the stack and printed. In non-interactive mode, an
367expression statement is terminated with \code{POP_STACK}.
368\end{opcodedesc}
369
370\begin{opcodedesc}{PRINT_ITEM}{}
371Prints TOS to the file-like object bound to \code{sys.stdout}. There
372is one such instruction for each item in the \keyword{print} statement.
373\end{opcodedesc}
374
375\begin{opcodedesc}{PRINT_ITEM_TO}{}
376Like \code{PRINT_ITEM}, but prints the item second from TOS to the
377file-like object at TOS. This is used by the extended print statement.
378\end{opcodedesc}
379
380\begin{opcodedesc}{PRINT_NEWLINE}{}
381Prints a new line on \code{sys.stdout}. This is generated as the
382last operation of a \keyword{print} statement, unless the statement
383ends with a comma.
384\end{opcodedesc}
385
386\begin{opcodedesc}{PRINT_NEWLINE_TO}{}
387Like \code{PRINT_NEWLINE}, but prints the new line on the file-like
388object on the TOS. This is used by the extended print statement.
389\end{opcodedesc}
390
391\begin{opcodedesc}{BREAK_LOOP}{}
392Terminates a loop due to a \keyword{break} statement.
393\end{opcodedesc}
394
395\begin{opcodedesc}{CONTINUE_LOOP}{target}
396Continues a loop due to a \keyword{continue} statement. \var{target}
397is the address to jump to (which should be a \code{FOR_ITER}
398instruction).
399\end{opcodedesc}
400
401\begin{opcodedesc}{LIST_APPEND}{}
402Calls \code{list.append(TOS1, TOS)}. Used to implement list comprehensions.
403\end{opcodedesc}
404
405\begin{opcodedesc}{LOAD_LOCALS}{}
406Pushes a reference to the locals of the current scope on the stack.
407This is used in the code for a class definition: After the class body
408is evaluated, the locals are passed to the class definition.
409\end{opcodedesc}
410
411\begin{opcodedesc}{RETURN_VALUE}{}
412Returns with TOS to the caller of the function.
413\end{opcodedesc}
414
415\begin{opcodedesc}{YIELD_VALUE}{}
416Pops \code{TOS} and yields it from a generator.
417\end{opcodedesc}
418
419\begin{opcodedesc}{IMPORT_STAR}{}
420Loads all symbols not starting with \character{_} directly from the module TOS
421to the local namespace. The module is popped after loading all names.
422This opcode implements \code{from module import *}.
423\end{opcodedesc}
424
425\begin{opcodedesc}{EXEC_STMT}{}
426Implements \code{exec TOS2,TOS1,TOS}. The compiler fills
427missing optional parameters with \code{None}.
428\end{opcodedesc}
429
430\begin{opcodedesc}{POP_BLOCK}{}
431Removes one block from the block stack. Per frame, there is a
432stack of blocks, denoting nested loops, try statements, and such.
433\end{opcodedesc}
434
435\begin{opcodedesc}{END_FINALLY}{}
436Terminates a \keyword{finally} clause. The interpreter recalls
437whether the exception has to be re-raised, or whether the function
438returns, and continues with the outer-next block.
439\end{opcodedesc}
440
441\begin{opcodedesc}{BUILD_CLASS}{}
442Creates a new class object. TOS is the methods dictionary, TOS1
443the tuple of the names of the base classes, and TOS2 the class name.
444\end{opcodedesc}
445
446All of the following opcodes expect arguments. An argument is two
447bytes, with the more significant byte last.
448
449\begin{opcodedesc}{STORE_NAME}{namei}
450Implements \code{name = TOS}. \var{namei} is the index of \var{name}
451in the attribute \member{co_names} of the code object.
452The compiler tries to use \code{STORE_LOCAL} or \code{STORE_GLOBAL}
453if possible.
454\end{opcodedesc}
455
456\begin{opcodedesc}{DELETE_NAME}{namei}
457Implements \code{del name}, where \var{namei} is the index into
458\member{co_names} attribute of the code object.
459\end{opcodedesc}
460
461\begin{opcodedesc}{UNPACK_SEQUENCE}{count}
462Unpacks TOS into \var{count} individual values, which are put onto
463the stack right-to-left.
464\end{opcodedesc}
465
466%\begin{opcodedesc}{UNPACK_LIST}{count}
467%This opcode is obsolete.
468%\end{opcodedesc}
469
470%\begin{opcodedesc}{UNPACK_ARG}{count}
471%This opcode is obsolete.
472%\end{opcodedesc}
473
474\begin{opcodedesc}{DUP_TOPX}{count}
475Duplicate \var{count} items, keeping them in the same order. Due to
476implementation limits, \var{count} should be between 1 and 5 inclusive.
477\end{opcodedesc}
478
479\begin{opcodedesc}{STORE_ATTR}{namei}
480Implements \code{TOS.name = TOS1}, where \var{namei} is the index
481of name in \member{co_names}.
482\end{opcodedesc}
483
484\begin{opcodedesc}{DELETE_ATTR}{namei}
485Implements \code{del TOS.name}, using \var{namei} as index into
486\member{co_names}.
487\end{opcodedesc}
488
489\begin{opcodedesc}{STORE_GLOBAL}{namei}
490Works as \code{STORE_NAME}, but stores the name as a global.
491\end{opcodedesc}
492
493\begin{opcodedesc}{DELETE_GLOBAL}{namei}
494Works as \code{DELETE_NAME}, but deletes a global name.
495\end{opcodedesc}
496
497%\begin{opcodedesc}{UNPACK_VARARG}{argc}
498%This opcode is obsolete.
499%\end{opcodedesc}
500
501\begin{opcodedesc}{LOAD_CONST}{consti}
502Pushes \samp{co_consts[\var{consti}]} onto the stack.
503\end{opcodedesc}
504
505\begin{opcodedesc}{LOAD_NAME}{namei}
506Pushes the value associated with \samp{co_names[\var{namei}]} onto the stack.
507\end{opcodedesc}
508
509\begin{opcodedesc}{BUILD_TUPLE}{count}
510Creates a tuple consuming \var{count} items from the stack, and pushes
511the resulting tuple onto the stack.
512\end{opcodedesc}
513
514\begin{opcodedesc}{BUILD_LIST}{count}
515Works as \code{BUILD_TUPLE}, but creates a list.
516\end{opcodedesc}
517
518\begin{opcodedesc}{BUILD_MAP}{zero}
519Pushes a new empty dictionary object onto the stack. The argument is
520ignored and set to zero by the compiler.
521\end{opcodedesc}
522
523\begin{opcodedesc}{LOAD_ATTR}{namei}
524Replaces TOS with \code{getattr(TOS, co_names[\var{namei}])}.
525\end{opcodedesc}
526
527\begin{opcodedesc}{COMPARE_OP}{opname}
528Performs a Boolean operation. The operation name can be found
529in \code{cmp_op[\var{opname}]}.
530\end{opcodedesc}
531
532\begin{opcodedesc}{IMPORT_NAME}{namei}
533Imports the module \code{co_names[\var{namei}]}. The module object is
534pushed onto the stack. The current namespace is not affected: for a
535proper import statement, a subsequent \code{STORE_FAST} instruction
536modifies the namespace.
537\end{opcodedesc}
538
539\begin{opcodedesc}{IMPORT_FROM}{namei}
540Loads the attribute \code{co_names[\var{namei}]} from the module found in
541TOS. The resulting object is pushed onto the stack, to be subsequently
542stored by a \code{STORE_FAST} instruction.
543\end{opcodedesc}
544
545\begin{opcodedesc}{JUMP_FORWARD}{delta}
546Increments byte code counter by \var{delta}.
547\end{opcodedesc}
548
549\begin{opcodedesc}{JUMP_IF_TRUE}{delta}
550If TOS is true, increment the byte code counter by \var{delta}. TOS is
551left on the stack.
552\end{opcodedesc}
553
554\begin{opcodedesc}{JUMP_IF_FALSE}{delta}
555If TOS is false, increment the byte code counter by \var{delta}. TOS
556is not changed.
557\end{opcodedesc}
558
559\begin{opcodedesc}{JUMP_ABSOLUTE}{target}
560Set byte code counter to \var{target}.
561\end{opcodedesc}
562
563\begin{opcodedesc}{FOR_ITER}{delta}
564\code{TOS} is an iterator. Call its \method{next()} method. If this
565yields a new value, push it on the stack (leaving the iterator below
566it). If the iterator indicates it is exhausted \code{TOS} is
567popped, and the byte code counter is incremented by \var{delta}.
568\end{opcodedesc}
569
570%\begin{opcodedesc}{FOR_LOOP}{delta}
571%This opcode is obsolete.
572%\end{opcodedesc}
573
574%\begin{opcodedesc}{LOAD_LOCAL}{namei}
575%This opcode is obsolete.
576%\end{opcodedesc}
577
578\begin{opcodedesc}{LOAD_GLOBAL}{namei}
579Loads the global named \code{co_names[\var{namei}]} onto the stack.
580\end{opcodedesc}
581
582%\begin{opcodedesc}{SET_FUNC_ARGS}{argc}
583%This opcode is obsolete.
584%\end{opcodedesc}
585
586\begin{opcodedesc}{SETUP_LOOP}{delta}
587Pushes a block for a loop onto the block stack. The block spans
588from the current instruction with a size of \var{delta} bytes.
589\end{opcodedesc}
590
591\begin{opcodedesc}{SETUP_EXCEPT}{delta}
592Pushes a try block from a try-except clause onto the block stack.
593\var{delta} points to the first except block.
594\end{opcodedesc}
595
596\begin{opcodedesc}{SETUP_FINALLY}{delta}
597Pushes a try block from a try-except clause onto the block stack.
598\var{delta} points to the finally block.
599\end{opcodedesc}
600
601\begin{opcodedesc}{LOAD_FAST}{var_num}
602Pushes a reference to the local \code{co_varnames[\var{var_num}]} onto
603the stack.
604\end{opcodedesc}
605
606\begin{opcodedesc}{STORE_FAST}{var_num}
607Stores TOS into the local \code{co_varnames[\var{var_num}]}.
608\end{opcodedesc}
609
610\begin{opcodedesc}{DELETE_FAST}{var_num}
611Deletes local \code{co_varnames[\var{var_num}]}.
612\end{opcodedesc}
613
614\begin{opcodedesc}{LOAD_CLOSURE}{i}
615Pushes a reference to the cell contained in slot \var{i} of the
616cell and free variable storage. The name of the variable is
617\code{co_cellvars[\var{i}]} if \var{i} is less than the length of
618\var{co_cellvars}. Otherwise it is
619\code{co_freevars[\var{i} - len(co_cellvars)]}.
620\end{opcodedesc}
621
622\begin{opcodedesc}{LOAD_DEREF}{i}
623Loads the cell contained in slot \var{i} of the cell and free variable
624storage. Pushes a reference to the object the cell contains on the
625stack.
626\end{opcodedesc}
627
628\begin{opcodedesc}{STORE_DEREF}{i}
629Stores TOS into the cell contained in slot \var{i} of the cell and
630free variable storage.
631\end{opcodedesc}
632
633\begin{opcodedesc}{SET_LINENO}{lineno}
634This opcode is obsolete.
635\end{opcodedesc}
636
637\begin{opcodedesc}{RAISE_VARARGS}{argc}
638Raises an exception. \var{argc} indicates the number of parameters
639to the raise statement, ranging from 0 to 3. The handler will find
640the traceback as TOS2, the parameter as TOS1, and the exception
641as TOS.
642\end{opcodedesc}
643
644\begin{opcodedesc}{CALL_FUNCTION}{argc}
645Calls a function. The low byte of \var{argc} indicates the number of
646positional parameters, the high byte the number of keyword parameters.
647On the stack, the opcode finds the keyword parameters first. For each
648keyword argument, the value is on top of the key. Below the keyword
649parameters, the positional parameters are on the stack, with the
650right-most parameter on top. Below the parameters, the function object
651to call is on the stack.
652\end{opcodedesc}
653
654\begin{opcodedesc}{MAKE_FUNCTION}{argc}
655Pushes a new function object on the stack. TOS is the code associated
656with the function. The function object is defined to have \var{argc}
657default parameters, which are found below TOS.
658\end{opcodedesc}
659
660\begin{opcodedesc}{MAKE_CLOSURE}{argc}
661Creates a new function object, sets its \var{func_closure} slot, and
662pushes it on the stack. TOS is the code associated with the function.
663If the code object has N free variables, the next N items on the stack
664are the cells for these variables. The function also has \var{argc}
665default parameters, where are found before the cells.
666\end{opcodedesc}
667
668\begin{opcodedesc}{BUILD_SLICE}{argc}
669Pushes a slice object on the stack. \var{argc} must be 2 or 3. If it
670is 2, \code{slice(TOS1, TOS)} is pushed; if it is 3,
671\code{slice(TOS2, TOS1, TOS)} is pushed.
672See the \code{slice()}\bifuncindex{slice} built-in function for more
673information.
674\end{opcodedesc}
675
676\begin{opcodedesc}{EXTENDED_ARG}{ext}
677Prefixes any opcode which has an argument too big to fit into the
678default two bytes. \var{ext} holds two additional bytes which, taken
679together with the subsequent opcode's argument, comprise a four-byte
680argument, \var{ext} being the two most-significant bytes.
681\end{opcodedesc}
682
683\begin{opcodedesc}{CALL_FUNCTION_VAR}{argc}
684Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
685The top element on the stack contains the variable argument list, followed
686by keyword and positional arguments.
687\end{opcodedesc}
688
689\begin{opcodedesc}{CALL_FUNCTION_KW}{argc}
690Calls a function. \var{argc} is interpreted as in \code{CALL_FUNCTION}.
691The top element on the stack contains the keyword arguments dictionary,
692followed by explicit keyword and positional arguments.
693\end{opcodedesc}
694
695\begin{opcodedesc}{CALL_FUNCTION_VAR_KW}{argc}
696Calls a function. \var{argc} is interpreted as in
697\code{CALL_FUNCTION}. The top element on the stack contains the
698keyword arguments dictionary, followed by the variable-arguments
699tuple, followed by explicit keyword and positional arguments.
700\end{opcodedesc}
701
702\begin{opcodedesc}{HAVE_ARGUMENT}{}
703This is not really an opcode. It identifies the dividing line between
704opcodes which don't take arguments \code{< HAVE_ARGUMENT} and those which do
705\code{>= HAVE_ARGUMENT}.
706\end{opcodedesc}
Note: See TracBrowser for help on using the repository browser.