blob: 8b6890fe27932431933cd42a77308376206949c3 [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_OPCODE_H
2#define Py_OPCODE_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossumf70e43a1991-02-19 12:39:46 +00007/***********************************************************
Guido van Rossum5799b521995-01-04 19:06:22 +00008Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000010
11 All Rights Reserved
12
Guido van Rossumd266eb41996-10-25 14:44:06 +000013Permission to use, copy, modify, and distribute this software and its
14documentation for any purpose and without fee is hereby granted,
Guido van Rossumf70e43a1991-02-19 12:39:46 +000015provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000016both that copyright notice and this permission notice appear in
Guido van Rossumf70e43a1991-02-19 12:39:46 +000017supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000018Centrum or CWI or Corporation for National Research Initiatives or
19CNRI not be used in advertising or publicity pertaining to
20distribution of the software without specific, written prior
21permission.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000022
Guido van Rossumd266eb41996-10-25 14:44:06 +000023While CWI is the initial source for this software, a modified version
24is made available by the Corporation for National Research Initiatives
25(CNRI) at the Internet address ftp://ftp.python.org.
26
27STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
28REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
29MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
30CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
31DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
32PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
33TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
34PERFORMANCE OF THIS SOFTWARE.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000035
36******************************************************************/
37
Guido van Rossum10dc2e81990-11-18 17:27:39 +000038/* Instruction opcodes for compiled code */
39
Guido van Rossum3f5da241990-12-20 15:06:42 +000040#define STOP_CODE 0
Guido van Rossum10dc2e81990-11-18 17:27:39 +000041#define POP_TOP 1
42#define ROT_TWO 2
43#define ROT_THREE 3
Guido van Rossum3f5da241990-12-20 15:06:42 +000044#define DUP_TOP 4
Guido van Rossum10dc2e81990-11-18 17:27:39 +000045
46#define UNARY_POSITIVE 10
47#define UNARY_NEGATIVE 11
48#define UNARY_NOT 12
49#define UNARY_CONVERT 13
Guido van Rossum884afd61995-07-18 14:21:06 +000050
Guido van Rossum7928cd71991-10-24 14:59:31 +000051#define UNARY_INVERT 15
Guido van Rossum10dc2e81990-11-18 17:27:39 +000052
Guido van Rossum3d1f0951996-01-12 00:51:44 +000053#define BINARY_POWER 19
54
Guido van Rossum10dc2e81990-11-18 17:27:39 +000055#define BINARY_MULTIPLY 20
56#define BINARY_DIVIDE 21
57#define BINARY_MODULO 22
58#define BINARY_ADD 23
59#define BINARY_SUBTRACT 24
60#define BINARY_SUBSCR 25
Guido van Rossum10dc2e81990-11-18 17:27:39 +000061
62#define SLICE 30
63/* Also uses 31-33 */
64
65#define STORE_SLICE 40
66/* Also uses 41-43 */
67
68#define DELETE_SLICE 50
69/* Also uses 51-53 */
70
71#define STORE_SUBSCR 60
72#define DELETE_SUBSCR 61
73
Guido van Rossum7928cd71991-10-24 14:59:31 +000074#define BINARY_LSHIFT 62
75#define BINARY_RSHIFT 63
76#define BINARY_AND 64
77#define BINARY_XOR 65
78#define BINARY_OR 66
79
80
Guido van Rossum10dc2e81990-11-18 17:27:39 +000081#define PRINT_EXPR 70
82#define PRINT_ITEM 71
83#define PRINT_NEWLINE 72
84
85#define BREAK_LOOP 80
Guido van Rossum884afd61995-07-18 14:21:06 +000086
Guido van Rossumf1270271990-11-18 17:38:15 +000087#define LOAD_LOCALS 82
Guido van Rossum10dc2e81990-11-18 17:27:39 +000088#define RETURN_VALUE 83
Guido van Rossum884afd61995-07-18 14:21:06 +000089
Guido van Rossumdb3165e1993-10-18 17:06:59 +000090#define EXEC_STMT 85
Guido van Rossum8b17d6b1993-03-30 13:18:41 +000091
Guido van Rossum10dc2e81990-11-18 17:27:39 +000092#define POP_BLOCK 87
93#define END_FINALLY 88
Guido van Rossumf1270271990-11-18 17:38:15 +000094#define BUILD_CLASS 89
Guido van Rossum10dc2e81990-11-18 17:27:39 +000095
96#define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */
97
98#define STORE_NAME 90 /* Index in name list */
99#define DELETE_NAME 91 /* "" */
100#define UNPACK_TUPLE 92 /* Number of tuple items */
101#define UNPACK_LIST 93 /* Number of list items */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000102#define STORE_ATTR 95 /* Index in name list */
103#define DELETE_ATTR 96 /* "" */
Guido van Rossum97ff5301991-12-10 13:59:17 +0000104#define STORE_GLOBAL 97 /* "" */
105#define DELETE_GLOBAL 98 /* "" */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000106
107#define LOAD_CONST 100 /* Index in const list */
108#define LOAD_NAME 101 /* Index in name list */
109#define BUILD_TUPLE 102 /* Number of tuple items */
110#define BUILD_LIST 103 /* Number of list items */
111#define BUILD_MAP 104 /* Always zero for now */
112#define LOAD_ATTR 105 /* Index in name list */
113#define COMPARE_OP 106 /* Comparison operator */
114#define IMPORT_NAME 107 /* Index in name list */
115#define IMPORT_FROM 108 /* Index in name list */
116
117#define JUMP_FORWARD 110 /* Number of bytes to skip */
118#define JUMP_IF_FALSE 111 /* "" */
119#define JUMP_IF_TRUE 112 /* "" */
120#define JUMP_ABSOLUTE 113 /* Target byte offset from beginning of code */
121#define FOR_LOOP 114 /* Number of bytes to skip */
122
Guido van Rossum054ff1f1991-04-04 10:45:01 +0000123#define LOAD_GLOBAL 116 /* Index in name list */
124
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000125#define SETUP_LOOP 120 /* Target address (absolute) */
126#define SETUP_EXCEPT 121 /* "" */
127#define SETUP_FINALLY 122 /* "" */
128
Guido van Rossum8b17d6b1993-03-30 13:18:41 +0000129#define LOAD_FAST 124 /* Local variable number */
130#define STORE_FAST 125 /* Local variable number */
131#define DELETE_FAST 126 /* Local variable number */
132
Guido van Rossum3f5da241990-12-20 15:06:42 +0000133#define SET_LINENO 127 /* Current line number */
134
Guido van Rossum3b46a501995-07-07 22:32:10 +0000135/* It used to be the case that opcodes should fit in 7 bits. This is
136 no longer the case -- 8 bits is fine (the instruction stream is now
137 a sequence of unsigned characters). We gladly use the new space
138 for new opcodes. */
139
140#define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
141#define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
Guido van Rossum884afd61995-07-18 14:21:06 +0000142#define MAKE_FUNCTION 132 /* #defaults */
Guido van Rossumdb3b0411996-07-30 16:41:26 +0000143#define BUILD_SLICE 133 /* Number of items */
Guido van Rossum3b46a501995-07-07 22:32:10 +0000144
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000145/* Comparison operator codes (argument to COMPARE_OP) */
146enum cmp_op {LT, LE, EQ, NE, GT, GE, IN, NOT_IN, IS, IS_NOT, EXC_MATCH, BAD};
Guido van Rossum3f5da241990-12-20 15:06:42 +0000147
148#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
Guido van Rossuma3309961993-07-28 09:05:47 +0000149
150#ifdef __cplusplus
151}
152#endif
153#endif /* !Py_OPCODE_H */