blob: c777ac7ccc93949c16cfb5dee6327c65427e6d4f [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
Nick Coghlan1f7ce622012-01-13 21:43:40 +100010#define POP_TOP 1
11#define ROT_TWO 2
12#define ROT_THREE 3
13#define DUP_TOP 4
Antoine Pitrou74a69fa2010-09-04 18:43:52 +000014#define DUP_TOP_TWO 5
Nick Coghlan1f7ce622012-01-13 21:43:40 +100015#define NOP 9
Guido van Rossum10dc2e81990-11-18 17:27:39 +000016
Nick Coghlan1f7ce622012-01-13 21:43:40 +100017#define UNARY_POSITIVE 10
18#define UNARY_NEGATIVE 11
19#define UNARY_NOT 12
Guido van Rossum884afd61995-07-18 14:21:06 +000020
Nick Coghlan1f7ce622012-01-13 21:43:40 +100021#define UNARY_INVERT 15
Guido van Rossum10dc2e81990-11-18 17:27:39 +000022
Nick Coghlan1f7ce622012-01-13 21:43:40 +100023#define BINARY_POWER 19
Guido van Rossum3d1f0951996-01-12 00:51:44 +000024
Nick Coghlan1f7ce622012-01-13 21:43:40 +100025#define BINARY_MULTIPLY 20
Neal Norwitzc6d210c2006-03-16 06:02:10 +000026
Nick Coghlan1f7ce622012-01-13 21:43:40 +100027#define BINARY_MODULO 22
28#define BINARY_ADD 23
29#define BINARY_SUBTRACT 24
30#define BINARY_SUBSCR 25
Guido van Rossum4668b002001-08-08 05:00:18 +000031#define BINARY_FLOOR_DIVIDE 26
32#define BINARY_TRUE_DIVIDE 27
33#define INPLACE_FLOOR_DIVIDE 28
34#define INPLACE_TRUE_DIVIDE 29
Guido van Rossum10dc2e81990-11-18 17:27:39 +000035
Nick Coghlan1f7ce622012-01-13 21:43:40 +100036#define STORE_MAP 54
37#define INPLACE_ADD 55
38#define INPLACE_SUBTRACT 56
39#define INPLACE_MULTIPLY 57
Neal Norwitze7086d42006-03-17 08:59:09 +000040
Nick Coghlan1f7ce622012-01-13 21:43:40 +100041#define INPLACE_MODULO 59
42#define STORE_SUBSCR 60
43#define DELETE_SUBSCR 61
Guido van Rossum10dc2e81990-11-18 17:27:39 +000044
Nick Coghlan1f7ce622012-01-13 21:43:40 +100045#define BINARY_LSHIFT 62
46#define BINARY_RSHIFT 63
47#define BINARY_AND 64
48#define BINARY_XOR 65
49#define BINARY_OR 66
50#define INPLACE_POWER 67
51#define GET_ITER 68
52#define STORE_LOCALS 69
53#define PRINT_EXPR 70
Guido van Rossum52cc1d82007-03-18 15:41:51 +000054#define LOAD_BUILD_CLASS 71
Nick Coghlan1f7ce622012-01-13 21:43:40 +100055#define YIELD_FROM 72
Georg Brandl88fc6642007-02-09 21:28:07 +000056
Nick Coghlan1f7ce622012-01-13 21:43:40 +100057#define INPLACE_LSHIFT 75
58#define INPLACE_RSHIFT 76
59#define INPLACE_AND 77
60#define INPLACE_XOR 78
61#define INPLACE_OR 79
62#define BREAK_LOOP 80
Guido van Rossumc2e20742006-02-27 22:32:47 +000063#define WITH_CLEANUP 81
Guido van Rossum52cc1d82007-03-18 15:41:51 +000064
Nick Coghlan1f7ce622012-01-13 21:43:40 +100065#define RETURN_VALUE 83
66#define IMPORT_STAR 84
Guido van Rossum98297ee2007-11-06 21:34:58 +000067
Nick Coghlan1f7ce622012-01-13 21:43:40 +100068#define YIELD_VALUE 86
69#define POP_BLOCK 87
70#define END_FINALLY 88
71#define POP_EXCEPT 89
Guido van Rossum10dc2e81990-11-18 17:27:39 +000072
Nick Coghlan1f7ce622012-01-13 21:43:40 +100073#define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */
Guido van Rossum10dc2e81990-11-18 17:27:39 +000074
Nick Coghlan1f7ce622012-01-13 21:43:40 +100075#define STORE_NAME 90 /* Index in name list */
76#define DELETE_NAME 91 /* "" */
77#define UNPACK_SEQUENCE 92 /* Number of sequence items */
78#define FOR_ITER 93
Guido van Rossum0368b722007-05-11 16:50:42 +000079#define UNPACK_EX 94 /* Num items before variable part +
80 (Num items after variable part << 8) */
Thomas Wouters0be5aab2000-08-11 22:15:52 +000081
Nick Coghlan1f7ce622012-01-13 21:43:40 +100082#define STORE_ATTR 95 /* Index in name list */
83#define DELETE_ATTR 96 /* "" */
84#define STORE_GLOBAL 97 /* "" */
85#define DELETE_GLOBAL 98 /* "" */
Antoine Pitrou74a69fa2010-09-04 18:43:52 +000086
Nick Coghlan1f7ce622012-01-13 21:43:40 +100087#define LOAD_CONST 100 /* Index in const list */
88#define LOAD_NAME 101 /* Index in name list */
89#define BUILD_TUPLE 102 /* Number of tuple items */
90#define BUILD_LIST 103 /* Number of list items */
91#define BUILD_SET 104 /* Number of set items */
92#define BUILD_MAP 105 /* Always zero for now */
93#define LOAD_ATTR 106 /* Index in name list */
94#define COMPARE_OP 107 /* Comparison operator */
95#define IMPORT_NAME 108 /* Index in name list */
96#define IMPORT_FROM 109 /* Index in name list */
Guido van Rossum10dc2e81990-11-18 17:27:39 +000097
Nick Coghlan1f7ce622012-01-13 21:43:40 +100098#define JUMP_FORWARD 110 /* Number of bytes to skip */
99#define JUMP_IF_FALSE_OR_POP 111 /* Target byte offset from beginning of code */
100#define JUMP_IF_TRUE_OR_POP 112 /* "" */
101#define JUMP_ABSOLUTE 113 /* "" */
102#define POP_JUMP_IF_FALSE 114 /* "" */
103#define POP_JUMP_IF_TRUE 115 /* "" */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000104
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000105#define LOAD_GLOBAL 116 /* Index in name list */
Guido van Rossum054ff1f1991-04-04 10:45:01 +0000106
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000107#define CONTINUE_LOOP 119 /* Start of loop (absolute) */
108#define SETUP_LOOP 120 /* Target address (relative) */
109#define SETUP_EXCEPT 121 /* "" */
110#define SETUP_FINALLY 122 /* "" */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000111
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000112#define LOAD_FAST 124 /* Local variable number */
113#define STORE_FAST 125 /* Local variable number */
114#define DELETE_FAST 126 /* Local variable number */
Guido van Rossum8b17d6b1993-03-30 13:18:41 +0000115
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000116#define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
Jeremy Hylton76901512000-03-28 23:49:17 +0000117/* CALL_FUNCTION_XXX opcodes defined below depend on this definition */
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000118#define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
119#define MAKE_FUNCTION 132 /* #defaults + #kwdefaults<<8 + #annotations<<16 */
120#define BUILD_SLICE 133 /* Number of items */
Guido van Rossum3b46a501995-07-07 22:32:10 +0000121
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000122#define MAKE_CLOSURE 134 /* same as MAKE_FUNCTION */
Jeremy Hylton64949cb2001-01-25 20:06:59 +0000123#define LOAD_CLOSURE 135 /* Load free variable from closure */
124#define LOAD_DEREF 136 /* Load and dereference from closure cell */
125#define STORE_DEREF 137 /* Store into cell */
Amaury Forgeot d'Arcba117ef2010-09-10 21:39:53 +0000126#define DELETE_DEREF 138 /* Delete closure cell */
Jeremy Hylton64949cb2001-01-25 20:06:59 +0000127
Jeremy Hylton76901512000-03-28 23:49:17 +0000128/* The next 3 opcodes must be contiguous and satisfy
Jeremy Hyltona403d7d2000-03-29 00:10:03 +0000129 (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000130#define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */
131#define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */
132#define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */
Jeremy Hylton76901512000-03-28 23:49:17 +0000133
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000134#define SETUP_WITH 143
135
Fred Drakeef8ace32000-08-24 00:32:09 +0000136/* Support for opargs more than 16 bits long */
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000137#define EXTENDED_ARG 144
Fred Drakeef8ace32000-08-24 00:32:09 +0000138
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000139#define LIST_APPEND 145
140#define SET_ADD 146
141#define MAP_ADD 147
142
Benjamin Peterson3b0431d2013-04-30 09:41:40 -0400143#define LOAD_CLASSDEREF 148
Martin v. Löwis7198a522002-01-01 19:59:11 +0000144
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000145/* EXCEPT_HANDLER is a special, implicit block type which is created when
146 entering an except handler. It is not an opcode but we define it here
147 as we want it to be available to both frameobject.c and ceval.c, while
148 remaining private.*/
149#define EXCEPT_HANDLER 257
150
151
Martin v. Löwis7198a522002-01-01 19:59:11 +0000152enum 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,
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000153 PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD};
Guido van Rossum3f5da241990-12-20 15:06:42 +0000154
155#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
Guido van Rossuma3309961993-07-28 09:05:47 +0000156
157#ifdef __cplusplus
158}
159#endif
160#endif /* !Py_OPCODE_H */