Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(29304)

Delta Between Two Patch Sets: Doc/library/dis.rst

Issue 27095: Simplify MAKE_FUNCTION
Left Patch Set: Created 3 years, 3 months ago
Right Patch Set: Created 3 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | Include/opcode.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 :mod:`dis` --- Disassembler for Python bytecode 1 :mod:`dis` --- Disassembler for Python bytecode
2 =============================================== 2 ===============================================
3 3
4 .. module:: dis 4 .. module:: dis
5 :synopsis: Disassembler for Python bytecode. 5 :synopsis: Disassembler for Python bytecode.
6 6
7 **Source code:** :source:`Lib/dis.py` 7 **Source code:** :source:`Lib/dis.py`
8 8
9 -------------- 9 --------------
10 10
(...skipping 13 matching lines...) Expand all
24 Example: Given the function :func:`myfunc`:: 24 Example: Given the function :func:`myfunc`::
25 25
26 def myfunc(alist): 26 def myfunc(alist):
27 return len(alist) 27 return len(alist)
28 28
29 the following command can be used to display the disassembly of 29 the following command can be used to display the disassembly of
30 :func:`myfunc`:: 30 :func:`myfunc`::
31 31
32 >>> dis.dis(myfunc) 32 >>> dis.dis(myfunc)
33 2 0 LOAD_GLOBAL 0 (len) 33 2 0 LOAD_GLOBAL 0 (len)
34 3 LOAD_FAST 0 (alist) 34 2 LOAD_FAST 0 (alist)
35 6 CALL_FUNCTION 1 35 4 CALL_FUNCTION 1
36 9 RETURN_VALUE 36 6 RETURN_VALUE
37 37
38 (The "2" is a line number). 38 (The "2" is a line number).
39 39
40 Bytecode analysis 40 Bytecode analysis
41 ----------------- 41 -----------------
42 42
43 .. versionadded:: 3.4 43 .. versionadded:: 3.4
44 44
45 The bytecode analysis API allows pieces of Python code to be wrapped in a 45 The bytecode analysis API allows pieces of Python code to be wrapped in a
46 :class:`Bytecode` object that provides easy access to details of the compiled 46 :class:`Bytecode` object that provides easy access to details of the compiled
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 Pops exception type and result of 'exit' function call from the stack. 675 Pops exception type and result of 'exit' function call from the stack.
676 676
677 If the stack represents an exception, *and* the function call returns a 677 If the stack represents an exception, *and* the function call returns a
678 'true' value, this information is "zapped" and replaced with a single 678 'true' value, this information is "zapped" and replaced with a single
679 ``WHY_SILENCED`` to prevent :opcode:`END_FINALLY` from re-raising the 679 ``WHY_SILENCED`` to prevent :opcode:`END_FINALLY` from re-raising the
680 exception. (But non-local gotos will still be resumed.) 680 exception. (But non-local gotos will still be resumed.)
681 681
682 .. XXX explain the WHY stuff! 682 .. XXX explain the WHY stuff!
683 683
684 684
685 All of the following opcodes expect arguments. An argument is two bytes, with 685 All of the following opcodes use their arguments.
686 the more significant byte last.
687 686
688 .. opcode:: STORE_NAME (namei) 687 .. opcode:: STORE_NAME (namei)
689 688
690 Implements ``name = TOS``. *namei* is the index of *name* in the attribute 689 Implements ``name = TOS``. *namei* is the index of *name* in the attribute
691 :attr:`co_names` of the code object. The compiler tries to use 690 :attr:`co_names` of the code object. The compiler tries to use
692 :opcode:`STORE_FAST` or :opcode:`STORE_GLOBAL` if possible. 691 :opcode:`STORE_FAST` or :opcode:`STORE_GLOBAL` if possible.
693 692
694 693
695 .. opcode:: DELETE_NAME (namei) 694 .. opcode:: DELETE_NAME (namei)
696 695
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 759
761 .. opcode:: BUILD_SET (count) 760 .. opcode:: BUILD_SET (count)
762 761
763 Works as :opcode:`BUILD_TUPLE`, but creates a set. 762 Works as :opcode:`BUILD_TUPLE`, but creates a set.
764 763
765 764
766 .. opcode:: BUILD_MAP (count) 765 .. opcode:: BUILD_MAP (count)
767 766
768 Pushes a new dictionary object onto the stack. The dictionary is pre-sized 767 Pushes a new dictionary object onto the stack. The dictionary is pre-sized
769 to hold *count* entries. 768 to hold *count* entries.
769
770
771 .. opcode:: BUILD_CONST_KEY_MAP (count)
772
773 The version of :opcode:`BUILD_MAP` specialized for constant keys. *count*
774 values are consumed from the stack. The top element on the stack contains
775 a tuple of keys.
776
777 .. versionadded:: 3.6
770 778
771 779
772 .. opcode:: LOAD_ATTR (namei) 780 .. opcode:: LOAD_ATTR (namei)
773 781
774 Replaces TOS with ``getattr(TOS, co_names[namei])``. 782 Replaces TOS with ``getattr(TOS, co_names[namei])``.
775 783
776 784
777 .. opcode:: COMPARE_OP (opname) 785 .. opcode:: COMPARE_OP (opname)
778 786
779 Performs a Boolean operation. The operation name can be found in 787 Performs a Boolean operation. The operation name can be found in
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 951
944 .. index:: builtin: slice 952 .. index:: builtin: slice
945 953
946 Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2, 954 Pushes a slice object on the stack. *argc* must be 2 or 3. If it is 2,
947 ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is 955 ``slice(TOS1, TOS)`` is pushed; if it is 3, ``slice(TOS2, TOS1, TOS)`` is
948 pushed. See the :func:`slice` built-in function for more information. 956 pushed. See the :func:`slice` built-in function for more information.
949 957
950 958
951 .. opcode:: EXTENDED_ARG (ext) 959 .. opcode:: EXTENDED_ARG (ext)
952 960
953 Prefixes any opcode which has an argument too big to fit into the default two 961 EXTENDED_ARG adds ``*ext* * 256`` to the next instruction's argument.
storchaka 2016/06/12 16:36:42 I would prefer to commit this in issue26647 togeth
954 bytes. *ext* holds two additional bytes which, taken together with the 962 This is used for arguments exceeding a byte in size, and can be chained
955 subsequent opcode's argument, comprise a four-byte argument, *ext* being the 963 to create 4-byte arguments.
956 two most-significant bytes.
957 964
958 965
959 .. opcode:: CALL_FUNCTION_VAR (argc) 966 .. opcode:: CALL_FUNCTION_VAR (argc)
960 967
961 Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The 968 Calls a function. *argc* is interpreted as in :opcode:`CALL_FUNCTION`. The
962 top element on the stack contains the variable argument list, followed by 969 top element on the stack contains the variable argument list, followed by
963 keyword and positional arguments. 970 keyword and positional arguments.
964 971
965 972
966 .. opcode:: CALL_FUNCTION_KW (argc) 973 .. opcode:: CALL_FUNCTION_KW (argc)
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 1065
1059 1066
1060 .. data:: haslocal 1067 .. data:: haslocal
1061 1068
1062 Sequence of bytecodes that access a local variable. 1069 Sequence of bytecodes that access a local variable.
1063 1070
1064 1071
1065 .. data:: hascompare 1072 .. data:: hascompare
1066 1073
1067 Sequence of bytecodes of Boolean operations. 1074 Sequence of bytecodes of Boolean operations.
LEFTRIGHT
« no previous file | Include/opcode.h » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+