blob: d46e5b8fde03c11a906fe6b5e4e65e723fec0141 [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 Rossumfd71b9e2000-06-30 23:50:40 +00008Copyright (c) 2000, BeOpen.com.
9Copyright (c) 1995-2000, Corporation for National Research Initiatives.
10Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
11All rights reserved.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000012
Guido van Rossumfd71b9e2000-06-30 23:50:40 +000013See the file "Misc/COPYRIGHT" for information on usage and
14redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000015******************************************************************/
16
Guido van Rossum10dc2e81990-11-18 17:27:39 +000017/* Instruction opcodes for compiled code */
18
Guido van Rossum3f5da241990-12-20 15:06:42 +000019#define STOP_CODE 0
Guido van Rossum10dc2e81990-11-18 17:27:39 +000020#define POP_TOP 1
21#define ROT_TWO 2
22#define ROT_THREE 3
Guido van Rossum3f5da241990-12-20 15:06:42 +000023#define DUP_TOP 4
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000024#define ROT_FOUR 5
Guido van Rossum10dc2e81990-11-18 17:27:39 +000025
26#define UNARY_POSITIVE 10
27#define UNARY_NEGATIVE 11
28#define UNARY_NOT 12
29#define UNARY_CONVERT 13
Guido van Rossum884afd61995-07-18 14:21:06 +000030
Guido van Rossum7928cd71991-10-24 14:59:31 +000031#define UNARY_INVERT 15
Guido van Rossum10dc2e81990-11-18 17:27:39 +000032
Guido van Rossum3d1f0951996-01-12 00:51:44 +000033#define BINARY_POWER 19
34
Guido van Rossum10dc2e81990-11-18 17:27:39 +000035#define BINARY_MULTIPLY 20
36#define BINARY_DIVIDE 21
37#define BINARY_MODULO 22
38#define BINARY_ADD 23
39#define BINARY_SUBTRACT 24
40#define BINARY_SUBSCR 25
Guido van Rossum10dc2e81990-11-18 17:27:39 +000041
42#define SLICE 30
43/* Also uses 31-33 */
44
45#define STORE_SLICE 40
46/* Also uses 41-43 */
47
48#define DELETE_SLICE 50
49/* Also uses 51-53 */
50
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000051#define INPLACE_ADD 55
52#define INPLACE_SUBTRACT 56
53#define INPLACE_MULTIPLY 57
54#define INPLACE_DIVIDE 58
55#define INPLACE_MODULO 59
Guido van Rossum10dc2e81990-11-18 17:27:39 +000056#define STORE_SUBSCR 60
57#define DELETE_SUBSCR 61
58
Guido van Rossum7928cd71991-10-24 14:59:31 +000059#define BINARY_LSHIFT 62
60#define BINARY_RSHIFT 63
61#define BINARY_AND 64
62#define BINARY_XOR 65
63#define BINARY_OR 66
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000064#define INPLACE_POWER 67
Guido van Rossum7928cd71991-10-24 14:59:31 +000065
Guido van Rossum10dc2e81990-11-18 17:27:39 +000066#define PRINT_EXPR 70
67#define PRINT_ITEM 71
68#define PRINT_NEWLINE 72
Barry Warsaw35fd6652000-08-21 15:36:27 +000069#define PRINT_ITEM_TO 73
70#define PRINT_NEWLINE_TO 74
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000071#define INPLACE_LSHIFT 75
72#define INPLACE_RSHIFT 76
73#define INPLACE_AND 77
74#define INPLACE_XOR 78
75#define INPLACE_OR 79
Guido van Rossum10dc2e81990-11-18 17:27:39 +000076#define BREAK_LOOP 80
Guido van Rossum884afd61995-07-18 14:21:06 +000077
Guido van Rossumf1270271990-11-18 17:38:15 +000078#define LOAD_LOCALS 82
Guido van Rossum10dc2e81990-11-18 17:27:39 +000079#define RETURN_VALUE 83
Thomas Wouters52152252000-08-17 22:55:00 +000080#define IMPORT_STAR 84
Guido van Rossumdb3165e1993-10-18 17:06:59 +000081#define EXEC_STMT 85
Guido van Rossum8b17d6b1993-03-30 13:18:41 +000082
Guido van Rossum10dc2e81990-11-18 17:27:39 +000083#define POP_BLOCK 87
84#define END_FINALLY 88
Guido van Rossumf1270271990-11-18 17:38:15 +000085#define BUILD_CLASS 89
Guido van Rossum10dc2e81990-11-18 17:27:39 +000086
87#define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */
88
89#define STORE_NAME 90 /* Index in name list */
90#define DELETE_NAME 91 /* "" */
Thomas Wouters0be5aab2000-08-11 22:15:52 +000091#define UNPACK_SEQUENCE 92 /* Number of sequence items */
92
Guido van Rossum10dc2e81990-11-18 17:27:39 +000093#define STORE_ATTR 95 /* Index in name list */
94#define DELETE_ATTR 96 /* "" */
Guido van Rossum97ff5301991-12-10 13:59:17 +000095#define STORE_GLOBAL 97 /* "" */
96#define DELETE_GLOBAL 98 /* "" */
Thomas Woutersdd8dbdb2000-08-24 20:09:45 +000097#define DUP_TOPX 99 /* number of items to duplicate */
Guido van Rossum10dc2e81990-11-18 17:27:39 +000098#define LOAD_CONST 100 /* Index in const list */
99#define LOAD_NAME 101 /* Index in name list */
100#define BUILD_TUPLE 102 /* Number of tuple items */
101#define BUILD_LIST 103 /* Number of list items */
102#define BUILD_MAP 104 /* Always zero for now */
103#define LOAD_ATTR 105 /* Index in name list */
104#define COMPARE_OP 106 /* Comparison operator */
105#define IMPORT_NAME 107 /* Index in name list */
106#define IMPORT_FROM 108 /* Index in name list */
107
108#define JUMP_FORWARD 110 /* Number of bytes to skip */
109#define JUMP_IF_FALSE 111 /* "" */
110#define JUMP_IF_TRUE 112 /* "" */
111#define JUMP_ABSOLUTE 113 /* Target byte offset from beginning of code */
112#define FOR_LOOP 114 /* Number of bytes to skip */
113
Guido van Rossum054ff1f1991-04-04 10:45:01 +0000114#define LOAD_GLOBAL 116 /* Index in name list */
115
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000116#define SETUP_LOOP 120 /* Target address (absolute) */
117#define SETUP_EXCEPT 121 /* "" */
118#define SETUP_FINALLY 122 /* "" */
119
Guido van Rossum8b17d6b1993-03-30 13:18:41 +0000120#define LOAD_FAST 124 /* Local variable number */
121#define STORE_FAST 125 /* Local variable number */
122#define DELETE_FAST 126 /* Local variable number */
123
Guido van Rossum3f5da241990-12-20 15:06:42 +0000124#define SET_LINENO 127 /* Current line number */
125
Guido van Rossum3b46a501995-07-07 22:32:10 +0000126/* It used to be the case that opcodes should fit in 7 bits. This is
127 no longer the case -- 8 bits is fine (the instruction stream is now
128 a sequence of unsigned characters). We gladly use the new space
129 for new opcodes. */
130
131#define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
Jeremy Hylton76901512000-03-28 23:49:17 +0000132/* CALL_FUNCTION_XXX opcodes defined below depend on this definition */
Guido van Rossum3b46a501995-07-07 22:32:10 +0000133#define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
Guido van Rossum884afd61995-07-18 14:21:06 +0000134#define MAKE_FUNCTION 132 /* #defaults */
Guido van Rossumdb3b0411996-07-30 16:41:26 +0000135#define BUILD_SLICE 133 /* Number of items */
Guido van Rossum3b46a501995-07-07 22:32:10 +0000136
Jeremy Hylton76901512000-03-28 23:49:17 +0000137/* The next 3 opcodes must be contiguous and satisfy
Jeremy Hyltona403d7d2000-03-29 00:10:03 +0000138 (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
Jeremy Hylton76901512000-03-28 23:49:17 +0000139#define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */
140#define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */
141#define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */
142
Fred Drakeef8ace32000-08-24 00:32:09 +0000143/* Support for opargs more than 16 bits long */
144#define EXTENDED_ARG 143
145
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000146/* Comparison operator codes (argument to COMPARE_OP) */
147enum cmp_op {LT, LE, EQ, NE, GT, GE, IN, NOT_IN, IS, IS_NOT, EXC_MATCH, BAD};
Guido van Rossum3f5da241990-12-20 15:06:42 +0000148
149#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
Guido van Rossuma3309961993-07-28 09:05:47 +0000150
151#ifdef __cplusplus
152}
153#endif
154#endif /* !Py_OPCODE_H */