Debian Codegraph @

rhino/src/org/mozilla/javascript/Icode.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 package org.mozilla.javascript;
8
9 /**
10 * Additional interpreter-specific codes
11 */
12 abstract class Icode {
13
14 static final int
15
16 // delete operator used on a name
17 Icode_DELNAME = 0,
18
19 // Stack: ... value1 -> ... value1 value1
20 Icode_DUP = -1,
21
22 // Stack: ... value2 value1 -> ... value2 value1 value2 value1
23 Icode_DUP2 = -2,
24
25 // Stack: ... value2 value1 -> ... value1 value2
26 Icode_SWAP = -3,
27
28 // Stack: ... value1 -> ...
29 Icode_POP = -4,
30
31 // Store stack top into return register and then pop it
32 Icode_POP_RESULT = -5,
33
34 // To jump conditionally and pop additional stack value
35 Icode_IFEQ_POP = -6,
36
37 // various types of ++/--
38 Icode_VAR_INC_DEC = -7,
39 Icode_NAME_INC_DEC = -8,
40 Icode_PROP_INC_DEC = -9,
41 Icode_ELEM_INC_DEC = -10,
42 Icode_REF_INC_DEC = -11,
43
44 // load/save scope from/to local
45 Icode_SCOPE_LOAD = -12,
46 Icode_SCOPE_SAVE = -13,
47
48 Icode_TYPEOFNAME = -14,
49
50 // helper for function calls
51 Icode_NAME_AND_THIS = -15,
52 Icode_PROP_AND_THIS = -16,
53 Icode_ELEM_AND_THIS = -17,
54 Icode_VALUE_AND_THIS = -18,
55
56 // Create closure object for nested functions
57 Icode_CLOSURE_EXPR = -19,
58 Icode_CLOSURE_STMT = -20,
59
60 // Special calls
61 Icode_CALLSPECIAL = -21,
62
63 // To return undefined value
64 Icode_RETUNDEF = -22,
65
66 // Exception handling implementation
67 Icode_GOSUB = -23,
68 Icode_STARTSUB = -24,
69 Icode_RETSUB = -25,
70
71 // To indicating a line number change in icodes.
72 Icode_LINE = -26,
73
74 // To store shorts and ints inline
75 Icode_SHORTNUMBER = -27,
76 Icode_INTNUMBER = -28,
77
78 // To create and populate array to hold values for [] and {} literals
79 Icode_LITERAL_NEW = -29,
80 Icode_LITERAL_SET = -30,
81
82 // Array literal with skipped index like [1,,2]
83 Icode_SPARE_ARRAYLIT = -31,
84
85 // Load index register to prepare for the following index operation
86 Icode_REG_IND_C0 = -32,
87 Icode_REG_IND_C1 = -33,
88 Icode_REG_IND_C2 = -34,
89 Icode_REG_IND_C3 = -35,
90 Icode_REG_IND_C4 = -36,
91 Icode_REG_IND_C5 = -37,
92 Icode_REG_IND1 = -38,
93 Icode_REG_IND2 = -39,
94 Icode_REG_IND4 = -40,
95
96 // Load string register to prepare for the following string operation
97 Icode_REG_STR_C0 = -41,
98 Icode_REG_STR_C1 = -42,
99 Icode_REG_STR_C2 = -43,
100 Icode_REG_STR_C3 = -44,
101 Icode_REG_STR1 = -45,
102 Icode_REG_STR2 = -46,
103 Icode_REG_STR4 = -47,
104
105 // Version of getvar/setvar that read var index directly from bytecode
106 Icode_GETVAR1 = -48,
107 Icode_SETVAR1 = -49,
108
109 // Load undefined
110 Icode_UNDEF = -50,
111 Icode_ZERO = -51,
112 Icode_ONE = -52,
113
114 // entrance and exit from .()
115 Icode_ENTERDQ = -53,
116 Icode_LEAVEDQ = -54,
117
118 Icode_TAIL_CALL = -55,
119
120 // Clear local to allow GC its context
121 Icode_LOCAL_CLEAR = -56,
122
123 // Literal get/set
124 Icode_LITERAL_GETTER = -57,
125 Icode_LITERAL_SETTER = -58,
126
127 // const
128 Icode_SETCONST = -59,
129 Icode_SETCONSTVAR = -60,
130 Icode_SETCONSTVAR1 = -61,
131
132 // Generator opcodes (along with Token.YIELD)
133 Icode_GENERATOR = -62,
134 Icode_GENERATOR_END = -63,
135
136 Icode_DEBUGGER = -64,
137
138 // Last icode
139 MIN_ICODE = -64;
140
141 static String bytecodeName(int bytecode)
142 {
143 if (!validBytecode(bytecode)) {
144 throw new IllegalArgumentException(String.valueOf(bytecode));
145 }
146
147 if (!Token.printICode) {
148 return String.valueOf(bytecode);
149 }
150
151 if (validTokenCode(bytecode)) {
152 return Token.name(bytecode);
153 }
154
155 switch (bytecode) {
156 case Icode_DUP: return "DUP";
157 case Icode_DUP2: return "DUP2";
158 case Icode_SWAP: return "SWAP";
159 case Icode_POP: return "POP";
160 case Icode_POP_RESULT: return "POP_RESULT";
161 case Icode_IFEQ_POP: return "IFEQ_POP";
162 case Icode_VAR_INC_DEC: return "VAR_INC_DEC";
163 case Icode_NAME_INC_DEC: return "NAME_INC_DEC";
164 case Icode_PROP_INC_DEC: return "PROP_INC_DEC";
165 case Icode_ELEM_INC_DEC: return "ELEM_INC_DEC";
166 case Icode_REF_INC_DEC: return "REF_INC_DEC";
167 case Icode_SCOPE_LOAD: return "SCOPE_LOAD";
168 case Icode_SCOPE_SAVE: return "SCOPE_SAVE";
169 case Icode_TYPEOFNAME: return "TYPEOFNAME";
170 case Icode_NAME_AND_THIS: return "NAME_AND_THIS";
171 case Icode_PROP_AND_THIS: return "PROP_AND_THIS";
172 case Icode_ELEM_AND_THIS: return "ELEM_AND_THIS";
173 case Icode_VALUE_AND_THIS: return "VALUE_AND_THIS";
174 case Icode_CLOSURE_EXPR: return "CLOSURE_EXPR";
175 case Icode_CLOSURE_STMT: return "CLOSURE_STMT";
176 case Icode_CALLSPECIAL: return "CALLSPECIAL";
177 case Icode_RETUNDEF: return "RETUNDEF";
178 case Icode_GOSUB: return "GOSUB";
179 case Icode_STARTSUB: return "STARTSUB";
180 case Icode_RETSUB: return "RETSUB";
181 case Icode_LINE: return "LINE";
182 case Icode_SHORTNUMBER: return "SHORTNUMBER";
183 case Icode_INTNUMBER: return "INTNUMBER";
184 case Icode_LITERAL_NEW: return "LITERAL_NEW";
185 case Icode_LITERAL_SET: return "LITERAL_SET";
186 case Icode_SPARE_ARRAYLIT: return "SPARE_ARRAYLIT";
187 case Icode_REG_IND_C0: return "REG_IND_C0";
188 case Icode_REG_IND_C1: return "REG_IND_C1";
189 case Icode_REG_IND_C2: return "REG_IND_C2";
190 case Icode_REG_IND_C3: return "REG_IND_C3";
191 case Icode_REG_IND_C4: return "REG_IND_C4";
192 case Icode_REG_IND_C5: return "REG_IND_C5";
193 case Icode_REG_IND1: return "LOAD_IND1";
194 case Icode_REG_IND2: return "LOAD_IND2";
195 case Icode_REG_IND4: return "LOAD_IND4";
196 case Icode_REG_STR_C0: return "REG_STR_C0";
197 case Icode_REG_STR_C1: return "REG_STR_C1";
198 case Icode_REG_STR_C2: return "REG_STR_C2";
199 case Icode_REG_STR_C3: return "REG_STR_C3";
200 case Icode_REG_STR1: return "LOAD_STR1";
201 case Icode_REG_STR2: return "LOAD_STR2";
202 case Icode_REG_STR4: return "LOAD_STR4";
203 case Icode_GETVAR1: return "GETVAR1";
204 case Icode_SETVAR1: return "SETVAR1";
205 case Icode_UNDEF: return "UNDEF";
206 case Icode_ZERO: return "ZERO";
207 case Icode_ONE: return "ONE";
208 case Icode_ENTERDQ: return "ENTERDQ";
209 case Icode_LEAVEDQ: return "LEAVEDQ";
210 case Icode_TAIL_CALL: return "TAIL_CALL";
211 case Icode_LOCAL_CLEAR: return "LOCAL_CLEAR";
212 case Icode_LITERAL_GETTER: return "LITERAL_GETTER";
213 case Icode_LITERAL_SETTER: return "LITERAL_SETTER";
214 case Icode_SETCONST: return "SETCONST";
215 case Icode_SETCONSTVAR: return "SETCONSTVAR";
216 case Icode_SETCONSTVAR1: return "SETCONSTVAR1";
217 case Icode_GENERATOR: return "GENERATOR";
218 case Icode_GENERATOR_END: return "GENERATOR_END";
219 case Icode_DEBUGGER: return "DEBUGGER";
220 }
221
222 // icode without name
223 throw new IllegalStateException(String.valueOf(bytecode));
224 }
225
226 static boolean validIcode(int icode)
227 {
228 return MIN_ICODE <= icode && icode <= 0;
229 }
230
231 static boolean validTokenCode(int token)
232 {
233 return Token.FIRST_BYTECODE_TOKEN <= token
234 && token <= Token.LAST_BYTECODE_TOKEN;
235 }
236
237 static boolean validBytecode(int bytecode)
238 {
239 return validIcode(bytecode) || validTokenCode(bytecode);
240 }
241 }