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 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 10 | #define STOP_CODE 0 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 11 | #define POP_TOP 1 |
| 12 | #define ROT_TWO 2 |
| 13 | #define ROT_THREE 3 |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 14 | #define DUP_TOP 4 |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 15 | #define ROT_FOUR 5 |
Raymond Hettinger | 9c18e81 | 2004-06-21 16:31:15 +0000 | [diff] [blame] | 16 | #define NOP 9 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 17 | |
| 18 | #define UNARY_POSITIVE 10 |
| 19 | #define UNARY_NEGATIVE 11 |
| 20 | #define UNARY_NOT 12 |
Guido van Rossum | 884afd6 | 1995-07-18 14:21:06 +0000 | [diff] [blame] | 21 | |
Guido van Rossum | 7928cd7 | 1991-10-24 14:59:31 +0000 | [diff] [blame] | 22 | #define UNARY_INVERT 15 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 23 | |
Raymond Hettinger | dd80f76 | 2004-03-07 07:31:06 +0000 | [diff] [blame] | 24 | #define LIST_APPEND 18 |
Guido van Rossum | 3d1f095 | 1996-01-12 00:51:44 +0000 | [diff] [blame] | 25 | #define BINARY_POWER 19 |
| 26 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 27 | #define BINARY_MULTIPLY 20 |
Neal Norwitz | c6d210c | 2006-03-16 06:02:10 +0000 | [diff] [blame] | 28 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 29 | #define BINARY_MODULO 22 |
| 30 | #define BINARY_ADD 23 |
| 31 | #define BINARY_SUBTRACT 24 |
| 32 | #define BINARY_SUBSCR 25 |
Guido van Rossum | 4668b00 | 2001-08-08 05:00:18 +0000 | [diff] [blame] | 33 | #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 Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 37 | |
| 38 | #define SLICE 30 |
| 39 | /* Also uses 31-33 */ |
| 40 | |
| 41 | #define STORE_SLICE 40 |
| 42 | /* Also uses 41-43 */ |
| 43 | |
| 44 | #define DELETE_SLICE 50 |
| 45 | /* Also uses 51-53 */ |
| 46 | |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 47 | #define INPLACE_ADD 55 |
| 48 | #define INPLACE_SUBTRACT 56 |
| 49 | #define INPLACE_MULTIPLY 57 |
Neal Norwitz | e7086d4 | 2006-03-17 08:59:09 +0000 | [diff] [blame] | 50 | |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 51 | #define INPLACE_MODULO 59 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 52 | #define STORE_SUBSCR 60 |
| 53 | #define DELETE_SUBSCR 61 |
| 54 | |
Guido van Rossum | 7928cd7 | 1991-10-24 14:59:31 +0000 | [diff] [blame] | 55 | #define BINARY_LSHIFT 62 |
| 56 | #define BINARY_RSHIFT 63 |
| 57 | #define BINARY_AND 64 |
| 58 | #define BINARY_XOR 65 |
| 59 | #define BINARY_OR 66 |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 60 | #define INPLACE_POWER 67 |
Guido van Rossum | 59d1d2b | 2001-04-20 19:13:02 +0000 | [diff] [blame] | 61 | #define GET_ITER 68 |
Guido van Rossum | 7928cd7 | 1991-10-24 14:59:31 +0000 | [diff] [blame] | 62 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 63 | #define PRINT_EXPR 70 |
| 64 | #define PRINT_ITEM 71 |
| 65 | #define PRINT_NEWLINE 72 |
Barry Warsaw | 35fd665 | 2000-08-21 15:36:27 +0000 | [diff] [blame] | 66 | #define PRINT_ITEM_TO 73 |
| 67 | #define PRINT_NEWLINE_TO 74 |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 68 | #define INPLACE_LSHIFT 75 |
| 69 | #define INPLACE_RSHIFT 76 |
| 70 | #define INPLACE_AND 77 |
| 71 | #define INPLACE_XOR 78 |
| 72 | #define INPLACE_OR 79 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 73 | #define BREAK_LOOP 80 |
Guido van Rossum | c2e2074 | 2006-02-27 22:32:47 +0000 | [diff] [blame] | 74 | #define WITH_CLEANUP 81 |
Guido van Rossum | f127027 | 1990-11-18 17:38:15 +0000 | [diff] [blame] | 75 | #define LOAD_LOCALS 82 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 76 | #define RETURN_VALUE 83 |
Thomas Wouters | 5215225 | 2000-08-17 22:55:00 +0000 | [diff] [blame] | 77 | #define IMPORT_STAR 84 |
Guido van Rossum | db3165e | 1993-10-18 17:06:59 +0000 | [diff] [blame] | 78 | #define EXEC_STMT 85 |
Tim Peters | 5ca576e | 2001-06-18 22:08:13 +0000 | [diff] [blame] | 79 | #define YIELD_VALUE 86 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 80 | #define POP_BLOCK 87 |
| 81 | #define END_FINALLY 88 |
Guido van Rossum | f127027 | 1990-11-18 17:38:15 +0000 | [diff] [blame] | 82 | #define BUILD_CLASS 89 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 83 | |
| 84 | #define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */ |
| 85 | |
| 86 | #define STORE_NAME 90 /* Index in name list */ |
| 87 | #define DELETE_NAME 91 /* "" */ |
Thomas Wouters | 0be5aab | 2000-08-11 22:15:52 +0000 | [diff] [blame] | 88 | #define UNPACK_SEQUENCE 92 /* Number of sequence items */ |
Guido van Rossum | 59d1d2b | 2001-04-20 19:13:02 +0000 | [diff] [blame] | 89 | #define FOR_ITER 93 |
Thomas Wouters | 0be5aab | 2000-08-11 22:15:52 +0000 | [diff] [blame] | 90 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 91 | #define STORE_ATTR 95 /* Index in name list */ |
| 92 | #define DELETE_ATTR 96 /* "" */ |
Guido van Rossum | 97ff530 | 1991-12-10 13:59:17 +0000 | [diff] [blame] | 93 | #define STORE_GLOBAL 97 /* "" */ |
| 94 | #define DELETE_GLOBAL 98 /* "" */ |
Thomas Wouters | dd8dbdb | 2000-08-24 20:09:45 +0000 | [diff] [blame] | 95 | #define DUP_TOPX 99 /* number of items to duplicate */ |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 96 | #define LOAD_CONST 100 /* Index in const list */ |
| 97 | #define LOAD_NAME 101 /* Index in name list */ |
| 98 | #define BUILD_TUPLE 102 /* Number of tuple items */ |
| 99 | #define BUILD_LIST 103 /* Number of list items */ |
Guido van Rossum | 86e58e2 | 2006-08-28 15:27:34 +0000 | [diff] [blame^] | 100 | #define BUILD_SET 104 /* Number of set items */ |
| 101 | #define BUILD_MAP 105 /* Always zero for now */ |
| 102 | #define LOAD_ATTR 106 /* Index in name list */ |
| 103 | #define COMPARE_OP 107 /* Comparison operator */ |
| 104 | #define IMPORT_NAME 108 /* Index in name list */ |
| 105 | #define IMPORT_FROM 109 /* Index in name list */ |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 106 | |
| 107 | #define JUMP_FORWARD 110 /* Number of bytes to skip */ |
| 108 | #define JUMP_IF_FALSE 111 /* "" */ |
| 109 | #define JUMP_IF_TRUE 112 /* "" */ |
| 110 | #define JUMP_ABSOLUTE 113 /* Target byte offset from beginning of code */ |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 111 | |
Guido van Rossum | 054ff1f | 1991-04-04 10:45:01 +0000 | [diff] [blame] | 112 | #define LOAD_GLOBAL 116 /* Index in name list */ |
| 113 | |
Jeremy Hylton | 3faa52e | 2001-02-01 22:48:12 +0000 | [diff] [blame] | 114 | #define CONTINUE_LOOP 119 /* Start of loop (absolute) */ |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 115 | #define SETUP_LOOP 120 /* Target address (absolute) */ |
| 116 | #define SETUP_EXCEPT 121 /* "" */ |
| 117 | #define SETUP_FINALLY 122 /* "" */ |
| 118 | |
Guido van Rossum | 8b17d6b | 1993-03-30 13:18:41 +0000 | [diff] [blame] | 119 | #define LOAD_FAST 124 /* Local variable number */ |
| 120 | #define STORE_FAST 125 /* Local variable number */ |
| 121 | #define DELETE_FAST 126 /* Local variable number */ |
| 122 | |
Guido van Rossum | 3b46a50 | 1995-07-07 22:32:10 +0000 | [diff] [blame] | 123 | #define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */ |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 124 | /* CALL_FUNCTION_XXX opcodes defined below depend on this definition */ |
Guido van Rossum | 3b46a50 | 1995-07-07 22:32:10 +0000 | [diff] [blame] | 125 | #define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */ |
Guido van Rossum | 884afd6 | 1995-07-18 14:21:06 +0000 | [diff] [blame] | 126 | #define MAKE_FUNCTION 132 /* #defaults */ |
Guido van Rossum | db3b041 | 1996-07-30 16:41:26 +0000 | [diff] [blame] | 127 | #define BUILD_SLICE 133 /* Number of items */ |
Guido van Rossum | 3b46a50 | 1995-07-07 22:32:10 +0000 | [diff] [blame] | 128 | |
Jeremy Hylton | 64949cb | 2001-01-25 20:06:59 +0000 | [diff] [blame] | 129 | #define MAKE_CLOSURE 134 /* #free vars */ |
| 130 | #define LOAD_CLOSURE 135 /* Load free variable from closure */ |
| 131 | #define LOAD_DEREF 136 /* Load and dereference from closure cell */ |
| 132 | #define STORE_DEREF 137 /* Store into cell */ |
| 133 | |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 134 | /* The next 3 opcodes must be contiguous and satisfy |
Jeremy Hylton | a403d7d | 2000-03-29 00:10:03 +0000 | [diff] [blame] | 135 | (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */ |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 136 | #define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */ |
| 137 | #define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */ |
| 138 | #define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */ |
| 139 | |
Fred Drake | ef8ace3 | 2000-08-24 00:32:09 +0000 | [diff] [blame] | 140 | /* Support for opargs more than 16 bits long */ |
| 141 | #define EXTENDED_ARG 143 |
| 142 | |
Martin v. Löwis | 7198a52 | 2002-01-01 19:59:11 +0000 | [diff] [blame] | 143 | |
| 144 | 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, |
| 145 | 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] | 146 | |
| 147 | #define HAS_ARG(op) ((op) >= HAVE_ARGUMENT) |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 148 | |
| 149 | #ifdef __cplusplus |
| 150 | } |
| 151 | #endif |
| 152 | #endif /* !Py_OPCODE_H */ |