diff options
author | Adam Frisby | 2007-07-05 00:09:45 +0000 |
---|---|---|
committer | Adam Frisby | 2007-07-05 00:09:45 +0000 |
commit | 3c46e5b170991e41e8c82e25bae65cf46152b924 (patch) | |
tree | 1d8bb69cc57b9508fd8da25657f1c0bc088e5908 /OpenSim/Region/Environment/Scenes/scripting | |
parent | A bit more work on Building tools/support. (diff) | |
download | opensim-SC_OLD-3c46e5b170991e41e8c82e25bae65cf46152b924.zip opensim-SC_OLD-3c46e5b170991e41e8c82e25bae65cf46152b924.tar.gz opensim-SC_OLD-3c46e5b170991e41e8c82e25bae65cf46152b924.tar.bz2 opensim-SC_OLD-3c46e5b170991e41e8c82e25bae65cf46152b924.tar.xz |
* Added Java support back into Sugilite (although it still needs a calling host to be added).
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/scripting')
27 files changed, 1926 insertions, 5 deletions
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpScriptEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs index 7928088..9cb881a 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpScriptEngine.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs | |||
@@ -31,7 +31,7 @@ using System.Collections.Generic; | |||
31 | using Microsoft.CSharp; | 31 | using Microsoft.CSharp; |
32 | using OpenSim.Framework.Console; | 32 | using OpenSim.Framework.Console; |
33 | 33 | ||
34 | namespace OpenSim.Region.Enviorment.Scripting | 34 | namespace OpenSim.Region.Environment.Scripting |
35 | { | 35 | { |
36 | public class CSharpScriptEngine : IScriptCompiler | 36 | public class CSharpScriptEngine : IScriptCompiler |
37 | { | 37 | { |
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs index d9d6f7e..be1fe56 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs | |||
@@ -31,7 +31,7 @@ using System.Collections.Generic; | |||
31 | using Microsoft.JScript; | 31 | using Microsoft.JScript; |
32 | using OpenSim.Framework.Console; | 32 | using OpenSim.Framework.Console; |
33 | 33 | ||
34 | namespace OpenSim.Region.Enviorment.Scripting | 34 | namespace OpenSim.Region.Environment.Scripting |
35 | { | 35 | { |
36 | public class JScriptEngine : IScriptCompiler | 36 | public class JScriptEngine : IScriptCompiler |
37 | { | 37 | { |
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassInstance.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassInstance.cs new file mode 100644 index 0000000..1d93197 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassInstance.cs | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
32 | |||
33 | namespace OpenSim.Scripting.EmbeddedJVM | ||
34 | { | ||
35 | public class ClassInstance : Object | ||
36 | { | ||
37 | public int size; | ||
38 | public Dictionary<string, BaseType> Fields = new Dictionary<string, BaseType>(); | ||
39 | |||
40 | public ClassInstance() | ||
41 | { | ||
42 | |||
43 | } | ||
44 | } | ||
45 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassRecord.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassRecord.cs new file mode 100644 index 0000000..f4ab1a2 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/ClassRecord.cs | |||
@@ -0,0 +1,503 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
33 | |||
34 | namespace OpenSim.Scripting.EmbeddedJVM | ||
35 | { | ||
36 | public class ClassRecord | ||
37 | { | ||
38 | private ushort _majorVersion; | ||
39 | private ushort _minorVersion; | ||
40 | private ushort _constantPoolCount; | ||
41 | private ushort _accessFlags; | ||
42 | private ushort _thisClass; | ||
43 | private ushort _supperClass; | ||
44 | private ushort _interfaceCount; | ||
45 | private ushort _fieldCount; | ||
46 | private ushort _methodCount; | ||
47 | //private ushort _attributeCount; | ||
48 | //private string _name; | ||
49 | public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>(); | ||
50 | public PoolClass mClass; | ||
51 | |||
52 | public List<PoolItem> _constantsPool = new List<PoolItem>(); | ||
53 | private List<MethodInfo> _methodsList = new List<MethodInfo>(); | ||
54 | private List<FieldInfo> _fieldList = new List<FieldInfo>(); | ||
55 | |||
56 | public ClassRecord() | ||
57 | { | ||
58 | |||
59 | } | ||
60 | |||
61 | public ClassInstance CreateNewInstance() | ||
62 | { | ||
63 | return new ClassInstance(); | ||
64 | } | ||
65 | |||
66 | public void LoadClassFromFile(string fileName) | ||
67 | { | ||
68 | Console.WriteLine("loading script " + fileName); | ||
69 | FileStream fs = File.OpenRead(fileName); | ||
70 | this.LoadClassFromBytes(ReadFully(fs)); | ||
71 | fs.Close(); | ||
72 | } | ||
73 | |||
74 | public void LoadClassFromBytes(byte[] data) | ||
75 | { | ||
76 | int i = 0; | ||
77 | i += 4; | ||
78 | _minorVersion = (ushort)((data[i++] << 8) + data[i++] ); | ||
79 | _majorVersion = (ushort)((data[i++] << 8) + data[i++] ); | ||
80 | _constantPoolCount = (ushort)((data[i++] << 8) + data[i++] ); | ||
81 | // Console.WriteLine("there should be " + _constantPoolCount + " items in the pool"); | ||
82 | for (int count = 0; count < _constantPoolCount -1 ; count++) | ||
83 | { | ||
84 | //read in the constant pool | ||
85 | byte pooltype = data[i++]; | ||
86 | //Console.WriteLine("#" +count +": new constant type = " +pooltype); | ||
87 | //Console.WriteLine("start position is: " + i); | ||
88 | switch (pooltype) | ||
89 | { | ||
90 | case 1: //Utf8 | ||
91 | ushort uLength = (ushort)((data[i++] << 8) + data[i++] ); | ||
92 | |||
93 | // Console.WriteLine("new utf8 type, length is " + uLength); | ||
94 | PoolUtf8 utf8 = new PoolUtf8(); | ||
95 | utf8.readValue(data, ref i, uLength); | ||
96 | this._constantsPool.Add(utf8); | ||
97 | break; | ||
98 | case 3: //Int | ||
99 | break; | ||
100 | case 7: //Class | ||
101 | PoolClass pClass = new PoolClass(this); | ||
102 | pClass.readValue(data, ref i); | ||
103 | this._constantsPool.Add(pClass); | ||
104 | break; | ||
105 | case 10: //Method | ||
106 | PoolMethodRef pMeth = new PoolMethodRef(this); | ||
107 | pMeth.readValue(data, ref i); | ||
108 | this._constantsPool.Add(pMeth); | ||
109 | break; | ||
110 | case 12: //NamedType | ||
111 | PoolNamedType pNamed = new PoolNamedType(this); | ||
112 | pNamed.readValue(data, ref i); | ||
113 | this._constantsPool.Add(pNamed); | ||
114 | break; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | _accessFlags = (ushort)((data[i++] << 8) + data[i++] ); | ||
119 | _thisClass = (ushort)((data[i++] << 8) + data[i++] ); | ||
120 | _supperClass = (ushort)((data[i++] << 8) + data[i++] ); | ||
121 | |||
122 | if (this._constantsPool[this._thisClass - 1] is PoolClass) | ||
123 | { | ||
124 | this.mClass = ((PoolClass)this._constantsPool[this._thisClass - 1]); | ||
125 | } | ||
126 | |||
127 | _interfaceCount = (ushort)((data[i++] << 8) + data[i++]); | ||
128 | //should now read in the info for each interface | ||
129 | _fieldCount = (ushort)((data[i++] << 8) + data[i++]); | ||
130 | //should now read in the info for each field | ||
131 | _methodCount = (ushort)((data[i++] << 8) + data[i++]); | ||
132 | for (int count = 0; count < _methodCount; count++) | ||
133 | { | ||
134 | MethodInfo methInf = new MethodInfo(this); | ||
135 | methInf.ReadData(data, ref i); | ||
136 | this._methodsList.Add(methInf); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | public void AddMethodsToMemory(MethodMemory memory) | ||
141 | { | ||
142 | for (int count = 0; count < _methodCount; count++) | ||
143 | { | ||
144 | this._methodsList[count].AddMethodCode(memory); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | public bool StartMethod(Thread thread, string methodName) | ||
149 | { | ||
150 | for (int count = 0; count < _methodCount; count++) | ||
151 | { | ||
152 | if (this._constantsPool[this._methodsList[count].NameIndex-1] is PoolUtf8) | ||
153 | { | ||
154 | if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex-1]).Value == methodName) | ||
155 | { | ||
156 | //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value); | ||
157 | thread.SetPC(this._methodsList[count].CodePointer); | ||
158 | return true; | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | return false; | ||
163 | } | ||
164 | |||
165 | public void PrintToConsole() | ||
166 | { | ||
167 | Console.WriteLine("Class File:"); | ||
168 | Console.WriteLine("Major version: " + _majorVersion); | ||
169 | Console.WriteLine("Minor version: " + _minorVersion); | ||
170 | Console.WriteLine("Pool size: " + _constantPoolCount); | ||
171 | |||
172 | for (int i = 0; i < _constantsPool.Count; i++) | ||
173 | { | ||
174 | this._constantsPool[i].Print(); | ||
175 | } | ||
176 | |||
177 | Console.WriteLine("Access flags: " + _accessFlags); | ||
178 | Console.WriteLine("This class: " + _thisClass ); | ||
179 | Console.WriteLine("Super class: " + _supperClass); | ||
180 | |||
181 | for (int count = 0; count < _methodCount; count++) | ||
182 | { | ||
183 | Console.WriteLine(); | ||
184 | this._methodsList[count].Print(); | ||
185 | } | ||
186 | |||
187 | Console.WriteLine("class name is " + this.mClass.Name.Value); | ||
188 | } | ||
189 | |||
190 | public static byte[] ReadFully(Stream stream) | ||
191 | { | ||
192 | byte[] buffer = new byte[1024]; | ||
193 | using (MemoryStream ms = new MemoryStream()) | ||
194 | { | ||
195 | while (true) | ||
196 | { | ||
197 | int read = stream.Read(buffer, 0, buffer.Length); | ||
198 | if (read <= 0) | ||
199 | return ms.ToArray(); | ||
200 | ms.Write(buffer, 0, read); | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | |||
205 | #region nested classes | ||
206 | public class PoolItem | ||
207 | { | ||
208 | public virtual void Print() | ||
209 | { | ||
210 | |||
211 | } | ||
212 | } | ||
213 | |||
214 | public class PoolUtf8 : PoolItem | ||
215 | { | ||
216 | public string Value = ""; | ||
217 | |||
218 | public void readValue(byte[] data,ref int pointer , int length) | ||
219 | { | ||
220 | for (int i = 0; i < length; i++) | ||
221 | { | ||
222 | int a =(int) data[pointer++]; | ||
223 | if ((a & 0x80) == 0) | ||
224 | { | ||
225 | Value = Value + (char)a; | ||
226 | } | ||
227 | else if ((a & 0x20) == 0) | ||
228 | { | ||
229 | int b = (int) data[pointer++]; | ||
230 | Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f)); | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | int b = (int)data[pointer++]; | ||
235 | int c = (int)data[pointer++]; | ||
236 | Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f)); | ||
237 | } | ||
238 | } | ||
239 | } | ||
240 | |||
241 | public override void Print() | ||
242 | { | ||
243 | Console.WriteLine("Utf8 type: " + Value); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | private class PoolInt : PoolItem | ||
248 | { | ||
249 | |||
250 | } | ||
251 | |||
252 | public class PoolClass : PoolItem | ||
253 | { | ||
254 | //public string name = ""; | ||
255 | public ushort namePointer = 0; | ||
256 | private ClassRecord parent; | ||
257 | public PoolUtf8 Name; | ||
258 | |||
259 | public PoolClass(ClassRecord paren) | ||
260 | { | ||
261 | parent = paren; | ||
262 | } | ||
263 | |||
264 | public void readValue(byte[] data, ref int pointer) | ||
265 | { | ||
266 | namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); | ||
267 | } | ||
268 | |||
269 | public override void Print() | ||
270 | { | ||
271 | this.Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]); | ||
272 | Console.Write("Class type: " + namePointer); | ||
273 | Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value); | ||
274 | |||
275 | } | ||
276 | } | ||
277 | |||
278 | public class PoolMethodRef : PoolItem | ||
279 | { | ||
280 | public ushort classPointer = 0; | ||
281 | public ushort nameTypePointer = 0; | ||
282 | public PoolNamedType mNameType; | ||
283 | public PoolClass mClass; | ||
284 | private ClassRecord parent; | ||
285 | |||
286 | public PoolMethodRef(ClassRecord paren) | ||
287 | { | ||
288 | parent = paren; | ||
289 | } | ||
290 | |||
291 | public void readValue(byte[] data, ref int pointer) | ||
292 | { | ||
293 | classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
294 | nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
295 | } | ||
296 | |||
297 | public override void Print() | ||
298 | { | ||
299 | this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]); | ||
300 | this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]); | ||
301 | Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); | ||
302 | } | ||
303 | } | ||
304 | |||
305 | public class PoolNamedType : PoolItem | ||
306 | { | ||
307 | public ushort namePointer = 0; | ||
308 | public ushort typePointer = 0; | ||
309 | private ClassRecord parent; | ||
310 | public PoolUtf8 Name; | ||
311 | public PoolUtf8 Type; | ||
312 | |||
313 | public PoolNamedType(ClassRecord paren) | ||
314 | { | ||
315 | parent = paren; | ||
316 | } | ||
317 | |||
318 | public void readValue(byte[] data, ref int pointer) | ||
319 | { | ||
320 | namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); | ||
321 | typePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); | ||
322 | } | ||
323 | |||
324 | public override void Print() | ||
325 | { | ||
326 | Name = ((PoolUtf8)this.parent._constantsPool[namePointer-1]); | ||
327 | Type = ((PoolUtf8)this.parent._constantsPool[typePointer-1]); | ||
328 | Console.Write("Named type: " + namePointer + " , " + typePointer ); | ||
329 | Console.WriteLine(" // "+ ((PoolUtf8)this.parent._constantsPool[namePointer-1]).Value); | ||
330 | } | ||
331 | } | ||
332 | |||
333 | //*********************** | ||
334 | public class MethodInfo | ||
335 | { | ||
336 | public ushort AccessFlags = 0; | ||
337 | public ushort NameIndex = 0; | ||
338 | public string Name = ""; | ||
339 | public ushort DescriptorIndex = 0; | ||
340 | public ushort AttributeCount = 0; | ||
341 | public List<MethodAttribute> Attributes = new List<MethodAttribute>(); | ||
342 | private ClassRecord parent; | ||
343 | public int CodePointer = 0; | ||
344 | |||
345 | public MethodInfo(ClassRecord paren) | ||
346 | { | ||
347 | parent = paren; | ||
348 | } | ||
349 | |||
350 | public void AddMethodCode(MethodMemory memory) | ||
351 | { | ||
352 | Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length); | ||
353 | memory.Methodcount++; | ||
354 | this.CodePointer = memory.NextMethodPC; | ||
355 | memory.NextMethodPC += this.Attributes[0].Code.Length; | ||
356 | } | ||
357 | |||
358 | public void ReadData(byte[] data, ref int pointer) | ||
359 | { | ||
360 | AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
361 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
362 | DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
363 | AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
364 | for(int i =0; i< AttributeCount; i++) | ||
365 | { | ||
366 | MethodAttribute attri = new MethodAttribute(this.parent); | ||
367 | attri.ReadData(data, ref pointer); | ||
368 | this.Attributes.Add(attri); | ||
369 | } | ||
370 | } | ||
371 | |||
372 | public void Print() | ||
373 | { | ||
374 | Console.WriteLine("Method Info Struct: "); | ||
375 | Console.WriteLine("AccessFlags: " + AccessFlags); | ||
376 | Console.WriteLine("NameIndex: " + NameIndex +" // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); | ||
377 | Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[DescriptorIndex-1]).Value); | ||
378 | Console.WriteLine("Attribute Count:" + AttributeCount); | ||
379 | for (int i = 0; i < AttributeCount; i++) | ||
380 | { | ||
381 | this.Attributes[i].Print(); | ||
382 | } | ||
383 | } | ||
384 | |||
385 | public class MethodAttribute | ||
386 | { | ||
387 | public ushort NameIndex = 0; | ||
388 | public string Name = ""; | ||
389 | public Int32 Length = 0; | ||
390 | //for now only support code attribute | ||
391 | public ushort MaxStack = 0; | ||
392 | public ushort MaxLocals = 0; | ||
393 | public Int32 CodeLength = 0; | ||
394 | public byte[] Code; | ||
395 | public ushort ExceptionTableLength = 0; | ||
396 | public ushort SubAttributeCount = 0; | ||
397 | public List<SubAttribute> SubAttributes = new List<SubAttribute>(); | ||
398 | private ClassRecord parent; | ||
399 | |||
400 | public MethodAttribute(ClassRecord paren) | ||
401 | { | ||
402 | parent = paren; | ||
403 | } | ||
404 | |||
405 | public void ReadData(byte[] data, ref int pointer) | ||
406 | { | ||
407 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
408 | Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); | ||
409 | MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
410 | MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
411 | CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); | ||
412 | Code = new byte[CodeLength]; | ||
413 | for (int i = 0; i < CodeLength; i++) | ||
414 | { | ||
415 | Code[i] = data[pointer++]; | ||
416 | } | ||
417 | ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
418 | SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
419 | for (int i = 0; i < SubAttributeCount; i++) | ||
420 | { | ||
421 | SubAttribute subAttri = new SubAttribute(this.parent); | ||
422 | subAttri.ReadData(data, ref pointer); | ||
423 | this.SubAttributes.Add(subAttri); | ||
424 | } | ||
425 | } | ||
426 | |||
427 | public void Print() | ||
428 | { | ||
429 | Console.WriteLine("Method Attribute: "); | ||
430 | Console.WriteLine("Name Index: " + NameIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); | ||
431 | Console.WriteLine("Length: " + Length); | ||
432 | Console.WriteLine("MaxStack: " + MaxStack); | ||
433 | Console.WriteLine("MaxLocals: " + MaxLocals); | ||
434 | Console.WriteLine("CodeLength: " + CodeLength); | ||
435 | for (int i = 0; i < Code.Length; i++) | ||
436 | { | ||
437 | Console.WriteLine("OpCode #" + i + " is: " + Code[i]); | ||
438 | } | ||
439 | Console.WriteLine("SubAttributes: " + SubAttributeCount); | ||
440 | for (int i = 0; i < SubAttributeCount; i++) | ||
441 | { | ||
442 | this.SubAttributes[i].Print(); | ||
443 | } | ||
444 | } | ||
445 | |||
446 | public class SubAttribute | ||
447 | { | ||
448 | public ushort NameIndex = 0; | ||
449 | public string Name = ""; | ||
450 | public Int32 Length = 0; | ||
451 | public byte[] Data; | ||
452 | private ClassRecord parent; | ||
453 | |||
454 | public SubAttribute(ClassRecord paren) | ||
455 | { | ||
456 | parent = paren; | ||
457 | } | ||
458 | |||
459 | public void ReadData(byte[] data, ref int pointer) | ||
460 | { | ||
461 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
462 | Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); | ||
463 | Data = new byte[Length]; | ||
464 | for (int i = 0; i < Length; i++) | ||
465 | { | ||
466 | Data[i] = data[pointer++]; | ||
467 | } | ||
468 | } | ||
469 | |||
470 | public void Print() | ||
471 | { | ||
472 | Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); | ||
473 | } | ||
474 | |||
475 | } | ||
476 | } | ||
477 | |||
478 | } | ||
479 | private class InterfaceInfo | ||
480 | { | ||
481 | public void ReadData(byte[] data, ref int i) | ||
482 | { | ||
483 | |||
484 | } | ||
485 | } | ||
486 | private class FieldInfo | ||
487 | { | ||
488 | public void ReadData(byte[] data, ref int i) | ||
489 | { | ||
490 | |||
491 | } | ||
492 | } | ||
493 | private class AttributeInfo | ||
494 | { | ||
495 | public void ReadData(byte[] data, ref int i) | ||
496 | { | ||
497 | |||
498 | } | ||
499 | } | ||
500 | #endregion | ||
501 | |||
502 | } | ||
503 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Heap.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Heap.cs new file mode 100644 index 0000000..f213c36 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Heap.cs | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | |||
32 | namespace OpenSim.Scripting.EmbeddedJVM | ||
33 | { | ||
34 | public class Heap | ||
35 | { | ||
36 | public List<ClassInstance> ClassObjects = new List<ClassInstance>(); | ||
37 | |||
38 | public Heap() | ||
39 | { | ||
40 | |||
41 | } | ||
42 | } | ||
43 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Interpreter.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Interpreter.cs new file mode 100644 index 0000000..c5995b2 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Interpreter.cs | |||
@@ -0,0 +1,135 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
32 | using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes; | ||
33 | |||
34 | namespace OpenSim.Scripting.EmbeddedJVM | ||
35 | { | ||
36 | partial class Thread | ||
37 | { | ||
38 | private partial class Interpreter | ||
39 | { | ||
40 | private Thread _mThread; | ||
41 | |||
42 | public Interpreter(Thread parentThread) | ||
43 | { | ||
44 | _mThread = parentThread; | ||
45 | } | ||
46 | |||
47 | public bool Excute() | ||
48 | { | ||
49 | bool run = true; | ||
50 | byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC++]; | ||
51 | // Console.WriteLine("opCode is: " + currentOpCode); | ||
52 | bool handled = false; | ||
53 | |||
54 | handled = this.IsLogicOpCode(currentOpCode); | ||
55 | if (!handled) | ||
56 | { | ||
57 | handled = this.IsMethodOpCode(currentOpCode); | ||
58 | } | ||
59 | if (!handled) | ||
60 | { | ||
61 | if (currentOpCode == 172) | ||
62 | { | ||
63 | if (this._mThread.stack.StackFrames.Count > 1) | ||
64 | { | ||
65 | Console.WriteLine("returning int from function"); | ||
66 | int retPC1 = this._mThread.currentFrame.ReturnPC; | ||
67 | BaseType bas1 = this._mThread.currentFrame.OpStack.Pop(); | ||
68 | this._mThread.stack.StackFrames.Pop(); | ||
69 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
70 | this._mThread.PC = retPC1; | ||
71 | if (bas1 is Int) | ||
72 | { | ||
73 | this._mThread.currentFrame.OpStack.Push((Int)bas1); | ||
74 | } | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | // Console.WriteLine("No parent function so ending program"); | ||
79 | this._mThread.stack.StackFrames.Pop(); | ||
80 | run = false; | ||
81 | } | ||
82 | handled = true; | ||
83 | } | ||
84 | if (currentOpCode == 174) | ||
85 | { | ||
86 | if (this._mThread.stack.StackFrames.Count > 1) | ||
87 | { | ||
88 | Console.WriteLine("returning float from function"); | ||
89 | int retPC1 = this._mThread.currentFrame.ReturnPC; | ||
90 | BaseType bas1 = this._mThread.currentFrame.OpStack.Pop(); | ||
91 | this._mThread.stack.StackFrames.Pop(); | ||
92 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
93 | this._mThread.PC = retPC1; | ||
94 | if (bas1 is Float) | ||
95 | { | ||
96 | this._mThread.currentFrame.OpStack.Push((Float)bas1); | ||
97 | } | ||
98 | } | ||
99 | else | ||
100 | { | ||
101 | // Console.WriteLine("No parent function so ending program"); | ||
102 | this._mThread.stack.StackFrames.Pop(); | ||
103 | run = false; | ||
104 | } | ||
105 | handled = true; | ||
106 | } | ||
107 | if (currentOpCode == 177) | ||
108 | { | ||
109 | if (this._mThread.stack.StackFrames.Count > 1) | ||
110 | { | ||
111 | Console.WriteLine("returning from function"); | ||
112 | int retPC = this._mThread.currentFrame.ReturnPC; | ||
113 | this._mThread.stack.StackFrames.Pop(); | ||
114 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
115 | this._mThread.PC = retPC; | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | // Console.WriteLine("No parent function so ending program"); | ||
120 | this._mThread.stack.StackFrames.Pop(); | ||
121 | run = false; | ||
122 | } | ||
123 | handled = true; | ||
124 | } | ||
125 | } | ||
126 | if (!handled) | ||
127 | { | ||
128 | Console.WriteLine("opcode " + currentOpCode + " not been handled "); | ||
129 | } | ||
130 | return run; | ||
131 | |||
132 | } | ||
133 | } | ||
134 | } | ||
135 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterLogic.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterLogic.cs new file mode 100644 index 0000000..2a11afd --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterLogic.cs | |||
@@ -0,0 +1,427 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
32 | using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes; | ||
33 | |||
34 | namespace OpenSim.Scripting.EmbeddedJVM | ||
35 | { | ||
36 | partial class Thread | ||
37 | { | ||
38 | private partial class Interpreter | ||
39 | { | ||
40 | private bool IsLogicOpCode(byte opcode) | ||
41 | { | ||
42 | bool result = false; | ||
43 | switch (opcode) | ||
44 | { | ||
45 | case 2: | ||
46 | Int m_int= new Int(); | ||
47 | m_int.mValue = -1; | ||
48 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
49 | result = true; | ||
50 | break; | ||
51 | case 3: | ||
52 | m_int= new Int(); | ||
53 | m_int.mValue = 0; | ||
54 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
55 | result = true; | ||
56 | break; | ||
57 | case 4: | ||
58 | m_int = new Int(); | ||
59 | m_int.mValue = 1; | ||
60 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
61 | result = true; | ||
62 | break; | ||
63 | case 5: | ||
64 | m_int = new Int(); | ||
65 | m_int.mValue = 2; | ||
66 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
67 | result = true; | ||
68 | break; | ||
69 | case 6: | ||
70 | m_int = new Int(); | ||
71 | m_int.mValue = 3; | ||
72 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
73 | break; | ||
74 | case 7: | ||
75 | m_int = new Int(); | ||
76 | m_int.mValue = 4; | ||
77 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
78 | result = true; | ||
79 | break; | ||
80 | case 8: | ||
81 | m_int = new Int(); | ||
82 | m_int.mValue = 5; | ||
83 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
84 | result = true; | ||
85 | break; | ||
86 | case 11: | ||
87 | Float m_float = new Float(); | ||
88 | m_float.mValue = 0.0f; | ||
89 | this._mThread.currentFrame.OpStack.Push(m_float); | ||
90 | result = true; | ||
91 | break; | ||
92 | case 12: | ||
93 | m_float = new Float(); | ||
94 | m_float.mValue = 1.0f; | ||
95 | this._mThread.currentFrame.OpStack.Push(m_float); | ||
96 | result = true; | ||
97 | break; | ||
98 | case 13: | ||
99 | m_float = new Float(); | ||
100 | m_float.mValue = 2.0f; | ||
101 | this._mThread.currentFrame.OpStack.Push(m_float); | ||
102 | result = true; | ||
103 | break; | ||
104 | case 16: | ||
105 | int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]; | ||
106 | Int pushInt = new Int(); | ||
107 | pushInt.mValue = pushvalue; | ||
108 | this._mThread.currentFrame.OpStack.Push(pushInt); | ||
109 | this._mThread.PC++; | ||
110 | result = true; | ||
111 | break; | ||
112 | case 17: | ||
113 | short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
114 | Int pushInt2 = new Int(); | ||
115 | pushInt2.mValue = pushvalue2; | ||
116 | this._mThread.currentFrame.OpStack.Push(pushInt2); | ||
117 | this._mThread.PC += 2; | ||
118 | result = true; | ||
119 | break; | ||
120 | case 23: | ||
121 | short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC])); | ||
122 | Float fload = new Float(); | ||
123 | if (this._mThread.currentFrame.LocalVariables[findex1] != null) | ||
124 | { | ||
125 | if (this._mThread.currentFrame.LocalVariables[findex1] is Float) | ||
126 | { | ||
127 | fload.mValue = ((Float)this._mThread.currentFrame.LocalVariables[findex1]).mValue; | ||
128 | this._mThread.currentFrame.OpStack.Push(fload); | ||
129 | } | ||
130 | } | ||
131 | this._mThread.PC++; | ||
132 | result = true; | ||
133 | break; | ||
134 | case 26: | ||
135 | if (this._mThread.currentFrame.LocalVariables[0] != null) | ||
136 | { | ||
137 | if (this._mThread.currentFrame.LocalVariables[0] is Int) | ||
138 | { | ||
139 | Int newInt = new Int(); | ||
140 | newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue; | ||
141 | this._mThread.currentFrame.OpStack.Push(newInt); | ||
142 | } | ||
143 | } | ||
144 | result = true; | ||
145 | break; | ||
146 | case 27: | ||
147 | if (this._mThread.currentFrame.LocalVariables[1] != null) | ||
148 | { | ||
149 | if (this._mThread.currentFrame.LocalVariables[1] is Int) | ||
150 | { | ||
151 | Int newInt = new Int(); | ||
152 | newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue; | ||
153 | this._mThread.currentFrame.OpStack.Push(newInt); | ||
154 | } | ||
155 | } | ||
156 | result = true; | ||
157 | break; | ||
158 | case 34: | ||
159 | if (this._mThread.currentFrame.LocalVariables[0] != null) | ||
160 | { | ||
161 | if (this._mThread.currentFrame.LocalVariables[0] is Float) | ||
162 | { | ||
163 | Float newfloat = new Float(); | ||
164 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue; | ||
165 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
166 | } | ||
167 | } | ||
168 | result = true; | ||
169 | break; | ||
170 | case 35: | ||
171 | if (this._mThread.currentFrame.LocalVariables[1] != null) | ||
172 | { | ||
173 | if (this._mThread.currentFrame.LocalVariables[1] is Float) | ||
174 | { | ||
175 | Float newfloat = new Float(); | ||
176 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue; | ||
177 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
178 | } | ||
179 | } | ||
180 | result = true; | ||
181 | break; | ||
182 | case 36: | ||
183 | if (this._mThread.currentFrame.LocalVariables[2] != null) | ||
184 | { | ||
185 | if (this._mThread.currentFrame.LocalVariables[2] is Float) | ||
186 | { | ||
187 | Float newfloat = new Float(); | ||
188 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[2]).mValue; | ||
189 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
190 | } | ||
191 | } | ||
192 | result = true; | ||
193 | break; | ||
194 | case 37: | ||
195 | if (this._mThread.currentFrame.LocalVariables[3] != null) | ||
196 | { | ||
197 | if (this._mThread.currentFrame.LocalVariables[3] is Float) | ||
198 | { | ||
199 | Float newfloat = new Float(); | ||
200 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[3]).mValue; | ||
201 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
202 | } | ||
203 | } | ||
204 | result = true; | ||
205 | break; | ||
206 | case 56: | ||
207 | short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] )); | ||
208 | BaseType fstor = this._mThread.currentFrame.OpStack.Pop(); | ||
209 | if (fstor is Float) | ||
210 | { | ||
211 | this._mThread.currentFrame.LocalVariables[findex] = (Float)fstor; | ||
212 | } | ||
213 | this._mThread.PC++; | ||
214 | result = true; | ||
215 | break; | ||
216 | case 59: | ||
217 | BaseType baset = this._mThread.currentFrame.OpStack.Pop(); | ||
218 | if (baset is Int) | ||
219 | { | ||
220 | this._mThread.currentFrame.LocalVariables[0] = (Int)baset; | ||
221 | } | ||
222 | result = true; | ||
223 | break; | ||
224 | case 60: | ||
225 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
226 | if (baset is Int) | ||
227 | { | ||
228 | this._mThread.currentFrame.LocalVariables[1] = (Int)baset; | ||
229 | } | ||
230 | result = true; | ||
231 | break; | ||
232 | case 67: | ||
233 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
234 | if (baset is Float) | ||
235 | { | ||
236 | this._mThread.currentFrame.LocalVariables[0] = (Float)baset; | ||
237 | } | ||
238 | result = true; | ||
239 | break; | ||
240 | case 68: | ||
241 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
242 | if (baset is Float) | ||
243 | { | ||
244 | this._mThread.currentFrame.LocalVariables[1] = (Float)baset; | ||
245 | } | ||
246 | result = true; | ||
247 | break; | ||
248 | case 69: | ||
249 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
250 | if (baset is Float) | ||
251 | { | ||
252 | this._mThread.currentFrame.LocalVariables[2] = (Float)baset; | ||
253 | } | ||
254 | result = true; | ||
255 | break; | ||
256 | case 70: | ||
257 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
258 | if (baset is Float) | ||
259 | { | ||
260 | this._mThread.currentFrame.LocalVariables[3] = (Float)baset; | ||
261 | } | ||
262 | result = true; | ||
263 | break; | ||
264 | case 87: | ||
265 | this._mThread.currentFrame.OpStack.Pop(); | ||
266 | result = true; | ||
267 | break; | ||
268 | case 98: | ||
269 | BaseType bf2 = this._mThread.currentFrame.OpStack.Pop(); | ||
270 | BaseType bf1 = this._mThread.currentFrame.OpStack.Pop(); | ||
271 | if (bf1 is Float && bf2 is Float) | ||
272 | { | ||
273 | Float nflt = new Float(); | ||
274 | nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue; | ||
275 | this._mThread.currentFrame.OpStack.Push(nflt); | ||
276 | } | ||
277 | result = true; | ||
278 | break; | ||
279 | case 102: | ||
280 | BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop(); | ||
281 | BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop(); | ||
282 | if (bsf1 is Float && bsf2 is Float) | ||
283 | { | ||
284 | Float resf = new Float(); | ||
285 | resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue; | ||
286 | this._mThread.currentFrame.OpStack.Push(resf); | ||
287 | } | ||
288 | result = true; | ||
289 | break; | ||
290 | case 104: //check the order of the two values off the stack is correct | ||
291 | BaseType bs2 = this._mThread.currentFrame.OpStack.Pop(); | ||
292 | BaseType bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
293 | if (bs1 is Int && bs2 is Int) | ||
294 | { | ||
295 | Int nInt = new Int(); | ||
296 | nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue; | ||
297 | this._mThread.currentFrame.OpStack.Push(nInt); | ||
298 | } | ||
299 | result = true; | ||
300 | break; | ||
301 | case 132: | ||
302 | if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null) | ||
303 | { | ||
304 | if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int) | ||
305 | { | ||
306 | ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]; | ||
307 | } | ||
308 | } | ||
309 | this._mThread.PC += 2; | ||
310 | result = true; | ||
311 | break; | ||
312 | case 139: | ||
313 | BaseType conv1 = this._mThread.currentFrame.OpStack.Pop(); | ||
314 | if (conv1 is Float) | ||
315 | { | ||
316 | Int newconv = new Int(); | ||
317 | newconv.mValue = (int)((Float)conv1).mValue; | ||
318 | this._mThread.currentFrame.OpStack.Push(newconv); | ||
319 | } | ||
320 | result = true; | ||
321 | break; | ||
322 | case 149: | ||
323 | BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop(); | ||
324 | BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop(); | ||
325 | if (flcom1 is Float && flcom2 is Float) | ||
326 | { | ||
327 | Int compres = new Int(); | ||
328 | if (((Float)flcom1).mValue < ((Float)flcom2).mValue) | ||
329 | { | ||
330 | compres.mValue = -1; | ||
331 | } | ||
332 | else if (((Float)flcom1).mValue > ((Float)flcom2).mValue) | ||
333 | { | ||
334 | compres.mValue = 1; | ||
335 | } | ||
336 | else | ||
337 | { | ||
338 | compres.mValue = 0; | ||
339 | } | ||
340 | this._mThread.currentFrame.OpStack.Push(compres); | ||
341 | } | ||
342 | result = true; | ||
343 | break; | ||
344 | case 158: | ||
345 | short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
346 | BaseType comp1 = this._mThread.currentFrame.OpStack.Pop(); | ||
347 | if (comp1 is Int) | ||
348 | { | ||
349 | if (((Int)comp1).mValue <= 0) | ||
350 | { | ||
351 | this._mThread.PC += -1 + compareoffset1; | ||
352 | } | ||
353 | else | ||
354 | { | ||
355 | this._mThread.PC += 2; | ||
356 | } | ||
357 | } | ||
358 | else | ||
359 | { | ||
360 | this._mThread.PC += 2; | ||
361 | } | ||
362 | result = true; | ||
363 | break; | ||
364 | case 162: | ||
365 | short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
366 | BaseType bc2 = this._mThread.currentFrame.OpStack.Pop(); | ||
367 | BaseType bc1 = this._mThread.currentFrame.OpStack.Pop(); | ||
368 | if (bc1 is Int && bc2 is Int) | ||
369 | { | ||
370 | //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue); | ||
371 | if (((Int)bc1).mValue >= ((Int)bc2).mValue) | ||
372 | { | ||
373 | // Console.WriteLine("branch compare true , offset is " +compareoffset); | ||
374 | // Console.WriteLine("current PC is " + this._mThread.PC); | ||
375 | this._mThread.PC += -1 + compareoffset; | ||
376 | //Console.WriteLine("new PC is " + this._mThread.PC); | ||
377 | } | ||
378 | else | ||
379 | { | ||
380 | //Console.WriteLine("branch compare false"); | ||
381 | this._mThread.PC += 2; | ||
382 | } | ||
383 | } | ||
384 | else | ||
385 | { | ||
386 | this._mThread.PC += 2; | ||
387 | } | ||
388 | result = true; | ||
389 | break; | ||
390 | case 164: | ||
391 | short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
392 | BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop(); | ||
393 | BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop(); | ||
394 | if (bcl1 is Int && bcl2 is Int) | ||
395 | { | ||
396 | //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue); | ||
397 | if (((Int)bcl1).mValue <= ((Int)bcl2).mValue) | ||
398 | { | ||
399 | // Console.WriteLine("branch compare true , offset is " + compareloffset); | ||
400 | // Console.WriteLine("current PC is " + this._mThread.PC); | ||
401 | this._mThread.PC += -1 + compareloffset; | ||
402 | // Console.WriteLine("new PC is " + this._mThread.PC); | ||
403 | } | ||
404 | else | ||
405 | { | ||
406 | //Console.WriteLine("branch compare false"); | ||
407 | this._mThread.PC += 2; | ||
408 | } | ||
409 | } | ||
410 | else | ||
411 | { | ||
412 | this._mThread.PC += 2; | ||
413 | } | ||
414 | result = true; | ||
415 | break; | ||
416 | case 167: | ||
417 | short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]); | ||
418 | this._mThread.PC += -1 + offset; | ||
419 | result = true; | ||
420 | break; | ||
421 | } | ||
422 | |||
423 | return result; | ||
424 | } | ||
425 | } | ||
426 | } | ||
427 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterMethods.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterMethods.cs new file mode 100644 index 0000000..4d60559 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterMethods.cs | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
32 | using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes; | ||
33 | using OpenSim.Framework.Interfaces; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Types; | ||
36 | |||
37 | namespace OpenSim.Scripting.EmbeddedJVM | ||
38 | { | ||
39 | partial class Thread | ||
40 | { | ||
41 | private partial class Interpreter | ||
42 | { | ||
43 | private bool IsMethodOpCode(byte opcode) | ||
44 | { | ||
45 | bool result = false; | ||
46 | switch (opcode) | ||
47 | { | ||
48 | case 184: | ||
49 | short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]); | ||
50 | if (this._mThread.currentClass._constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef) | ||
51 | { | ||
52 | string typ = ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value; | ||
53 | string typeparam = ""; | ||
54 | string typereturn = ""; | ||
55 | int firstbrak = 0; | ||
56 | int secondbrak = 0; | ||
57 | firstbrak = typ.LastIndexOf('('); | ||
58 | secondbrak = typ.LastIndexOf(')'); | ||
59 | typeparam = typ.Substring(firstbrak + 1, secondbrak - firstbrak - 1); | ||
60 | typereturn = typ.Substring(secondbrak + 1, typ.Length - secondbrak - 1); | ||
61 | if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value) | ||
62 | { | ||
63 | //calling a method in this class | ||
64 | if (typeparam.Length == 0) | ||
65 | { | ||
66 | this._mThread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, (this._mThread.PC + 2)); | ||
67 | } | ||
68 | else | ||
69 | { | ||
70 | this._mThread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this._mThread.PC + 2)); | ||
71 | } | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | //calling a method of a different class | ||
76 | |||
77 | // OpenSimAPI Class | ||
78 | if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI") | ||
79 | { | ||
80 | this._mThread.scriptInfo.api.CallMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, null); | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | this._mThread.PC += 2; | ||
87 | } | ||
88 | result = true; | ||
89 | break; | ||
90 | } | ||
91 | |||
92 | return result; | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterReturn.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterReturn.cs new file mode 100644 index 0000000..cbedb71 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/InterpreterReturn.cs | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | |||
32 | namespace OpenSim.Scripting.EmbeddedJVM | ||
33 | { | ||
34 | partial class Thread | ||
35 | { | ||
36 | private partial class Interpreter | ||
37 | { | ||
38 | } | ||
39 | } | ||
40 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MainMemory.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MainMemory.cs new file mode 100644 index 0000000..97d9fb6 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MainMemory.cs | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | |||
32 | namespace OpenSim.Scripting.EmbeddedJVM | ||
33 | { | ||
34 | public class MainMemory | ||
35 | { | ||
36 | public Heap HeapArea; | ||
37 | public MethodMemory MethodArea; | ||
38 | |||
39 | public MainMemory() | ||
40 | { | ||
41 | MethodArea = new MethodMemory(); | ||
42 | HeapArea = new Heap(); | ||
43 | } | ||
44 | } | ||
45 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MethodMemory.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MethodMemory.cs new file mode 100644 index 0000000..7e938b4 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/MethodMemory.cs | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | |||
32 | namespace OpenSim.Scripting.EmbeddedJVM | ||
33 | { | ||
34 | public class MethodMemory | ||
35 | { | ||
36 | public byte[] MethodBuffer; | ||
37 | public List<ClassRecord> Classes = new List<ClassRecord>(); | ||
38 | public int NextMethodPC = 0; | ||
39 | public int Methodcount = 0; | ||
40 | |||
41 | public MethodMemory() | ||
42 | { | ||
43 | MethodBuffer = new byte[20000]; | ||
44 | } | ||
45 | } | ||
46 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Object.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Object.cs new file mode 100644 index 0000000..2c3bedd --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Object.cs | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | |||
32 | namespace OpenSim.Scripting.EmbeddedJVM | ||
33 | { | ||
34 | public class Object | ||
35 | { | ||
36 | } | ||
37 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs new file mode 100644 index 0000000..7ed734b --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs | |||
@@ -0,0 +1,176 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using System.IO; | ||
32 | using System.Threading; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Framework.Utilities; | ||
36 | using OpenSim.Region.Environment.Scripting; | ||
37 | using OpenSim.Region.Environment.Scenes; | ||
38 | |||
39 | namespace OpenSim.Scripting.EmbeddedJVM | ||
40 | { | ||
41 | public class OpenSimJVM : IScript | ||
42 | { | ||
43 | private List<Thread> _threads = new List<Thread>(); | ||
44 | private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>(); | ||
45 | private MainMemory _mainMemory; | ||
46 | private System.Threading.Thread compileThread; | ||
47 | |||
48 | ScriptInfo scriptInfo; | ||
49 | |||
50 | public OpenSimJVM() | ||
51 | { | ||
52 | |||
53 | } | ||
54 | |||
55 | public void Initialise(ScriptInfo info) | ||
56 | { | ||
57 | scriptInfo = info; | ||
58 | } | ||
59 | |||
60 | public string getName() | ||
61 | { | ||
62 | return "JVM Scripting Engine"; | ||
63 | } | ||
64 | |||
65 | public bool Init(Scene world) | ||
66 | { | ||
67 | Console.WriteLine("Creating OpenSim JVM scripting engine"); | ||
68 | _mainMemory = new MainMemory(); | ||
69 | Thread.GlobalMemory = this._mainMemory; | ||
70 | Thread.World = world; | ||
71 | compileThread = new System.Threading.Thread(new ThreadStart(CompileScript)); | ||
72 | compileThread.IsBackground = true; | ||
73 | compileThread.Start(); | ||
74 | return true; | ||
75 | } | ||
76 | |||
77 | public string GetName() | ||
78 | { | ||
79 | return "OpenSimJVM"; | ||
80 | } | ||
81 | |||
82 | public void LoadScript(string script, string scriptName, uint entityID) | ||
83 | { | ||
84 | Console.WriteLine("OpenSimJVM - loading new script: " + scriptName); | ||
85 | CompileInfo comp = new CompileInfo(); | ||
86 | comp.entityId = entityID; | ||
87 | comp.script = script; | ||
88 | comp.scriptName = scriptName; | ||
89 | this.CompileScripts.Enqueue(comp); | ||
90 | } | ||
91 | |||
92 | public void CompileScript() | ||
93 | { | ||
94 | while (true) | ||
95 | { | ||
96 | CompileInfo comp = this.CompileScripts.Dequeue(); | ||
97 | string script = comp.script; | ||
98 | string scriptName = comp.scriptName; | ||
99 | uint entityID = comp.entityId; | ||
100 | try | ||
101 | { | ||
102 | //need to compile the script into a java class file | ||
103 | |||
104 | //first save it to a java source file | ||
105 | TextWriter tw = new StreamWriter(scriptName + ".java"); | ||
106 | tw.WriteLine(script); | ||
107 | tw.Close(); | ||
108 | |||
109 | //now compile | ||
110 | System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java"); | ||
111 | // psi.RedirectStandardOutput = true; | ||
112 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; | ||
113 | psi.UseShellExecute = false; | ||
114 | |||
115 | System.Diagnostics.Process javacomp; | ||
116 | javacomp = System.Diagnostics.Process.Start(psi); | ||
117 | javacomp.WaitForExit(); | ||
118 | |||
119 | |||
120 | //now load in class file | ||
121 | ClassRecord class1 = new ClassRecord(); | ||
122 | class1.LoadClassFromFile(scriptName + ".class"); | ||
123 | class1.PrintToConsole(); | ||
124 | //Console.WriteLine(); | ||
125 | this._mainMemory.MethodArea.Classes.Add(class1); | ||
126 | class1.AddMethodsToMemory(this._mainMemory.MethodArea); | ||
127 | |||
128 | Thread newThread = new Thread(); | ||
129 | this._threads.Add(newThread); | ||
130 | newThread.EntityId = entityID; | ||
131 | newThread.currentClass = class1; | ||
132 | newThread.scriptInfo = scriptInfo; | ||
133 | |||
134 | //now delete the created files | ||
135 | System.IO.File.Delete(scriptName + ".java"); | ||
136 | System.IO.File.Delete(scriptName + ".class"); | ||
137 | //this.OnFrame(); | ||
138 | } | ||
139 | catch (Exception e) | ||
140 | { | ||
141 | Console.WriteLine("exception"); | ||
142 | Console.WriteLine(e.StackTrace); | ||
143 | Console.WriteLine(e.Message); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | |||
148 | public void OnFrame() | ||
149 | { | ||
150 | for (int i = 0; i < this._threads.Count; i++) | ||
151 | { | ||
152 | if (!this._threads[i].running) | ||
153 | { | ||
154 | this._threads[i].StartMethod("OnFrame"); | ||
155 | bool run = true; | ||
156 | while (run) | ||
157 | { | ||
158 | run = this._threads[i].Excute(); | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | } | ||
163 | |||
164 | private class CompileInfo | ||
165 | { | ||
166 | public string script; | ||
167 | public string scriptName; | ||
168 | public uint entityId; | ||
169 | |||
170 | public CompileInfo() | ||
171 | { | ||
172 | |||
173 | } | ||
174 | } | ||
175 | } | ||
176 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Stack.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Stack.cs new file mode 100644 index 0000000..69a274c --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Stack.cs | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | |||
32 | namespace OpenSim.Scripting.EmbeddedJVM | ||
33 | { | ||
34 | public class Stack | ||
35 | { | ||
36 | public Stack<StackFrame> StackFrames = new Stack<StackFrame>(); | ||
37 | |||
38 | public Stack() | ||
39 | { | ||
40 | } | ||
41 | } | ||
42 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/StackFrame.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/StackFrame.cs new file mode 100644 index 0000000..3a2b58a --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/StackFrame.cs | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
32 | |||
33 | namespace OpenSim.Scripting.EmbeddedJVM | ||
34 | { | ||
35 | public class StackFrame | ||
36 | { | ||
37 | public BaseType[] LocalVariables; | ||
38 | public Stack<BaseType> OpStack = new Stack<BaseType>(); | ||
39 | |||
40 | public int ReturnPC = 0; | ||
41 | public ClassRecord CallingClass = null; | ||
42 | |||
43 | public StackFrame() | ||
44 | { | ||
45 | LocalVariables = new BaseType[20]; | ||
46 | } | ||
47 | |||
48 | } | ||
49 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Thread.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Thread.cs new file mode 100644 index 0000000..806f833 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Thread.cs | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
32 | using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Region.Environment.Scenes; | ||
36 | using OpenSim.Region.Environment.Scripting; | ||
37 | |||
38 | namespace OpenSim.Scripting.EmbeddedJVM | ||
39 | { | ||
40 | public partial class Thread | ||
41 | { | ||
42 | // Is this smart? | ||
43 | public static MainMemory GlobalMemory; | ||
44 | public static Scene World; | ||
45 | private int PC = 0; | ||
46 | private Stack stack; | ||
47 | private Interpreter mInterpreter; | ||
48 | public ClassRecord currentClass; | ||
49 | public ClassInstance currentInstance; | ||
50 | private StackFrame currentFrame; | ||
51 | public int excutionCounter = 0; | ||
52 | public bool running = false; | ||
53 | public uint EntityId = 0; | ||
54 | |||
55 | public ScriptInfo scriptInfo; | ||
56 | |||
57 | public Thread() | ||
58 | { | ||
59 | this.mInterpreter = new Interpreter(this); | ||
60 | this.stack = new Stack(); | ||
61 | } | ||
62 | |||
63 | public void SetPC(int methodpointer) | ||
64 | { | ||
65 | //Console.WriteLine("Thread PC has been set to " + methodpointer); | ||
66 | PC = methodpointer; | ||
67 | } | ||
68 | |||
69 | public void StartMethod(ClassRecord rec, string methName) | ||
70 | { | ||
71 | currentFrame = new StackFrame(); | ||
72 | this.stack.StackFrames.Push(currentFrame); | ||
73 | this.currentClass = rec; | ||
74 | currentClass.StartMethod(this, methName); | ||
75 | } | ||
76 | |||
77 | public void StartMethod( string methName) | ||
78 | { | ||
79 | currentFrame = new StackFrame(); | ||
80 | this.stack.StackFrames.Push(currentFrame); | ||
81 | currentClass.StartMethod(this, methName); | ||
82 | } | ||
83 | |||
84 | public void JumpToStaticVoidMethod(string methName, int returnPC) | ||
85 | { | ||
86 | currentFrame = new StackFrame(); | ||
87 | currentFrame.ReturnPC = returnPC; | ||
88 | this.stack.StackFrames.Push(currentFrame); | ||
89 | currentClass.StartMethod(this, methName); | ||
90 | } | ||
91 | |||
92 | public void JumpToStaticParamMethod(string methName, string param, int returnPC) | ||
93 | { | ||
94 | if (param == "I") | ||
95 | { | ||
96 | BaseType bs1 = currentFrame.OpStack.Pop(); | ||
97 | currentFrame = new StackFrame(); | ||
98 | currentFrame.ReturnPC = returnPC; | ||
99 | this.stack.StackFrames.Push(currentFrame); | ||
100 | currentFrame.LocalVariables[0] = ((Int)bs1); | ||
101 | currentClass.StartMethod(this, methName); | ||
102 | } | ||
103 | if (param == "F") | ||
104 | { | ||
105 | |||
106 | } | ||
107 | } | ||
108 | |||
109 | public void JumpToClassStaticVoidMethod(string className, string methName, int returnPC) | ||
110 | { | ||
111 | |||
112 | } | ||
113 | |||
114 | public bool Excute() | ||
115 | { | ||
116 | excutionCounter++; | ||
117 | return this.mInterpreter.Excute(); | ||
118 | } | ||
119 | } | ||
120 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs new file mode 100644 index 0000000..2854eab --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs | |||
@@ -0,0 +1,10 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM.Types | ||
6 | { | ||
7 | public class ArrayReference :BaseType | ||
8 | { | ||
9 | } | ||
10 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs new file mode 100644 index 0000000..270aa7b --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs | |||
@@ -0,0 +1,10 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM.Types | ||
6 | { | ||
7 | public class BaseType : Object | ||
8 | { | ||
9 | } | ||
10 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs new file mode 100644 index 0000000..da28eaa --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs | |||
@@ -0,0 +1,16 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM.Types | ||
6 | { | ||
7 | public class ObjectReference : BaseType | ||
8 | { | ||
9 | public ushort Reference; | ||
10 | |||
11 | public ObjectReference() | ||
12 | { | ||
13 | |||
14 | } | ||
15 | } | ||
16 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs new file mode 100644 index 0000000..1a3ecff --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs | |||
@@ -0,0 +1,10 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes | ||
6 | { | ||
7 | public class Byte : BaseType | ||
8 | { | ||
9 | } | ||
10 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs new file mode 100644 index 0000000..19002d4 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs | |||
@@ -0,0 +1,10 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes | ||
6 | { | ||
7 | public class Char : BaseType | ||
8 | { | ||
9 | } | ||
10 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs new file mode 100644 index 0000000..91f1679 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs | |||
@@ -0,0 +1,16 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes | ||
6 | { | ||
7 | public class Float : BaseType | ||
8 | { | ||
9 | public float mValue = 0; | ||
10 | |||
11 | public Float() | ||
12 | { | ||
13 | |||
14 | } | ||
15 | } | ||
16 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs new file mode 100644 index 0000000..4ecd325 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs | |||
@@ -0,0 +1,16 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes | ||
6 | { | ||
7 | public class Int : BaseType | ||
8 | { | ||
9 | public int mValue = 0; | ||
10 | |||
11 | public Int() | ||
12 | { | ||
13 | |||
14 | } | ||
15 | } | ||
16 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Script.cs b/OpenSim/Region/Environment/Scenes/scripting/Script.cs index 8029883..139bdf1 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Script.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Script.cs | |||
@@ -27,7 +27,7 @@ | |||
27 | */ | 27 | */ |
28 | using OpenSim.Region.Environment.Scenes; | 28 | using OpenSim.Region.Environment.Scenes; |
29 | 29 | ||
30 | namespace OpenSim.Region.Enviorment.Scripting | 30 | namespace OpenSim.Region.Environment.Scripting |
31 | { | 31 | { |
32 | public interface IScript | 32 | public interface IScript |
33 | { | 33 | { |
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs new file mode 100644 index 0000000..fd601cb --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs | |||
@@ -0,0 +1,25 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | using OpenSim.Region.Environment.Scenes; | ||
6 | |||
7 | namespace OpenSim.Region.Environment.Scripting | ||
8 | { | ||
9 | // This class is to be used for engines which may not be able to access the Scene directly. | ||
10 | // Scene access is preffered, but obviously not possible on some non-.NET languages. | ||
11 | public class ScriptAPI | ||
12 | { | ||
13 | Scene scene; | ||
14 | |||
15 | public ScriptAPI(Scene world) | ||
16 | { | ||
17 | scene = world; | ||
18 | } | ||
19 | |||
20 | public Object CallMethod(String method, Object[] args) | ||
21 | { | ||
22 | return null; | ||
23 | } | ||
24 | } | ||
25 | } | ||
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs index d984d60..ed6f033 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs | |||
@@ -28,7 +28,7 @@ | |||
28 | using OpenSim.Framework.Console; | 28 | using OpenSim.Framework.Console; |
29 | using OpenSim.Region.Environment.Scenes; | 29 | using OpenSim.Region.Environment.Scenes; |
30 | 30 | ||
31 | namespace OpenSim.Region.Enviorment.Scripting | 31 | namespace OpenSim.Region.Environment.Scripting |
32 | { | 32 | { |
33 | /// <summary> | 33 | /// <summary> |
34 | /// Class which provides access to the world | 34 | /// Class which provides access to the world |
@@ -44,11 +44,15 @@ namespace OpenSim.Region.Enviorment.Scripting | |||
44 | // The console | 44 | // The console |
45 | public LogBase logger; | 45 | public LogBase logger; |
46 | 46 | ||
47 | // API Access | ||
48 | public ScriptAPI api; | ||
49 | |||
47 | public ScriptInfo(Scene scene) | 50 | public ScriptInfo(Scene scene) |
48 | { | 51 | { |
49 | world = scene; | 52 | world = scene; |
50 | events = world.eventManager; | 53 | events = world.eventManager; |
51 | logger = MainLog.Instance; | 54 | logger = MainLog.Instance; |
55 | api = new ScriptAPI(scene); | ||
52 | } | 56 | } |
53 | } | 57 | } |
54 | } | 58 | } |
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs index 1d47c24..250a4f0 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs | |||
@@ -29,7 +29,7 @@ using System.Collections.Generic; | |||
29 | using OpenSim.Framework.Console; | 29 | using OpenSim.Framework.Console; |
30 | using OpenSim.Region.Environment.Scenes; | 30 | using OpenSim.Region.Environment.Scenes; |
31 | 31 | ||
32 | namespace OpenSim.Region.Enviorment.Scripting | 32 | namespace OpenSim.Region.Environment.Scripting |
33 | { | 33 | { |
34 | public class ScriptManager | 34 | public class ScriptManager |
35 | { | 35 | { |