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 | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 8 | Copyright (c) 2000, BeOpen.com. |
| 9 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 10 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 11 | All rights reserved. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 12 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 13 | See the file "Misc/COPYRIGHT" for information on usage and |
| 14 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 15 | ******************************************************************/ |
| 16 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 17 | /* Instruction opcodes for compiled code */ |
| 18 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 19 | #define STOP_CODE 0 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 20 | #define POP_TOP 1 |
| 21 | #define ROT_TWO 2 |
| 22 | #define ROT_THREE 3 |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 23 | #define DUP_TOP 4 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 24 | |
| 25 | #define UNARY_POSITIVE 10 |
| 26 | #define UNARY_NEGATIVE 11 |
| 27 | #define UNARY_NOT 12 |
| 28 | #define UNARY_CONVERT 13 |
Guido van Rossum | 884afd6 | 1995-07-18 14:21:06 +0000 | [diff] [blame] | 29 | |
Guido van Rossum | 7928cd7 | 1991-10-24 14:59:31 +0000 | [diff] [blame] | 30 | #define UNARY_INVERT 15 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 31 | |
Guido van Rossum | 3d1f095 | 1996-01-12 00:51:44 +0000 | [diff] [blame] | 32 | #define BINARY_POWER 19 |
| 33 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 34 | #define BINARY_MULTIPLY 20 |
| 35 | #define BINARY_DIVIDE 21 |
| 36 | #define BINARY_MODULO 22 |
| 37 | #define BINARY_ADD 23 |
| 38 | #define BINARY_SUBTRACT 24 |
| 39 | #define BINARY_SUBSCR 25 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 40 | |
| 41 | #define SLICE 30 |
| 42 | /* Also uses 31-33 */ |
| 43 | |
| 44 | #define STORE_SLICE 40 |
| 45 | /* Also uses 41-43 */ |
| 46 | |
| 47 | #define DELETE_SLICE 50 |
| 48 | /* Also uses 51-53 */ |
| 49 | |
| 50 | #define STORE_SUBSCR 60 |
| 51 | #define DELETE_SUBSCR 61 |
| 52 | |
Guido van Rossum | 7928cd7 | 1991-10-24 14:59:31 +0000 | [diff] [blame] | 53 | #define BINARY_LSHIFT 62 |
| 54 | #define BINARY_RSHIFT 63 |
| 55 | #define BINARY_AND 64 |
| 56 | #define BINARY_XOR 65 |
| 57 | #define BINARY_OR 66 |
| 58 | |
| 59 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 60 | #define PRINT_EXPR 70 |
| 61 | #define PRINT_ITEM 71 |
| 62 | #define PRINT_NEWLINE 72 |
| 63 | |
| 64 | #define BREAK_LOOP 80 |
Guido van Rossum | 884afd6 | 1995-07-18 14:21:06 +0000 | [diff] [blame] | 65 | |
Guido van Rossum | f127027 | 1990-11-18 17:38:15 +0000 | [diff] [blame] | 66 | #define LOAD_LOCALS 82 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 67 | #define RETURN_VALUE 83 |
Guido van Rossum | 884afd6 | 1995-07-18 14:21:06 +0000 | [diff] [blame] | 68 | |
Guido van Rossum | db3165e | 1993-10-18 17:06:59 +0000 | [diff] [blame] | 69 | #define EXEC_STMT 85 |
Guido van Rossum | 8b17d6b | 1993-03-30 13:18:41 +0000 | [diff] [blame] | 70 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 71 | #define POP_BLOCK 87 |
| 72 | #define END_FINALLY 88 |
Guido van Rossum | f127027 | 1990-11-18 17:38:15 +0000 | [diff] [blame] | 73 | #define BUILD_CLASS 89 |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 74 | |
| 75 | #define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */ |
| 76 | |
| 77 | #define STORE_NAME 90 /* Index in name list */ |
| 78 | #define DELETE_NAME 91 /* "" */ |
| 79 | #define UNPACK_TUPLE 92 /* Number of tuple items */ |
| 80 | #define UNPACK_LIST 93 /* Number of list items */ |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 81 | #define STORE_ATTR 95 /* Index in name list */ |
| 82 | #define DELETE_ATTR 96 /* "" */ |
Guido van Rossum | 97ff530 | 1991-12-10 13:59:17 +0000 | [diff] [blame] | 83 | #define STORE_GLOBAL 97 /* "" */ |
| 84 | #define DELETE_GLOBAL 98 /* "" */ |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 85 | |
| 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_MAP 104 /* Always zero for now */ |
| 91 | #define LOAD_ATTR 105 /* Index in name list */ |
| 92 | #define COMPARE_OP 106 /* Comparison operator */ |
| 93 | #define IMPORT_NAME 107 /* Index in name list */ |
| 94 | #define IMPORT_FROM 108 /* Index in name list */ |
| 95 | |
| 96 | #define JUMP_FORWARD 110 /* Number of bytes to skip */ |
| 97 | #define JUMP_IF_FALSE 111 /* "" */ |
| 98 | #define JUMP_IF_TRUE 112 /* "" */ |
| 99 | #define JUMP_ABSOLUTE 113 /* Target byte offset from beginning of code */ |
| 100 | #define FOR_LOOP 114 /* Number of bytes to skip */ |
| 101 | |
Guido van Rossum | 054ff1f | 1991-04-04 10:45:01 +0000 | [diff] [blame] | 102 | #define LOAD_GLOBAL 116 /* Index in name list */ |
| 103 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 104 | #define SETUP_LOOP 120 /* Target address (absolute) */ |
| 105 | #define SETUP_EXCEPT 121 /* "" */ |
| 106 | #define SETUP_FINALLY 122 /* "" */ |
| 107 | |
Guido van Rossum | 8b17d6b | 1993-03-30 13:18:41 +0000 | [diff] [blame] | 108 | #define LOAD_FAST 124 /* Local variable number */ |
| 109 | #define STORE_FAST 125 /* Local variable number */ |
| 110 | #define DELETE_FAST 126 /* Local variable number */ |
| 111 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 112 | #define SET_LINENO 127 /* Current line number */ |
| 113 | |
Guido van Rossum | 3b46a50 | 1995-07-07 22:32:10 +0000 | [diff] [blame] | 114 | /* It used to be the case that opcodes should fit in 7 bits. This is |
| 115 | no longer the case -- 8 bits is fine (the instruction stream is now |
| 116 | a sequence of unsigned characters). We gladly use the new space |
| 117 | for new opcodes. */ |
| 118 | |
| 119 | #define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */ |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 120 | /* CALL_FUNCTION_XXX opcodes defined below depend on this definition */ |
Guido van Rossum | 3b46a50 | 1995-07-07 22:32:10 +0000 | [diff] [blame] | 121 | #define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */ |
Guido van Rossum | 884afd6 | 1995-07-18 14:21:06 +0000 | [diff] [blame] | 122 | #define MAKE_FUNCTION 132 /* #defaults */ |
Guido van Rossum | db3b041 | 1996-07-30 16:41:26 +0000 | [diff] [blame] | 123 | #define BUILD_SLICE 133 /* Number of items */ |
Guido van Rossum | 3b46a50 | 1995-07-07 22:32:10 +0000 | [diff] [blame] | 124 | |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 125 | /* The next 3 opcodes must be contiguous and satisfy |
Jeremy Hylton | a403d7d | 2000-03-29 00:10:03 +0000 | [diff] [blame] | 126 | (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */ |
Jeremy Hylton | 7690151 | 2000-03-28 23:49:17 +0000 | [diff] [blame] | 127 | #define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */ |
| 128 | #define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */ |
| 129 | #define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */ |
| 130 | |
Guido van Rossum | 10dc2e8 | 1990-11-18 17:27:39 +0000 | [diff] [blame] | 131 | /* Comparison operator codes (argument to COMPARE_OP) */ |
| 132 | enum cmp_op {LT, LE, EQ, NE, GT, GE, IN, NOT_IN, IS, IS_NOT, EXC_MATCH, BAD}; |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 133 | |
| 134 | #define HAS_ARG(op) ((op) >= HAVE_ARGUMENT) |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 135 | |
| 136 | #ifdef __cplusplus |
| 137 | } |
| 138 | #endif |
| 139 | #endif /* !Py_OPCODE_H */ |