diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterLogic.cs | 400 |
1 files changed, 400 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterLogic.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterLogic.cs new file mode 100644 index 0000000..3b7da35 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterLogic.cs | |||
@@ -0,0 +1,400 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
5 | using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes; | ||
6 | |||
7 | namespace OpenSim.Scripting.EmbeddedJVM | ||
8 | { | ||
9 | partial class Thread | ||
10 | { | ||
11 | private partial class Interpreter | ||
12 | { | ||
13 | private bool IsLogicOpCode(byte opcode) | ||
14 | { | ||
15 | bool result = false; | ||
16 | switch (opcode) | ||
17 | { | ||
18 | case 2: | ||
19 | Int m_int= new Int(); | ||
20 | m_int.mValue = -1; | ||
21 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
22 | result = true; | ||
23 | break; | ||
24 | case 3: | ||
25 | m_int= new Int(); | ||
26 | m_int.mValue = 0; | ||
27 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
28 | result = true; | ||
29 | break; | ||
30 | case 4: | ||
31 | m_int = new Int(); | ||
32 | m_int.mValue = 1; | ||
33 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
34 | result = true; | ||
35 | break; | ||
36 | case 5: | ||
37 | m_int = new Int(); | ||
38 | m_int.mValue = 2; | ||
39 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
40 | result = true; | ||
41 | break; | ||
42 | case 6: | ||
43 | m_int = new Int(); | ||
44 | m_int.mValue = 3; | ||
45 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
46 | break; | ||
47 | case 7: | ||
48 | m_int = new Int(); | ||
49 | m_int.mValue = 4; | ||
50 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
51 | result = true; | ||
52 | break; | ||
53 | case 8: | ||
54 | m_int = new Int(); | ||
55 | m_int.mValue = 5; | ||
56 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
57 | result = true; | ||
58 | break; | ||
59 | case 11: | ||
60 | Float m_float = new Float(); | ||
61 | m_float.mValue = 0.0f; | ||
62 | this._mThread.currentFrame.OpStack.Push(m_float); | ||
63 | result = true; | ||
64 | break; | ||
65 | case 12: | ||
66 | m_float = new Float(); | ||
67 | m_float.mValue = 1.0f; | ||
68 | this._mThread.currentFrame.OpStack.Push(m_float); | ||
69 | result = true; | ||
70 | break; | ||
71 | case 13: | ||
72 | m_float = new Float(); | ||
73 | m_float.mValue = 2.0f; | ||
74 | this._mThread.currentFrame.OpStack.Push(m_float); | ||
75 | result = true; | ||
76 | break; | ||
77 | case 16: | ||
78 | int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]; | ||
79 | Int pushInt = new Int(); | ||
80 | pushInt.mValue = pushvalue; | ||
81 | this._mThread.currentFrame.OpStack.Push(pushInt); | ||
82 | this._mThread.PC++; | ||
83 | result = true; | ||
84 | break; | ||
85 | case 17: | ||
86 | short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
87 | Int pushInt2 = new Int(); | ||
88 | pushInt2.mValue = pushvalue2; | ||
89 | this._mThread.currentFrame.OpStack.Push(pushInt2); | ||
90 | this._mThread.PC += 2; | ||
91 | result = true; | ||
92 | break; | ||
93 | case 23: | ||
94 | short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC])); | ||
95 | Float fload = new Float(); | ||
96 | if (this._mThread.currentFrame.LocalVariables[findex1] != null) | ||
97 | { | ||
98 | if (this._mThread.currentFrame.LocalVariables[findex1] is Float) | ||
99 | { | ||
100 | fload.mValue = ((Float)this._mThread.currentFrame.LocalVariables[findex1]).mValue; | ||
101 | this._mThread.currentFrame.OpStack.Push(fload); | ||
102 | } | ||
103 | } | ||
104 | this._mThread.PC++; | ||
105 | result = true; | ||
106 | break; | ||
107 | case 26: | ||
108 | if (this._mThread.currentFrame.LocalVariables[0] != null) | ||
109 | { | ||
110 | if (this._mThread.currentFrame.LocalVariables[0] is Int) | ||
111 | { | ||
112 | Int newInt = new Int(); | ||
113 | newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue; | ||
114 | this._mThread.currentFrame.OpStack.Push(newInt); | ||
115 | } | ||
116 | } | ||
117 | result = true; | ||
118 | break; | ||
119 | case 27: | ||
120 | if (this._mThread.currentFrame.LocalVariables[1] != null) | ||
121 | { | ||
122 | if (this._mThread.currentFrame.LocalVariables[1] is Int) | ||
123 | { | ||
124 | Int newInt = new Int(); | ||
125 | newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue; | ||
126 | this._mThread.currentFrame.OpStack.Push(newInt); | ||
127 | } | ||
128 | } | ||
129 | result = true; | ||
130 | break; | ||
131 | case 34: | ||
132 | if (this._mThread.currentFrame.LocalVariables[0] != null) | ||
133 | { | ||
134 | if (this._mThread.currentFrame.LocalVariables[0] is Float) | ||
135 | { | ||
136 | Float newfloat = new Float(); | ||
137 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue; | ||
138 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
139 | } | ||
140 | } | ||
141 | result = true; | ||
142 | break; | ||
143 | case 35: | ||
144 | if (this._mThread.currentFrame.LocalVariables[1] != null) | ||
145 | { | ||
146 | if (this._mThread.currentFrame.LocalVariables[1] is Float) | ||
147 | { | ||
148 | Float newfloat = new Float(); | ||
149 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue; | ||
150 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
151 | } | ||
152 | } | ||
153 | result = true; | ||
154 | break; | ||
155 | case 36: | ||
156 | if (this._mThread.currentFrame.LocalVariables[2] != null) | ||
157 | { | ||
158 | if (this._mThread.currentFrame.LocalVariables[2] is Float) | ||
159 | { | ||
160 | Float newfloat = new Float(); | ||
161 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[2]).mValue; | ||
162 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
163 | } | ||
164 | } | ||
165 | result = true; | ||
166 | break; | ||
167 | case 37: | ||
168 | if (this._mThread.currentFrame.LocalVariables[3] != null) | ||
169 | { | ||
170 | if (this._mThread.currentFrame.LocalVariables[3] is Float) | ||
171 | { | ||
172 | Float newfloat = new Float(); | ||
173 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[3]).mValue; | ||
174 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
175 | } | ||
176 | } | ||
177 | result = true; | ||
178 | break; | ||
179 | case 56: | ||
180 | short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] )); | ||
181 | BaseType fstor = this._mThread.currentFrame.OpStack.Pop(); | ||
182 | if (fstor is Float) | ||
183 | { | ||
184 | this._mThread.currentFrame.LocalVariables[findex] = (Float)fstor; | ||
185 | } | ||
186 | this._mThread.PC++; | ||
187 | result = true; | ||
188 | break; | ||
189 | case 59: | ||
190 | BaseType baset = this._mThread.currentFrame.OpStack.Pop(); | ||
191 | if (baset is Int) | ||
192 | { | ||
193 | this._mThread.currentFrame.LocalVariables[0] = (Int)baset; | ||
194 | } | ||
195 | result = true; | ||
196 | break; | ||
197 | case 60: | ||
198 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
199 | if (baset is Int) | ||
200 | { | ||
201 | this._mThread.currentFrame.LocalVariables[1] = (Int)baset; | ||
202 | } | ||
203 | result = true; | ||
204 | break; | ||
205 | case 67: | ||
206 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
207 | if (baset is Float) | ||
208 | { | ||
209 | this._mThread.currentFrame.LocalVariables[0] = (Float)baset; | ||
210 | } | ||
211 | result = true; | ||
212 | break; | ||
213 | case 68: | ||
214 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
215 | if (baset is Float) | ||
216 | { | ||
217 | this._mThread.currentFrame.LocalVariables[1] = (Float)baset; | ||
218 | } | ||
219 | result = true; | ||
220 | break; | ||
221 | case 69: | ||
222 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
223 | if (baset is Float) | ||
224 | { | ||
225 | this._mThread.currentFrame.LocalVariables[2] = (Float)baset; | ||
226 | } | ||
227 | result = true; | ||
228 | break; | ||
229 | case 70: | ||
230 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
231 | if (baset is Float) | ||
232 | { | ||
233 | this._mThread.currentFrame.LocalVariables[3] = (Float)baset; | ||
234 | } | ||
235 | result = true; | ||
236 | break; | ||
237 | case 87: | ||
238 | this._mThread.currentFrame.OpStack.Pop(); | ||
239 | result = true; | ||
240 | break; | ||
241 | case 98: | ||
242 | BaseType bf2 = this._mThread.currentFrame.OpStack.Pop(); | ||
243 | BaseType bf1 = this._mThread.currentFrame.OpStack.Pop(); | ||
244 | if (bf1 is Float && bf2 is Float) | ||
245 | { | ||
246 | Float nflt = new Float(); | ||
247 | nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue; | ||
248 | this._mThread.currentFrame.OpStack.Push(nflt); | ||
249 | } | ||
250 | result = true; | ||
251 | break; | ||
252 | case 102: | ||
253 | BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop(); | ||
254 | BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop(); | ||
255 | if (bsf1 is Float && bsf2 is Float) | ||
256 | { | ||
257 | Float resf = new Float(); | ||
258 | resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue; | ||
259 | this._mThread.currentFrame.OpStack.Push(resf); | ||
260 | } | ||
261 | result = true; | ||
262 | break; | ||
263 | case 104: //check the order of the two values off the stack is correct | ||
264 | BaseType bs2 = this._mThread.currentFrame.OpStack.Pop(); | ||
265 | BaseType bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
266 | if (bs1 is Int && bs2 is Int) | ||
267 | { | ||
268 | Int nInt = new Int(); | ||
269 | nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue; | ||
270 | this._mThread.currentFrame.OpStack.Push(nInt); | ||
271 | } | ||
272 | result = true; | ||
273 | break; | ||
274 | case 132: | ||
275 | if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null) | ||
276 | { | ||
277 | if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int) | ||
278 | { | ||
279 | ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]; | ||
280 | } | ||
281 | } | ||
282 | this._mThread.PC += 2; | ||
283 | result = true; | ||
284 | break; | ||
285 | case 139: | ||
286 | BaseType conv1 = this._mThread.currentFrame.OpStack.Pop(); | ||
287 | if (conv1 is Float) | ||
288 | { | ||
289 | Int newconv = new Int(); | ||
290 | newconv.mValue = (int)((Float)conv1).mValue; | ||
291 | this._mThread.currentFrame.OpStack.Push(newconv); | ||
292 | } | ||
293 | result = true; | ||
294 | break; | ||
295 | case 149: | ||
296 | BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop(); | ||
297 | BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop(); | ||
298 | if (flcom1 is Float && flcom2 is Float) | ||
299 | { | ||
300 | Int compres = new Int(); | ||
301 | if (((Float)flcom1).mValue < ((Float)flcom2).mValue) | ||
302 | { | ||
303 | compres.mValue = -1; | ||
304 | } | ||
305 | else if (((Float)flcom1).mValue > ((Float)flcom2).mValue) | ||
306 | { | ||
307 | compres.mValue = 1; | ||
308 | } | ||
309 | else | ||
310 | { | ||
311 | compres.mValue = 0; | ||
312 | } | ||
313 | this._mThread.currentFrame.OpStack.Push(compres); | ||
314 | } | ||
315 | result = true; | ||
316 | break; | ||
317 | case 158: | ||
318 | short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
319 | BaseType comp1 = this._mThread.currentFrame.OpStack.Pop(); | ||
320 | if (comp1 is Int) | ||
321 | { | ||
322 | if (((Int)comp1).mValue <= 0) | ||
323 | { | ||
324 | this._mThread.PC += -1 + compareoffset1; | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | this._mThread.PC += 2; | ||
329 | } | ||
330 | } | ||
331 | else | ||
332 | { | ||
333 | this._mThread.PC += 2; | ||
334 | } | ||
335 | result = true; | ||
336 | break; | ||
337 | case 162: | ||
338 | short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
339 | BaseType bc2 = this._mThread.currentFrame.OpStack.Pop(); | ||
340 | BaseType bc1 = this._mThread.currentFrame.OpStack.Pop(); | ||
341 | if (bc1 is Int && bc2 is Int) | ||
342 | { | ||
343 | //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue); | ||
344 | if (((Int)bc1).mValue >= ((Int)bc2).mValue) | ||
345 | { | ||
346 | // Console.WriteLine("branch compare true , offset is " +compareoffset); | ||
347 | // Console.WriteLine("current PC is " + this._mThread.PC); | ||
348 | this._mThread.PC += -1 + compareoffset; | ||
349 | //Console.WriteLine("new PC is " + this._mThread.PC); | ||
350 | } | ||
351 | else | ||
352 | { | ||
353 | //Console.WriteLine("branch compare false"); | ||
354 | this._mThread.PC += 2; | ||
355 | } | ||
356 | } | ||
357 | else | ||
358 | { | ||
359 | this._mThread.PC += 2; | ||
360 | } | ||
361 | result = true; | ||
362 | break; | ||
363 | case 164: | ||
364 | short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
365 | BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop(); | ||
366 | BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop(); | ||
367 | if (bcl1 is Int && bcl2 is Int) | ||
368 | { | ||
369 | //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue); | ||
370 | if (((Int)bcl1).mValue <= ((Int)bcl2).mValue) | ||
371 | { | ||
372 | // Console.WriteLine("branch compare true , offset is " + compareloffset); | ||
373 | // Console.WriteLine("current PC is " + this._mThread.PC); | ||
374 | this._mThread.PC += -1 + compareloffset; | ||
375 | // Console.WriteLine("new PC is " + this._mThread.PC); | ||
376 | } | ||
377 | else | ||
378 | { | ||
379 | //Console.WriteLine("branch compare false"); | ||
380 | this._mThread.PC += 2; | ||
381 | } | ||
382 | } | ||
383 | else | ||
384 | { | ||
385 | this._mThread.PC += 2; | ||
386 | } | ||
387 | result = true; | ||
388 | break; | ||
389 | case 167: | ||
390 | short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]); | ||
391 | this._mThread.PC += -1 + offset; | ||
392 | result = true; | ||
393 | break; | ||
394 | } | ||
395 | |||
396 | return result; | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | } | ||