Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_OPCODE_H |
| 2 | #define Py_OPCODE_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 7 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 8 | /* Instruction opcodes for compiled code */ |
| 9 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 10 | #define POP_TOP 1 |
| 11 | #define ROT_TWO 2 |
| 12 | #define ROT_THREE 3 |
| 13 | #define DUP_TOP 4 |
Antoine Pitrou | 74a69fa | 2010-09-04 18:43:52 +0000 | [diff] [blame] | 14 | #define DUP_TOP_TWO 5 |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 15 | #define NOP 9 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 16 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 17 | #define UNARY_POSITIVE 10 |
| 18 | #define UNARY_NEGATIVE 11 |
| 19 | #define UNARY_NOT 12 |
Guido van Rossum | 884afd6 | 1995-07-18 14:21:06 +0000 | [diff] [blame] | 20 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 21 | #define UNARY_INVERT 15 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 22 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 23 | #define BINARY_POWER 19 |
Guido van Rossum | 3d1f095 | 1996-01-12 00:51:44 +0000 | [diff] [blame] | 24 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 25 | #define BINARY_MULTIPLY 20 |
Neal Norwitz | c6d210c | 2006-03-16 06:02:10 +0000 | [diff] [blame] | 26 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 27 | #define BINARY_MODULO 22 |
| 28 | #define BINARY_ADD 23 |
| 29 | #define BINARY_SUBTRACT 24 |
| 30 | #define BINARY_SUBSCR 25 |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 31 | #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 Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 35 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 36 | #define STORE_MAP 54 |
| 37 | #define INPLACE_ADD 55 |
| 38 | #define INPLACE_SUBTRACT 56 |
| 39 | #define INPLACE_MULTIPLY 57 |
Neal Norwitz | e7086d4 | 2006-03-17 08:59:09 +0000 | [diff] [blame] | 40 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 41 | #define INPLACE_MODULO 59 |
| 42 | #define STORE_SUBSCR 60 |
| 43 | #define DELETE_SUBSCR 61 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 44 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 45 | #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 Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 52 | #define PRINT_EXPR 70 |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 53 | #define LOAD_BUILD_CLASS 71 |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 54 | #define YIELD_FROM 72 |
Georg Brandl | 88fc664 | 2007-02-09 21:28:07 +0000 | [diff] [blame] | 55 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 56 | #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 Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 62 | #define WITH_CLEANUP 81 |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 63 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 64 | #define RETURN_VALUE 83 |
| 65 | #define IMPORT_STAR 84 |
Guido van Rossum | 98297ee | 2007-11-06 21:34:58 +0000 | [diff] [blame] | 66 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 67 | #define YIELD_VALUE 86 |
| 68 | #define POP_BLOCK 87 |
| 69 | #define END_FINALLY 88 |
| 70 | #define POP_EXCEPT 89 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 71 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 72 | #define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */ |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 73 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 74 | #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 Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 78 | #define UNPACK_EX 94 /* Num items before variable part + |
| 79 | (Num items after variable part << 8) */ |
Thomas Wouters | 0be5aab | 2000-08-11 22:15:52 +0000 | [diff] [blame] | 80 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 81 | #define STORE_ATTR 95 /* Index in name list */ |
| 82 | #define DELETE_ATTR 96 /* "" */ |
| 83 | #define STORE_GLOBAL 97 /* "" */ |
| 84 | #define DELETE_GLOBAL 98 /* "" */ |
Antoine Pitrou | 74a69fa | 2010-09-04 18:43:52 +0000 | [diff] [blame] | 85 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 86 | #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 Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 96 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 97 | #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 Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 103 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 104 | #define LOAD_GLOBAL 116 /* Index in name list */ |
Guido van Rossum | 054ff1f | 1991-04-04 10:45:01 +0000 | [diff] [blame] | 105 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 106 | #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 Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 110 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 111 | #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 Rossum | 8b17d6b | 1993-03-30 13:18:41 +0000 | [diff] [blame] | 114 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 115 | #define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */ |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 116 | /* CALL_FUNCTION_XXX opcodes defined below depend on this definition */ |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 117 | #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 Rossum | 3b46a50 | 1995-07-07 22:32:10 +0000 | [diff] [blame] | 120 | |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 121 | #define MAKE_CLOSURE 134 /* same as MAKE_FUNCTION */ |
Jeremy Hylton | 64949cb | 2001-01-25 20:06:59 +0000 | [diff] [blame] | 122 | #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'Arc | ba117ef | 2010-09-10 21:39:53 +0000 | [diff] [blame] | 125 | #define DELETE_DEREF 138 /* Delete closure cell */ |
Jeremy Hylton | 64949cb | 2001-01-25 20:06:59 +0000 | [diff] [blame] | 126 | |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 127 | /* The next 3 opcodes must be contiguous and satisfy |
Jeremy Hylton | a403d7d | 2000-03-29 00:10:03 +0000 | [diff] [blame] | 128 | (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */ |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 129 | #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 Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 132 | |
Benjamin Peterson | 876b2f2 | 2009-06-28 03:18:59 +0000 | [diff] [blame] | 133 | #define SETUP_WITH 143 |
| 134 | |
Fred Drake | ef8ace3 | 2000-08-24 00:32:09 +0000 | [diff] [blame] | 135 | /* Support for opargs more than 16 bits long */ |
Benjamin Peterson | 876b2f2 | 2009-06-28 03:18:59 +0000 | [diff] [blame] | 136 | #define EXTENDED_ARG 144 |
Fred Drake | ef8ace3 | 2000-08-24 00:32:09 +0000 | [diff] [blame] | 137 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 138 | #define LIST_APPEND 145 |
| 139 | #define SET_ADD 146 |
| 140 | #define MAP_ADD 147 |
| 141 | |
Benjamin Peterson | 3b0431d | 2013-04-30 09:41:40 -0400 | [diff] [blame] | 142 | #define LOAD_CLASSDEREF 148 |
Martin v. Löwis | 7198a52 | 2002-01-01 19:59:11 +0000 | [diff] [blame] | 143 | |
Benjamin Peterson | eec3d71 | 2008-06-11 15:59:43 +0000 | [diff] [blame] | 144 | /* 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öwis | 7198a52 | 2002-01-01 19:59:11 +0000 | [diff] [blame] | 151 | enum 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 Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 152 | PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD}; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 153 | |
| 154 | #define HAS_ARG(op) ((op) >= HAVE_ARGUMENT) |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 155 | |
| 156 | #ifdef __cplusplus |
| 157 | } |
| 158 | #endif |
| 159 | #endif /* !Py_OPCODE_H */ |