diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim.Scripting.EmbeddedJVM/Interpreter.cs | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/OpenSim.Scripting.EmbeddedJVM/Interpreter.cs b/OpenSim.Scripting.EmbeddedJVM/Interpreter.cs new file mode 100644 index 0000000..aeeee0a --- /dev/null +++ b/OpenSim.Scripting.EmbeddedJVM/Interpreter.cs | |||
@@ -0,0 +1,105 @@ | |||
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 Thread _mThread; | ||
14 | |||
15 | public Interpreter(Thread parentThread) | ||
16 | { | ||
17 | _mThread = parentThread; | ||
18 | } | ||
19 | |||
20 | public bool Excute() | ||
21 | { | ||
22 | bool run = true; | ||
23 | byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC++]; | ||
24 | // Console.WriteLine("opCode is: " + currentOpCode); | ||
25 | bool handled = false; | ||
26 | |||
27 | handled = this.IsLogicOpCode(currentOpCode); | ||
28 | if (!handled) | ||
29 | { | ||
30 | handled = this.IsMethodOpCode(currentOpCode); | ||
31 | } | ||
32 | if (!handled) | ||
33 | { | ||
34 | if (currentOpCode == 172) | ||
35 | { | ||
36 | if (this._mThread.stack.StackFrames.Count > 1) | ||
37 | { | ||
38 | Console.WriteLine("returning int from function"); | ||
39 | int retPC1 = this._mThread.currentFrame.ReturnPC; | ||
40 | BaseType bas1 = this._mThread.currentFrame.OpStack.Pop(); | ||
41 | this._mThread.stack.StackFrames.Pop(); | ||
42 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
43 | this._mThread.PC = retPC1; | ||
44 | if (bas1 is Int) | ||
45 | { | ||
46 | this._mThread.currentFrame.OpStack.Push((Int)bas1); | ||
47 | } | ||
48 | } | ||
49 | else | ||
50 | { | ||
51 | // Console.WriteLine("No parent function so ending program"); | ||
52 | run = false; | ||
53 | } | ||
54 | handled = true; | ||
55 | } | ||
56 | if (currentOpCode == 174) | ||
57 | { | ||
58 | if (this._mThread.stack.StackFrames.Count > 1) | ||
59 | { | ||
60 | Console.WriteLine("returning float from function"); | ||
61 | int retPC1 = this._mThread.currentFrame.ReturnPC; | ||
62 | BaseType bas1 = this._mThread.currentFrame.OpStack.Pop(); | ||
63 | this._mThread.stack.StackFrames.Pop(); | ||
64 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
65 | this._mThread.PC = retPC1; | ||
66 | if (bas1 is Float) | ||
67 | { | ||
68 | this._mThread.currentFrame.OpStack.Push((Float)bas1); | ||
69 | } | ||
70 | } | ||
71 | else | ||
72 | { | ||
73 | // Console.WriteLine("No parent function so ending program"); | ||
74 | run = false; | ||
75 | } | ||
76 | handled = true; | ||
77 | } | ||
78 | if (currentOpCode == 177) | ||
79 | { | ||
80 | if (this._mThread.stack.StackFrames.Count > 1) | ||
81 | { | ||
82 | Console.WriteLine("returning from function"); | ||
83 | int retPC = this._mThread.currentFrame.ReturnPC; | ||
84 | this._mThread.stack.StackFrames.Pop(); | ||
85 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
86 | this._mThread.PC = retPC; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | // Console.WriteLine("No parent function so ending program"); | ||
91 | run = false; | ||
92 | } | ||
93 | handled = true; | ||
94 | } | ||
95 | } | ||
96 | if (!handled) | ||
97 | { | ||
98 | Console.WriteLine("opcode " + currentOpCode + " not been handled "); | ||
99 | } | ||
100 | return run; | ||
101 | |||
102 | } | ||
103 | } | ||
104 | } | ||
105 | } | ||