blob: 972558060c7ef0750487f4fc2a2922ee3b2b9551 [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 Rossum5799b521995-01-04 19:06:22 +00008Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
9The Netherlands.
Guido van Rossumf70e43a1991-02-19 12:39:46 +000010
11 All Rights Reserved
12
13Permission to use, copy, modify, and distribute this software and its
14documentation for any purpose and without fee is hereby granted,
15provided that the above copyright notice appear in all copies and that
16both that copyright notice and this permission notice appear in
17supporting documentation, and that the names of Stichting Mathematisch
18Centrum or CWI not be used in advertising or publicity pertaining to
19distribution of the software without specific, written prior permission.
20
21STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
22THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
23FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
24FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
27OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
29******************************************************************/
30
Guido van Rossum10dc2e81990-11-18 17:27:39 +000031/* Instruction opcodes for compiled code */
32
Guido van Rossum3f5da241990-12-20 15:06:42 +000033#define STOP_CODE 0
Guido van Rossum10dc2e81990-11-18 17:27:39 +000034#define POP_TOP 1
35#define ROT_TWO 2
36#define ROT_THREE 3
Guido van Rossum3f5da241990-12-20 15:06:42 +000037#define DUP_TOP 4
Guido van Rossum10dc2e81990-11-18 17:27:39 +000038
39#define UNARY_POSITIVE 10
40#define UNARY_NEGATIVE 11
41#define UNARY_NOT 12
42#define UNARY_CONVERT 13
Guido van Rossum884afd61995-07-18 14:21:06 +000043
Guido van Rossum7928cd71991-10-24 14:59:31 +000044#define UNARY_INVERT 15
Guido van Rossum10dc2e81990-11-18 17:27:39 +000045
46#define BINARY_MULTIPLY 20
47#define BINARY_DIVIDE 21
48#define BINARY_MODULO 22
49#define BINARY_ADD 23
50#define BINARY_SUBTRACT 24
51#define BINARY_SUBSCR 25
Guido van Rossum10dc2e81990-11-18 17:27:39 +000052
53#define SLICE 30
54/* Also uses 31-33 */
55
56#define STORE_SLICE 40
57/* Also uses 41-43 */
58
59#define DELETE_SLICE 50
60/* Also uses 51-53 */
61
62#define STORE_SUBSCR 60
63#define DELETE_SUBSCR 61
64
Guido van Rossum7928cd71991-10-24 14:59:31 +000065#define BINARY_LSHIFT 62
66#define BINARY_RSHIFT 63
67#define BINARY_AND 64
68#define BINARY_XOR 65
69#define BINARY_OR 66
70
71
Guido van Rossum10dc2e81990-11-18 17:27:39 +000072#define PRINT_EXPR 70
73#define PRINT_ITEM 71
74#define PRINT_NEWLINE 72
75
76#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
Guido van Rossum884afd61995-07-18 14:21:06 +000080
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 /* "" */
91#define UNPACK_TUPLE 92 /* Number of tuple items */
92#define UNPACK_LIST 93 /* Number of list items */
Guido van Rossum750bf141991-12-16 13:07:35 +000093#define UNPACK_ARG 94 /* Number of arguments */
Guido van Rossum10dc2e81990-11-18 17:27:39 +000094#define STORE_ATTR 95 /* Index in name list */
95#define DELETE_ATTR 96 /* "" */
Guido van Rossum97ff5301991-12-10 13:59:17 +000096#define STORE_GLOBAL 97 /* "" */
97#define DELETE_GLOBAL 98 /* "" */
Guido van Rossum22f863f1992-01-14 18:38:56 +000098#define UNPACK_VARARG 99 /* Minimal number of arguments */
Guido van Rossum10dc2e81990-11-18 17:27:39 +000099
100#define LOAD_CONST 100 /* Index in const list */
101#define LOAD_NAME 101 /* Index in name list */
102#define BUILD_TUPLE 102 /* Number of tuple items */
103#define BUILD_LIST 103 /* Number of list items */
104#define BUILD_MAP 104 /* Always zero for now */
105#define LOAD_ATTR 105 /* Index in name list */
106#define COMPARE_OP 106 /* Comparison operator */
107#define IMPORT_NAME 107 /* Index in name list */
108#define IMPORT_FROM 108 /* Index in name list */
Guido van Rossum25831651993-05-19 14:50:45 +0000109#define ACCESS_MODE 109 /* Name (mode is int on top of stack) */
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000110
111#define JUMP_FORWARD 110 /* Number of bytes to skip */
112#define JUMP_IF_FALSE 111 /* "" */
113#define JUMP_IF_TRUE 112 /* "" */
114#define JUMP_ABSOLUTE 113 /* Target byte offset from beginning of code */
115#define FOR_LOOP 114 /* Number of bytes to skip */
116
Guido van Rossum054ff1f1991-04-04 10:45:01 +0000117#define LOAD_LOCAL 115 /* Index in name list */
118#define LOAD_GLOBAL 116 /* Index in name list */
119
Guido van Rossumb6775db1994-08-01 11:34:53 +0000120#define SET_FUNC_ARGS 117 /* Argcount */
121
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000122#define SETUP_LOOP 120 /* Target address (absolute) */
123#define SETUP_EXCEPT 121 /* "" */
124#define SETUP_FINALLY 122 /* "" */
125
Guido van Rossum8b17d6b1993-03-30 13:18:41 +0000126#define LOAD_FAST 124 /* Local variable number */
127#define STORE_FAST 125 /* Local variable number */
128#define DELETE_FAST 126 /* Local variable number */
129
Guido van Rossum3f5da241990-12-20 15:06:42 +0000130#define SET_LINENO 127 /* Current line number */
131
Guido van Rossum3b46a501995-07-07 22:32:10 +0000132/* It used to be the case that opcodes should fit in 7 bits. This is
133 no longer the case -- 8 bits is fine (the instruction stream is now
134 a sequence of unsigned characters). We gladly use the new space
135 for new opcodes. */
136
137#define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
138#define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
Guido van Rossum884afd61995-07-18 14:21:06 +0000139#define MAKE_FUNCTION 132 /* #defaults */
Guido van Rossum3b46a501995-07-07 22:32:10 +0000140
Guido van Rossum10dc2e81990-11-18 17:27:39 +0000141/* Comparison operator codes (argument to COMPARE_OP) */
142enum 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 +0000143
144#define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
Guido van Rossuma3309961993-07-28 09:05:47 +0000145
146#ifdef __cplusplus
147}
148#endif
149#endif /* !Py_OPCODE_H */