diff options
author | MW | 2007-04-11 09:45:48 +0000 |
---|---|---|
committer | MW | 2007-04-11 09:45:48 +0000 |
commit | ffd7a6b8c22cd21e355f77fea20b145424e3d912 (patch) | |
tree | 94deb515b2b7cb5233fc8fc8d9d531e1a789b7c7 /OpenSim.Scripting.EmbeddedJVM | |
parent | (no commit message) (diff) | |
download | opensim-SC-ffd7a6b8c22cd21e355f77fea20b145424e3d912.zip opensim-SC-ffd7a6b8c22cd21e355f77fea20b145424e3d912.tar.gz opensim-SC-ffd7a6b8c22cd21e355f77fea20b145424e3d912.tar.bz2 opensim-SC-ffd7a6b8c22cd21e355f77fea20b145424e3d912.tar.xz |
Changed so that a bin\ScriptEngines\ directory will be searched for scripting Engines.
Added the work in progress JVM scripting engine.
Diffstat (limited to 'OpenSim.Scripting.EmbeddedJVM')
24 files changed, 1786 insertions, 0 deletions
diff --git a/OpenSim.Scripting.EmbeddedJVM/ClassInstance.cs b/OpenSim.Scripting.EmbeddedJVM/ClassInstance.cs new file mode 100644 index 0000000..15ef814 --- /dev/null +++ b/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.Scripting.EmbeddedJVM/ClassRecord.cs b/OpenSim.Scripting.EmbeddedJVM/ClassRecord.cs new file mode 100644 index 0000000..15d8a4b --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Heap.cs b/OpenSim.Scripting.EmbeddedJVM/Heap.cs new file mode 100644 index 0000000..138e85e --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Interpreter.cs b/OpenSim.Scripting.EmbeddedJVM/Interpreter.cs new file mode 100644 index 0000000..aeeee0a --- /dev/null +++ b/OpenSim.Scripting.EmbeddedJVM/Interpreter.cs | |||
@@ -0,0 +1,105 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Scripting.EmbeddedJVM.Types; | ||
5 | using OpenSim.Scripting.EmbeddedJVM.Types.PrimitiveTypes; | ||
6 | |||
7 | namespace OpenSim.Scripting.EmbeddedJVM | ||
8 | { | ||
9 | partial class Thread | ||
10 | { | ||
11 | private partial class Interpreter | ||
12 | { | ||
13 | private Thread _mThread; | ||
14 | |||
15 | public Interpreter(Thread parentThread) | ||
16 | { | ||
17 | _mThread = parentThread; | ||
18 | } | ||
19 | |||
20 | public bool Excute() | ||
21 | { | ||
22 | bool run = true; | ||
23 | byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC++]; | ||
24 | // Console.WriteLine("opCode is: " + currentOpCode); | ||
25 | bool handled = false; | ||
26 | |||
27 | handled = this.IsLogicOpCode(currentOpCode); | ||
28 | if (!handled) | ||
29 | { | ||
30 | handled = this.IsMethodOpCode(currentOpCode); | ||
31 | } | ||
32 | if (!handled) | ||
33 | { | ||
34 | if (currentOpCode == 172) | ||
35 | { | ||
36 | if (this._mThread.stack.StackFrames.Count > 1) | ||
37 | { | ||
38 | Console.WriteLine("returning int from function"); | ||
39 | int retPC1 = this._mThread.currentFrame.ReturnPC; | ||
40 | BaseType bas1 = this._mThread.currentFrame.OpStack.Pop(); | ||
41 | this._mThread.stack.StackFrames.Pop(); | ||
42 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
43 | this._mThread.PC = retPC1; | ||
44 | if (bas1 is Int) | ||
45 | { | ||
46 | this._mThread.currentFrame.OpStack.Push((Int)bas1); | ||
47 | } | ||
48 | } | ||
49 | else | ||
50 | { | ||
51 | // Console.WriteLine("No parent function so ending program"); | ||
52 | run = false; | ||
53 | } | ||
54 | handled = true; | ||
55 | } | ||
56 | if (currentOpCode == 174) | ||
57 | { | ||
58 | if (this._mThread.stack.StackFrames.Count > 1) | ||
59 | { | ||
60 | Console.WriteLine("returning float from function"); | ||
61 | int retPC1 = this._mThread.currentFrame.ReturnPC; | ||
62 | BaseType bas1 = this._mThread.currentFrame.OpStack.Pop(); | ||
63 | this._mThread.stack.StackFrames.Pop(); | ||
64 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
65 | this._mThread.PC = retPC1; | ||
66 | if (bas1 is Float) | ||
67 | { | ||
68 | this._mThread.currentFrame.OpStack.Push((Float)bas1); | ||
69 | } | ||
70 | } | ||
71 | else | ||
72 | { | ||
73 | // Console.WriteLine("No parent function so ending program"); | ||
74 | run = false; | ||
75 | } | ||
76 | handled = true; | ||
77 | } | ||
78 | if (currentOpCode == 177) | ||
79 | { | ||
80 | if (this._mThread.stack.StackFrames.Count > 1) | ||
81 | { | ||
82 | Console.WriteLine("returning from function"); | ||
83 | int retPC = this._mThread.currentFrame.ReturnPC; | ||
84 | this._mThread.stack.StackFrames.Pop(); | ||
85 | this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); | ||
86 | this._mThread.PC = retPC; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | // Console.WriteLine("No parent function so ending program"); | ||
91 | run = false; | ||
92 | } | ||
93 | handled = true; | ||
94 | } | ||
95 | } | ||
96 | if (!handled) | ||
97 | { | ||
98 | Console.WriteLine("opcode " + currentOpCode + " not been handled "); | ||
99 | } | ||
100 | return run; | ||
101 | |||
102 | } | ||
103 | } | ||
104 | } | ||
105 | } | ||
diff --git a/OpenSim.Scripting.EmbeddedJVM/InterpreterLogic.cs b/OpenSim.Scripting.EmbeddedJVM/InterpreterLogic.cs new file mode 100644 index 0000000..673970a --- /dev/null +++ b/OpenSim.Scripting.EmbeddedJVM/InterpreterLogic.cs | |||
@@ -0,0 +1,376 @@ | |||
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 26: | ||
94 | if (this._mThread.currentFrame.LocalVariables[0] != null) | ||
95 | { | ||
96 | if (this._mThread.currentFrame.LocalVariables[0] is Int) | ||
97 | { | ||
98 | Int newInt = new Int(); | ||
99 | newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue; | ||
100 | this._mThread.currentFrame.OpStack.Push(newInt); | ||
101 | } | ||
102 | } | ||
103 | result = true; | ||
104 | break; | ||
105 | case 27: | ||
106 | if (this._mThread.currentFrame.LocalVariables[1] != null) | ||
107 | { | ||
108 | if (this._mThread.currentFrame.LocalVariables[1] is Int) | ||
109 | { | ||
110 | Int newInt = new Int(); | ||
111 | newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue; | ||
112 | this._mThread.currentFrame.OpStack.Push(newInt); | ||
113 | } | ||
114 | } | ||
115 | result = true; | ||
116 | break; | ||
117 | case 34: | ||
118 | if (this._mThread.currentFrame.LocalVariables[0] != null) | ||
119 | { | ||
120 | if (this._mThread.currentFrame.LocalVariables[0] is Float) | ||
121 | { | ||
122 | Float newfloat = new Float(); | ||
123 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue; | ||
124 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
125 | } | ||
126 | } | ||
127 | result = true; | ||
128 | break; | ||
129 | case 35: | ||
130 | if (this._mThread.currentFrame.LocalVariables[1] != null) | ||
131 | { | ||
132 | if (this._mThread.currentFrame.LocalVariables[1] is Float) | ||
133 | { | ||
134 | Float newfloat = new Float(); | ||
135 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue; | ||
136 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
137 | } | ||
138 | } | ||
139 | result = true; | ||
140 | break; | ||
141 | case 36: | ||
142 | if (this._mThread.currentFrame.LocalVariables[2] != null) | ||
143 | { | ||
144 | if (this._mThread.currentFrame.LocalVariables[2] is Float) | ||
145 | { | ||
146 | Float newfloat = new Float(); | ||
147 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[2]).mValue; | ||
148 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
149 | } | ||
150 | } | ||
151 | result = true; | ||
152 | break; | ||
153 | case 37: | ||
154 | if (this._mThread.currentFrame.LocalVariables[3] != null) | ||
155 | { | ||
156 | if (this._mThread.currentFrame.LocalVariables[3] is Float) | ||
157 | { | ||
158 | Float newfloat = new Float(); | ||
159 | newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[3]).mValue; | ||
160 | this._mThread.currentFrame.OpStack.Push(newfloat); | ||
161 | } | ||
162 | } | ||
163 | result = true; | ||
164 | break; | ||
165 | case 59: | ||
166 | BaseType baset = this._mThread.currentFrame.OpStack.Pop(); | ||
167 | if (baset is Int) | ||
168 | { | ||
169 | this._mThread.currentFrame.LocalVariables[0] = (Int)baset; | ||
170 | } | ||
171 | result = true; | ||
172 | break; | ||
173 | case 60: | ||
174 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
175 | if (baset is Int) | ||
176 | { | ||
177 | this._mThread.currentFrame.LocalVariables[1] = (Int)baset; | ||
178 | } | ||
179 | result = true; | ||
180 | break; | ||
181 | case 67: | ||
182 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
183 | if (baset is Float) | ||
184 | { | ||
185 | this._mThread.currentFrame.LocalVariables[0] = (Float)baset; | ||
186 | } | ||
187 | result = true; | ||
188 | break; | ||
189 | case 68: | ||
190 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
191 | if (baset is Float) | ||
192 | { | ||
193 | this._mThread.currentFrame.LocalVariables[1] = (Float)baset; | ||
194 | } | ||
195 | result = true; | ||
196 | break; | ||
197 | case 69: | ||
198 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
199 | if (baset is Float) | ||
200 | { | ||
201 | this._mThread.currentFrame.LocalVariables[2] = (Float)baset; | ||
202 | } | ||
203 | result = true; | ||
204 | break; | ||
205 | case 70: | ||
206 | baset = this._mThread.currentFrame.OpStack.Pop(); | ||
207 | if (baset is Float) | ||
208 | { | ||
209 | this._mThread.currentFrame.LocalVariables[3] = (Float)baset; | ||
210 | } | ||
211 | result = true; | ||
212 | break; | ||
213 | case 87: | ||
214 | this._mThread.currentFrame.OpStack.Pop(); | ||
215 | result = true; | ||
216 | break; | ||
217 | case 98: | ||
218 | BaseType bf2 = this._mThread.currentFrame.OpStack.Pop(); | ||
219 | BaseType bf1 = this._mThread.currentFrame.OpStack.Pop(); | ||
220 | if (bf1 is Float && bf2 is Float) | ||
221 | { | ||
222 | Float nflt = new Float(); | ||
223 | nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue; | ||
224 | this._mThread.currentFrame.OpStack.Push(nflt); | ||
225 | } | ||
226 | result = true; | ||
227 | break; | ||
228 | case 102: | ||
229 | BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop(); | ||
230 | BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop(); | ||
231 | if (bsf1 is Float && bsf2 is Float) | ||
232 | { | ||
233 | Float resf = new Float(); | ||
234 | resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue; | ||
235 | this._mThread.currentFrame.OpStack.Push(resf); | ||
236 | } | ||
237 | result = true; | ||
238 | break; | ||
239 | case 104: //check the order of the two values off the stack is correct | ||
240 | BaseType bs2 = this._mThread.currentFrame.OpStack.Pop(); | ||
241 | BaseType bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
242 | if (bs1 is Int && bs2 is Int) | ||
243 | { | ||
244 | Int nInt = new Int(); | ||
245 | nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue; | ||
246 | this._mThread.currentFrame.OpStack.Push(nInt); | ||
247 | } | ||
248 | result = true; | ||
249 | break; | ||
250 | case 132: | ||
251 | if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null) | ||
252 | { | ||
253 | if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int) | ||
254 | { | ||
255 | ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]; | ||
256 | } | ||
257 | } | ||
258 | this._mThread.PC += 2; | ||
259 | result = true; | ||
260 | break; | ||
261 | case 139: | ||
262 | BaseType conv1 = this._mThread.currentFrame.OpStack.Pop(); | ||
263 | if (conv1 is Float) | ||
264 | { | ||
265 | Int newconv = new Int(); | ||
266 | newconv.mValue = (int)((Float)conv1).mValue; | ||
267 | this._mThread.currentFrame.OpStack.Push(newconv); | ||
268 | } | ||
269 | result = true; | ||
270 | break; | ||
271 | case 149: | ||
272 | BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop(); | ||
273 | BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop(); | ||
274 | if (flcom1 is Float && flcom2 is Float) | ||
275 | { | ||
276 | Int compres = new Int(); | ||
277 | if (((Float)flcom1).mValue > ((Float)flcom2).mValue) | ||
278 | { | ||
279 | compres.mValue = -1; | ||
280 | } | ||
281 | else if (((Float)flcom1).mValue < ((Float)flcom2).mValue) | ||
282 | { | ||
283 | compres.mValue = 1; | ||
284 | } | ||
285 | else | ||
286 | { | ||
287 | compres.mValue = 0; | ||
288 | } | ||
289 | this._mThread.currentFrame.OpStack.Push(compres); | ||
290 | } | ||
291 | result = true; | ||
292 | break; | ||
293 | case 158: | ||
294 | short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
295 | BaseType comp1 = this._mThread.currentFrame.OpStack.Pop(); | ||
296 | if (comp1 is Int) | ||
297 | { | ||
298 | if (((Int)comp1).mValue <= 0) | ||
299 | { | ||
300 | this._mThread.PC += -1 + compareoffset1; | ||
301 | } | ||
302 | else | ||
303 | { | ||
304 | this._mThread.PC += 2; | ||
305 | } | ||
306 | } | ||
307 | else | ||
308 | { | ||
309 | this._mThread.PC += 2; | ||
310 | } | ||
311 | result = true; | ||
312 | break; | ||
313 | case 162: | ||
314 | short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
315 | BaseType bc2 = this._mThread.currentFrame.OpStack.Pop(); | ||
316 | BaseType bc1 = this._mThread.currentFrame.OpStack.Pop(); | ||
317 | if (bc1 is Int && bc2 is Int) | ||
318 | { | ||
319 | //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue); | ||
320 | if (((Int)bc1).mValue >= ((Int)bc2).mValue) | ||
321 | { | ||
322 | // Console.WriteLine("branch compare true , offset is " +compareoffset); | ||
323 | // Console.WriteLine("current PC is " + this._mThread.PC); | ||
324 | this._mThread.PC += -1 + compareoffset; | ||
325 | //Console.WriteLine("new PC is " + this._mThread.PC); | ||
326 | } | ||
327 | else | ||
328 | { | ||
329 | //Console.WriteLine("branch compare false"); | ||
330 | this._mThread.PC += 2; | ||
331 | } | ||
332 | } | ||
333 | else | ||
334 | { | ||
335 | this._mThread.PC += 2; | ||
336 | } | ||
337 | result = true; | ||
338 | break; | ||
339 | case 164: | ||
340 | short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); | ||
341 | BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop(); | ||
342 | BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop(); | ||
343 | if (bcl1 is Int && bcl2 is Int) | ||
344 | { | ||
345 | //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue); | ||
346 | if (((Int)bcl1).mValue <= ((Int)bcl2).mValue) | ||
347 | { | ||
348 | // Console.WriteLine("branch compare true , offset is " + compareloffset); | ||
349 | // Console.WriteLine("current PC is " + this._mThread.PC); | ||
350 | this._mThread.PC += -1 + compareloffset; | ||
351 | // Console.WriteLine("new PC is " + this._mThread.PC); | ||
352 | } | ||
353 | else | ||
354 | { | ||
355 | //Console.WriteLine("branch compare false"); | ||
356 | this._mThread.PC += 2; | ||
357 | } | ||
358 | } | ||
359 | else | ||
360 | { | ||
361 | this._mThread.PC += 2; | ||
362 | } | ||
363 | result = true; | ||
364 | break; | ||
365 | case 167: | ||
366 | short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]); | ||
367 | this._mThread.PC += -1 + offset; | ||
368 | result = true; | ||
369 | break; | ||
370 | } | ||
371 | |||
372 | return result; | ||
373 | } | ||
374 | } | ||
375 | } | ||
376 | } | ||
diff --git a/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs b/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs new file mode 100644 index 0000000..e025293 --- /dev/null +++ b/OpenSim.Scripting.EmbeddedJVM/InterpreterMethods.cs | |||
@@ -0,0 +1,139 @@ | |||
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 | |||
9 | namespace OpenSim.Scripting.EmbeddedJVM | ||
10 | { | ||
11 | partial class Thread | ||
12 | { | ||
13 | private partial class Interpreter | ||
14 | { | ||
15 | private bool IsMethodOpCode(byte opcode) | ||
16 | { | ||
17 | bool result = false; | ||
18 | switch (opcode) | ||
19 | { | ||
20 | case 184: | ||
21 | short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]); | ||
22 | //Console.WriteLine("call to method : "+refIndex); | ||
23 | if (this._mThread.currentClass._constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef) | ||
24 | { | ||
25 | // 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); | ||
26 | // Console.WriteLine("of type " + ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value); | ||
27 | string typ = ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value; | ||
28 | string typeparam = ""; | ||
29 | string typereturn = ""; | ||
30 | int firstbrak = 0; | ||
31 | int secondbrak = 0; | ||
32 | firstbrak = typ.LastIndexOf('('); | ||
33 | secondbrak = typ.LastIndexOf(')'); | ||
34 | typeparam = typ.Substring(firstbrak + 1, secondbrak - firstbrak - 1); | ||
35 | typereturn = typ.Substring(secondbrak + 1, typ.Length - secondbrak - 1); | ||
36 | //Console.WriteLine("split is " + typeparam + " which is length " + typeparam.Length + " , " + typereturn); | ||
37 | if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value) | ||
38 | { | ||
39 | //calling a method in this class | ||
40 | if (typeparam.Length == 0) | ||
41 | { | ||
42 | this._mThread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, (this._mThread.PC + 2)); | ||
43 | } | ||
44 | else | ||
45 | { | ||
46 | this._mThread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this._mThread.PC + 2)); | ||
47 | } | ||
48 | } | ||
49 | else | ||
50 | { | ||
51 | //calling a method of a different class | ||
52 | |||
53 | //for now we will have a built in OpenSimAPI class, but this should be a java class that then calls native methods | ||
54 | if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI") | ||
55 | { | ||
56 | switch (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value) | ||
57 | { | ||
58 | case "GetEntityID": | ||
59 | Int entityID = new Int(); | ||
60 | entityID.mValue =(int) this._mThread.EntityId; | ||
61 | this._mThread.currentFrame.OpStack.Push(entityID); | ||
62 | this._mThread.PC += 2; | ||
63 | break; | ||
64 | case "GetRandomAvatarID": | ||
65 | entityID = new Int(); | ||
66 | entityID.mValue = (int)Thread.OpenSimScriptAPI.GetRandomAvatarID(); | ||
67 | this._mThread.currentFrame.OpStack.Push(entityID); | ||
68 | this._mThread.PC += 2; | ||
69 | break; | ||
70 | case "GetEntityPositionX": | ||
71 | BaseType bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
72 | if (bs1 is Int) | ||
73 | { | ||
74 | Console.WriteLine("get entity pos for " + ((Int)bs1).mValue); | ||
75 | //should get the position of the entity from the IScriptAPI | ||
76 | OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue); | ||
77 | Float pos = new Float(); | ||
78 | pos.mValue = vec3.X; | ||
79 | this._mThread.currentFrame.OpStack.Push(pos); | ||
80 | } | ||
81 | this._mThread.PC += 2; | ||
82 | break; | ||
83 | case "GetEntityPositionY": | ||
84 | bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
85 | if (bs1 is Int) | ||
86 | { | ||
87 | //should get the position of the entity from the IScriptAPI | ||
88 | OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue); | ||
89 | Float pos = new Float(); | ||
90 | pos.mValue = vec3.Y; | ||
91 | this._mThread.currentFrame.OpStack.Push(pos); | ||
92 | } | ||
93 | this._mThread.PC += 2; | ||
94 | break; | ||
95 | case "GetEntityPositionZ": | ||
96 | bs1 = this._mThread.currentFrame.OpStack.Pop(); | ||
97 | if (bs1 is Int) | ||
98 | { | ||
99 | //should get the position of the entity from the IScriptAPI | ||
100 | OSVector3 vec3 = Thread.OpenSimScriptAPI.GetEntityPosition((uint)((Int)bs1).mValue); | ||
101 | Float pos = new Float(); | ||
102 | pos.mValue = vec3.Z; | ||
103 | this._mThread.currentFrame.OpStack.Push(pos); | ||
104 | } | ||
105 | this._mThread.PC += 2; | ||
106 | break; | ||
107 | case "SetEntityPosition": | ||
108 | //pop the three float values and the entity id | ||
109 | BaseType ft3 = this._mThread.currentFrame.OpStack.Pop(); | ||
110 | BaseType ft2 = this._mThread.currentFrame.OpStack.Pop(); | ||
111 | BaseType ft1 = this._mThread.currentFrame.OpStack.Pop(); | ||
112 | BaseType in1 = this._mThread.currentFrame.OpStack.Pop(); | ||
113 | if (ft1 is Float && ft2 is Float && ft3 is Float) | ||
114 | { | ||
115 | if(in1 is Int) | ||
116 | { | ||
117 | //Console.WriteLine("set: " + ((Int)in1).mValue + " , " + ((Float)ft1).mValue + " , " + ((Float)ft2).mValue + " , " + ((Float)ft3).mValue); | ||
118 | Thread.OpenSimScriptAPI.SetEntityPosition((uint)((Int) in1).mValue, ((Float)ft1).mValue, ((Float)ft2).mValue, ((Float)ft3).mValue); | ||
119 | } | ||
120 | } | ||
121 | this._mThread.PC += 2; | ||
122 | break; | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | this._mThread.PC += 2; | ||
130 | } | ||
131 | result = true; | ||
132 | break; | ||
133 | } | ||
134 | |||
135 | return result; | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | } | ||
diff --git a/OpenSim.Scripting.EmbeddedJVM/InterpreterReturn.cs b/OpenSim.Scripting.EmbeddedJVM/InterpreterReturn.cs new file mode 100644 index 0000000..6704e31 --- /dev/null +++ b/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.Scripting.EmbeddedJVM/MainMemory.cs b/OpenSim.Scripting.EmbeddedJVM/MainMemory.cs new file mode 100644 index 0000000..ff18f90 --- /dev/null +++ b/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.Scripting.EmbeddedJVM/MethodMemory.cs b/OpenSim.Scripting.EmbeddedJVM/MethodMemory.cs new file mode 100644 index 0000000..2541991 --- /dev/null +++ b/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.Scripting.EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj b/OpenSim.Scripting.EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj new file mode 100644 index 0000000..90aeff8 --- /dev/null +++ b/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="..\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.Scripting.EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj.user b/OpenSim.Scripting.EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.csproj.user new file mode 100644 index 0000000..90c1e94 --- /dev/null +++ b/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\opensim02-04\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.Scripting.EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.dll.build b/OpenSim.Scripting.EmbeddedJVM/OpenSim.Scripting.EmbeddedJVM.dll.build new file mode 100644 index 0000000..46067c1 --- /dev/null +++ b/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.Scripting.EmbeddedJVM/OpenSimJVM.cs b/OpenSim.Scripting.EmbeddedJVM/OpenSimJVM.cs new file mode 100644 index 0000000..77a92e5 --- /dev/null +++ b/OpenSim.Scripting.EmbeddedJVM/OpenSimJVM.cs | |||
@@ -0,0 +1,133 @@ | |||
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(@"C:\Program Files\Java\jdk1.6.0_01\bin\javac.exe", "*.java"); | ||
70 | psi.RedirectStandardOutput = true; | ||
71 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; | ||
72 | psi.UseShellExecute = false; | ||
73 | System.Diagnostics.Process javacomp; | ||
74 | javacomp = System.Diagnostics.Process.Start(psi); | ||
75 | javacomp.WaitForExit(); | ||
76 | |||
77 | |||
78 | //now load in class file | ||
79 | ClassRecord class1 = new ClassRecord(); | ||
80 | class1.LoadClassFromFile(scriptName + ".class"); | ||
81 | class1.PrintToConsole(); | ||
82 | //Console.WriteLine(); | ||
83 | this._mainMemory.MethodArea.Classes.Add(class1); | ||
84 | class1.AddMethodsToMemory(this._mainMemory.MethodArea); | ||
85 | |||
86 | Thread newThread = new Thread(); | ||
87 | this._threads.Add(newThread); | ||
88 | newThread.EntityId = entityID; | ||
89 | newThread.currentClass = class1; | ||
90 | |||
91 | //now delete the created files | ||
92 | System.IO.File.Delete(scriptName + ".java"); | ||
93 | System.IO.File.Delete(scriptName + ".class"); | ||
94 | this.OnFrame(); | ||
95 | } | ||
96 | catch (Exception e) | ||
97 | { | ||
98 | Console.WriteLine("exception"); | ||
99 | Console.WriteLine(e.StackTrace); | ||
100 | Console.WriteLine(e.Message); | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | |||
105 | public void OnFrame() | ||
106 | { | ||
107 | for (int i = 0; i < this._threads.Count; i++) | ||
108 | { | ||
109 | if (!this._threads[i].running) | ||
110 | { | ||
111 | this._threads[i].StartMethod("OnFrame"); | ||
112 | bool run = true; | ||
113 | while (run) | ||
114 | { | ||
115 | run = this._threads[i].Excute(); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | |||
121 | private class CompileInfo | ||
122 | { | ||
123 | public string script; | ||
124 | public string scriptName; | ||
125 | public uint entityId; | ||
126 | |||
127 | public CompileInfo() | ||
128 | { | ||
129 | |||
130 | } | ||
131 | } | ||
132 | } | ||
133 | } | ||
diff --git a/OpenSim.Scripting.EmbeddedJVM/Properties/AssemblyInfo.cs b/OpenSim.Scripting.EmbeddedJVM/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..53a0f08 --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Stack.cs b/OpenSim.Scripting.EmbeddedJVM/Stack.cs new file mode 100644 index 0000000..d77d82e --- /dev/null +++ b/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.Scripting.EmbeddedJVM/StackFrame.cs b/OpenSim.Scripting.EmbeddedJVM/StackFrame.cs new file mode 100644 index 0000000..afca7a9 --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Thread.cs b/OpenSim.Scripting.EmbeddedJVM/Thread.cs new file mode 100644 index 0000000..436949c --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Types/ArrayReference.cs b/OpenSim.Scripting.EmbeddedJVM/Types/ArrayReference.cs new file mode 100644 index 0000000..2854eab --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Types/BaseType.cs b/OpenSim.Scripting.EmbeddedJVM/Types/BaseType.cs new file mode 100644 index 0000000..270aa7b --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Types/ObjectReference.cs b/OpenSim.Scripting.EmbeddedJVM/Types/ObjectReference.cs new file mode 100644 index 0000000..da28eaa --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Types/PrimitiveTypes/Byte.cs b/OpenSim.Scripting.EmbeddedJVM/Types/PrimitiveTypes/Byte.cs new file mode 100644 index 0000000..1a3ecff --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Types/PrimitiveTypes/Char.cs b/OpenSim.Scripting.EmbeddedJVM/Types/PrimitiveTypes/Char.cs new file mode 100644 index 0000000..19002d4 --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Types/PrimitiveTypes/Float.cs b/OpenSim.Scripting.EmbeddedJVM/Types/PrimitiveTypes/Float.cs new file mode 100644 index 0000000..91f1679 --- /dev/null +++ b/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.Scripting.EmbeddedJVM/Types/PrimitiveTypes/Int.cs b/OpenSim.Scripting.EmbeddedJVM/Types/PrimitiveTypes/Int.cs new file mode 100644 index 0000000..4ecd325 --- /dev/null +++ b/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 | } | ||