blob: 0936f2d9f421e53d7c24c85ca47fdb9f99fc4f70 [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
Nick Coghlan1f7ce622012-01-13 21:43:40 +100052#define PRINT_EXPR 70
Guido van Rossum52cc1d82007-03-18 15:41:51 +000053#define LOAD_BUILD_CLASS 71
Nick Coghlan1f7ce622012-01-13 21:43:40 +100054#define YIELD_FROM 72
Georg Brandl88fc6642007-02-09 21:28:07 +000055
Nick Coghlan1f7ce622012-01-13 21:43:40 +100056#define INPLACE_LSHIFT 75
57#define INPLACE_RSHIFT 76
58#define INPLACE_AND 77
59#define INPLACE_XOR 78
60#define INPLACE_OR 79
61#define BREAK_LOOP 80
Guido van Rossumc2e20742006-02-27 22:32:47 +000062#define WITH_CLEANUP 81
Guido van Rossum52cc1d82007-03-18 15:41:51 +000063
Nick Coghlan1f7ce622012-01-13 21:43:40 +100064#define RETURN_VALUE 83
65#define IMPORT_STAR 84
Guido van Rossum98297ee2007-11-06 21:34:58 +000066
Nick Coghlan1f7ce622012-01-13 21:43:40 +100067#define YIELD_VALUE 86
68#define POP_BLOCK 87
69#define END_FINALLY 88
70#define POP_EXCEPT 89
Guido van Rossum10dc2e81990-11-18 17:27:39 +000071
Nick Coghlan1f7ce622012-01-13 21:43:40 +100072#define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */
Guido van Rossum10dc2e81990-11-18 17:27:39 +000073
Nick Coghlan1f7ce622012-01-13 21:43:40 +100074#define STORE_NAME 90 /* Index in name list */
75#define DELETE_NAME 91 /* "" */
76#define UNPACK_SEQUENCE 92 /* Number of sequence items */
77#define FOR_ITER 93
Guido van Rossum0368b722007-05-11 16:50:42 +000078#define UNPACK_EX 94 /* Num items before variable part +
79 (Num items after variable part << 8) */
Thomas Wouters0be5aab2000-08-11 22:15:52 +000080
Nick Coghlan1f7ce622012-01-13 21:43:40 +100081#define STORE_ATTR 95 /* Index in name list */
82#define DELETE_ATTR 96 /* "" */
83#define STORE_GLOBAL 97 /* "" */
84#define DELETE_GLOBAL 98 /* "" */
Antoine Pitrou74a69fa2010-09-04 18:43:52 +000085
Nick Coghlan1f7ce622012-01-13 21:43:40 +100086#define LOAD_CONST 100 /* Index in const list */
87#define LOAD_NAME 101 /* Index in name list */
88#define BUILD_TUPLE 102 /* Number of tuple items */
89#define BUILD_LIST 103 /* Number of list items */
90#define BUILD_SET 104 /* Number of set items */
91#define BUILD_MAP 105 /* Always zero for now */
92#define LOAD_ATTR 106 /* Index in name list */
93#define COMPARE_OP 107 /* Comparison operator */
94#define IMPORT_NAME 108 /* Index in name list */
95#define IMPORT_FROM 109 /* Index in name list */
Guido van Rossum10dc2e81990-11-18 17:27:39 +000096
Nick Coghlan1f7ce622012-01-13 21:43:40 +100097#define JUMP_FORWARD 110 /* Number of bytes to skip */
98#define JUMP_IF_FALSE_OR_POP 111 /* Target byte offset from beginning of code */
99#define JUMP_IF_TRUE_OR_POP 112 /* "" */
100#define JUMP_ABSOLUTE 113 /* "" */
101#define POP_JUMP_IF_FALSE 114 /* "" */
102#define POP_JUMP_IF_TRUE 115 /* "" */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000103
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000104#define LOAD_GLOBAL 116 /* Index in name list */
Guido van Rossum054ff1f1991-04-04 10:45:01 +0000105
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000106#define CONTINUE_LOOP 119 /* Start of loop (absolute) */
107#define SETUP_LOOP 120 /* Target address (relative) */
108#define SETUP_EXCEPT 121 /* "" */
109#define SETUP_FINALLY 122 /* "" */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000110
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000111#define LOAD_FAST 124 /* Local variable number */
112#define STORE_FAST 125 /* Local variable number */
113#define DELETE_FAST 126 /* Local variable number */
Guido van Rossum8b17d6b1993-03-30 13:18:41 +0000114
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000115#define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
Jeremy Hylton76901512000-03-28 23:49:17 +0000116/* CALL_FUNCTION_XXX opcodes defined below depend on this definition */
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000117#define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
118#define MAKE_FUNCTION 132 /* #defaults + #kwdefaults<<8 + #annotations<<16 */
119#define BUILD_SLICE 133 /* Number of items */
Guido van Rossum3b46a501995-07-07 22:32:10 +0000120
Guido van Rossum52cc1d82007-03-18 15:41:51 +0000121#define MAKE_CLOSURE 134 /* same as MAKE_FUNCTION */
Jeremy Hylton64949cb2001-01-25 20:06:59 +0000122#define LOAD_CLOSURE 135 /* Load free variable from closure */
123#define LOAD_DEREF 136 /* Load and dereference from closure cell */
124#define STORE_DEREF 137 /* Store into cell */
Amaury Forgeot d'Arcba117ef2010-09-10 21:39:53 +0000125#define DELETE_DEREF 138 /* Delete closure cell */
Jeremy Hylton64949cb2001-01-25 20:06:59 +0000126
Jeremy Hylton76901512000-03-28 23:49:17 +0000127/* The next 3 opcodes must be contiguous and satisfy
Jeremy Hyltona403d7d2000-03-29 00:10:03 +0000128 (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
Nick Coghlan1f7ce622012-01-13 21:43:40 +1000129#define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */
130#define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */
131#define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */
Jeremy Hylton76901512000-03-28 23:49:17 +0000132
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000133#define SETUP_WITH 143
134
Fred Drakeef8ace32000-08-24 00:32:09 +0000135/* Support for opargs more than 16 bits long */
Benjamin Peterson876b2f22009-06-28 03:18:59 +0000136#define EXTENDED_ARG 144
Fred Drakeef8ace32000-08-24 00:32:09 +0000137
Antoine Pitrouf289ae62008-12-18 11:06:25 +0000138#define LIST_APPEND 145
139#define SET_ADD 146
140#define MAP_ADD 147
141
Benjamin Peterson3b0431d2013-04-30 09:41:40 -0400142#define LOAD_CLASSDEREF 148
Martin v. Löwis7198a522002-01-01 19:59:11 +0000143
Benjamin Petersoneec3d712008-06-11 15:59:43 +0000144/* EXCEPT_HANDLER is a special, implicit block type which is created when
145 entering an except handler. It is not an opcode but we define it here
146 as we want it to be available to both frameobject.c and ceval.c, while
147 remaining private.*/
148#define EXCEPT_HANDLER 257
149
150
Martin v. Löwis7198a522002-01-01 19:59:11 +0000151enum 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 +1000152 PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD};
Guido van Rossum3f5da241990-12-20 15:06:42 +0000153
154#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
Guido van Rossuma3309961993-07-28 09:05:47 +0000155
156#ifdef __cplusplus
157}
158#endif
159#endif /* !Py_OPCODE_H */