blob: 9ed548729e6e928fa8f22f3821fa40ad6e0a5506 [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 Rossum10dc2e81990-11-18 17:27:39 +00008/* Instruction opcodes for compiled code */
9
Guido van Rossum3f5da241990-12-20 15:06:42 +000010#define STOP_CODE 0
Guido van Rossum10dc2e81990-11-18 17:27:39 +000011#define POP_TOP 1
12#define ROT_TWO 2
13#define ROT_THREE 3
Guido van Rossum3f5da241990-12-20 15:06:42 +000014#define DUP_TOP 4
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000015#define ROT_FOUR 5
Raymond Hettinger9c18e812004-06-21 16:31:15 +000016#define NOP 9
Guido van Rossum10dc2e81990-11-18 17:27:39 +000017
18#define UNARY_POSITIVE 10
19#define UNARY_NEGATIVE 11
20#define UNARY_NOT 12
21#define UNARY_CONVERT 13
Guido van Rossum884afd61995-07-18 14:21:06 +000022
Guido van Rossum7928cd71991-10-24 14:59:31 +000023#define UNARY_INVERT 15
Guido van Rossum10dc2e81990-11-18 17:27:39 +000024
Guido van Rossum3d1f0951996-01-12 00:51:44 +000025#define BINARY_POWER 19
26
Guido van Rossum10dc2e81990-11-18 17:27:39 +000027#define BINARY_MULTIPLY 20
28#define BINARY_DIVIDE 21
29#define BINARY_MODULO 22
30#define BINARY_ADD 23
31#define BINARY_SUBTRACT 24
32#define BINARY_SUBSCR 25
Guido van Rossum4668b002001-08-08 05:00:18 +000033#define BINARY_FLOOR_DIVIDE 26
34#define BINARY_TRUE_DIVIDE 27
35#define INPLACE_FLOOR_DIVIDE 28
36#define INPLACE_TRUE_DIVIDE 29
Guido van Rossum10dc2e81990-11-18 17:27:39 +000037
38#define SLICE 30
39/* Also uses 31-33 */
Benjamin Peterson2c992a02015-05-28 12:45:31 -050040#define SLICE_1 31
41#define SLICE_2 32
42#define SLICE_3 33
Guido van Rossum10dc2e81990-11-18 17:27:39 +000043
44#define STORE_SLICE 40
45/* Also uses 41-43 */
Benjamin Peterson2c992a02015-05-28 12:45:31 -050046#define STORE_SLICE_1 41
47#define STORE_SLICE_2 42
48#define STORE_SLICE_3 43
Guido van Rossum10dc2e81990-11-18 17:27:39 +000049
50#define DELETE_SLICE 50
51/* Also uses 51-53 */
Benjamin Peterson2c992a02015-05-28 12:45:31 -050052#define DELETE_SLICE_1 51
53#define DELETE_SLICE_2 52
54#define DELETE_SLICE_3 53
Guido van Rossum10dc2e81990-11-18 17:27:39 +000055
Raymond Hettingereffde122007-12-18 18:26:18 +000056#define STORE_MAP 54
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000057#define INPLACE_ADD 55
58#define INPLACE_SUBTRACT 56
59#define INPLACE_MULTIPLY 57
60#define INPLACE_DIVIDE 58
61#define INPLACE_MODULO 59
Guido van Rossum10dc2e81990-11-18 17:27:39 +000062#define STORE_SUBSCR 60
63#define DELETE_SUBSCR 61
64
Guido van Rossum7928cd71991-10-24 14:59:31 +000065#define BINARY_LSHIFT 62
66#define BINARY_RSHIFT 63
67#define BINARY_AND 64
68#define BINARY_XOR 65
69#define BINARY_OR 66
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000070#define INPLACE_POWER 67
Guido van Rossum59d1d2b2001-04-20 19:13:02 +000071#define GET_ITER 68
Guido van Rossum7928cd71991-10-24 14:59:31 +000072
Guido van Rossum10dc2e81990-11-18 17:27:39 +000073#define PRINT_EXPR 70
74#define PRINT_ITEM 71
75#define PRINT_NEWLINE 72
Barry Warsaw35fd6652000-08-21 15:36:27 +000076#define PRINT_ITEM_TO 73
77#define PRINT_NEWLINE_TO 74
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000078#define INPLACE_LSHIFT 75
79#define INPLACE_RSHIFT 76
80#define INPLACE_AND 77
81#define INPLACE_XOR 78
82#define INPLACE_OR 79
Guido van Rossum10dc2e81990-11-18 17:27:39 +000083#define BREAK_LOOP 80
Guido van Rossumc2e20742006-02-27 22:32:47 +000084#define WITH_CLEANUP 81
Guido van Rossumf1270271990-11-18 17:38:15 +000085#define LOAD_LOCALS 82
Guido van Rossum10dc2e81990-11-18 17:27:39 +000086#define RETURN_VALUE 83
Thomas Wouters52152252000-08-17 22:55:00 +000087#define IMPORT_STAR 84
Guido van Rossumdb3165e1993-10-18 17:06:59 +000088#define EXEC_STMT 85
Tim Peters5ca576e2001-06-18 22:08:13 +000089#define YIELD_VALUE 86
Guido van Rossum10dc2e81990-11-18 17:27:39 +000090#define POP_BLOCK 87
91#define END_FINALLY 88
Guido van Rossumf1270271990-11-18 17:38:15 +000092#define BUILD_CLASS 89
Guido van Rossum10dc2e81990-11-18 17:27:39 +000093
94#define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */
95
96#define STORE_NAME 90 /* Index in name list */
97#define DELETE_NAME 91 /* "" */
Thomas Wouters0be5aab2000-08-11 22:15:52 +000098#define UNPACK_SEQUENCE 92 /* Number of sequence items */
Guido van Rossum59d1d2b2001-04-20 19:13:02 +000099#define FOR_ITER 93
Antoine Pitroud0c35152008-12-17 00:38:28 +0000100#define LIST_APPEND 94
Thomas Wouters0be5aab2000-08-11 22:15:52 +0000101
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 /* "" */
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +0000106#define DUP_TOPX 99 /* number of items to duplicate */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000107#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 */
Alexandre Vassalottiee936a22010-01-09 23:35:54 +0000111#define BUILD_SET 104 /* Number of set items */
112#define BUILD_MAP 105 /* Always zero for now */
113#define LOAD_ATTR 106 /* Index in name list */
114#define COMPARE_OP 107 /* Comparison operator */
115#define IMPORT_NAME 108 /* Index in name list */
116#define IMPORT_FROM 109 /* Index in name list */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000117#define JUMP_FORWARD 110 /* Number of bytes to skip */
Alexandre Vassalottiee936a22010-01-09 23:35:54 +0000118
Jeffrey Yasskin68d68522009-02-28 19:03:21 +0000119#define JUMP_IF_FALSE_OR_POP 111 /* Target byte offset from beginning
120 of code */
121#define JUMP_IF_TRUE_OR_POP 112 /* "" */
122#define JUMP_ABSOLUTE 113 /* "" */
123#define POP_JUMP_IF_FALSE 114 /* "" */
124#define POP_JUMP_IF_TRUE 115 /* "" */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000125
Guido van Rossum054ff1f1991-04-04 10:45:01 +0000126#define LOAD_GLOBAL 116 /* Index in name list */
127
Jeremy Hylton3faa52e2001-02-01 22:48:12 +0000128#define CONTINUE_LOOP 119 /* Start of loop (absolute) */
Georg Brandlc6057c72007-07-11 19:41:49 +0000129#define SETUP_LOOP 120 /* Target address (relative) */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000130#define SETUP_EXCEPT 121 /* "" */
131#define SETUP_FINALLY 122 /* "" */
132
Guido van Rossum8b17d6b1993-03-30 13:18:41 +0000133#define LOAD_FAST 124 /* Local variable number */
134#define STORE_FAST 125 /* Local variable number */
135#define DELETE_FAST 126 /* Local variable number */
136
Guido van Rossum3b46a501995-07-07 22:32:10 +0000137#define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
Jeremy Hylton76901512000-03-28 23:49:17 +0000138/* CALL_FUNCTION_XXX opcodes defined below depend on this definition */
Guido van Rossum3b46a501995-07-07 22:32:10 +0000139#define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
Guido van Rossum884afd61995-07-18 14:21:06 +0000140#define MAKE_FUNCTION 132 /* #defaults */
Guido van Rossumdb3b0411996-07-30 16:41:26 +0000141#define BUILD_SLICE 133 /* Number of items */
Guido van Rossum3b46a501995-07-07 22:32:10 +0000142
Jeremy Hylton64949cb2001-01-25 20:06:59 +0000143#define MAKE_CLOSURE 134 /* #free vars */
144#define LOAD_CLOSURE 135 /* Load free variable from closure */
145#define LOAD_DEREF 136 /* Load and dereference from closure cell */
146#define STORE_DEREF 137 /* Store into cell */
147
Jeremy Hylton76901512000-03-28 23:49:17 +0000148/* The next 3 opcodes must be contiguous and satisfy
Jeremy Hyltona403d7d2000-03-29 00:10:03 +0000149 (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
Jeremy Hylton76901512000-03-28 23:49:17 +0000150#define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */
151#define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */
152#define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */
153
Benjamin Peterson1880d8b2009-05-25 13:13:44 +0000154#define SETUP_WITH 143
155
Fred Drakeef8ace32000-08-24 00:32:09 +0000156/* Support for opargs more than 16 bits long */
Benjamin Peterson1880d8b2009-05-25 13:13:44 +0000157#define EXTENDED_ARG 145
Fred Drakeef8ace32000-08-24 00:32:09 +0000158
Alexandre Vassalottib6465472010-01-11 22:36:12 +0000159#define SET_ADD 146
160#define MAP_ADD 147
161
Martin v. Löwis7198a522002-01-01 19:59:11 +0000162
163enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, PyCmp_GT=Py_GT, PyCmp_GE=Py_GE,
164 PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD};
Guido van Rossum3f5da241990-12-20 15:06:42 +0000165
166#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
Guido van Rossuma3309961993-07-28 09:05:47 +0000167
168#ifdef __cplusplus
169}
170#endif
171#endif /* !Py_OPCODE_H */