diff options
author | MW | 2007-05-26 13:40:19 +0000 |
---|---|---|
committer | MW | 2007-05-26 13:40:19 +0000 |
commit | 3436961bb5c01d659d09be134368f4f69460cef9 (patch) | |
tree | 3753ba4d7818df2a6bce0bbe863ff033cdfd568a /OpenSim/OpenSim.Scripting | |
download | opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.zip opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.gz opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.bz2 opensim-SC_OLD-3436961bb5c01d659d09be134368f4f69460cef9.tar.xz |
Start of rewrite 5279!
Diffstat (limited to '')
25 files changed, 1826 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/ClassInstance.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/ClassInstance.cs new file mode 100644 index 0000000..15ef814 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/ClassInstance.cs | |||
@@ -0,0 +1,18 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
5 | |||
6 | namespace OpenSim.Scripting.EmbeddedJVM | ||
7 | { | ||
8 | public class ClassInstance : Object | ||
9 | { | ||
10 | public int size; | ||
11 | public Dictionary<string, BaseType> Fields = new Dictionary<string, BaseType>(); | ||
12 | |||
13 | public ClassInstance() | ||
14 | { | ||
15 | |||
16 | } | ||
17 | } | ||
18 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/ClassRecord.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/ClassRecord.cs new file mode 100644 index 0000000..f2f0da5 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/ClassRecord.cs | |||
@@ -0,0 +1,476 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using System.Collections.Generic; | ||
4 | using System.Text; | ||
5 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
6 | |||
7 | namespace OpenSim.Scripting.EmbeddedJVM | ||
8 | { | ||
9 | public class ClassRecord | ||
10 | { | ||
11 | private ushort _majorVersion; | ||
12 | private ushort _minorVersion; | ||
13 | private ushort _constantPoolCount; | ||
14 | private ushort _accessFlags; | ||
15 | private ushort _thisClass; | ||
16 | private ushort _supperClass; | ||
17 | private ushort _interfaceCount; | ||
18 | private ushort _fieldCount; | ||
19 | private ushort _methodCount; | ||
20 | //private ushort _attributeCount; | ||
21 | //private string _name; | ||
22 | public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>(); | ||
23 | public PoolClass mClass; | ||
24 | |||
25 | public List<PoolItem> _constantsPool = new List<PoolItem>(); | ||
26 | private List<MethodInfo> _methodsList = new List<MethodInfo>(); | ||
27 | private List<FieldInfo> _fieldList = new List<FieldInfo>(); | ||
28 | |||
29 | public ClassRecord() | ||
30 | { | ||
31 | |||
32 | } | ||
33 | |||
34 | public ClassInstance CreateNewInstance() | ||
35 | { | ||
36 | return new ClassInstance(); | ||
37 | } | ||
38 | |||
39 | public void LoadClassFromFile(string fileName) | ||
40 | { | ||
41 | Console.WriteLine("loading script " + fileName); | ||
42 | FileStream fs = File.OpenRead(fileName); | ||
43 | this.LoadClassFromBytes(ReadFully(fs)); | ||
44 | fs.Close(); | ||
45 | } | ||
46 | |||
47 | public void LoadClassFromBytes(byte[] data) | ||
48 | { | ||
49 | int i = 0; | ||
50 | i += 4; | ||
51 | _minorVersion = (ushort)((data[i++] << 8) + data[i++] ); | ||
52 | _majorVersion = (ushort)((data[i++] << 8) + data[i++] ); | ||
53 | _constantPoolCount = (ushort)((data[i++] << 8) + data[i++] ); | ||
54 | // Console.WriteLine("there should be " + _constantPoolCount + " items in the pool"); | ||
55 | for (int count = 0; count < _constantPoolCount -1 ; count++) | ||
56 | { | ||
57 | //read in the constant pool | ||
58 | byte pooltype = data[i++]; | ||
59 | //Console.WriteLine("#" +count +": new constant type = " +pooltype); | ||
60 | //Console.WriteLine("start position is: " + i); | ||
61 | switch (pooltype) | ||
62 | { | ||
63 | case 1: //Utf8 | ||
64 | ushort uLength = (ushort)((data[i++] << 8) + data[i++] ); | ||
65 | |||
66 | // Console.WriteLine("new utf8 type, length is " + uLength); | ||
67 | PoolUtf8 utf8 = new PoolUtf8(); | ||
68 | utf8.readValue(data, ref i, uLength); | ||
69 | this._constantsPool.Add(utf8); | ||
70 | break; | ||
71 | case 3: //Int | ||
72 | break; | ||
73 | case 7: //Class | ||
74 | PoolClass pClass = new PoolClass(this); | ||
75 | pClass.readValue(data, ref i); | ||
76 | this._constantsPool.Add(pClass); | ||
77 | break; | ||
78 | case 10: //Method | ||
79 | PoolMethodRef pMeth = new PoolMethodRef(this); | ||
80 | pMeth.readValue(data, ref i); | ||
81 | this._constantsPool.Add(pMeth); | ||
82 | break; | ||
83 | case 12: //NamedType | ||
84 | PoolNamedType pNamed = new PoolNamedType(this); | ||
85 | pNamed.readValue(data, ref i); | ||
86 | this._constantsPool.Add(pNamed); | ||
87 | break; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | _accessFlags = (ushort)((data[i++] << 8) + data[i++] ); | ||
92 | _thisClass = (ushort)((data[i++] << 8) + data[i++] ); | ||
93 | _supperClass = (ushort)((data[i++] << 8) + data[i++] ); | ||
94 | |||
95 | if (this._constantsPool[this._thisClass - 1] is PoolClass) | ||
96 | { | ||
97 | this.mClass = ((PoolClass)this._constantsPool[this._thisClass - 1]); | ||
98 | } | ||
99 | |||
100 | _interfaceCount = (ushort)((data[i++] << 8) + data[i++]); | ||
101 | //should now read in the info for each interface | ||
102 | _fieldCount = (ushort)((data[i++] << 8) + data[i++]); | ||
103 | //should now read in the info for each field | ||
104 | _methodCount = (ushort)((data[i++] << 8) + data[i++]); | ||
105 | for (int count = 0; count < _methodCount; count++) | ||
106 | { | ||
107 | MethodInfo methInf = new MethodInfo(this); | ||
108 | methInf.ReadData(data, ref i); | ||
109 | this._methodsList.Add(methInf); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | public void AddMethodsToMemory(MethodMemory memory) | ||
114 | { | ||
115 | for (int count = 0; count < _methodCount; count++) | ||
116 | { | ||
117 | this._methodsList[count].AddMethodCode(memory); | ||
118 | } | ||
119 | } | ||
120 | |||
121 | public bool StartMethod(Thread thread, string methodName) | ||
122 | { | ||
123 | for (int count = 0; count < _methodCount; count++) | ||
124 | { | ||
125 | if (this._constantsPool[this._methodsList[count].NameIndex-1] is PoolUtf8) | ||
126 | { | ||
127 | if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex-1]).Value == methodName) | ||
128 | { | ||
129 | //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value); | ||
130 | thread.SetPC(this._methodsList[count].CodePointer); | ||
131 | return true; | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | return false; | ||
136 | } | ||
137 | |||
138 | public void PrintToConsole() | ||
139 | { | ||
140 | Console.WriteLine("Class File:"); | ||
141 | Console.WriteLine("Major version: " + _majorVersion); | ||
142 | Console.WriteLine("Minor version: " + _minorVersion); | ||
143 | Console.WriteLine("Pool size: " + _constantPoolCount); | ||
144 | |||
145 | for (int i = 0; i < _constantsPool.Count; i++) | ||
146 | { | ||
147 | this._constantsPool[i].Print(); | ||
148 | } | ||
149 | |||
150 | Console.WriteLine("Access flags: " + _accessFlags); | ||
151 | Console.WriteLine("This class: " + _thisClass ); | ||
152 | Console.WriteLine("Super class: " + _supperClass); | ||
153 | |||
154 | for (int count = 0; count < _methodCount; count++) | ||
155 | { | ||
156 | Console.WriteLine(); | ||
157 | this._methodsList[count].Print(); | ||
158 | } | ||
159 | |||
160 | Console.WriteLine("class name is " + this.mClass.Name.Value); | ||
161 | } | ||
162 | |||
163 | public static byte[] ReadFully(Stream stream) | ||
164 | { | ||
165 | byte[] buffer = new byte[1024]; | ||
166 | using (MemoryStream ms = new MemoryStream()) | ||
167 | { | ||
168 | while (true) | ||
169 | { | ||
170 | int read = stream.Read(buffer, 0, buffer.Length); | ||
171 | if (read <= 0) | ||
172 | return ms.ToArray(); | ||
173 | ms.Write(buffer, 0, read); | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | |||
178 | #region nested classes | ||
179 | public class PoolItem | ||
180 | { | ||
181 | public virtual void Print() | ||
182 | { | ||
183 | |||
184 | } | ||
185 | } | ||
186 | |||
187 | public class PoolUtf8 : PoolItem | ||
188 | { | ||
189 | public string Value = ""; | ||
190 | |||
191 | public void readValue(byte[] data,ref int pointer , int length) | ||
192 | { | ||
193 | for (int i = 0; i < length; i++) | ||
194 | { | ||
195 | int a =(int) data[pointer++]; | ||
196 | if ((a & 0x80) == 0) | ||
197 | { | ||
198 | Value = Value + (char)a; | ||
199 | } | ||
200 | else if ((a & 0x20) == 0) | ||
201 | { | ||
202 | int b = (int) data[pointer++]; | ||
203 | Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f)); | ||
204 | } | ||
205 | else | ||
206 | { | ||
207 | int b = (int)data[pointer++]; | ||
208 | int c = (int)data[pointer++]; | ||
209 | Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f)); | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | public override void Print() | ||
215 | { | ||
216 | Console.WriteLine("Utf8 type: " + Value); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | private class PoolInt : PoolItem | ||
221 | { | ||
222 | |||
223 | } | ||
224 | |||
225 | public class PoolClass : PoolItem | ||
226 | { | ||
227 | //public string name = ""; | ||
228 | public ushort namePointer = 0; | ||
229 | private ClassRecord parent; | ||
230 | public PoolUtf8 Name; | ||
231 | |||
232 | public PoolClass(ClassRecord paren) | ||
233 | { | ||
234 | parent = paren; | ||
235 | } | ||
236 | |||
237 | public void readValue(byte[] data, ref int pointer) | ||
238 | { | ||
239 | namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); | ||
240 | } | ||
241 | |||
242 | public override void Print() | ||
243 | { | ||
244 | this.Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]); | ||
245 | Console.Write("Class type: " + namePointer); | ||
246 | Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value); | ||
247 | |||
248 | } | ||
249 | } | ||
250 | |||
251 | public class PoolMethodRef : PoolItem | ||
252 | { | ||
253 | public ushort classPointer = 0; | ||
254 | public ushort nameTypePointer = 0; | ||
255 | public PoolNamedType mNameType; | ||
256 | public PoolClass mClass; | ||
257 | private ClassRecord parent; | ||
258 | |||
259 | public PoolMethodRef(ClassRecord paren) | ||
260 | { | ||
261 | parent = paren; | ||
262 | } | ||
263 | |||
264 | public void readValue(byte[] data, ref int pointer) | ||
265 | { | ||
266 | classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
267 | nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
268 | } | ||
269 | |||
270 | public override void Print() | ||
271 | { | ||
272 | this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]); | ||
273 | this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]); | ||
274 | Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | public class PoolNamedType : PoolItem | ||
279 | { | ||
280 | public ushort namePointer = 0; | ||
281 | public ushort typePointer = 0; | ||
282 | private ClassRecord parent; | ||
283 | public PoolUtf8 Name; | ||
284 | public PoolUtf8 Type; | ||
285 | |||
286 | public PoolNamedType(ClassRecord paren) | ||
287 | { | ||
288 | parent = paren; | ||
289 | } | ||
290 | |||
291 | public void readValue(byte[] data, ref int pointer) | ||
292 | { | ||
293 | namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); | ||
294 | typePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); | ||
295 | } | ||
296 | |||
297 | public override void Print() | ||
298 | { | ||
299 | Name = ((PoolUtf8)this.parent._constantsPool[namePointer-1]); | ||
300 | Type = ((PoolUtf8)this.parent._constantsPool[typePointer-1]); | ||
301 | Console.Write("Named type: " + namePointer + " , " + typePointer ); | ||
302 | Console.WriteLine(" // "+ ((PoolUtf8)this.parent._constantsPool[namePointer-1]).Value); | ||
303 | } | ||
304 | } | ||
305 | |||
306 | //*********************** | ||
307 | public class MethodInfo | ||
308 | { | ||
309 | public ushort AccessFlags = 0; | ||
310 | public ushort NameIndex = 0; | ||
311 | public string Name = ""; | ||
312 | public ushort DescriptorIndex = 0; | ||
313 | public ushort AttributeCount = 0; | ||
314 | public List<MethodAttribute> Attributes = new List<MethodAttribute>(); | ||
315 | private ClassRecord parent; | ||
316 | public int CodePointer = 0; | ||
317 | |||
318 | public MethodInfo(ClassRecord paren) | ||
319 | { | ||
320 | parent = paren; | ||
321 | } | ||
322 | |||
323 | public void AddMethodCode(MethodMemory memory) | ||
324 | { | ||
325 | Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length); | ||
326 | memory.Methodcount++; | ||
327 | this.CodePointer = memory.NextMethodPC; | ||
328 | memory.NextMethodPC += this.Attributes[0].Code.Length; | ||
329 | } | ||
330 | |||
331 | public void ReadData(byte[] data, ref int pointer) | ||
332 | { | ||
333 | AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
334 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
335 | DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
336 | AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
337 | for(int i =0; i< AttributeCount; i++) | ||
338 | { | ||
339 | MethodAttribute attri = new MethodAttribute(this.parent); | ||
340 | attri.ReadData(data, ref pointer); | ||
341 | this.Attributes.Add(attri); | ||
342 | } | ||
343 | } | ||
344 | |||
345 | public void Print() | ||
346 | { | ||
347 | Console.WriteLine("Method Info Struct: "); | ||
348 | Console.WriteLine("AccessFlags: " + AccessFlags); | ||
349 | Console.WriteLine("NameIndex: " + NameIndex +" // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); | ||
350 | Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[DescriptorIndex-1]).Value); | ||
351 | Console.WriteLine("Attribute Count:" + AttributeCount); | ||
352 | for (int i = 0; i < AttributeCount; i++) | ||
353 | { | ||
354 | this.Attributes[i].Print(); | ||
355 | } | ||
356 | } | ||
357 | |||
358 | public class MethodAttribute | ||
359 | { | ||
360 | public ushort NameIndex = 0; | ||
361 | public string Name = ""; | ||
362 | public Int32 Length = 0; | ||
363 | //for now only support code attribute | ||
364 | public ushort MaxStack = 0; | ||
365 | public ushort MaxLocals = 0; | ||
366 | public Int32 CodeLength = 0; | ||
367 | public byte[] Code; | ||
368 | public ushort ExceptionTableLength = 0; | ||
369 | public ushort SubAttributeCount = 0; | ||
370 | public List<SubAttribute> SubAttributes = new List<SubAttribute>(); | ||
371 | private ClassRecord parent; | ||
372 | |||
373 | public MethodAttribute(ClassRecord paren) | ||
374 | { | ||
375 | parent = paren; | ||
376 | } | ||
377 | |||
378 | public void ReadData(byte[] data, ref int pointer) | ||
379 | { | ||
380 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
381 | Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); | ||
382 | MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
383 | MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
384 | CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); | ||
385 | Code = new byte[CodeLength]; | ||
386 | for (int i = 0; i < CodeLength; i++) | ||
387 | { | ||
388 | Code[i] = data[pointer++]; | ||
389 | } | ||
390 | ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
391 | SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
392 | for (int i = 0; i < SubAttributeCount; i++) | ||
393 | { | ||
394 | SubAttribute subAttri = new SubAttribute(this.parent); | ||
395 | subAttri.ReadData(data, ref pointer); | ||
396 | this.SubAttributes.Add(subAttri); | ||
397 | } | ||
398 | } | ||
399 | |||
400 | public void Print() | ||
401 | { | ||
402 | Console.WriteLine("Method Attribute: "); | ||
403 | Console.WriteLine("Name Index: " + NameIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); | ||
404 | Console.WriteLine("Length: " + Length); | ||
405 | Console.WriteLine("MaxStack: " + MaxStack); | ||
406 | Console.WriteLine("MaxLocals: " + MaxLocals); | ||
407 | Console.WriteLine("CodeLength: " + CodeLength); | ||
408 | for (int i = 0; i < Code.Length; i++) | ||
409 | { | ||
410 | Console.WriteLine("OpCode #" + i + " is: " + Code[i]); | ||
411 | } | ||
412 | Console.WriteLine("SubAttributes: " + SubAttributeCount); | ||
413 | for (int i = 0; i < SubAttributeCount; i++) | ||
414 | { | ||
415 | this.SubAttributes[i].Print(); | ||
416 | } | ||
417 | } | ||
418 | |||
419 | public class SubAttribute | ||
420 | { | ||
421 | public ushort NameIndex = 0; | ||
422 | public string Name = ""; | ||
423 | public Int32 Length = 0; | ||
424 | public byte[] Data; | ||
425 | private ClassRecord parent; | ||
426 | |||
427 | public SubAttribute(ClassRecord paren) | ||
428 | { | ||
429 | parent = paren; | ||
430 | } | ||
431 | |||
432 | public void ReadData(byte[] data, ref int pointer) | ||
433 | { | ||
434 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | ||
435 | Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); | ||
436 | Data = new byte[Length]; | ||
437 | for (int i = 0; i < Length; i++) | ||
438 | { | ||
439 | Data[i] = data[pointer++]; | ||
440 | } | ||
441 | } | ||
442 | |||
443 | public void Print() | ||
444 | { | ||
445 | Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); | ||
446 | } | ||
447 | |||
448 | } | ||
449 | } | ||
450 | |||
451 | } | ||
452 | private class InterfaceInfo | ||
453 | { | ||
454 | public void ReadData(byte[] data, ref int i) | ||
455 | { | ||
456 | |||
457 | } | ||
458 | } | ||
459 | private class FieldInfo | ||
460 | { | ||
461 | public void ReadData(byte[] data, ref int i) | ||
462 | { | ||
463 | |||
464 | } | ||
465 | } | ||
466 | private class AttributeInfo | ||
467 | { | ||
468 | public void ReadData(byte[] data, ref int i) | ||
469 | { | ||
470 | |||
471 | } | ||
472 | } | ||
473 | #endregion | ||
474 | |||
475 | } | ||
476 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/Heap.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Heap.cs new file mode 100644 index 0000000..138e85e --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Heap.cs | |||
@@ -0,0 +1,16 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM | ||
6 | { | ||
7 | public class Heap | ||
8 | { | ||
9 | public List<ClassInstance> ClassObjects = new List<ClassInstance>(); | ||
10 | |||
11 | public Heap() | ||
12 | { | ||
13 | |||
14 | } | ||
15 | } | ||
16 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/Interpreter.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Interpreter.cs new file mode 100644 index 0000000..b94248c --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Interpreter.cs | |||
@@ -0,0 +1,108 @@ | |||
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 | this._mThread.stack.StackFrames.Pop(); | ||
53 | run = false; | ||
54 | } | ||
55 | handled = true; | ||
56 | } | ||
57 | if (currentOpCode == 174) | ||
58 | { | ||
59 | if (this._mThread.stack.StackFrames.Count > 1) | ||
60 | { | ||
61 | Console.WriteLine("returning float from function"); | ||
62 | int retPC1 = this._mThread.currentFrame.ReturnPC; | ||
63 | BaseType bas1 = this._mThread.currentFrame.OpStack.Pop(); | ||
64 | this._mThread.stack.StackFrames.Pop(); | ||
65 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
66 | this._mThread.PC = retPC1; | ||
67 | if (bas1 is Float) | ||
68 | { | ||
69 | this._mThread.currentFrame.OpStack.Push((Float)bas1); | ||
70 | } | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | // Console.WriteLine("No parent function so ending program"); | ||
75 | this._mThread.stack.StackFrames.Pop(); | ||
76 | run = false; | ||
77 | } | ||
78 | handled = true; | ||
79 | } | ||
80 | if (currentOpCode == 177) | ||
81 | { | ||
82 | if (this._mThread.stack.StackFrames.Count > 1) | ||
83 | { | ||
84 | Console.WriteLine("returning from function"); | ||
85 | int retPC = this._mThread.currentFrame.ReturnPC; | ||
86 | this._mThread.stack.StackFrames.Pop(); | ||
87 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
88 | this._mThread.PC = retPC; | ||
89 | } | ||
90 | else | ||
91 | { | ||
92 | // Console.WriteLine("No parent function so ending program"); | ||
93 | this._mThread.stack.StackFrames.Pop(); | ||
94 | run = false; | ||
95 | } | ||
96 | handled = true; | ||
97 | } | ||
98 | } | ||
99 | if (!handled) | ||
100 | { | ||
101 | Console.WriteLine("opcode " + currentOpCode + " not been handled "); | ||
102 | } | ||
103 | return run; | ||
104 | |||
105 | } | ||
106 | } | ||
107 | } | ||
108 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterLogic.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterLogic.cs new file mode 100644 index 0000000..3b7da35 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterLogic.cs | |||
@@ -0,0 +1,400 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
5 | using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes; | ||
6 | |||
7 | namespace OpenSim.Scripting.EmbeddedJVM | ||
8 | { | ||
9 | partial class Thread | ||
10 | { | ||
11 | private partial class Interpreter | ||
12 | { | ||
13 | private bool IsLogicOpCode(byte opcode) | ||
14 | { | ||
15 | bool result = false; | ||
16 | switch (opcode) | ||
17 | { | ||
18 | case 2: | ||
19 | Int m_int= new Int(); | ||
20 | m_int.mValue = -1; | ||
21 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
22 | result = true; | ||
23 | break; | ||
24 | case 3: | ||
25 | m_int= new Int(); | ||
26 | m_int.mValue = 0; | ||
27 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
28 | result = true; | ||
29 | break; | ||
30 | case 4: | ||
31 | m_int = new Int(); | ||
32 | m_int.mValue = 1; | ||
33 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
34 | result = true; | ||
35 | break; | ||
36 | case 5: | ||
37 | m_int = new Int(); | ||
38 | m_int.mValue = 2; | ||
39 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
40 | result = true; | ||
41 | break; | ||
42 | case 6: | ||
43 | m_int = new Int(); | ||
44 | m_int.mValue = 3; | ||
45 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
46 | break; | ||
47 | case 7: | ||
48 | m_int = new Int(); | ||
49 | m_int.mValue = 4; | ||
50 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
51 | result = true; | ||
52 | break; | ||
53 | case 8: | ||
54 | m_int = new Int(); | ||
55 | m_int.mValue = 5; | ||
56 | this._mThread.currentFrame.OpStack.Push(m_int); | ||
57 | result = true; | ||
58 | break; | ||
59 | case 11: | ||
60 | Float m_float = new Float(); | ||
61 | m_float.mValue = 0.0f; | ||
62 | this._mThread.currentFrame.OpStack.Push(m_float); | ||
63 | result = true; | ||
64 | break; | ||
65 | case 12: | ||
66 | m_float = new Float(); | ||
67 | m_float.mValue = 1.0f; | ||
68 | this._mThread.currentFrame.OpStack.Push(m_float); | ||
69 | result = true; | ||
70 | break; | ||
71 | case 13: | ||
72 | m_float = new Float(); | ||
73 | m_float.mValue = 2.0f; | ||
74 | this._mThread.currentFrame.OpStack.Push(m_float); | ||
75 | result = true; | ||
76 | break; | ||
77 | case 16: | ||
78 | int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]; | ||
79 | Int pushInt = new Int(); | ||
80 | pushInt.mValue = pushvalue; | ||
81 | this._mThread.currentFrame.OpStack.Push(pushInt); | ||
82 | this._mThread.PC++; | ||
83 | result = true; | ||
84 | break; | ||
85 | case 17: | ||
86 | short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
87 | Int pushInt2 = new Int(); | ||
88 | pushInt2.mValue = pushvalue2; | ||
89 | this._mThread.currentFrame.OpStack.Push(pushInt2); | ||
90 | this._mThread.PC += 2; | ||
91 | result = true; | ||
92 | break; | ||
93 | case 23: | ||
94 | short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC])); | ||
95 | Float fload = new Float(); | ||
96 | if (this._mThread.currentFrame.LocalVariables[findex1] != null) | ||
97 | { | ||
98 | if (this._mThread.currentFrame.LocalVariables[findex1] is Float) | ||
99 | { | ||
100 | fload.mValue = ((Float)this._mThread.currentFrame.LocalVariables[findex1]).mValue; | ||
101 | this._mThread.currentFrame.OpStack.Push(fload); | ||
102 | } | ||
103 | } | ||
104 | this._mThread.PC++; | ||
105 | result = true; | ||
106 | break; | ||
107 | case 26: | ||
108 | if (this._mThread.currentFrame.LocalVariables[0] != null) | ||
109 | { | ||
110 | if (this._mThread.currentFrame.LocalVariables[0] is Int) | ||
111 | { | ||
112 | Int newInt = new Int(); | ||
113 | newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue; | ||
114 | this._mThread.currentFrame.OpStack.Push(newInt); | ||
115 | } | ||
116 | } | ||
117 | result = true; | ||
118 | break; | ||
119 | case 27: | ||
120 | if (this._mThread.currentFrame.LocalVariables[1] != null) | ||
121 | { | ||
122 | if (this._mThread.currentFrame.LocalVariables[1] is Int) | ||
123 | { | ||
124 | Int newInt = new Int(); | ||
125 | newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue; | ||
126 | this._mThread.currentFrame.OpStack.Push(newInt); | ||
127 | } | ||
128 | } | ||
129 | result = true; | ||
130 | break; | ||
131 | case 34: | ||
132 | if (this._mThread.currentFrame.LocalVariables[0] != null) | ||
133 | { | ||
134 | if (this._mThread.currentFrame.LocalVariables[0] is Float) | ||
135 | { | ||
136 | Float newfloat = new Float(); | ||
137 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue; | ||
138 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
139 | } | ||
140 | } | ||
141 | result = true; | ||
142 | break; | ||
143 | case 35: | ||
144 | if (this._mThread.currentFrame.LocalVariables[1] != null) | ||
145 | { | ||
146 | if (this._mThread.currentFrame.LocalVariables[1] is Float) | ||
147 | { | ||
148 | Float newfloat = new Float(); | ||
149 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue; | ||
150 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
151 | } | ||
152 | } | ||
153 | result = true; | ||
154 | break; | ||
155 | case 36: | ||
156 | if (this._mThread.currentFrame.LocalVariables[2] != null) | ||
157 | { | ||
158 | if (this._mThread.currentFrame.LocalVariables[2] is Float) | ||
159 | { | ||
160 | Float newfloat = new Float(); | ||
161 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[2]).mValue; | ||
162 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
163 | } | ||
164 | } | ||
165 | result = true; | ||
166 | break; | ||
167 | case 37: | ||
168 | if (this._mThread.currentFrame.LocalVariables[3] != null) | ||
169 | { | ||
170 | if (this._mThread.currentFrame.LocalVariables[3] is Float) | ||
171 | { | ||
172 | Float newfloat = new Float(); | ||
173 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[3]).mValue; | ||
174 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
175 | } | ||
176 | } | ||
177 | result = true; | ||
178 | break; | ||
179 | case 56: | ||
180 | short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] )); | ||
181 | BaseType fstor = this._mThread.currentFrame.OpStack.Pop(); | ||
182 | if (fstor is Float) | ||
183 | { | ||
184 | this._mThread.currentFrame.LocalVariables[findex] = (Float)fstor; | ||
185 | } | ||
186 | this._mThread.PC++; | ||
187 | result = true; | ||
188 | break; | ||
189 | case 59: | ||
190 | BaseType baset = this._mThread.currentFrame.OpStack.Pop(); | ||
191 | if (baset is Int) | ||
192 | { | ||
193 | this._mThread.currentFrame.LocalVariables[0] = (Int)baset; | ||
194 | } | ||
195 | result = true; | ||
196 | break; | ||
197 | case 60: | ||
198 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
199 | if (baset is Int) | ||
200 | { | ||
201 | this._mThread.currentFrame.LocalVariables[1] = (Int)baset; | ||
202 | } | ||
203 | result = true; | ||
204 | break; | ||
205 | case 67: | ||
206 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
207 | if (baset is Float) | ||
208 | { | ||
209 | this._mThread.currentFrame.LocalVariables[0] = (Float)baset; | ||
210 | } | ||
211 | result = true; | ||
212 | break; | ||
213 | case 68: | ||
214 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
215 | if (baset is Float) | ||
216 | { | ||
217 | this._mThread.currentFrame.LocalVariables[1] = (Float)baset; | ||
218 | } | ||
219 | result = true; | ||
220 | break; | ||
221 | case 69: | ||
222 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
223 | if (baset is Float) | ||
224 | { | ||
225 | this._mThread.currentFrame.LocalVariables[2] = (Float)baset; | ||
226 | } | ||
227 | result = true; | ||
228 | break; | ||
229 | case 70: | ||
230 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
231 | if (baset is Float) | ||
232 | { | ||
233 | this._mThread.currentFrame.LocalVariables[3] = (Float)baset; | ||
234 | } | ||
235 | result = true; | ||
236 | break; | ||
237 | case 87: | ||
238 | this._mThread.currentFrame.OpStack.Pop(); | ||
239 | result = true; | ||
240 | break; | ||
241 | case 98: | ||
242 | BaseType bf2 = this._mThread.currentFrame.OpStack.Pop(); | ||
243 | BaseType bf1 = this._mThread.currentFrame.OpStack.Pop(); | ||
244 | if (bf1 is Float && bf2 is Float) | ||
245 | { | ||
246 | Float nflt = new Float(); | ||
247 | nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue; | ||
248 | this._mThread.currentFrame.OpStack.Push(nflt); | ||
249 | } | ||
250 | result = true; | ||
251 | break; | ||
252 | case 102: | ||
253 | BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop(); | ||
254 | BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop(); | ||
255 | if (bsf1 is Float && bsf2 is Float) | ||
256 | { | ||
257 | Float resf = new Float(); | ||
258 | resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue; | ||
259 | this._mThread.currentFrame.OpStack.Push(resf); | ||
260 | } | ||
261 | result = true; | ||
262 | break; | ||
263 | case 104: //check the order of the two values off the stack is correct | ||
264 | BaseType bs2 = this._mThread.currentFrame.OpStack.Pop(); | ||
265 | BaseType bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
266 | if (bs1 is Int && bs2 is Int) | ||
267 | { | ||
268 | Int nInt = new Int(); | ||
269 | nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue; | ||
270 | this._mThread.currentFrame.OpStack.Push(nInt); | ||
271 | } | ||
272 | result = true; | ||
273 | break; | ||
274 | case 132: | ||
275 | if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null) | ||
276 | { | ||
277 | if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int) | ||
278 | { | ||
279 | ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]; | ||
280 | } | ||
281 | } | ||
282 | this._mThread.PC += 2; | ||
283 | result = true; | ||
284 | break; | ||
285 | case 139: | ||
286 | BaseType conv1 = this._mThread.currentFrame.OpStack.Pop(); | ||
287 | if (conv1 is Float) | ||
288 | { | ||
289 | Int newconv = new Int(); | ||
290 | newconv.mValue = (int)((Float)conv1).mValue; | ||
291 | this._mThread.currentFrame.OpStack.Push(newconv); | ||
292 | } | ||
293 | result = true; | ||
294 | break; | ||
295 | case 149: | ||
296 | BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop(); | ||
297 | BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop(); | ||
298 | if (flcom1 is Float && flcom2 is Float) | ||
299 | { | ||
300 | Int compres = new Int(); | ||
301 | if (((Float)flcom1).mValue < ((Float)flcom2).mValue) | ||
302 | { | ||
303 | compres.mValue = -1; | ||
304 | } | ||
305 | else if (((Float)flcom1).mValue > ((Float)flcom2).mValue) | ||
306 | { | ||
307 | compres.mValue = 1; | ||
308 | } | ||
309 | else | ||
310 | { | ||
311 | compres.mValue = 0; | ||
312 | } | ||
313 | this._mThread.currentFrame.OpStack.Push(compres); | ||
314 | } | ||
315 | result = true; | ||
316 | break; | ||
317 | case 158: | ||
318 | short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
319 | BaseType comp1 = this._mThread.currentFrame.OpStack.Pop(); | ||
320 | if (comp1 is Int) | ||
321 | { | ||
322 | if (((Int)comp1).mValue <= 0) | ||
323 | { | ||
324 | this._mThread.PC += -1 + compareoffset1; | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | this._mThread.PC += 2; | ||
329 | } | ||
330 | } | ||
331 | else | ||
332 | { | ||
333 | this._mThread.PC += 2; | ||
334 | } | ||
335 | result = true; | ||
336 | break; | ||
337 | case 162: | ||
338 | short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
339 | BaseType bc2 = this._mThread.currentFrame.OpStack.Pop(); | ||
340 | BaseType bc1 = this._mThread.currentFrame.OpStack.Pop(); | ||
341 | if (bc1 is Int && bc2 is Int) | ||
342 | { | ||
343 | //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue); | ||
344 | if (((Int)bc1).mValue >= ((Int)bc2).mValue) | ||
345 | { | ||
346 | // Console.WriteLine("branch compare true , offset is " +compareoffset); | ||
347 | // Console.WriteLine("current PC is " + this._mThread.PC); | ||
348 | this._mThread.PC += -1 + compareoffset; | ||
349 | //Console.WriteLine("new PC is " + this._mThread.PC); | ||
350 | } | ||
351 | else | ||
352 | { | ||
353 | //Console.WriteLine("branch compare false"); | ||
354 | this._mThread.PC += 2; | ||
355 | } | ||
356 | } | ||
357 | else | ||
358 | { | ||
359 | this._mThread.PC += 2; | ||
360 | } | ||
361 | result = true; | ||
362 | break; | ||
363 | case 164: | ||
364 | short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
365 | BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop(); | ||
366 | BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop(); | ||
367 | if (bcl1 is Int && bcl2 is Int) | ||
368 | { | ||
369 | //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue); | ||
370 | if (((Int)bcl1).mValue <= ((Int)bcl2).mValue) | ||
371 | { | ||
372 | // Console.WriteLine("branch compare true , offset is " + compareloffset); | ||
373 | // Console.WriteLine("current PC is " + this._mThread.PC); | ||
374 | this._mThread.PC += -1 + compareloffset; | ||
375 | // Console.WriteLine("new PC is " + this._mThread.PC); | ||
376 | } | ||
377 | else | ||
378 | { | ||
379 | //Console.WriteLine("branch compare false"); | ||
380 | this._mThread.PC += 2; | ||
381 | } | ||
382 | } | ||
383 | else | ||
384 | { | ||
385 | this._mThread.PC += 2; | ||
386 | } | ||
387 | result = true; | ||
388 | break; | ||
389 | case 167: | ||
390 | short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]); | ||
391 | this._mThread.PC += -1 + offset; | ||
392 | result = true; | ||
393 | break; | ||
394 | } | ||
395 | |||
396 | return result; | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterMethods.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterMethods.cs new file mode 100644 index 0000000..c66c148 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterMethods.cs | |||
@@ -0,0 +1,141 @@ | |||
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 | using OpenSim.Framework.Interfaces; | ||
7 | using OpenSim.Framework; | ||
8 | using OpenSim.Framework.Types; | ||
9 | |||
10 | namespace OpenSim.Scripting.EmbeddedJVM | ||
11 | { | ||
12 | partial class Thread | ||
13 | { | ||
14 | private partial class Interpreter | ||
15 | { | ||
16 | private bool IsMethodOpCode(byte opcode) | ||
17 | { | ||
18 | bool result = false; | ||
19 | switch (opcode) | ||
20 | { | ||
21 | case 184: | ||
22 | short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]); | ||
23 | //Console.WriteLine("call to method : "+refIndex); | ||
24 | if (this._mThread.currentClass._constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef) | ||
25 | { | ||
26 | // Console.WriteLine("which is " + ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value + "." + ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value); | ||
27 | // Console.WriteLine("of type " + ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value); | ||
28 | string typ = ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value; | ||
29 | string typeparam = ""; | ||
30 | string typereturn = ""; | ||
31 | int firstbrak = 0; | ||
32 | int secondbrak = 0; | ||
33 | firstbrak = typ.LastIndexOf('('); | ||
34 | secondbrak = typ.LastIndexOf(')'); | ||
35 | typeparam = typ.Substring(firstbrak + 1, secondbrak - firstbrak - 1); | ||
36 | typereturn = typ.Substring(secondbrak + 1, typ.Length - secondbrak - 1); | ||
37 | //Console.WriteLine("split is " + typeparam + " which is length " + typeparam.Length + " , " + typereturn); | ||
38 | if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value) | ||
39 | { | ||
40 | //calling a method in this class | ||
41 | if (typeparam.Length == 0) | ||
42 | { | ||
43 | this._mThread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, (this._mThread.PC + 2)); | ||
44 | } | ||
45 | else | ||
46 | { | ||
47 | this._mThread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this._mThread.PC + 2)); | ||
48 | } | ||
49 | } | ||
50 | else | ||
51 | { | ||
52 | //calling a method of a different class | ||
53 | |||
54 | //for now we will have a built in OpenSimAPI class, but this should be a java class that then calls native methods | ||
55 | if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI") | ||
56 | { | ||
57 | switch (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value) | ||
58 | { | ||
59 | case "GetEntityID": | ||
60 | Int entityID = new Int(); | ||
61 | entityID.mValue =(int) this._mThread.EntityId; | ||
62 | this._mThread.currentFrame.OpStack.Push(entityID); | ||
63 | this._mThread.PC += 2; | ||
64 | break; | ||
65 | case "GetRandomAvatarID": | ||
66 | entityID = new Int(); | ||
67 | entityID.mValue = (int)Thread.OpenSimScriptAPI.GetRandomAvatarID(); | ||
68 | this._mThread.currentFrame.OpStack.Push(entityID); | ||
69 | this._mThread.PC += 2; | ||
70 | break; | ||
71 | case "GetEntityPositionX": | ||
72 | BaseType bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
73 | if (bs1 is Int) | ||
74 | { | ||
75 | //Console.WriteLine("get entity pos for " + ((Int)bs1).mValue); | ||
76 | //should get the position of the entity from the IScriptAPI | ||
77 | OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue); | ||
78 | Float pos = new Float(); | ||
79 | pos.mValue = vec3.X; | ||
80 | // Console.WriteLine("returned x value " + vec3.X.ToString()); | ||
81 | this._mThread.currentFrame.OpStack.Push(pos); | ||
82 | } | ||
83 | this._mThread.PC += 2; | ||
84 | break; | ||
85 | case "GetEntityPositionY": | ||
86 | bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
87 | if (bs1 is Int) | ||
88 | { | ||
89 | //should get the position of the entity from the IScriptAPI | ||
90 | OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue); | ||
91 | Float pos = new Float(); | ||
92 | pos.mValue = vec3.Y; | ||
93 | this._mThread.currentFrame.OpStack.Push(pos); | ||
94 | } | ||
95 | this._mThread.PC += 2; | ||
96 | break; | ||
97 | case "GetEntityPositionZ": | ||
98 | bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
99 | if (bs1 is Int) | ||
100 | { | ||
101 | //should get the position of the entity from the IScriptAPI | ||
102 | OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue); | ||
103 | Float pos = new Float(); | ||
104 | pos.mValue = vec3.Z; | ||
105 | this._mThread.currentFrame.OpStack.Push(pos); | ||
106 | } | ||
107 | this._mThread.PC += 2; | ||
108 | break; | ||
109 | case "SetEntityPosition": | ||
110 | //pop the three float values and the entity id | ||
111 | BaseType ft3 = this._mThread.currentFrame.OpStack.Pop(); | ||
112 | BaseType ft2 = this._mThread.currentFrame.OpStack.Pop(); | ||
113 | BaseType ft1 = this._mThread.currentFrame.OpStack.Pop(); | ||
114 | BaseType in1 = this._mThread.currentFrame.OpStack.Pop(); | ||
115 | if (ft1 is Float && ft2 is Float && ft3 is Float) | ||
116 | { | ||
117 | if(in1 is Int) | ||
118 | { | ||
119 | //Console.WriteLine("set: " + ((Int)in1).mValue + " , " + ((Float)ft1).mValue + " , " + ((Float)ft2).mValue + " , " + ((Float)ft3).mValue); | ||
120 | Thread.OpenSimScriptAPI.SetEntityPosition((uint)((Int) in1).mValue, ((Float)ft1).mValue, ((Float)ft2).mValue, ((Float)ft3).mValue); | ||
121 | } | ||
122 | } | ||
123 | this._mThread.PC += 2; | ||
124 | break; | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | this._mThread.PC += 2; | ||
132 | } | ||
133 | result = true; | ||
134 | break; | ||
135 | } | ||
136 | |||
137 | return result; | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterReturn.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterReturn.cs new file mode 100644 index 0000000..6704e31 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/InterpreterReturn.cs | |||
@@ -0,0 +1,13 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM | ||
6 | { | ||
7 | partial class Thread | ||
8 | { | ||
9 | private partial class Interpreter | ||
10 | { | ||
11 | } | ||
12 | } | ||
13 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/MainMemory.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/MainMemory.cs new file mode 100644 index 0000000..ff18f90 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/MainMemory.cs | |||
@@ -0,0 +1,18 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM | ||
6 | { | ||
7 | public class MainMemory | ||
8 | { | ||
9 | public Heap HeapArea; | ||
10 | public MethodMemory MethodArea; | ||
11 | |||
12 | public MainMemory() | ||
13 | { | ||
14 | MethodArea = new MethodMemory(); | ||
15 | HeapArea = new Heap(); | ||
16 | } | ||
17 | } | ||
18 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/MethodMemory.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/MethodMemory.cs new file mode 100644 index 0000000..2541991 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/MethodMemory.cs | |||
@@ -0,0 +1,19 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM | ||
6 | { | ||
7 | public class MethodMemory | ||
8 | { | ||
9 | public byte[] MethodBuffer; | ||
10 | public List<ClassRecord> Classes = new List<ClassRecord>(); | ||
11 | public int NextMethodPC = 0; | ||
12 | public int Methodcount = 0; | ||
13 | |||
14 | public MethodMemory() | ||
15 | { | ||
16 | MethodBuffer = new byte[20000]; | ||
17 | } | ||
18 | } | ||
19 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/Object.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Object.cs new file mode 100644 index 0000000..e6e392c --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Object.cs | |||
@@ -0,0 +1,10 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM | ||
6 | { | ||
7 | public class Object | ||
8 | { | ||
9 | } | ||
10 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj b/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj new file mode 100644 index 0000000..bd1a332 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj | |||
@@ -0,0 +1,153 @@ | |||
1 | <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
2 | <PropertyGroup> | ||
3 | <ProjectType>Local</ProjectType> | ||
4 | <ProductVersion>8.0.50727</ProductVersion> | ||
5 | <SchemaVersion>2.0</SchemaVersion> | ||
6 | <ProjectGuid>{97A82740-0000-0000-0000-000000000000}</ProjectGuid> | ||
7 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
8 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
9 | <ApplicationIcon></ApplicationIcon> | ||
10 | <AssemblyKeyContainerName> | ||
11 | </AssemblyKeyContainerName> | ||
12 | <AssemblyName>OpenSim.Scripting.EmbeddedJVM</AssemblyName> | ||
13 | <DefaultClientScript>JScript</DefaultClientScript> | ||
14 | <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> | ||
15 | <DefaultTargetSchema>IE50</DefaultTargetSchema> | ||
16 | <DelaySign>false</DelaySign> | ||
17 | <OutputType>Library</OutputType> | ||
18 | <AppDesignerFolder></AppDesignerFolder> | ||
19 | <RootNamespace>OpenSim.Scripting.EmbeddedJVM</RootNamespace> | ||
20 | <StartupObject></StartupObject> | ||
21 | <FileUpgradeFlags> | ||
22 | </FileUpgradeFlags> | ||
23 | </PropertyGroup> | ||
24 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
25 | <AllowUnsafeBlocks>False</AllowUnsafeBlocks> | ||
26 | <BaseAddress>285212672</BaseAddress> | ||
27 | <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
28 | <ConfigurationOverrideFile> | ||
29 | </ConfigurationOverrideFile> | ||
30 | <DefineConstants>TRACE;DEBUG</DefineConstants> | ||
31 | <DocumentationFile></DocumentationFile> | ||
32 | <DebugSymbols>True</DebugSymbols> | ||
33 | <FileAlignment>4096</FileAlignment> | ||
34 | <Optimize>False</Optimize> | ||
35 | <OutputPath>..\..\..\bin\ScriptEngines\</OutputPath> | ||
36 | <RegisterForComInterop>False</RegisterForComInterop> | ||
37 | <RemoveIntegerChecks>False</RemoveIntegerChecks> | ||
38 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> | ||
39 | <WarningLevel>4</WarningLevel> | ||
40 | <NoWarn></NoWarn> | ||
41 | </PropertyGroup> | ||
42 | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
43 | <AllowUnsafeBlocks>False</AllowUnsafeBlocks> | ||
44 | <BaseAddress>285212672</BaseAddress> | ||
45 | <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
46 | <ConfigurationOverrideFile> | ||
47 | </ConfigurationOverrideFile> | ||
48 | <DefineConstants>TRACE</DefineConstants> | ||
49 | <DocumentationFile></DocumentationFile> | ||
50 | <DebugSymbols>False</DebugSymbols> | ||
51 | <FileAlignment>4096</FileAlignment> | ||
52 | <Optimize>True</Optimize> | ||
53 | <OutputPath>..\..\..\bin\ScriptEngines\</OutputPath> | ||
54 | <RegisterForComInterop>False</RegisterForComInterop> | ||
55 | <RemoveIntegerChecks>False</RemoveIntegerChecks> | ||
56 | <TreatWarningsAsErrors>False</TreatWarningsAsErrors> | ||
57 | <WarningLevel>4</WarningLevel> | ||
58 | <NoWarn></NoWarn> | ||
59 | </PropertyGroup> | ||
60 | <ItemGroup> | ||
61 | <Reference Include="System" > | ||
62 | <HintPath>System.dll</HintPath> | ||
63 | <Private>False</Private> | ||
64 | </Reference> | ||
65 | <Reference Include="System.Xml" > | ||
66 | <HintPath>System.Xml.dll</HintPath> | ||
67 | <Private>False</Private> | ||
68 | </Reference> | ||
69 | </ItemGroup> | ||
70 | <ItemGroup> | ||
71 | <ProjectReference Include="..\..\..\Common\OpenSim.Framework\OpenSim.Framework.csproj"> | ||
72 | <Name>OpenSim.Framework</Name> | ||
73 | <Project>{8ACA2445-0000-0000-0000-000000000000}</Project> | ||
74 | <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package> | ||
75 | <Private>False</Private> | ||
76 | </ProjectReference> | ||
77 | </ItemGroup> | ||
78 | <ItemGroup> | ||
79 | <Compile Include="ClassInstance.cs"> | ||
80 | <SubType>Code</SubType> | ||
81 | </Compile> | ||
82 | <Compile Include="ClassRecord.cs"> | ||
83 | <SubType>Code</SubType> | ||
84 | </Compile> | ||
85 | <Compile Include="Heap.cs"> | ||
86 | <SubType>Code</SubType> | ||
87 | </Compile> | ||
88 | <Compile Include="Interpreter.cs"> | ||
89 | <SubType>Code</SubType> | ||
90 | </Compile> | ||
91 | <Compile Include="InterpreterLogic.cs"> | ||
92 | <SubType>Code</SubType> | ||
93 | </Compile> | ||
94 | <Compile Include="InterpreterMethods.cs"> | ||
95 | <SubType>Code</SubType> | ||
96 | </Compile> | ||
97 | <Compile Include="InterpreterReturn.cs"> | ||
98 | <SubType>Code</SubType> | ||
99 | </Compile> | ||
100 | <Compile Include="MainMemory.cs"> | ||
101 | <SubType>Code</SubType> | ||
102 | </Compile> | ||
103 | <Compile Include="MethodMemory.cs"> | ||
104 | <SubType>Code</SubType> | ||
105 | </Compile> | ||
106 | <Compile Include="Object.cs"> | ||
107 | <SubType>Code</SubType> | ||
108 | </Compile> | ||
109 | <Compile Include="OpenSimJVM.cs"> | ||
110 | <SubType>Code</SubType> | ||
111 | </Compile> | ||
112 | <Compile Include="Stack.cs"> | ||
113 | <SubType>Code</SubType> | ||
114 | </Compile> | ||
115 | <Compile Include="StackFrame.cs"> | ||
116 | <SubType>Code</SubType> | ||
117 | </Compile> | ||
118 | <Compile Include="Thread.cs"> | ||
119 | <SubType>Code</SubType> | ||
120 | </Compile> | ||
121 | <Compile Include="Properties\AssemblyInfo.cs"> | ||
122 | <SubType>Code</SubType> | ||
123 | </Compile> | ||
124 | <Compile Include="Types\ArrayReference.cs"> | ||
125 | <SubType>Code</SubType> | ||
126 | </Compile> | ||
127 | <Compile Include="Types\BaseType.cs"> | ||
128 | <SubType>Code</SubType> | ||
129 | </Compile> | ||
130 | <Compile Include="Types\ObjectReference.cs"> | ||
131 | <SubType>Code</SubType> | ||
132 | </Compile> | ||
133 | <Compile Include="Types\PrimitiveTypes\Byte.cs"> | ||
134 | <SubType>Code</SubType> | ||
135 | </Compile> | ||
136 | <Compile Include="Types\PrimitiveTypes\Char.cs"> | ||
137 | <SubType>Code</SubType> | ||
138 | </Compile> | ||
139 | <Compile Include="Types\PrimitiveTypes\Float.cs"> | ||
140 | <SubType>Code</SubType> | ||
141 | </Compile> | ||
142 | <Compile Include="Types\PrimitiveTypes\Int.cs"> | ||
143 | <SubType>Code</SubType> | ||
144 | </Compile> | ||
145 | </ItemGroup> | ||
146 | <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> | ||
147 | <PropertyGroup> | ||
148 | <PreBuildEvent> | ||
149 | </PreBuildEvent> | ||
150 | <PostBuildEvent> | ||
151 | </PostBuildEvent> | ||
152 | </PropertyGroup> | ||
153 | </Project> | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj.user b/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj.user new file mode 100644 index 0000000..d47d65d --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj.user | |||
@@ -0,0 +1,12 @@ | |||
1 | <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
2 | <PropertyGroup> | ||
3 | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
4 | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
5 | <ReferencePath>C:\New Folder\second-life-viewer\opensim-dailys2\opensim15-07\bin\</ReferencePath> | ||
6 | <LastOpenVersion>8.0.50727</LastOpenVersion> | ||
7 | <ProjectView>ProjectFiles</ProjectView> | ||
8 | <ProjectTrust>0</ProjectTrust> | ||
9 | </PropertyGroup> | ||
10 | <PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " /> | ||
11 | <PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> | ||
12 | </Project> | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.dll.build b/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.dll.build new file mode 100644 index 0000000..c5255db --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.dll.build | |||
@@ -0,0 +1,62 @@ | |||
1 | <?xml version="1.0" ?> | ||
2 | <project name="OpenSim.Scripting.EmbeddedJVM" default="build"> | ||
3 | <target name="build"> | ||
4 | <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" /> | ||
5 | <mkdir dir="${project::get-base-directory()}/${build.dir}" /> | ||
6 | <copy todir="${project::get-base-directory()}/${build.dir}"> | ||
7 | <fileset basedir="${project::get-base-directory()}"> | ||
8 | </fileset> | ||
9 | </copy> | ||
10 | <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll"> | ||
11 | <resources prefix="OpenSim.Scripting.EmbeddedJVM" dynamicprefix="true" > | ||
12 | </resources> | ||
13 | <sources failonempty="true"> | ||
14 | <include name="ClassInstance.cs" /> | ||
15 | <include name="ClassRecord.cs" /> | ||
16 | <include name="Heap.cs" /> | ||
17 | <include name="Interpreter.cs" /> | ||
18 | <include name="InterpreterLogic.cs" /> | ||
19 | <include name="InterpreterMethods.cs" /> | ||
20 | <include name="InterpreterReturn.cs" /> | ||
21 | <include name="MainMemory.cs" /> | ||
22 | <include name="MethodMemory.cs" /> | ||
23 | <include name="Object.cs" /> | ||
24 | <include name="OpenSimJVM.cs" /> | ||
25 | <include name="Stack.cs" /> | ||
26 | <include name="StackFrame.cs" /> | ||
27 | <include name="Thread.cs" /> | ||
28 | <include name="Properties/AssemblyInfo.cs" /> | ||
29 | <include name="Types/ArrayReference.cs" /> | ||
30 | <include name="Types/BaseType.cs" /> | ||
31 | <include name="Types/ObjectReference.cs" /> | ||
32 | <include name="Types/PrimitiveTypes/Byte.cs" /> | ||
33 | <include name="Types/PrimitiveTypes/Char.cs" /> | ||
34 | <include name="Types/PrimitiveTypes/Float.cs" /> | ||
35 | <include name="Types/PrimitiveTypes/Int.cs" /> | ||
36 | </sources> | ||
37 | <references basedir="${project::get-base-directory()}"> | ||
38 | <lib> | ||
39 | <include name="${project::get-base-directory()}" /> | ||
40 | <include name="${project::get-base-directory()}/${build.dir}" /> | ||
41 | </lib> | ||
42 | <include name="System.dll" /> | ||
43 | <include name="System.Xml.dll" /> | ||
44 | <include name="../../../bin/OpenSim.Framework.dll" /> | ||
45 | </references> | ||
46 | </csc> | ||
47 | <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../../bin/ScriptEngines/" /> | ||
48 | <mkdir dir="${project::get-base-directory()}/../../../bin/ScriptEngines/"/> | ||
49 | <copy todir="${project::get-base-directory()}/../../../bin/ScriptEngines/"> | ||
50 | <fileset basedir="${project::get-base-directory()}/${build.dir}/" > | ||
51 | <include name="*.dll"/> | ||
52 | <include name="*.exe"/> | ||
53 | </fileset> | ||
54 | </copy> | ||
55 | </target> | ||
56 | <target name="clean"> | ||
57 | <delete dir="${bin.dir}" failonerror="false" /> | ||
58 | <delete dir="${obj.dir}" failonerror="false" /> | ||
59 | </target> | ||
60 | <target name="doc" description="Creates documentation."> | ||
61 | </target> | ||
62 | </project> | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs new file mode 100644 index 0000000..b47bb50 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/OpenSimJVM.cs | |||
@@ -0,0 +1,134 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using System.IO; | ||
5 | using System.Threading; | ||
6 | using OpenSim.Framework; | ||
7 | using OpenSim.Framework.Interfaces; | ||
8 | using OpenSim.Framework.Utilities; | ||
9 | |||
10 | namespace OpenSim.Scripting.EmbeddedJVM | ||
11 | { | ||
12 | public class OpenSimJVM : IScriptEngine | ||
13 | { | ||
14 | private List<Thread> _threads = new List<Thread>(); | ||
15 | private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>(); | ||
16 | private MainMemory _mainMemory; | ||
17 | private System.Threading.Thread compileThread; | ||
18 | |||
19 | public OpenSimJVM() | ||
20 | { | ||
21 | |||
22 | } | ||
23 | |||
24 | public bool Init(IScriptAPI api) | ||
25 | { | ||
26 | Console.WriteLine("Creating OpenSim JVM scripting engine"); | ||
27 | _mainMemory = new MainMemory(); | ||
28 | Thread.GlobalMemory = this._mainMemory; | ||
29 | Thread.OpenSimScriptAPI = api; | ||
30 | compileThread = new System.Threading.Thread(new ThreadStart(CompileScript)); | ||
31 | compileThread.IsBackground = true; | ||
32 | compileThread.Start(); | ||
33 | return true; | ||
34 | } | ||
35 | |||
36 | public string GetName() | ||
37 | { | ||
38 | return "OpenSimJVM"; | ||
39 | } | ||
40 | |||
41 | public void LoadScript(string script, string scriptName, uint entityID) | ||
42 | { | ||
43 | Console.WriteLine("OpenSimJVM - loading new script: " + scriptName); | ||
44 | CompileInfo comp = new CompileInfo(); | ||
45 | comp.entityId = entityID; | ||
46 | comp.script = script; | ||
47 | comp.scriptName = scriptName; | ||
48 | this.CompileScripts.Enqueue(comp); | ||
49 | } | ||
50 | |||
51 | public void CompileScript() | ||
52 | { | ||
53 | while (true) | ||
54 | { | ||
55 | CompileInfo comp = this.CompileScripts.Dequeue(); | ||
56 | string script = comp.script; | ||
57 | string scriptName = comp.scriptName; | ||
58 | uint entityID = comp.entityId; | ||
59 | try | ||
60 | { | ||
61 | //need to compile the script into a java class file | ||
62 | |||
63 | //first save it to a java source file | ||
64 | TextWriter tw = new StreamWriter(scriptName + ".java"); | ||
65 | tw.WriteLine(script); | ||
66 | tw.Close(); | ||
67 | |||
68 | //now compile | ||
69 | System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java"); | ||
70 | // psi.RedirectStandardOutput = true; | ||
71 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; | ||
72 | psi.UseShellExecute = false; | ||
73 | |||
74 | System.Diagnostics.Process javacomp; | ||
75 | javacomp = System.Diagnostics.Process.Start(psi); | ||
76 | javacomp.WaitForExit(); | ||
77 | |||
78 | |||
79 | //now load in class file | ||
80 | ClassRecord class1 = new ClassRecord(); | ||
81 | class1.LoadClassFromFile(scriptName + ".class"); | ||
82 | class1.PrintToConsole(); | ||
83 | //Console.WriteLine(); | ||
84 | this._mainMemory.MethodArea.Classes.Add(class1); | ||
85 | class1.AddMethodsToMemory(this._mainMemory.MethodArea); | ||
86 | |||
87 | Thread newThread = new Thread(); | ||
88 | this._threads.Add(newThread); | ||
89 | newThread.EntityId = entityID; | ||
90 | newThread.currentClass = class1; | ||
91 | |||
92 | //now delete the created files | ||
93 | System.IO.File.Delete(scriptName + ".java"); | ||
94 | System.IO.File.Delete(scriptName + ".class"); | ||
95 | //this.OnFrame(); | ||
96 | } | ||
97 | catch (Exception e) | ||
98 | { | ||
99 | Console.WriteLine("exception"); | ||
100 | Console.WriteLine(e.StackTrace); | ||
101 | Console.WriteLine(e.Message); | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | |||
106 | public void OnFrame() | ||
107 | { | ||
108 | for (int i = 0; i < this._threads.Count; i++) | ||
109 | { | ||
110 | if (!this._threads[i].running) | ||
111 | { | ||
112 | this._threads[i].StartMethod("OnFrame"); | ||
113 | bool run = true; | ||
114 | while (run) | ||
115 | { | ||
116 | run = this._threads[i].Excute(); | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | } | ||
121 | |||
122 | private class CompileInfo | ||
123 | { | ||
124 | public string script; | ||
125 | public string scriptName; | ||
126 | public uint entityId; | ||
127 | |||
128 | public CompileInfo() | ||
129 | { | ||
130 | |||
131 | } | ||
132 | } | ||
133 | } | ||
134 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/Properties/AssemblyInfo.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..53a0f08 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Scripting.EmbeddedJVM")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("")] | ||
12 | [assembly: AssemblyProduct("OpenSim.Scripting.EmbeddedJVM")] | ||
13 | [assembly: AssemblyCopyright("Copyright © 2007")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("087c0917-5a6a-4b47-a4dd-0928dd85bd4b")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("1.0.0.0")] | ||
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/Stack.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Stack.cs new file mode 100644 index 0000000..d77d82e --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Stack.cs | |||
@@ -0,0 +1,15 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | |||
5 | namespace OpenSim.Scripting.EmbeddedJVM | ||
6 | { | ||
7 | public class Stack | ||
8 | { | ||
9 | public Stack<StackFrame> StackFrames = new Stack<StackFrame>(); | ||
10 | |||
11 | public Stack() | ||
12 | { | ||
13 | } | ||
14 | } | ||
15 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/StackFrame.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/StackFrame.cs new file mode 100644 index 0000000..afca7a9 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/StackFrame.cs | |||
@@ -0,0 +1,22 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
5 | |||
6 | namespace OpenSim.Scripting.EmbeddedJVM | ||
7 | { | ||
8 | public class StackFrame | ||
9 | { | ||
10 | public BaseType[] LocalVariables; | ||
11 | public Stack<BaseType> OpStack = new Stack<BaseType>(); | ||
12 | |||
13 | public int ReturnPC = 0; | ||
14 | public ClassRecord CallingClass = null; | ||
15 | |||
16 | public StackFrame() | ||
17 | { | ||
18 | LocalVariables = new BaseType[20]; | ||
19 | } | ||
20 | |||
21 | } | ||
22 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/Thread.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Thread.cs new file mode 100644 index 0000000..436949c --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Thread.cs | |||
@@ -0,0 +1,88 @@ | |||
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 | using OpenSim.Framework; | ||
7 | using OpenSim.Framework.Interfaces; | ||
8 | |||
9 | namespace OpenSim.Scripting.EmbeddedJVM | ||
10 | { | ||
11 | public partial class Thread | ||
12 | { | ||
13 | public static MainMemory GlobalMemory; | ||
14 | public static IScriptAPI OpenSimScriptAPI; | ||
15 | private int PC = 0; | ||
16 | private Stack stack; | ||
17 | private Interpreter mInterpreter; | ||
18 | public ClassRecord currentClass; | ||
19 | public ClassInstance currentInstance; | ||
20 | private StackFrame currentFrame; | ||
21 | public int excutionCounter = 0; | ||
22 | public bool running = false; | ||
23 | public uint EntityId = 0; | ||
24 | |||
25 | public Thread() | ||
26 | { | ||
27 | this.mInterpreter = new Interpreter(this); | ||
28 | this.stack = new Stack(); | ||
29 | } | ||
30 | |||
31 | public void SetPC(int methodpointer) | ||
32 | { | ||
33 | //Console.WriteLine("Thread PC has been set to " + methodpointer); | ||
34 | PC = methodpointer; | ||
35 | } | ||
36 | |||
37 | public void StartMethod(ClassRecord rec, string methName) | ||
38 | { | ||
39 | currentFrame = new StackFrame(); | ||
40 | this.stack.StackFrames.Push(currentFrame); | ||
41 | this.currentClass = rec; | ||
42 | currentClass.StartMethod(this, methName); | ||
43 | } | ||
44 | |||
45 | public void StartMethod( string methName) | ||
46 | { | ||
47 | currentFrame = new StackFrame(); | ||
48 | this.stack.StackFrames.Push(currentFrame); | ||
49 | currentClass.StartMethod(this, methName); | ||
50 | } | ||
51 | |||
52 | public void JumpToStaticVoidMethod(string methName, int returnPC) | ||
53 | { | ||
54 | currentFrame = new StackFrame(); | ||
55 | currentFrame.ReturnPC = returnPC; | ||
56 | this.stack.StackFrames.Push(currentFrame); | ||
57 | currentClass.StartMethod(this, methName); | ||
58 | } | ||
59 | |||
60 | public void JumpToStaticParamMethod(string methName, string param, int returnPC) | ||
61 | { | ||
62 | if (param == "I") | ||
63 | { | ||
64 | BaseType bs1 = currentFrame.OpStack.Pop(); | ||
65 | currentFrame = new StackFrame(); | ||
66 | currentFrame.ReturnPC = returnPC; | ||
67 | this.stack.StackFrames.Push(currentFrame); | ||
68 | currentFrame.LocalVariables[0] = ((Int)bs1); | ||
69 | currentClass.StartMethod(this, methName); | ||
70 | } | ||
71 | if (param == "F") | ||
72 | { | ||
73 | |||
74 | } | ||
75 | } | ||
76 | |||
77 | public void JumpToClassStaticVoidMethod(string className, string methName, int returnPC) | ||
78 | { | ||
79 | |||
80 | } | ||
81 | |||
82 | public bool Excute() | ||
83 | { | ||
84 | excutionCounter++; | ||
85 | return this.mInterpreter.Excute(); | ||
86 | } | ||
87 | } | ||
88 | } | ||
diff --git a/OpenSim/OpenSim.Scripting/EmbeddedJVM/Types/ArrayReference.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Types/ArrayReference.cs new file mode 100644 index 0000000..2854eab --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/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/OpenSim.Scripting/EmbeddedJVM/Types/BaseType.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Types/BaseType.cs new file mode 100644 index 0000000..270aa7b --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/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/OpenSim.Scripting/EmbeddedJVM/Types/ObjectReference.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Types/ObjectReference.cs new file mode 100644 index 0000000..da28eaa --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/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/OpenSim.Scripting/EmbeddedJVM/Types/PrimitiveTypes/Byte.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Types/PrimitiveTypes/Byte.cs new file mode 100644 index 0000000..1a3ecff --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/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/OpenSim.Scripting/EmbeddedJVM/Types/PrimitiveTypes/Char.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Types/PrimitiveTypes/Char.cs new file mode 100644 index 0000000..19002d4 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/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/OpenSim.Scripting/EmbeddedJVM/Types/PrimitiveTypes/Float.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Types/PrimitiveTypes/Float.cs new file mode 100644 index 0000000..91f1679 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/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/OpenSim.Scripting/EmbeddedJVM/Types/PrimitiveTypes/Int.cs b/OpenSim/OpenSim.Scripting/EmbeddedJVM/Types/PrimitiveTypes/Int.cs new file mode 100644 index 0000000..4ecd325 --- /dev/null +++ b/OpenSim/OpenSim.Scripting/EmbeddedJVM/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 | } | ||