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 |
| 52 | #define STORE_LOCALS 69 |
| 53 | #define PRINT_EXPR 70 |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 54 | #define LOAD_BUILD_CLASS 71 |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 55 | #define YIELD_FROM 72 |
Georg Brandl | 88fc664 | 2007-02-09 21:28:07 +0000 | [diff] [blame] | 56 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 57 | #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 Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 63 | #define WITH_CLEANUP 81 |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 64 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 65 | #define RETURN_VALUE 83 |
| 66 | #define IMPORT_STAR 84 |
Guido van Rossum | 98297ee | 2007-11-06 21:34:58 +0000 | [diff] [blame] | 67 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 68 | #define YIELD_VALUE 86 |
| 69 | #define POP_BLOCK 87 |
| 70 | #define END_FINALLY 88 |
| 71 | #define POP_EXCEPT 89 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 72 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 73 | #define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */ |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 74 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 75 | #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 Rossum | 0368b72 | 2007-05-11 16:50:42 +0000 | [diff] [blame] | 79 | #define UNPACK_EX 94 /* Num items before variable part + |
| 80 | (Num items after variable part << 8) */ |
Thomas Wouters | 0be5aab | 2000-08-11 22:15:52 +0000 | [diff] [blame] | 81 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 82 | #define STORE_ATTR 95 /* Index in name list */ |
| 83 | #define DELETE_ATTR 96 /* "" */ |
| 84 | #define STORE_GLOBAL 97 /* "" */ |
| 85 | #define DELETE_GLOBAL 98 /* "" */ |
Antoine Pitrou | 74a69fa | 2010-09-04 18:43:52 +0000 | [diff] [blame] | 86 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 87 | #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 Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 97 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 98 | #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 Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 104 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 105 | #define LOAD_GLOBAL 116 /* Index in name list */ |
Guido van Rossum | 054ff1f | 1991-04-04 10:45:01 +0000 | [diff] [blame] | 106 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 107 | #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 Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 111 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 112 | #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 Rossum | 8b17d6b | 1993-03-30 13:18:41 +0000 | [diff] [blame] | 115 | |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 116 | #define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */ |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 117 | /* CALL_FUNCTION_XXX opcodes defined below depend on this definition */ |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 118 | #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 Rossum | 3b46a50 | 1995-07-07 22:32:10 +0000 | [diff] [blame] | 121 | |
Guido van Rossum | 52cc1d8 | 2007-03-18 15:41:51 +0000 | [diff] [blame] | 122 | #define MAKE_CLOSURE 134 /* same as MAKE_FUNCTION */ |
Jeremy Hylton | 64949cb | 2001-01-25 20:06:59 +0000 | [diff] [blame] | 123 | #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'Arc | ba117ef | 2010-09-10 21:39:53 +0000 | [diff] [blame] | 126 | #define DELETE_DEREF 138 /* Delete closure cell */ |
Jeremy Hylton | 64949cb | 2001-01-25 20:06:59 +0000 | [diff] [blame] | 127 | |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 128 | /* The next 3 opcodes must be contiguous and satisfy |
Jeremy Hylton | a403d7d | 2000-03-29 00:10:03 +0000 | [diff] [blame] | 129 | (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */ |
Nick Coghlan | 1f7ce62 | 2012-01-13 21:43:40 +1000 | [diff] [blame] | 130 | #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 Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 133 | |
Benjamin Peterson | 876b2f2 | 2009-06-28 03:18:59 +0000 | [diff] [blame] | 134 | #define SETUP_WITH 143 |
| 135 | |
Fred Drake | ef8ace3 | 2000-08-24 00:32:09 +0000 | [diff] [blame] | 136 | /* Support for opargs more than 16 bits long */ |
Benjamin Peterson | 876b2f2 | 2009-06-28 03:18:59 +0000 | [diff] [blame] | 137 | #define EXTENDED_ARG 144 |
Fred Drake | ef8ace3 | 2000-08-24 00:32:09 +0000 | [diff] [blame] | 138 | |
Antoine Pitrou | f289ae6 | 2008-12-18 11:06:25 +0000 | [diff] [blame] | 139 | #define LIST_APPEND 145 |
| 140 | #define SET_ADD 146 |
| 141 | #define MAP_ADD 147 |
| 142 | |
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 */ |