From 1d5544a23a79c981cde44e6d49b73e07db407535 Mon Sep 17 00:00:00 2001 From: MW Date: Wed, 1 Aug 2007 20:11:42 +0000 Subject: Little bit more work on AllNewSceneObjectPart2 --- .../Environment/Scenes/AllNewSceneObjectPart2.cs | 37 +- .../Engines/JVMEngine/JVM/ClassInstance.cs | 2 +- .../scripting/Engines/JVMEngine/JVM/ClassRecord.cs | 146 ++-- .../Engines/JVMEngine/JVM/Interpreter.Logic.cs | 266 +++--- .../Engines/JVMEngine/JVM/Interpreter.Methods.cs | 18 +- .../scripting/Engines/JVMEngine/JVM/Interpreter.cs | 50 +- .../scripting/Engines/JVMEngine/JVM/Thread.cs | 32 +- .../LSLHandler/LSL_OPCODE_IL_processor.cs | 588 ++++++------- .../Engines/LSLEngine/LSLHandler/LSO_Parser.cs | 946 +++++++++++---------- 9 files changed, 1061 insertions(+), 1024 deletions(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Scenes/AllNewSceneObjectPart2.cs b/OpenSim/Region/Environment/Scenes/AllNewSceneObjectPart2.cs index cf511ae..3552f33 100644 --- a/OpenSim/Region/Environment/Scenes/AllNewSceneObjectPart2.cs +++ b/OpenSim/Region/Environment/Scenes/AllNewSceneObjectPart2.cs @@ -32,10 +32,10 @@ namespace OpenSim.Region.Environment.Scenes public uint BaseMask = FULL_MASK_PERMISSIONS; protected PrimitiveBaseShape m_Shape; + protected byte[] m_particleSystem = new byte[0]; protected AllNewSceneObjectGroup2 m_parentGroup; - #region Properties protected LLUUID m_uuid; @@ -271,6 +271,35 @@ namespace OpenSim.Region.Environment.Scenes } #endregion + #region Inventory + public void GetInventory(IClientAPI client, uint localID) + { + if (localID == this.m_localID) + { + client.SendTaskInventory(this.m_uuid, 0, new byte[0]); + } + } + #endregion + + public void UpdateExtraParam(ushort type, bool inUse, byte[] data) + { + this.m_Shape.ExtraParams = new byte[data.Length + 7]; + int i = 0; + uint length = (uint)data.Length; + this.m_Shape.ExtraParams[i++] = 1; + this.m_Shape.ExtraParams[i++] = (byte)(type % 256); + this.m_Shape.ExtraParams[i++] = (byte)((type >> 8) % 256); + + this.m_Shape.ExtraParams[i++] = (byte)(length % 256); + this.m_Shape.ExtraParams[i++] = (byte)((length >> 8) % 256); + this.m_Shape.ExtraParams[i++] = (byte)((length >> 16) % 256); + this.m_Shape.ExtraParams[i++] = (byte)((length >> 24) % 256); + Array.Copy(data, 0, this.m_Shape.ExtraParams, i, data.Length); + + //this.ScheduleFullUpdate(); + } + + #region Texture /// /// @@ -282,6 +311,12 @@ namespace OpenSim.Region.Environment.Scenes } #endregion + public void AddNewParticleSystem(libsecondlife.Primitive.ParticleSystem pSystem) + { + this.m_particleSystem = pSystem.GetBytes(); + } + + #region Position /// /// diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs index be29ee9..4b734a3 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs @@ -34,7 +34,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { public class ClassInstance : Object { - public int size; + public int Size; public ClassRecord ClassRec; public Dictionary Fields = new Dictionary(); diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs index a609a40..4b2aec3 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs @@ -36,23 +36,23 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { public class ClassRecord { - private ushort _majorVersion; - private ushort _minorVersion; - private ushort _constantPoolCount; - private ushort _accessFlags; - private ushort _thisClass; - private ushort _supperClass; - private ushort _interfaceCount; - private ushort _fieldCount; - private ushort _methodCount; + private ushort m_majorVersion; + private ushort m_minorVersion; + private ushort m_constantPoolCount; + private ushort m_accessFlags; + private ushort m_thisClass; + private ushort m_supperClass; + private ushort m_interfaceCount; + private ushort m_fieldCount; + private ushort m_methodCount; //private ushort _attributeCount; //private string _name; public Dictionary StaticFields = new Dictionary(); - public PoolClass mClass; + public PoolClass MClass; - public List _constantsPool = new List(); - private List _methodsList = new List(); - private List _fieldList = new List(); + public List m_constantsPool = new List(); + private List m_methodsList = new List(); + private List m_fieldList = new List(); public ClassRecord() { @@ -80,11 +80,11 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { int i = 0; i += 4; - _minorVersion = (ushort)((data[i++] << 8) + data[i++]); - _majorVersion = (ushort)((data[i++] << 8) + data[i++]); - _constantPoolCount = (ushort)((data[i++] << 8) + data[i++]); - Console.WriteLine("there should be " + _constantPoolCount + " items in the pool"); - for (int count = 0; count < (_constantPoolCount - 1); count++) + m_minorVersion = (ushort)((data[i++] << 8) + data[i++]); + m_majorVersion = (ushort)((data[i++] << 8) + data[i++]); + m_constantPoolCount = (ushort)((data[i++] << 8) + data[i++]); + Console.WriteLine("there should be " + m_constantPoolCount + " items in the pool"); + for (int count = 0; count < (m_constantPoolCount - 1); count++) { //read in the constant pool byte pooltype = data[i++]; @@ -98,7 +98,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM // Console.WriteLine("new utf8 type, length is " + uLength); PoolUtf8 utf8 = new PoolUtf8(); utf8.readValue(data, ref i, uLength); - this._constantsPool.Add(utf8); + this.m_constantsPool.Add(utf8); break; case 3: //Int break; @@ -107,74 +107,74 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM case 7: //Class PoolClass pClass = new PoolClass(this); pClass.readValue(data, ref i); - this._constantsPool.Add(pClass); + this.m_constantsPool.Add(pClass); break; case 9: //FieldRef PoolFieldRef pField = new PoolFieldRef(this); pField.readValue(data, ref i); - this._constantsPool.Add(pField); + this.m_constantsPool.Add(pField); break; case 10: //Method PoolMethodRef pMeth = new PoolMethodRef(this); pMeth.readValue(data, ref i); - this._constantsPool.Add(pMeth); + this.m_constantsPool.Add(pMeth); break; case 12: //NamedType PoolNamedType pNamed = new PoolNamedType(this); pNamed.readValue(data, ref i); - this._constantsPool.Add(pNamed); + this.m_constantsPool.Add(pNamed); break; } } - _accessFlags = (ushort)((data[i++] << 8) + data[i++]); - _thisClass = (ushort)((data[i++] << 8) + data[i++]); - _supperClass = (ushort)((data[i++] << 8) + data[i++]); + m_accessFlags = (ushort)((data[i++] << 8) + data[i++]); + m_thisClass = (ushort)((data[i++] << 8) + data[i++]); + m_supperClass = (ushort)((data[i++] << 8) + data[i++]); - if (this._constantsPool[this._thisClass - 1] is PoolClass) + if (this.m_constantsPool[this.m_thisClass - 1] is PoolClass) { - this.mClass = ((PoolClass)this._constantsPool[this._thisClass - 1]); + this.MClass = ((PoolClass)this.m_constantsPool[this.m_thisClass - 1]); } - _interfaceCount = (ushort)((data[i++] << 8) + data[i++]); + m_interfaceCount = (ushort)((data[i++] << 8) + data[i++]); //should now read in the info for each interface - _fieldCount = (ushort)((data[i++] << 8) + data[i++]); + m_fieldCount = (ushort)((data[i++] << 8) + data[i++]); //should now read in the info for each field - for (int count = 0; count < _fieldCount; count++) + for (int count = 0; count < m_fieldCount; count++) { FieldInfo fieldInf = new FieldInfo(this); fieldInf.ReadData(data, ref i); - this._fieldList.Add(fieldInf); + this.m_fieldList.Add(fieldInf); } - _methodCount = (ushort)((data[i++] << 8) + data[i++]); - for (int count = 0; count < _methodCount; count++) + m_methodCount = (ushort)((data[i++] << 8) + data[i++]); + for (int count = 0; count < m_methodCount; count++) { MethodInfo methInf = new MethodInfo(this); methInf.ReadData(data, ref i); - this._methodsList.Add(methInf); + this.m_methodsList.Add(methInf); } } public void AddMethodsToMemory(MethodMemory memory) { - for (int count = 0; count < _methodCount; count++) + for (int count = 0; count < m_methodCount; count++) { - this._methodsList[count].AddMethodCode(memory); + this.m_methodsList[count].AddMethodCode(memory); } } public bool StartMethod(Thread thread, string methodName) { - for (int count = 0; count < _methodCount; count++) + for (int count = 0; count < m_methodCount; count++) { - if (this._constantsPool[this._methodsList[count].NameIndex - 1] is PoolUtf8) + if (this.m_constantsPool[this.m_methodsList[count].NameIndex - 1] is PoolUtf8) { - if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value == methodName) + if (((PoolUtf8)this.m_constantsPool[this.m_methodsList[count].NameIndex - 1]).Value == methodName) { //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value); - thread.SetPC(this._methodsList[count].CodePointer); + thread.SetPC(this.m_methodsList[count].CodePointer); return true; } } @@ -185,32 +185,32 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void PrintToConsole() { Console.WriteLine("Class File:"); - Console.WriteLine("Major version: " + _majorVersion); - Console.WriteLine("Minor version: " + _minorVersion); - Console.WriteLine("Pool size: " + _constantPoolCount); + Console.WriteLine("Major version: " + m_majorVersion); + Console.WriteLine("Minor version: " + m_minorVersion); + Console.WriteLine("Pool size: " + m_constantPoolCount); - for (int i = 0; i < _constantsPool.Count; i++) + for (int i = 0; i < m_constantsPool.Count; i++) { - this._constantsPool[i].Print(); + this.m_constantsPool[i].Print(); } - Console.WriteLine("Access flags: " + _accessFlags); - Console.WriteLine("This class: " + _thisClass); - Console.WriteLine("Super class: " + _supperClass); + Console.WriteLine("Access flags: " + m_accessFlags); + Console.WriteLine("This class: " + m_thisClass); + Console.WriteLine("Super class: " + m_supperClass); - for (int count = 0; count < _fieldCount; count++) + for (int count = 0; count < m_fieldCount; count++) { Console.WriteLine(); - this._fieldList[count].Print(); + this.m_fieldList[count].Print(); } - for (int count = 0; count < _methodCount; count++) + for (int count = 0; count < m_methodCount; count++) { Console.WriteLine(); - this._methodsList[count].Print(); + this.m_methodsList[count].Print(); } - Console.WriteLine("class name is " + this.mClass.Name.Value); + Console.WriteLine("class name is " + this.MClass.Name.Value); } public static byte[] ReadFully(Stream stream) @@ -294,9 +294,9 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public override void Print() { - this.Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]); + this.Name = ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]); Console.Write("Class type: " + namePointer); - Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value); + Console.WriteLine(" // " + ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]).Value); } } @@ -322,8 +322,8 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public override void Print() { - this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]); - this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]); + this.mNameType = ((PoolNamedType)this.parent.m_constantsPool[nameTypePointer - 1]); + this.mClass = ((PoolClass)this.parent.m_constantsPool[classPointer - 1]); Console.WriteLine("FieldRef type: " + classPointer + " , " + nameTypePointer); } } @@ -349,8 +349,8 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public override void Print() { - this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]); - this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]); + this.mNameType = ((PoolNamedType)this.parent.m_constantsPool[nameTypePointer - 1]); + this.mClass = ((PoolClass)this.parent.m_constantsPool[classPointer - 1]); Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); } } @@ -376,10 +376,10 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public override void Print() { - Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]); - Type = ((PoolUtf8)this.parent._constantsPool[typePointer - 1]); + Name = ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]); + Type = ((PoolUtf8)this.parent.m_constantsPool[typePointer - 1]); Console.Write("Named type: " + namePointer + " , " + typePointer); - Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value); + Console.WriteLine(" // " + ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]).Value); } } @@ -426,8 +426,8 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { Console.WriteLine("Method Info Struct: "); Console.WriteLine("AccessFlags: " + AccessFlags); - Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); - Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent._constantsPool[DescriptorIndex - 1]).Value); + Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); + Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value); Console.WriteLine("Attribute Count:" + AttributeCount); for (int i = 0; i < AttributeCount; i++) { @@ -480,7 +480,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void Print() { Console.WriteLine("Method Attribute: "); - Console.WriteLine("Name Index: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); + Console.WriteLine("Name Index: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); Console.WriteLine("Length: " + Length); Console.WriteLine("MaxStack: " + MaxStack); Console.WriteLine("MaxLocals: " + MaxLocals); @@ -522,7 +522,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void Print() { - Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); + Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); } } @@ -570,22 +570,22 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { Console.WriteLine("Field Info Struct: "); Console.WriteLine("AccessFlags: " + AccessFlags); - Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); - Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent._constantsPool[DescriptorIndex - 1]).Value); + Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); + Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value); Console.WriteLine("Attribute Count:" + AttributeCount); //if static, add to static field list // if (this.AccessFlags == 9) //public and static if ((this.AccessFlags & 0x08) != 0) { - switch (((PoolUtf8)this.parent._constantsPool[DescriptorIndex - 1]).Value) + switch (((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value) { case "I": Int newin = new Int(); - this.parent.StaticFields.Add(((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value, newin); + this.parent.StaticFields.Add(((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value, newin); break; case "F": Float newfl = new Float(); - this.parent.StaticFields.Add(((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value, newfl); + this.parent.StaticFields.Add(((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value, newfl); break; } @@ -622,7 +622,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void Print() { - Console.WriteLine("FieldAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); + Console.WriteLine("FieldAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); } } } diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs index 6f8d70c..ef6570d 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs @@ -45,293 +45,293 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM case (byte)(byte)OpCode.iconst_m1: Int m_int = new Int(); m_int.mValue = -1; - this._mThread.currentFrame.OpStack.Push(m_int); + this.m_thread.m_currentFrame.OpStack.Push(m_int); result = true; break; case (byte)(byte)OpCode.iconst_0: m_int = new Int(); m_int.mValue = 0; - this._mThread.currentFrame.OpStack.Push(m_int); + this.m_thread.m_currentFrame.OpStack.Push(m_int); result = true; break; case (byte)(byte)OpCode.iconst_1: m_int = new Int(); m_int.mValue = 1; - this._mThread.currentFrame.OpStack.Push(m_int); + this.m_thread.m_currentFrame.OpStack.Push(m_int); result = true; break; case (byte)(byte)OpCode.iconst_2: m_int = new Int(); m_int.mValue = 2; - this._mThread.currentFrame.OpStack.Push(m_int); + this.m_thread.m_currentFrame.OpStack.Push(m_int); result = true; break; case (byte)(byte)OpCode.iconst_3: m_int = new Int(); m_int.mValue = 3; - this._mThread.currentFrame.OpStack.Push(m_int); + this.m_thread.m_currentFrame.OpStack.Push(m_int); break; case (byte)(byte)OpCode.iconst_4: m_int = new Int(); m_int.mValue = 4; - this._mThread.currentFrame.OpStack.Push(m_int); + this.m_thread.m_currentFrame.OpStack.Push(m_int); result = true; break; case (byte)OpCode.iconst_5: m_int = new Int(); m_int.mValue = 5; - this._mThread.currentFrame.OpStack.Push(m_int); + this.m_thread.m_currentFrame.OpStack.Push(m_int); result = true; break; case (byte)OpCode.fconst_0: Float m_float = new Float(); m_float.mValue = 0.0f; - this._mThread.currentFrame.OpStack.Push(m_float); + this.m_thread.m_currentFrame.OpStack.Push(m_float); result = true; break; case (byte)OpCode.fconst_1: m_float = new Float(); m_float.mValue = 1.0f; - this._mThread.currentFrame.OpStack.Push(m_float); + this.m_thread.m_currentFrame.OpStack.Push(m_float); result = true; break; case (byte)OpCode.fconst_2: m_float = new Float(); m_float.mValue = 2.0f; - this._mThread.currentFrame.OpStack.Push(m_float); + this.m_thread.m_currentFrame.OpStack.Push(m_float); result = true; break; case (byte)OpCode.bipush: //is this right? this should be pushing a byte onto stack not int? - int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]; + int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]; Int pushInt = new Int(); pushInt.mValue = pushvalue; - this._mThread.currentFrame.OpStack.Push(pushInt); - this._mThread.PC++; + this.m_thread.m_currentFrame.OpStack.Push(pushInt); + this.m_thread.PC++; result = true; break; case (byte)OpCode.sipush: - short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); + short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]); Int pushInt2 = new Int(); pushInt2.mValue = pushvalue2; - this._mThread.currentFrame.OpStack.Push(pushInt2); - this._mThread.PC += 2; + this.m_thread.m_currentFrame.OpStack.Push(pushInt2); + this.m_thread.PC += 2; result = true; break; case (byte)OpCode.fload: - short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC])); + short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC])); Float fload = new Float(); - if (this._mThread.currentFrame.LocalVariables[findex1] != null) + if (this.m_thread.m_currentFrame.LocalVariables[findex1] != null) { - if (this._mThread.currentFrame.LocalVariables[findex1] is Float) + if (this.m_thread.m_currentFrame.LocalVariables[findex1] is Float) { - fload.mValue = ((Float)this._mThread.currentFrame.LocalVariables[findex1]).mValue; - this._mThread.currentFrame.OpStack.Push(fload); + fload.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[findex1]).mValue; + this.m_thread.m_currentFrame.OpStack.Push(fload); } } - this._mThread.PC++; + this.m_thread.PC++; result = true; break; case (byte)OpCode.iload_0: - if (this._mThread.currentFrame.LocalVariables[0] != null) + if (this.m_thread.m_currentFrame.LocalVariables[0] != null) { - if (this._mThread.currentFrame.LocalVariables[0] is Int) + if (this.m_thread.m_currentFrame.LocalVariables[0] is Int) { Int newInt = new Int(); - newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue; - this._mThread.currentFrame.OpStack.Push(newInt); + newInt.mValue = ((Int)this.m_thread.m_currentFrame.LocalVariables[0]).mValue; + this.m_thread.m_currentFrame.OpStack.Push(newInt); } } result = true; break; case (byte)OpCode.iload_1: - if (this._mThread.currentFrame.LocalVariables[1] != null) + if (this.m_thread.m_currentFrame.LocalVariables[1] != null) { - if (this._mThread.currentFrame.LocalVariables[1] is Int) + if (this.m_thread.m_currentFrame.LocalVariables[1] is Int) { Int newInt = new Int(); - newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue; - this._mThread.currentFrame.OpStack.Push(newInt); + newInt.mValue = ((Int)this.m_thread.m_currentFrame.LocalVariables[1]).mValue; + this.m_thread.m_currentFrame.OpStack.Push(newInt); } } result = true; break; case (byte)OpCode.fload_0: - if (this._mThread.currentFrame.LocalVariables[0] != null) + if (this.m_thread.m_currentFrame.LocalVariables[0] != null) { - if (this._mThread.currentFrame.LocalVariables[0] is Float) + if (this.m_thread.m_currentFrame.LocalVariables[0] is Float) { Float newfloat = new Float(); - newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue; - this._mThread.currentFrame.OpStack.Push(newfloat); + newfloat.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[0]).mValue; + this.m_thread.m_currentFrame.OpStack.Push(newfloat); } } result = true; break; case (byte)OpCode.fload_1: - if (this._mThread.currentFrame.LocalVariables[1] != null) + if (this.m_thread.m_currentFrame.LocalVariables[1] != null) { - if (this._mThread.currentFrame.LocalVariables[1] is Float) + if (this.m_thread.m_currentFrame.LocalVariables[1] is Float) { Float newfloat = new Float(); - newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue; - this._mThread.currentFrame.OpStack.Push(newfloat); + newfloat.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[1]).mValue; + this.m_thread.m_currentFrame.OpStack.Push(newfloat); } } result = true; break; case (byte)OpCode.fload_2: - if (this._mThread.currentFrame.LocalVariables[2] != null) + if (this.m_thread.m_currentFrame.LocalVariables[2] != null) { - if (this._mThread.currentFrame.LocalVariables[2] is Float) + if (this.m_thread.m_currentFrame.LocalVariables[2] is Float) { Float newfloat = new Float(); - newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[2]).mValue; - this._mThread.currentFrame.OpStack.Push(newfloat); + newfloat.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[2]).mValue; + this.m_thread.m_currentFrame.OpStack.Push(newfloat); } } result = true; break; case (byte)OpCode.fload_3: - if (this._mThread.currentFrame.LocalVariables[3] != null) + if (this.m_thread.m_currentFrame.LocalVariables[3] != null) { - if (this._mThread.currentFrame.LocalVariables[3] is Float) + if (this.m_thread.m_currentFrame.LocalVariables[3] is Float) { Float newfloat = new Float(); - newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[3]).mValue; - this._mThread.currentFrame.OpStack.Push(newfloat); + newfloat.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[3]).mValue; + this.m_thread.m_currentFrame.OpStack.Push(newfloat); } } result = true; break; case (byte)OpCode.istore: - short findex3 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC])); - BaseType istor = this._mThread.currentFrame.OpStack.Pop(); + short findex3 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC])); + BaseType istor = this.m_thread.m_currentFrame.OpStack.Pop(); if (istor is Int) { - this._mThread.currentFrame.LocalVariables[findex3] = (Int)istor; + this.m_thread.m_currentFrame.LocalVariables[findex3] = (Int)istor; } - this._mThread.PC++; + this.m_thread.PC++; result = true; break; case (byte)OpCode.fstore: - short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC])); - BaseType fstor = this._mThread.currentFrame.OpStack.Pop(); + short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC])); + BaseType fstor = this.m_thread.m_currentFrame.OpStack.Pop(); if (fstor is Float) { - this._mThread.currentFrame.LocalVariables[findex] = (Float)fstor; + this.m_thread.m_currentFrame.LocalVariables[findex] = (Float)fstor; } - this._mThread.PC++; + this.m_thread.PC++; result = true; break; case (byte)OpCode.istore_0: - BaseType baset = this._mThread.currentFrame.OpStack.Pop(); + BaseType baset = this.m_thread.m_currentFrame.OpStack.Pop(); if (baset is Int) { - this._mThread.currentFrame.LocalVariables[0] = (Int)baset; + this.m_thread.m_currentFrame.LocalVariables[0] = (Int)baset; } result = true; break; case (byte)OpCode.istore_1: - baset = this._mThread.currentFrame.OpStack.Pop(); + baset = this.m_thread.m_currentFrame.OpStack.Pop(); if (baset is Int) { - this._mThread.currentFrame.LocalVariables[1] = (Int)baset; + this.m_thread.m_currentFrame.LocalVariables[1] = (Int)baset; } result = true; break; case (byte)OpCode.fstore_0: - baset = this._mThread.currentFrame.OpStack.Pop(); + baset = this.m_thread.m_currentFrame.OpStack.Pop(); if (baset is Float) { - this._mThread.currentFrame.LocalVariables[0] = (Float)baset; + this.m_thread.m_currentFrame.LocalVariables[0] = (Float)baset; } result = true; break; case (byte)OpCode.fstore_1: - baset = this._mThread.currentFrame.OpStack.Pop(); + baset = this.m_thread.m_currentFrame.OpStack.Pop(); if (baset is Float) { - this._mThread.currentFrame.LocalVariables[1] = (Float)baset; + this.m_thread.m_currentFrame.LocalVariables[1] = (Float)baset; } result = true; break; case (byte)OpCode.fstore_2: - baset = this._mThread.currentFrame.OpStack.Pop(); + baset = this.m_thread.m_currentFrame.OpStack.Pop(); if (baset is Float) { - this._mThread.currentFrame.LocalVariables[2] = (Float)baset; + this.m_thread.m_currentFrame.LocalVariables[2] = (Float)baset; } result = true; break; case (byte)OpCode.fstore_3: - baset = this._mThread.currentFrame.OpStack.Pop(); + baset = this.m_thread.m_currentFrame.OpStack.Pop(); if (baset is Float) { - this._mThread.currentFrame.LocalVariables[3] = (Float)baset; + this.m_thread.m_currentFrame.LocalVariables[3] = (Float)baset; } result = true; break; case (byte)OpCode.pop: - this._mThread.currentFrame.OpStack.Pop(); + this.m_thread.m_currentFrame.OpStack.Pop(); result = true; break; case (byte)OpCode.fadd: - BaseType bf2 = this._mThread.currentFrame.OpStack.Pop(); - BaseType bf1 = this._mThread.currentFrame.OpStack.Pop(); + BaseType bf2 = this.m_thread.m_currentFrame.OpStack.Pop(); + BaseType bf1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (bf1 is Float && bf2 is Float) { Float nflt = new Float(); nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue; - this._mThread.currentFrame.OpStack.Push(nflt); + this.m_thread.m_currentFrame.OpStack.Push(nflt); } result = true; break; case (byte)OpCode.fsub: - BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop(); - BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop(); + BaseType bsf2 = this.m_thread.m_currentFrame.OpStack.Pop(); + BaseType bsf1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (bsf1 is Float && bsf2 is Float) { Float resf = new Float(); resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue; - this._mThread.currentFrame.OpStack.Push(resf); + this.m_thread.m_currentFrame.OpStack.Push(resf); } result = true; break; case (byte)OpCode.imul: //check the order of the two values off the stack is correct - BaseType bs2 = this._mThread.currentFrame.OpStack.Pop(); - BaseType bs1 = this._mThread.currentFrame.OpStack.Pop(); + BaseType bs2 = this.m_thread.m_currentFrame.OpStack.Pop(); + BaseType bs1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (bs1 is Int && bs2 is Int) { Int nInt = new Int(); nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue; - this._mThread.currentFrame.OpStack.Push(nInt); + this.m_thread.m_currentFrame.OpStack.Push(nInt); } result = true; break; case (byte)OpCode.iinc: - if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null) + if (this.m_thread.m_currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]] != null) { - if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int) + if (this.m_thread.m_currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]] is Int) { - ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]; + ((Int)this.m_thread.m_currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]]).mValue += (sbyte)GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]; } } - this._mThread.PC += 2; + this.m_thread.PC += 2; result = true; break; case (byte)OpCode.f2i: - BaseType conv1 = this._mThread.currentFrame.OpStack.Pop(); + BaseType conv1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (conv1 is Float) { Int newconv = new Int(); newconv.mValue = (int)((Float)conv1).mValue; - this._mThread.currentFrame.OpStack.Push(newconv); + this.m_thread.m_currentFrame.OpStack.Push(newconv); } result = true; break; case (byte)OpCode.fcmpl: - BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop(); - BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop(); + BaseType flcom2 = this.m_thread.m_currentFrame.OpStack.Pop(); + BaseType flcom1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (flcom1 is Float && flcom2 is Float) { Int compres = new Int(); @@ -347,13 +347,13 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { compres.mValue = 0; } - this._mThread.currentFrame.OpStack.Push(compres); + this.m_thread.m_currentFrame.OpStack.Push(compres); } result = true; break; case (byte)OpCode.fcmpg: - flcom2 = this._mThread.currentFrame.OpStack.Pop(); - flcom1 = this._mThread.currentFrame.OpStack.Pop(); + flcom2 = this.m_thread.m_currentFrame.OpStack.Pop(); + flcom1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (flcom1 is Float && flcom2 is Float) { Int compres = new Int(); @@ -369,54 +369,54 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { compres.mValue = 0; } - this._mThread.currentFrame.OpStack.Push(compres); + this.m_thread.m_currentFrame.OpStack.Push(compres); } result = true; break; case (byte)OpCode.ifge: - short compareoffset2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); - BaseType compe1 = this._mThread.currentFrame.OpStack.Pop(); + short compareoffset2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]); + BaseType compe1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (compe1 is Int) { if (((Int)compe1).mValue >= 0) { - this._mThread.PC += -1 + compareoffset2; + this.m_thread.PC += -1 + compareoffset2; } else { - this._mThread.PC += 2; + this.m_thread.PC += 2; } } else { - this._mThread.PC += 2; + this.m_thread.PC += 2; } result = true; break; case (byte)OpCode.ifle: - short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); - BaseType comp1 = this._mThread.currentFrame.OpStack.Pop(); + short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]); + BaseType comp1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (comp1 is Int) { if (((Int)comp1).mValue <= 0) { - this._mThread.PC += -1 + compareoffset1; + this.m_thread.PC += -1 + compareoffset1; } else { - this._mThread.PC += 2; + this.m_thread.PC += 2; } } else { - this._mThread.PC += 2; + this.m_thread.PC += 2; } result = true; break; case (byte)OpCode.if_icmpge: - short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); - BaseType bc2 = this._mThread.currentFrame.OpStack.Pop(); - BaseType bc1 = this._mThread.currentFrame.OpStack.Pop(); + short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]); + BaseType bc2 = this.m_thread.m_currentFrame.OpStack.Pop(); + BaseType bc1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (bc1 is Int && bc2 is Int) { //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue); @@ -424,25 +424,25 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { // Console.WriteLine("branch compare true , offset is " +compareoffset); // Console.WriteLine("current PC is " + this._mThread.PC); - this._mThread.PC += -1 + compareoffset; + this.m_thread.PC += -1 + compareoffset; //Console.WriteLine("new PC is " + this._mThread.PC); } else { //Console.WriteLine("branch compare false"); - this._mThread.PC += 2; + this.m_thread.PC += 2; } } else { - this._mThread.PC += 2; + this.m_thread.PC += 2; } result = true; break; case (byte)OpCode.if_icmple: - short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); - BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop(); - BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop(); + short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]); + BaseType bcl2 = this.m_thread.m_currentFrame.OpStack.Pop(); + BaseType bcl1 = this.m_thread.m_currentFrame.OpStack.Pop(); if (bcl1 is Int && bcl2 is Int) { //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue); @@ -450,47 +450,47 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { // Console.WriteLine("branch compare true , offset is " + compareloffset); // Console.WriteLine("current PC is " + this._mThread.PC); - this._mThread.PC += -1 + compareloffset; + this.m_thread.PC += -1 + compareloffset; // Console.WriteLine("new PC is " + this._mThread.PC); } else { //Console.WriteLine("branch compare false"); - this._mThread.PC += 2; + this.m_thread.PC += 2; } } else { - this._mThread.PC += 2; + this.m_thread.PC += 2; } result = true; break; case (byte)OpCode._goto: - short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); - this._mThread.PC += -1 + offset; + short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]); + this.m_thread.PC += -1 + offset; result = true; break; case (byte)OpCode.getstatic: - short fieldrefIndex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); - if (this._mThread.currentClass._constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef) + short fieldrefIndex = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]); + if (this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef) { - if (((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value) + if (((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mClass.Name.Value == this.m_thread.currentClass.MClass.Name.Value) { //from this class - if (this._mThread.currentClass.StaticFields.ContainsKey(((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value)) + if (this.m_thread.currentClass.StaticFields.ContainsKey(((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value)) { - if (this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Float) + if (this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Float) { Float retFloat = new Float(); - retFloat.mValue = ((Float)this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value]).mValue; - this._mThread.currentFrame.OpStack.Push(retFloat); + retFloat.mValue = ((Float)this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value]).mValue; + this.m_thread.m_currentFrame.OpStack.Push(retFloat); } - else if (this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Int) + else if (this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Int) { Int retInt = new Int(); - retInt.mValue = ((Int)this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value]).mValue; + retInt.mValue = ((Int)this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value]).mValue; // Console.WriteLine("getting static field, " + retInt.mValue); - this._mThread.currentFrame.OpStack.Push(retInt); + this.m_thread.m_currentFrame.OpStack.Push(retInt); } } } @@ -499,36 +499,36 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM //get from a different class } } - this._mThread.PC += 2; + this.m_thread.PC += 2; result = true; break; case (byte)OpCode.putstatic: - fieldrefIndex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]); - BaseType addstatic = this._mThread.currentFrame.OpStack.Pop(); - if (this._mThread.currentClass._constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef) + fieldrefIndex = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]); + BaseType addstatic = this.m_thread.m_currentFrame.OpStack.Pop(); + if (this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef) { - if (((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value) + if (((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mClass.Name.Value == this.m_thread.currentClass.MClass.Name.Value) { // this class - if (this._mThread.currentClass.StaticFields.ContainsKey(((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value)) + if (this.m_thread.currentClass.StaticFields.ContainsKey(((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value)) { if (addstatic is Float) { - if (this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Float) + if (this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Float) { Float newf = new Float(); newf.mValue = ((Float)addstatic).mValue; - this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] = newf; + this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] = newf; } } else if (addstatic is Int) { - if (this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Int) + if (this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Int) { //Console.WriteLine("setting static field to " + ((Int)addstatic).mValue); Int newi = new Int(); newi.mValue = ((Int)addstatic).mValue; - this._mThread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this._mThread.currentClass._constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] = newi; + this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] = newi; } } } @@ -538,7 +538,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM // a different class } } - this._mThread.PC += 2; + this.m_thread.PC += 2; result = true; break; diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs index 6b85fcc..42fd299 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs @@ -46,10 +46,10 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM switch (opcode) { case 184: - short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]); - if (this._mThread.currentClass._constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef) + short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC+1]); + if (this.m_thread.currentClass.m_constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef) { - string typ = ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value; + string typ = ((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mNameType.Type.Value; string typeparam = ""; string typereturn = ""; int firstbrak = 0; @@ -58,16 +58,16 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM secondbrak = typ.LastIndexOf(')'); typeparam = typ.Substring(firstbrak + 1, secondbrak - firstbrak - 1); typereturn = typ.Substring(secondbrak + 1, typ.Length - secondbrak - 1); - if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value) + if (((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mClass.Name.Value == this.m_thread.currentClass.MClass.Name.Value) { //calling a method in this class if (typeparam.Length == 0) { - this._mThread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, (this._mThread.PC + 2)); + this.m_thread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mNameType.Name.Value, (this.m_thread.PC + 2)); } else { - this._mThread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this._mThread.PC + 2)); + this.m_thread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this.m_thread.PC + 2)); } } else @@ -75,15 +75,15 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM //calling a method of a different class // OpenSimAPI Class - if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI") + if (((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI") { - this._mThread.scriptInfo.api.CallMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, null); + this.m_thread.scriptInfo.api.CallMethod(((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mNameType.Name.Value, null); } } } else { - this._mThread.PC += 2; + this.m_thread.PC += 2; } result = true; break; diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.cs index 9961cbd..e718328 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.cs @@ -37,17 +37,17 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { private partial class Interpreter { - private Thread _mThread; + private Thread m_thread; public Interpreter(Thread parentThread) { - _mThread = parentThread; + m_thread = parentThread; } public bool Excute() { bool run = true; - byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC++]; + byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC++]; // Console.WriteLine("opCode is: " + currentOpCode); bool handled = false; @@ -60,64 +60,64 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { if (currentOpCode == 172) { - if (this._mThread.stack.StackFrames.Count > 1) + if (this.m_thread.stack.StackFrames.Count > 1) { Console.WriteLine("returning int from function"); - int retPC1 = this._mThread.currentFrame.ReturnPC; - BaseType bas1 = this._mThread.currentFrame.OpStack.Pop(); - this._mThread.stack.StackFrames.Pop(); - this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); - this._mThread.PC = retPC1; + int retPC1 = this.m_thread.m_currentFrame.ReturnPC; + BaseType bas1 = this.m_thread.m_currentFrame.OpStack.Pop(); + this.m_thread.stack.StackFrames.Pop(); + this.m_thread.m_currentFrame = this.m_thread.stack.StackFrames.Peek(); + this.m_thread.PC = retPC1; if (bas1 is Int) { - this._mThread.currentFrame.OpStack.Push((Int)bas1); + this.m_thread.m_currentFrame.OpStack.Push((Int)bas1); } } else { // Console.WriteLine("No parent function so ending program"); - this._mThread.stack.StackFrames.Pop(); + this.m_thread.stack.StackFrames.Pop(); run = false; } handled = true; } if (currentOpCode == 174) { - if (this._mThread.stack.StackFrames.Count > 1) + if (this.m_thread.stack.StackFrames.Count > 1) { Console.WriteLine("returning float from function"); - int retPC1 = this._mThread.currentFrame.ReturnPC; - BaseType bas1 = this._mThread.currentFrame.OpStack.Pop(); - this._mThread.stack.StackFrames.Pop(); - this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); - this._mThread.PC = retPC1; + int retPC1 = this.m_thread.m_currentFrame.ReturnPC; + BaseType bas1 = this.m_thread.m_currentFrame.OpStack.Pop(); + this.m_thread.stack.StackFrames.Pop(); + this.m_thread.m_currentFrame = this.m_thread.stack.StackFrames.Peek(); + this.m_thread.PC = retPC1; if (bas1 is Float) { - this._mThread.currentFrame.OpStack.Push((Float)bas1); + this.m_thread.m_currentFrame.OpStack.Push((Float)bas1); } } else { // Console.WriteLine("No parent function so ending program"); - this._mThread.stack.StackFrames.Pop(); + this.m_thread.stack.StackFrames.Pop(); run = false; } handled = true; } if (currentOpCode == 177) { - if (this._mThread.stack.StackFrames.Count > 1) + if (this.m_thread.stack.StackFrames.Count > 1) { Console.WriteLine("returning from function"); - int retPC = this._mThread.currentFrame.ReturnPC; - this._mThread.stack.StackFrames.Pop(); - this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek(); - this._mThread.PC = retPC; + int retPC = this.m_thread.m_currentFrame.ReturnPC; + this.m_thread.stack.StackFrames.Pop(); + this.m_thread.m_currentFrame = this.m_thread.stack.StackFrames.Peek(); + this.m_thread.PC = retPC; } else { // Console.WriteLine("No parent function so ending program"); - this._mThread.stack.StackFrames.Pop(); + this.m_thread.stack.StackFrames.Pop(); run = false; } handled = true; diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Thread.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Thread.cs index eda2640..aad1f47 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Thread.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Thread.cs @@ -44,10 +44,10 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public static Scene World; private int PC = 0; private Stack stack; - private Interpreter mInterpreter; + private Interpreter m_Interpreter; public ClassRecord currentClass; public ClassInstance currentInstance; - private StackFrame currentFrame; + private StackFrame m_currentFrame; public int excutionCounter = 0; public bool running = false; @@ -55,7 +55,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public Thread() { - this.mInterpreter = new Interpreter(this); + this.m_Interpreter = new Interpreter(this); this.stack = new Stack(); } @@ -67,24 +67,24 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public void StartMethod(ClassRecord rec, string methName) { - currentFrame = new StackFrame(); - this.stack.StackFrames.Push(currentFrame); + m_currentFrame = new StackFrame(); + this.stack.StackFrames.Push(m_currentFrame); this.currentClass = rec; currentClass.StartMethod(this, methName); } public void StartMethod( string methName) { - currentFrame = new StackFrame(); - this.stack.StackFrames.Push(currentFrame); + m_currentFrame = new StackFrame(); + this.stack.StackFrames.Push(m_currentFrame); currentClass.StartMethod(this, methName); } public void JumpToStaticVoidMethod(string methName, int returnPC) { - currentFrame = new StackFrame(); - currentFrame.ReturnPC = returnPC; - this.stack.StackFrames.Push(currentFrame); + m_currentFrame = new StackFrame(); + m_currentFrame.ReturnPC = returnPC; + this.stack.StackFrames.Push(m_currentFrame); currentClass.StartMethod(this, methName); } @@ -92,11 +92,11 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM { if (param == "I") { - BaseType bs1 = currentFrame.OpStack.Pop(); - currentFrame = new StackFrame(); - currentFrame.ReturnPC = returnPC; - this.stack.StackFrames.Push(currentFrame); - currentFrame.LocalVariables[0] = ((Int)bs1); + BaseType bs1 = m_currentFrame.OpStack.Pop(); + m_currentFrame = new StackFrame(); + m_currentFrame.ReturnPC = returnPC; + this.stack.StackFrames.Push(m_currentFrame); + m_currentFrame.LocalVariables[0] = ((Int)bs1); currentClass.StartMethod(this, methName); } if (param == "F") @@ -113,7 +113,7 @@ namespace OpenSim.Region.Scripting.EmbeddedJVM public bool Excute() { excutionCounter++; - return this.mInterpreter.Excute(); + return this.m_Interpreter.Excute(); } } } diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs index 46f6845..e85c1d0 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs @@ -27,325 +27,325 @@ */ /* Original code: Tedd Hansen */ using System; - using System.Collections.Generic; - using System.Text; - using System.Reflection; - using System.Reflection.Emit; +using System.Collections.Generic; +using System.Text; +using System.Reflection; +using System.Reflection.Emit; - namespace OpenSim.Region.Scripting.LSL +namespace OpenSim.Region.Scripting.LSL +{ + partial class LSO_Parser + { + //LSO_Enums MyLSO_Enums = new LSO_Enums(); + + internal bool LSL_PROCESS_OPCODE(ILGenerator il) { - partial class LSO_Parser + + byte bp1; + UInt32 u32p1; + UInt16 opcode = br_read(1)[0]; + Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString()); + string idesc = ((LSO_Enums.Operation_Table)opcode).ToString(); + switch ((LSO_Enums.Operation_Table)opcode) { - //LSO_Enums MyLSO_Enums = new LSO_Enums(); - internal bool LSL_PROCESS_OPCODE(ILGenerator il) - { - - byte bp1; - UInt32 u32p1; - UInt16 opcode = br_read(1)[0]; - Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString()); - string idesc = ((LSO_Enums.Operation_Table)opcode).ToString(); - switch ((LSO_Enums.Operation_Table)opcode) - { + case LSO_Enums.Operation_Table.POP: + case LSO_Enums.Operation_Table.POPL: + case LSO_Enums.Operation_Table.POPV: + case LSO_Enums.Operation_Table.POPQ: + case LSO_Enums.Operation_Table.POPIP: + case LSO_Enums.Operation_Table.POPBP: + case LSO_Enums.Operation_Table.POPSP: + case LSO_Enums.Operation_Table.POPSLR: + // ignore -- builds callframe + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Pop);"); + il.Emit(OpCodes.Pop); + break; + case LSO_Enums.Operation_Table.POPARG: + Common.SendToDebug("Instruction " + idesc + ": Ignored"); + Common.SendToDebug("Instruction " + idesc + ": Description: Drop x bytes from the stack "); + Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); + break; - case LSO_Enums.Operation_Table.POP: - case LSO_Enums.Operation_Table.POPL: - case LSO_Enums.Operation_Table.POPV: - case LSO_Enums.Operation_Table.POPQ: - case LSO_Enums.Operation_Table.POPIP: - case LSO_Enums.Operation_Table.POPBP: - case LSO_Enums.Operation_Table.POPSP: - case LSO_Enums.Operation_Table.POPSLR: - // ignore -- builds callframe - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Pop);"); - il.Emit(OpCodes.Pop); - break; - case LSO_Enums.Operation_Table.POPARG: - Common.SendToDebug("Instruction " + idesc + ": Ignored"); - Common.SendToDebug("Instruction " + idesc + ": Description: Drop x bytes from the stack "); - Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); - break; + // LONG + case LSO_Enums.Operation_Table.STORE: + case LSO_Enums.Operation_Table.STORES: + case LSO_Enums.Operation_Table.STOREL: + case LSO_Enums.Operation_Table.STOREV: + case LSO_Enums.Operation_Table.STOREQ: + case LSO_Enums.Operation_Table.STOREG: + case LSO_Enums.Operation_Table.STOREGS: + case LSO_Enums.Operation_Table.STOREGL: + case LSO_Enums.Operation_Table.STOREGV: + case LSO_Enums.Operation_Table.STOREGQ: + case LSO_Enums.Operation_Table.LOADP: + case LSO_Enums.Operation_Table.LOADSP: + case LSO_Enums.Operation_Table.LOADLP: + case LSO_Enums.Operation_Table.LOADVP: + case LSO_Enums.Operation_Table.LOADQP: + case LSO_Enums.Operation_Table.PUSH: + case LSO_Enums.Operation_Table.PUSHS: + case LSO_Enums.Operation_Table.PUSHL: + case LSO_Enums.Operation_Table.PUSHV: + case LSO_Enums.Operation_Table.PUSHQ: + case LSO_Enums.Operation_Table.PUSHG: + case LSO_Enums.Operation_Table.PUSHGS: + case LSO_Enums.Operation_Table.PUSHGL: + case LSO_Enums.Operation_Table.PUSHGV: + case LSO_Enums.Operation_Table.PUSHGQ: + Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); + break; + // None + case LSO_Enums.Operation_Table.PUSHIP: + case LSO_Enums.Operation_Table.PUSHBP: + case LSO_Enums.Operation_Table.PUSHSP: + // Push Stack Top (Memory Address) to stack + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, " + myHeader.SP + ");"); + Common.SendToDebug("Instruction " + idesc + ": Description: Pushing Stack Top (Memory Address from header) to stack"); + il.Emit(OpCodes.Ldc_I4, myHeader.SP); + break; + // BYTE + case LSO_Enums.Operation_Table.PUSHARGB: + Common.SendToDebug("Param1: " + br_read(1)[0]); + break; + // INTEGER + case LSO_Enums.Operation_Table.PUSHARGI: + // TODO: What is size of integer? + u32p1 = BitConverter.ToUInt32(br_read(4), 0); + Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes.Ldc_I4, " + u32p1 + ");"); + Common.SendToDebug("Param1: " + u32p1); + il.Emit(OpCodes.Ldc_I4, u32p1); + break; + // FLOAT + case LSO_Enums.Operation_Table.PUSHARGF: + // TODO: What is size of float? + Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); + break; + // STRING + case LSO_Enums.Operation_Table.PUSHARGS: + string s = Read_String(); + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldstr, \"" + s + "\");"); + Common.SendToDebug("Param1: " + s); + il.Emit(OpCodes.Ldstr, s); + break; + // VECTOR z,y,x + case LSO_Enums.Operation_Table.PUSHARGV: + Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); + Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); + Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); + break; + // ROTATION s,z,y,x + case LSO_Enums.Operation_Table.PUSHARGQ: + Common.SendToDebug("Param1 S: " + BitConverter.ToUInt32(br_read(4), 0)); + Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); + Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); + Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); + break; + // LONG + case LSO_Enums.Operation_Table.PUSHARGE: + u32p1 = BitConverter.ToUInt32(br_read(4), 0); + //Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes., " + u32p1 + ");"); + Common.SendToDebug("Instruction " + idesc + ": Ignoring (not in use according to doc)"); + //Common.SendToDebug("Instruction " + idesc + ": Description: Pushes X bytes of $00 onto the stack (used to put space for local variable memory for a call)"); + Common.SendToDebug("Param1: " + u32p1); + //il.Emit(OpCodes.ldc_i4, u32p1); + //if (u32p1 > 0) { + //for (int _ic=0; _ic < u32p1; _ic++) + //{ + // Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldnull);"); + // il.Emit(OpCodes.Ldnull); + //} + break; + // BYTE + case LSO_Enums.Operation_Table.ADD: + bp1 = br_read(1)[0]; + Common.SendToDebug("Instruction " + idesc + ": Add type: " + ((LSO_Enums.OpCode_Add_TypeDefs)bp1).ToString()); + Common.SendToDebug("Param1: " + bp1); + switch ((LSO_Enums.OpCode_Add_TypeDefs)bp1) + { + case LSO_Enums.OpCode_Add_TypeDefs.String: + Common.SendToDebug("Instruction " + idesc + + ": il.Emit(OpCodes.Call, typeof(System.String).GetMethod(\"Concat\", new Type[] { typeof(object), typeof(object) }));"); + il.Emit(OpCodes.Call, typeof(System.String).GetMethod + ("Concat", new Type[] { typeof(object), typeof(object) })); - // LONG - case LSO_Enums.Operation_Table.STORE: - case LSO_Enums.Operation_Table.STORES: - case LSO_Enums.Operation_Table.STOREL: - case LSO_Enums.Operation_Table.STOREV: - case LSO_Enums.Operation_Table.STOREQ: - case LSO_Enums.Operation_Table.STOREG: - case LSO_Enums.Operation_Table.STOREGS: - case LSO_Enums.Operation_Table.STOREGL: - case LSO_Enums.Operation_Table.STOREGV: - case LSO_Enums.Operation_Table.STOREGQ: - case LSO_Enums.Operation_Table.LOADP: - case LSO_Enums.Operation_Table.LOADSP: - case LSO_Enums.Operation_Table.LOADLP: - case LSO_Enums.Operation_Table.LOADVP: - case LSO_Enums.Operation_Table.LOADQP: - case LSO_Enums.Operation_Table.PUSH: - case LSO_Enums.Operation_Table.PUSHS: - case LSO_Enums.Operation_Table.PUSHL: - case LSO_Enums.Operation_Table.PUSHV: - case LSO_Enums.Operation_Table.PUSHQ: - case LSO_Enums.Operation_Table.PUSHG: - case LSO_Enums.Operation_Table.PUSHGS: - case LSO_Enums.Operation_Table.PUSHGL: - case LSO_Enums.Operation_Table.PUSHGV: - case LSO_Enums.Operation_Table.PUSHGQ: - Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); - break; - // None - case LSO_Enums.Operation_Table.PUSHIP: - case LSO_Enums.Operation_Table.PUSHBP: - case LSO_Enums.Operation_Table.PUSHSP: - // Push Stack Top (Memory Address) to stack - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, " + myHeader.SP + ");"); - Common.SendToDebug("Instruction " + idesc + ": Description: Pushing Stack Top (Memory Address from header) to stack"); - il.Emit(OpCodes.Ldc_I4, myHeader.SP); - break; - // BYTE - case LSO_Enums.Operation_Table.PUSHARGB: - Common.SendToDebug("Param1: " + br_read(1)[0]); - break; - // INTEGER - case LSO_Enums.Operation_Table.PUSHARGI: - // TODO: What is size of integer? - u32p1 = BitConverter.ToUInt32(br_read(4), 0); - Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes.Ldc_I4, " + u32p1 + ");"); - Common.SendToDebug("Param1: " + u32p1); - il.Emit(OpCodes.Ldc_I4, u32p1); - break; - // FLOAT - case LSO_Enums.Operation_Table.PUSHARGF: - // TODO: What is size of float? - Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); - break; - // STRING - case LSO_Enums.Operation_Table.PUSHARGS: - string s = Read_String(); - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldstr, \"" + s + "\");"); - Common.SendToDebug("Param1: " + s); - il.Emit(OpCodes.Ldstr, s); break; - // VECTOR z,y,x - case LSO_Enums.Operation_Table.PUSHARGV: - Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); - Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); - Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); + case LSO_Enums.OpCode_Add_TypeDefs.UInt32: + default: + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Add);"); + il.Emit(OpCodes.Add); break; - // ROTATION s,z,y,x - case LSO_Enums.Operation_Table.PUSHARGQ: - Common.SendToDebug("Param1 S: " + BitConverter.ToUInt32(br_read(4), 0)); - Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); - Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); - Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); - break; - // LONG - case LSO_Enums.Operation_Table.PUSHARGE: - u32p1 = BitConverter.ToUInt32(br_read(4), 0); - //Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes., " + u32p1 + ");"); - Common.SendToDebug("Instruction " + idesc + ": Ignoring (not in use according to doc)"); - //Common.SendToDebug("Instruction " + idesc + ": Description: Pushes X bytes of $00 onto the stack (used to put space for local variable memory for a call)"); - Common.SendToDebug("Param1: " + u32p1); - //il.Emit(OpCodes.ldc_i4, u32p1); - //if (u32p1 > 0) { - //for (int _ic=0; _ic < u32p1; _ic++) - //{ - // Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldnull);"); - // il.Emit(OpCodes.Ldnull); - //} - break; - // BYTE - case LSO_Enums.Operation_Table.ADD: - bp1 = br_read(1)[0]; - Common.SendToDebug("Instruction " + idesc + ": Add type: " + ((LSO_Enums.OpCode_Add_TypeDefs)bp1).ToString()); - Common.SendToDebug("Param1: " + bp1); - switch ((LSO_Enums.OpCode_Add_TypeDefs)bp1) - { - case LSO_Enums.OpCode_Add_TypeDefs.String: - Common.SendToDebug("Instruction " + idesc - + ": il.Emit(OpCodes.Call, typeof(System.String).GetMethod(\"Concat\", new Type[] { typeof(object), typeof(object) }));"); - il.Emit(OpCodes.Call, typeof(System.String).GetMethod - ("Concat", new Type[] { typeof(object), typeof(object) })); + } - break; - case LSO_Enums.OpCode_Add_TypeDefs.UInt32: - default: - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Add);"); - il.Emit(OpCodes.Add); - break; - } - - //il.Emit(OpCodes.Add, p1); - break; - case LSO_Enums.Operation_Table.SUB: - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Sub);"); - bp1 = br_read(1)[0]; - Common.SendToDebug("Param1: " + bp1); - il.Emit(OpCodes.Sub); - //il.Emit(OpCodes.Sub, p1); - break; - case LSO_Enums.Operation_Table.MUL: - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Mul);"); + //il.Emit(OpCodes.Add, p1); + break; + case LSO_Enums.Operation_Table.SUB: + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Sub);"); bp1 = br_read(1)[0]; - Common.SendToDebug("Param1: " + bp1); - il.Emit(OpCodes.Mul); - //il.Emit(OpCodes.Mul, p1); - break; - case LSO_Enums.Operation_Table.DIV: - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Div);"); - bp1 = br_read(1)[0]; - Common.SendToDebug("Param1: " + bp1); - il.Emit(OpCodes.Div); - //il.Emit(OpCodes.Div, p1); - break; - case LSO_Enums.Operation_Table.EQ: - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ceq);"); - bp1 = br_read(1)[0]; - Common.SendToDebug("Param1: " + bp1); - il.Emit(OpCodes.Ceq); - //il.Emit(OpCodes.Ceq, p1); - break; - case LSO_Enums.Operation_Table.NEQ: - case LSO_Enums.Operation_Table.LEQ: - case LSO_Enums.Operation_Table.GEQ: - case LSO_Enums.Operation_Table.LESS: - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Clt_Un);"); - bp1 = br_read(1)[0]; - Common.SendToDebug("Param1: " + bp1); - il.Emit(OpCodes.Clt_Un); - //il.Emit(OpCodes.Clt, p1); - break; - case LSO_Enums.Operation_Table.GREATER: - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Cgt_Un);"); - bp1 = br_read(1)[0]; - Common.SendToDebug("Param1: " + bp1); - il.Emit(OpCodes.Cgt_Un); - //il.Emit(OpCodes.Cgt, p1); - break; - case LSO_Enums.Operation_Table.MOD: - case LSO_Enums.Operation_Table.BOOLOR: - bp1 = br_read(1)[0]; - Common.SendToDebug("Param1: " + bp1); - break; - // LONG - case LSO_Enums.Operation_Table.JUMP: - Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); - break; - // BYTE, LONG - case LSO_Enums.Operation_Table.JUMPIF: - case LSO_Enums.Operation_Table.JUMPNIF: - Common.SendToDebug("Param1: " + br_read(1)[0]); - Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0)); - break; - // LONG - case LSO_Enums.Operation_Table.STATE: - bp1 = br_read(1)[0]; - //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack - //il.Emit(OpCodes.Ldc_I4, 0); // Push index position - //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value - //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value - break; - case LSO_Enums.Operation_Table.CALL: - Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); - break; - // BYTE - case LSO_Enums.Operation_Table.CAST: - bp1 = br_read(1)[0]; - Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + ((LSO_Enums.OpCode_Cast_TypeDefs)bp1)); - Common.SendToDebug("Param1: " + bp1); - switch ((LSO_Enums.OpCode_Cast_TypeDefs)bp1) - { - case LSO_Enums.OpCode_Cast_TypeDefs.String: - Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Calli, typeof(System.Convert).GetMethod(\"ToString\", new Type[] { typeof(object) }));"); - //il.Emit(OpCodes.Box, typeof (UInt32)); - il.Emit(OpCodes.Calli, typeof(Common).GetMethod - ("Cast_ToString", new Type[] { typeof(object) })); - - //il.Emit(OpCodes.Box, typeof(System.UInt32) ); - //il.Emit(OpCodes.Box, typeof(string)); + Common.SendToDebug("Param1: " + bp1); + il.Emit(OpCodes.Sub); + //il.Emit(OpCodes.Sub, p1); + break; + case LSO_Enums.Operation_Table.MUL: + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Mul);"); + bp1 = br_read(1)[0]; + Common.SendToDebug("Param1: " + bp1); + il.Emit(OpCodes.Mul); + //il.Emit(OpCodes.Mul, p1); + break; + case LSO_Enums.Operation_Table.DIV: + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Div);"); + bp1 = br_read(1)[0]; + Common.SendToDebug("Param1: " + bp1); + il.Emit(OpCodes.Div); + //il.Emit(OpCodes.Div, p1); + break; + case LSO_Enums.Operation_Table.EQ: + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ceq);"); + bp1 = br_read(1)[0]; + Common.SendToDebug("Param1: " + bp1); + il.Emit(OpCodes.Ceq); + //il.Emit(OpCodes.Ceq, p1); + break; + case LSO_Enums.Operation_Table.NEQ: + case LSO_Enums.Operation_Table.LEQ: + case LSO_Enums.Operation_Table.GEQ: + case LSO_Enums.Operation_Table.LESS: + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Clt_Un);"); + bp1 = br_read(1)[0]; + Common.SendToDebug("Param1: " + bp1); + il.Emit(OpCodes.Clt_Un); + //il.Emit(OpCodes.Clt, p1); + break; + case LSO_Enums.Operation_Table.GREATER: + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Cgt_Un);"); + bp1 = br_read(1)[0]; + Common.SendToDebug("Param1: " + bp1); + il.Emit(OpCodes.Cgt_Un); + //il.Emit(OpCodes.Cgt, p1); + break; + case LSO_Enums.Operation_Table.MOD: + case LSO_Enums.Operation_Table.BOOLOR: + bp1 = br_read(1)[0]; + Common.SendToDebug("Param1: " + bp1); + break; + // LONG + case LSO_Enums.Operation_Table.JUMP: + Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); + break; + // BYTE, LONG + case LSO_Enums.Operation_Table.JUMPIF: + case LSO_Enums.Operation_Table.JUMPNIF: + Common.SendToDebug("Param1: " + br_read(1)[0]); + Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0)); + break; + // LONG + case LSO_Enums.Operation_Table.STATE: + bp1 = br_read(1)[0]; + //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack + //il.Emit(OpCodes.Ldc_I4, 0); // Push index position + //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value + //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value + break; + case LSO_Enums.Operation_Table.CALL: + Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); + break; + // BYTE + case LSO_Enums.Operation_Table.CAST: + bp1 = br_read(1)[0]; + Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + ((LSO_Enums.OpCode_Cast_TypeDefs)bp1)); + Common.SendToDebug("Param1: " + bp1); + switch ((LSO_Enums.OpCode_Cast_TypeDefs)bp1) + { + case LSO_Enums.OpCode_Cast_TypeDefs.String: + Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Calli, typeof(System.Convert).GetMethod(\"ToString\", new Type[] { typeof(object) }));"); + //il.Emit(OpCodes.Box, typeof (UInt32)); + il.Emit(OpCodes.Calli, typeof(Common).GetMethod + ("Cast_ToString", new Type[] { typeof(object) })); + + //il.Emit(OpCodes.Box, typeof(System.UInt32) ); + //il.Emit(OpCodes.Box, typeof(string)); + + //il.Emit(OpCodes.Conv_R8); + //il.Emit(OpCodes.Call, typeof(System.Convert).GetMethod + // ("ToString", new Type[] { typeof(float) })); - //il.Emit(OpCodes.Conv_R8); - //il.Emit(OpCodes.Call, typeof(System.Convert).GetMethod - // ("ToString", new Type[] { typeof(float) })); - - break; - default: - Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!"); - break; - } - break; - // LONG - case LSO_Enums.Operation_Table.STACKTOS: - case LSO_Enums.Operation_Table.STACKTOL: - Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); break; - // BYTE - case LSO_Enums.Operation_Table.PRINT: - case LSO_Enums.Operation_Table.CALLLIB: - Common.SendToDebug("Param1: " + br_read(1)[0]); + default: + Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!"); break; - // SHORT - case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE: - // TODO: What is size of short? - UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0); - Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString()); - Common.SendToDebug("Param1: " + U16p1); - switch ((LSO_Enums.BuiltIn_Functions)U16p1) - { - case LSO_Enums.BuiltIn_Functions.llSay: - Common.SendToDebug("Instruction " + idesc + " " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() - + ": Mapped to internal function"); - - //il.Emit(OpCodes.Ldstr, "INTERNAL COMMAND: llSay({0}, \"{1}\""); - //il.Emit(OpCodes.Call, typeof(IL_Helper).GetMethod("ReverseFormatString", - // new Type[] { typeof(string), typeof(UInt32), typeof(string) } - //)); + } + break; + // LONG + case LSO_Enums.Operation_Table.STACKTOS: + case LSO_Enums.Operation_Table.STACKTOL: + Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); + break; + // BYTE + case LSO_Enums.Operation_Table.PRINT: + case LSO_Enums.Operation_Table.CALLLIB: + Common.SendToDebug("Param1: " + br_read(1)[0]); + break; + // SHORT + case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE: + // TODO: What is size of short? + UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0); + Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString()); + Common.SendToDebug("Param1: " + U16p1); + switch ((LSO_Enums.BuiltIn_Functions)U16p1) + { + case LSO_Enums.BuiltIn_Functions.llSay: + Common.SendToDebug("Instruction " + idesc + " " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() + + ": Mapped to internal function"); + //il.Emit(OpCodes.Ldstr, "INTERNAL COMMAND: llSay({0}, \"{1}\""); + //il.Emit(OpCodes.Call, typeof(IL_Helper).GetMethod("ReverseFormatString", + // new Type[] { typeof(string), typeof(UInt32), typeof(string) } + //)); - //il.Emit(OpCodes.Pop); - //il.Emit(OpCodes.Call, - // typeof(Console).GetMethod("WriteLine", - // new Type[] { typeof(string) } - //)); + //il.Emit(OpCodes.Pop); + //il.Emit(OpCodes.Call, + // typeof(Console).GetMethod("WriteLine", + // new Type[] { typeof(string) } + //)); - il.Emit(OpCodes.Call, - typeof(Common).GetMethod("SendToLog", - new Type[] { typeof(string) } - )); + il.Emit(OpCodes.Call, + typeof(Common).GetMethod("SendToLog", + new Type[] { typeof(string) } + )); - - //il.Emit(OpCodes.Pop); - //il.Emit(OpCodes.Ldind_I2, 0); - //il.Emit(OpCodes.Call, typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) })); - //il.EmitCalli(OpCodes.Calli, - //il.Emit(OpCodes.Call, typeof().GetMethod - // ("llSay", new Type[] { typeof(UInt32), typeof(string) })); - break; - default: - Common.SendToDebug("Instruction " + idesc + ": " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() + ": INTERNAL COMMAND NOT IMPLEMENTED"); - break; - } - - //Common.SendToDebug("Instruction " + idesc + ": DEBUG: Faking return code:"); - //Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, 0);"); - //il.Emit(OpCodes.Ldc_I4, 0); - break; + //il.Emit(OpCodes.Pop); - // RETURN - case LSO_Enums.Operation_Table.RETURN: + //il.Emit(OpCodes.Ldind_I2, 0); - Common.SendToDebug("Last OPCODE was return command. Code chunk execution complete."); - return true; + //il.Emit(OpCodes.Call, typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) })); + //il.EmitCalli(OpCodes.Calli, + //il.Emit(OpCodes.Call, typeof().GetMethod + // ("llSay", new Type[] { typeof(UInt32), typeof(string) })); + break; + default: + Common.SendToDebug("Instruction " + idesc + ": " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() + ": INTERNAL COMMAND NOT IMPLEMENTED"); + break; } - return false; - } + //Common.SendToDebug("Instruction " + idesc + ": DEBUG: Faking return code:"); + //Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, 0);"); + //il.Emit(OpCodes.Ldc_I4, 0); + break; + + // RETURN + case LSO_Enums.Operation_Table.RETURN: + + Common.SendToDebug("Last OPCODE was return command. Code chunk execution complete."); + return true; } + return false; } + + } +} diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs index 18dca74..4ad1f83 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs @@ -27,512 +27,514 @@ */ /* Original code: Tedd Hansen */ using System; - using System.Collections.Generic; - using System.Text; - using System.IO; - using System.Reflection; - using System.Reflection.Emit; - - namespace OpenSim.Region.Scripting.LSL +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Reflection; +using System.Reflection.Emit; + +namespace OpenSim.Region.Scripting.LSL +{ + partial class LSO_Parser { - partial class LSO_Parser + private FileStream fs; + private BinaryReader br; + private LSO_Struct.Header myHeader; + + private TypeBuilder typeBuilder; + private System.Collections.Generic.List EventList = new System.Collections.Generic.List(); + + /// + /// Parse LSO file. + /// Reads LSO ByteCode into memory structures. + /// TODO: What else does it do? + /// + /// FileName of LSO ByteCode file + public void ParseFile(string FileName, TypeBuilder _typeBuilder) { - private FileStream fs; - private BinaryReader br; - private LSO_Struct.Header myHeader; - - private TypeBuilder typeBuilder; - private System.Collections.Generic.List EventList = new System.Collections.Generic.List(); - - /// - /// Parse LSO file. - /// Reads LSO ByteCode into memory structures. - /// TODO: What else does it do? - /// - /// FileName of LSO ByteCode file - public void ParseFile(string FileName, TypeBuilder _typeBuilder) + typeBuilder = _typeBuilder; + //WorldAPI = _WorldAPI; + // Open + Common.SendToDebug("Opening filename: " + FileName); + fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read); + br = new BinaryReader(fs, Encoding.BigEndianUnicode); + + + // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack. + + + // HEADER BLOCK + Common.SendToDebug("Reading HEADER BLOCK at: 0"); + fs.Seek(0, SeekOrigin.Begin); + myHeader = new LSO_Struct.Header(); + myHeader.TM = BitConverter.ToUInt32(br_read(4), 0); + myHeader.IP = BitConverter.ToUInt32(br_read(4), 0); + myHeader.VN = BitConverter.ToUInt32(br_read(4), 0); + myHeader.BP = BitConverter.ToUInt32(br_read(4), 0); + myHeader.SP = BitConverter.ToUInt32(br_read(4), 0); + myHeader.HR = BitConverter.ToUInt32(br_read(4), 0); + myHeader.HP = BitConverter.ToUInt32(br_read(4), 0); + myHeader.CS = BitConverter.ToUInt32(br_read(4), 0); + myHeader.NS = BitConverter.ToUInt32(br_read(4), 0); + myHeader.CE = BitConverter.ToUInt32(br_read(4), 0); + myHeader.IE = BitConverter.ToUInt32(br_read(4), 0); + myHeader.ER = BitConverter.ToUInt32(br_read(4), 0); + myHeader.FR = BitConverter.ToUInt32(br_read(4), 0); + myHeader.SLR = BitConverter.ToUInt32(br_read(4), 0); + myHeader.GVR = BitConverter.ToUInt32(br_read(4), 0); + myHeader.GFR = BitConverter.ToUInt32(br_read(4), 0); + myHeader.PR = BitConverter.ToUInt32(br_read(4), 0); + myHeader.ESR = BitConverter.ToUInt32(br_read(4), 0); + myHeader.SR = BitConverter.ToUInt32(br_read(4), 0); + myHeader.NCE = BitConverter.ToUInt64(br_read(8), 0); + myHeader.NIE = BitConverter.ToUInt64(br_read(8), 0); + myHeader.NER = BitConverter.ToUInt64(br_read(8), 0); + + // Print Header Block to debug + Common.SendToDebug("TM - Top of memory (size): " + myHeader.TM); + Common.SendToDebug("IP - Instruction Pointer (0=not running): " + myHeader.IP); + Common.SendToDebug("VN - Version number: " + myHeader.VN); + Common.SendToDebug("BP - Local Frame Pointer: " + myHeader.BP); + Common.SendToDebug("SP - Stack Pointer: " + myHeader.SP); + Common.SendToDebug("HR - Heap Register: " + myHeader.HR); + Common.SendToDebug("HP - Heap Pointer: " + myHeader.HP); + Common.SendToDebug("CS - Current State: " + myHeader.CS); + Common.SendToDebug("NS - Next State: " + myHeader.NS); + Common.SendToDebug("CE - Current Events: " + myHeader.CE); + Common.SendToDebug("IE - In Event: " + myHeader.IE); + Common.SendToDebug("ER - Event Register: " + myHeader.ER); + Common.SendToDebug("FR - Fault Register: " + myHeader.FR); + Common.SendToDebug("SLR - Sleep Register: " + myHeader.SLR); + Common.SendToDebug("GVR - Global Variable Register: " + myHeader.GVR); + Common.SendToDebug("GFR - Global Function Register: " + myHeader.GFR); + Common.SendToDebug("PR - Parameter Register: " + myHeader.PR); + Common.SendToDebug("ESR - Energy Supply Register: " + myHeader.ESR); + Common.SendToDebug("SR - State Register: " + myHeader.SR); + Common.SendToDebug("NCE - 64-bit Current Events: " + myHeader.NCE); + Common.SendToDebug("NIE - 64-bit In Events: " + myHeader.NIE); + Common.SendToDebug("NER - 64-bit Event Register: " + myHeader.NER); + Common.SendToDebug("Read position when exiting HEADER BLOCK: " + fs.Position); + + // STATIC BLOCK + Common.SendToDebug("Reading STATIC BLOCK at: " + myHeader.GVR); + fs.Seek(myHeader.GVR, SeekOrigin.Begin); + int StaticBlockCount = 0; + // Read function blocks until we hit GFR + while (fs.Position < myHeader.GFR) { - typeBuilder = _typeBuilder; - //WorldAPI = _WorldAPI; - // Open - Common.SendToDebug("Opening filename: " + FileName); - fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read); - br = new BinaryReader(fs, Encoding.BigEndianUnicode); - - - // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack. - - - // HEADER BLOCK - Common.SendToDebug("Reading HEADER BLOCK at: 0"); - fs.Seek(0, SeekOrigin.Begin); - myHeader = new LSO_Struct.Header(); - myHeader.TM = BitConverter.ToUInt32(br_read(4), 0); - myHeader.IP = BitConverter.ToUInt32(br_read(4), 0); - myHeader.VN = BitConverter.ToUInt32(br_read(4), 0); - myHeader.BP = BitConverter.ToUInt32(br_read(4), 0); - myHeader.SP = BitConverter.ToUInt32(br_read(4), 0); - myHeader.HR = BitConverter.ToUInt32(br_read(4), 0); - myHeader.HP = BitConverter.ToUInt32(br_read(4), 0); - myHeader.CS = BitConverter.ToUInt32(br_read(4), 0); - myHeader.NS = BitConverter.ToUInt32(br_read(4), 0); - myHeader.CE = BitConverter.ToUInt32(br_read(4), 0); - myHeader.IE = BitConverter.ToUInt32(br_read(4), 0); - myHeader.ER = BitConverter.ToUInt32(br_read(4), 0); - myHeader.FR = BitConverter.ToUInt32(br_read(4), 0); - myHeader.SLR = BitConverter.ToUInt32(br_read(4), 0); - myHeader.GVR = BitConverter.ToUInt32(br_read(4), 0); - myHeader.GFR = BitConverter.ToUInt32(br_read(4), 0); - myHeader.PR = BitConverter.ToUInt32(br_read(4), 0); - myHeader.ESR = BitConverter.ToUInt32(br_read(4), 0); - myHeader.SR = BitConverter.ToUInt32(br_read(4), 0); - myHeader.NCE = BitConverter.ToUInt64(br_read(8), 0); - myHeader.NIE = BitConverter.ToUInt64(br_read(8), 0); - myHeader.NER = BitConverter.ToUInt64(br_read(8), 0); - - // Print Header Block to debug - Common.SendToDebug("TM - Top of memory (size): " + myHeader.TM); - Common.SendToDebug("IP - Instruction Pointer (0=not running): " + myHeader.IP); - Common.SendToDebug("VN - Version number: " + myHeader.VN); - Common.SendToDebug("BP - Local Frame Pointer: " + myHeader.BP); - Common.SendToDebug("SP - Stack Pointer: " + myHeader.SP); - Common.SendToDebug("HR - Heap Register: " + myHeader.HR); - Common.SendToDebug("HP - Heap Pointer: " + myHeader.HP); - Common.SendToDebug("CS - Current State: " + myHeader.CS); - Common.SendToDebug("NS - Next State: " + myHeader.NS); - Common.SendToDebug("CE - Current Events: " + myHeader.CE); - Common.SendToDebug("IE - In Event: " + myHeader.IE); - Common.SendToDebug("ER - Event Register: " + myHeader.ER); - Common.SendToDebug("FR - Fault Register: " + myHeader.FR); - Common.SendToDebug("SLR - Sleep Register: " + myHeader.SLR); - Common.SendToDebug("GVR - Global Variable Register: " + myHeader.GVR); - Common.SendToDebug("GFR - Global Function Register: " + myHeader.GFR); - Common.SendToDebug("PR - Parameter Register: " + myHeader.PR); - Common.SendToDebug("ESR - Energy Supply Register: " + myHeader.ESR); - Common.SendToDebug("SR - State Register: " + myHeader.SR); - Common.SendToDebug("NCE - 64-bit Current Events: " + myHeader.NCE); - Common.SendToDebug("NIE - 64-bit In Events: " + myHeader.NIE); - Common.SendToDebug("NER - 64-bit Event Register: " + myHeader.NER); - Common.SendToDebug("Read position when exiting HEADER BLOCK: " + fs.Position); - - // STATIC BLOCK - Common.SendToDebug("Reading STATIC BLOCK at: " + myHeader.GVR); - fs.Seek(myHeader.GVR, SeekOrigin.Begin); - int StaticBlockCount = 0; - // Read function blocks until we hit GFR - while (fs.Position < myHeader.GFR) - { - StaticBlockCount++; - Common.SendToDebug("Reading Static Block " + StaticBlockCount + " at: " + fs.Position); - //fs.Seek(myHeader.GVR, SeekOrigin.Begin); - LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); - myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); - myStaticBlock.ObjectType = br_read(1)[0]; - Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); - myStaticBlock.Unknown = br_read(1)[0]; - // Size of datatype varies - if (myStaticBlock.ObjectType != 0) - myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); - } - Common.SendToDebug("Number of Static Blocks read: " + StaticBlockCount); + StaticBlockCount++; + Common.SendToDebug("Reading Static Block " + StaticBlockCount + " at: " + fs.Position); + //fs.Seek(myHeader.GVR, SeekOrigin.Begin); + LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); + myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); + myStaticBlock.ObjectType = br_read(1)[0]; + Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); + myStaticBlock.Unknown = br_read(1)[0]; + // Size of datatype varies + if (myStaticBlock.ObjectType != 0) + myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); + } + Common.SendToDebug("Number of Static Blocks read: " + StaticBlockCount); - // FUNCTION BLOCK - // Always right after STATIC BLOCK - LSO_Struct.FunctionBlock myFunctionBlock = new LSO_Struct.FunctionBlock(); - if (myHeader.GFR == myHeader.SR) + // FUNCTION BLOCK + // Always right after STATIC BLOCK + LSO_Struct.FunctionBlock myFunctionBlock = new LSO_Struct.FunctionBlock(); + if (myHeader.GFR == myHeader.SR) + { + // If GFR and SR are at same position then there is no fuction block + Common.SendToDebug("No FUNCTION BLOCK found"); + } + else + { + Common.SendToDebug("Reading FUNCTION BLOCK at: " + myHeader.GFR); + fs.Seek(myHeader.GFR, SeekOrigin.Begin); + myFunctionBlock.FunctionCount = BitConverter.ToUInt32(br_read(4), 0); + Common.SendToDebug("Number of functions in Fuction Block: " + myFunctionBlock.FunctionCount); + if (myFunctionBlock.FunctionCount > 0) { - // If GFR and SR are at same position then there is no fuction block - Common.SendToDebug("No FUNCTION BLOCK found"); - } else { - Common.SendToDebug("Reading FUNCTION BLOCK at: " + myHeader.GFR); - fs.Seek(myHeader.GFR, SeekOrigin.Begin); - myFunctionBlock.FunctionCount = BitConverter.ToUInt32(br_read(4), 0); - Common.SendToDebug("Number of functions in Fuction Block: " + myFunctionBlock.FunctionCount); - if (myFunctionBlock.FunctionCount > 0) + myFunctionBlock.CodeChunkPointer = new UInt32[myFunctionBlock.FunctionCount]; + for (int i = 0; i < myFunctionBlock.FunctionCount; i++) { - myFunctionBlock.CodeChunkPointer = new UInt32[myFunctionBlock.FunctionCount]; - for (int i = 0; i < myFunctionBlock.FunctionCount; i++) - { - Common.SendToDebug("Reading function " + i + " at: " + fs.Position); - // TODO: ADD TO FUNCTION LIST (How do we identify it later?) - // Note! Absolute position - myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR; - Common.SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]); - } + Common.SendToDebug("Reading function " + i + " at: " + fs.Position); + // TODO: ADD TO FUNCTION LIST (How do we identify it later?) + // Note! Absolute position + myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR; + Common.SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]); } } + } - // STATE FRAME BLOCK - // Always right after FUNCTION BLOCK - Common.SendToDebug("Reading STATE BLOCK at: " + myHeader.SR); - fs.Seek(myHeader.SR, SeekOrigin.Begin); - LSO_Struct.StateFrameBlock myStateFrameBlock = new LSO_Struct.StateFrameBlock(); - myStateFrameBlock.StateCount = BitConverter.ToUInt32(br_read(4), 0); - if (myStateFrameBlock.StateCount > 0) + // STATE FRAME BLOCK + // Always right after FUNCTION BLOCK + Common.SendToDebug("Reading STATE BLOCK at: " + myHeader.SR); + fs.Seek(myHeader.SR, SeekOrigin.Begin); + LSO_Struct.StateFrameBlock myStateFrameBlock = new LSO_Struct.StateFrameBlock(); + myStateFrameBlock.StateCount = BitConverter.ToUInt32(br_read(4), 0); + if (myStateFrameBlock.StateCount > 0) + { + // Initialize array + myStateFrameBlock.StatePointer = new LSO_Struct.StatePointerBlock[myStateFrameBlock.StateCount]; + for (int i = 0; i < myStateFrameBlock.StateCount; i++) { - // Initialize array - myStateFrameBlock.StatePointer = new LSO_Struct.StatePointerBlock[myStateFrameBlock.StateCount]; - for (int i = 0; i < myStateFrameBlock.StateCount; i++) - { - Common.SendToDebug("Reading STATE POINTER BLOCK " + (i+1) + " at: " + fs.Position); - // Position is relative to state frame - myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0); - myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8)); - Common.SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location); - Common.SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count); + Common.SendToDebug("Reading STATE POINTER BLOCK " + (i + 1) + " at: " + fs.Position); + // Position is relative to state frame + myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0); + myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8)); + Common.SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location); + Common.SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count); - //// Read STATE BLOCK - //long CurPos = fs.Position; - //fs.Seek(CurPos, SeekOrigin.Begin); + //// Read STATE BLOCK + //long CurPos = fs.Position; + //fs.Seek(CurPos, SeekOrigin.Begin); - } } + } - // STATE BLOCK - // For each StateFrameBlock there is one StateBlock with multiple event handlers + // STATE BLOCK + // For each StateFrameBlock there is one StateBlock with multiple event handlers - if (myStateFrameBlock.StateCount > 0) + if (myStateFrameBlock.StateCount > 0) + { + // Go through all State Frame Pointers found + for (int i = 0; i < myStateFrameBlock.StateCount; i++) { - // Go through all State Frame Pointers found - for (int i = 0; i < myStateFrameBlock.StateCount; i++) - { - - fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin); - Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position); - // READ: STATE BLOCK HEADER - myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock(); - myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note - myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0); - myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0]; - myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note - Common.SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos); - Common.SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize); - Common.SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos); + fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin); + Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position); + + // READ: STATE BLOCK HEADER + myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock(); + myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0); + myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0]; + myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note + Common.SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos); + Common.SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize); + Common.SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos); - // We need to count number of bits flagged in EventMask? + // We need to count number of bits flagged in EventMask? - // for each bit in myStateFrameBlock.StatePointer[i].EventMask + // for each bit in myStateFrameBlock.StatePointer[i].EventMask - // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE - //TODO: Create event hooks - myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1]; - for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) + // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE + //TODO: Create event hooks + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1]; + for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) + { + + if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true) { - - if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true) - { - // We got an event - // READ: STATE BLOCK HANDLER - Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") at: " + fs.Position); - myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0); - myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0); - Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Code Chunk Pointer: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer); - Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Call Frame Size: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize ); - } + // We got an event + // READ: STATE BLOCK HANDLER + Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") at: " + fs.Position); + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0); + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0); + Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Code Chunk Pointer: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer); + Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Call Frame Size: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize); } } } + } - //// READ FUNCTION CODE CHUNKS - //// Functions + Function start pos (GFR) - //// TODO: Somehow be able to identify and reference this - //LSO_Struct.CodeChunk[] myFunctionCodeChunk; - //if (myFunctionBlock.FunctionCount > 0) - //{ - // myFunctionCodeChunk = new LSO_Struct.CodeChunk[myFunctionBlock.FunctionCount]; - // for (int i = 0; i < myFunctionBlock.FunctionCount; i++) - // { - // Common.SendToDebug("Reading Function Code Chunk " + i); - // myFunctionCodeChunk[i] = GetCodeChunk((UInt32)myFunctionBlock.CodeChunkPointer[i]); - // } + //// READ FUNCTION CODE CHUNKS + //// Functions + Function start pos (GFR) + //// TODO: Somehow be able to identify and reference this + //LSO_Struct.CodeChunk[] myFunctionCodeChunk; + //if (myFunctionBlock.FunctionCount > 0) + //{ + // myFunctionCodeChunk = new LSO_Struct.CodeChunk[myFunctionBlock.FunctionCount]; + // for (int i = 0; i < myFunctionBlock.FunctionCount; i++) + // { + // Common.SendToDebug("Reading Function Code Chunk " + i); + // myFunctionCodeChunk[i] = GetCodeChunk((UInt32)myFunctionBlock.CodeChunkPointer[i]); + // } - //} - // READ EVENT CODE CHUNKS - LSO_Struct.CodeChunk[] myEventCodeChunk; - if (myStateFrameBlock.StateCount > 0) + //} + // READ EVENT CODE CHUNKS + LSO_Struct.CodeChunk[] myEventCodeChunk; + if (myStateFrameBlock.StateCount > 0) + { + myEventCodeChunk = new LSO_Struct.CodeChunk[myStateFrameBlock.StateCount]; + for (int i = 0; i < myStateFrameBlock.StateCount; i++) { - myEventCodeChunk = new LSO_Struct.CodeChunk[myStateFrameBlock.StateCount]; - for (int i = 0; i < myStateFrameBlock.StateCount; i++) + // TODO: Somehow organize events and functions so they can be found again, + // two level search ain't no good + for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) { - // TODO: Somehow organize events and functions so they can be found again, - // two level search ain't no good - for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) - { - if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0) - { - Common.SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii); + if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0) + { + Common.SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii); - // Override a Method / Function - string eventname = i + "_event_" + (LSO_Enums.Event_Mask_Values)ii; - Common.SendToDebug("Event Name: " + eventname); - if (Common.IL_ProcessCodeChunks) - { - EventList.Add(eventname); + // Override a Method / Function + string eventname = i + "_event_" + (LSO_Enums.Event_Mask_Values)ii; + Common.SendToDebug("Event Name: " + eventname); + if (Common.IL_ProcessCodeChunks) + { + EventList.Add(eventname); - // JUMP TO CODE PROCESSOR - ProcessCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, typeBuilder, eventname); - } + // JUMP TO CODE PROCESSOR + ProcessCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, typeBuilder, eventname); } - } } } + } - // Close - br.Close(); - fs.Close(); - if (Common.IL_CreateFunctionList) - IL_INSERT_FUNCTIONLIST(); + // Close + br.Close(); + fs.Close(); - } + if (Common.IL_CreateFunctionList) + IL_INSERT_FUNCTIONLIST(); + + } + + private LSO_Struct.HeapBlock GetHeap(UInt32 pos) + { + // HEAP BLOCK + // TODO:? Special read for strings/keys (null terminated) and lists (pointers to other HEAP entries) + Common.SendToDebug("Reading HEAP BLOCK at: " + pos); + fs.Seek(pos, SeekOrigin.Begin); + + LSO_Struct.HeapBlock myHeapBlock = new LSO_Struct.HeapBlock(); + myHeapBlock.DataBlockSize = BitConverter.ToUInt32(br_read(4), 0); + myHeapBlock.ObjectType = br_read(1)[0]; + myHeapBlock.ReferenceCount = BitConverter.ToUInt16(br_read(2), 0); + myHeapBlock.Data = br_read(getObjectSize(myHeapBlock.ObjectType)); + + Common.SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize); + Common.SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString()); + Common.SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount); + + return myHeapBlock; + } + private byte[] br_read(int len) + { + if (len <= 0) + return null; - private LSO_Struct.HeapBlock GetHeap(UInt32 pos) + try { - // HEAP BLOCK - // TODO:? Special read for strings/keys (null terminated) and lists (pointers to other HEAP entries) - Common.SendToDebug("Reading HEAP BLOCK at: " + pos); - fs.Seek(pos, SeekOrigin.Begin); - - LSO_Struct.HeapBlock myHeapBlock = new LSO_Struct.HeapBlock(); - myHeapBlock.DataBlockSize = BitConverter.ToUInt32(br_read(4), 0); - myHeapBlock.ObjectType = br_read(1)[0]; - myHeapBlock.ReferenceCount = BitConverter.ToUInt16(br_read(2), 0); - myHeapBlock.Data = br_read(getObjectSize(myHeapBlock.ObjectType)); - - Common.SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize); - Common.SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString()); - Common.SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount); - - return myHeapBlock; + byte[] bytes = new byte[len]; + for (int i = len - 1; i > -1; i--) + bytes[i] = br.ReadByte(); + return bytes; } - private byte[] br_read(int len) + catch (Exception e) { - if (len <= 0) - return null; - - try - { - byte[] bytes = new byte[len]; - for (int i = len - 1; i > -1; i--) - bytes[i] = br.ReadByte(); - return bytes; - } - catch (Exception e) - { - Common.SendToDebug("Exception: " + e.ToString()); - throw (e); - } + Common.SendToDebug("Exception: " + e.ToString()); + throw (e); } - //private byte[] br_read_smallendian(int len) - //{ - // byte[] bytes = new byte[len]; - // br.Read(bytes,0, len); - // return bytes; - //} - private Type getLLObjectType(byte objectCode) + } + //private byte[] br_read_smallendian(int len) + //{ + // byte[] bytes = new byte[len]; + // br.Read(bytes,0, len); + // return bytes; + //} + private Type getLLObjectType(byte objectCode) + { + switch ((LSO_Enums.Variable_Type_Codes)objectCode) { - switch ((LSO_Enums.Variable_Type_Codes)objectCode) - { - case LSO_Enums.Variable_Type_Codes.Void: return typeof(void); - case LSO_Enums.Variable_Type_Codes.Integer: return typeof(UInt32); - case LSO_Enums.Variable_Type_Codes.Float: return typeof(float); - case LSO_Enums.Variable_Type_Codes.String: return typeof(string); - case LSO_Enums.Variable_Type_Codes.Key: return typeof(string); - case LSO_Enums.Variable_Type_Codes.Vector: return typeof(LSO_Enums.Vector); - case LSO_Enums.Variable_Type_Codes.Rotation: return typeof(LSO_Enums.Rotation); - case LSO_Enums.Variable_Type_Codes.List: - Common.SendToDebug("TODO: List datatype not implemented yet!"); - return typeof(System.Collections.ArrayList); - default: - Common.SendToDebug("Lookup of LSL datatype " + objectCode + " to .Net datatype failed: Unknown LSL datatype. Defaulting to object."); - return typeof(object); - } + case LSO_Enums.Variable_Type_Codes.Void: return typeof(void); + case LSO_Enums.Variable_Type_Codes.Integer: return typeof(UInt32); + case LSO_Enums.Variable_Type_Codes.Float: return typeof(float); + case LSO_Enums.Variable_Type_Codes.String: return typeof(string); + case LSO_Enums.Variable_Type_Codes.Key: return typeof(string); + case LSO_Enums.Variable_Type_Codes.Vector: return typeof(LSO_Enums.Vector); + case LSO_Enums.Variable_Type_Codes.Rotation: return typeof(LSO_Enums.Rotation); + case LSO_Enums.Variable_Type_Codes.List: + Common.SendToDebug("TODO: List datatype not implemented yet!"); + return typeof(System.Collections.ArrayList); + default: + Common.SendToDebug("Lookup of LSL datatype " + objectCode + " to .Net datatype failed: Unknown LSL datatype. Defaulting to object."); + return typeof(object); } - private int getObjectSize(byte ObjectType) + } + private int getObjectSize(byte ObjectType) + { + switch (ObjectType) { - switch (ObjectType) - { - case 1: - case 2: - case 3: - case 4: - case 7: - return 4; - case 5: - return 12; - case 6: - return 16; - default: - return 0; - } + case 1: + case 2: + case 3: + case 4: + case 7: + return 4; + case 5: + return 12; + case 6: + return 16; + default: + return 0; } - private string Read_String() + } + private string Read_String() + { + string ret = ""; + byte reader = br_read(1)[0]; + while (reader != 0x000) { - string ret = ""; - byte reader = br_read(1)[0]; - while (reader != 0x000) - { - ret += (char)reader; - reader = br_read(1)[0]; - } - return ret; + ret += (char)reader; + reader = br_read(1)[0]; } + return ret; + } + + /// + /// Reads a code chunk and creates IL + /// + /// Absolute position in file. REMEMBER TO ADD myHeader.GFR! + /// TypeBuilder for assembly + /// Name of event (function) to generate + private void ProcessCodeChunk(UInt32 pos, TypeBuilder typeBuilder, string eventname) + { - /// - /// Reads a code chunk and creates IL - /// - /// Absolute position in file. REMEMBER TO ADD myHeader.GFR! - /// TypeBuilder for assembly - /// Name of event (function) to generate - private void ProcessCodeChunk(UInt32 pos, TypeBuilder typeBuilder, string eventname) + LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk(); + + Common.SendToDebug("Reading Function Code Chunk at: " + pos); + fs.Seek(pos, SeekOrigin.Begin); + myCodeChunk.CodeChunkHeaderSize = BitConverter.ToUInt32(br_read(4), 0); + Common.SendToDebug("CodeChunk Header Size: " + myCodeChunk.CodeChunkHeaderSize); + // Read until null + myCodeChunk.Comment = Read_String(); + Common.SendToDebug("Function comment: " + myCodeChunk.Comment); + myCodeChunk.ReturnType = br_read(1)[0]; + Common.SendToDebug("Return type #" + myCodeChunk.ReturnType + ": " + (getLLObjectType(myCodeChunk.ReturnType).ToString())); + + // TODO: How to determine number of codechunks -- does this method work? + myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List(); + byte reader = br_read(1)[0]; + reader = br_read(1)[0]; + + // NOTE ON CODE CHUNK ARGUMENTS + // This determins type definition + int ccount = 0; + while (reader != 0x000) { - - LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk(); - - Common.SendToDebug("Reading Function Code Chunk at: " + pos); - fs.Seek(pos, SeekOrigin.Begin); - myCodeChunk.CodeChunkHeaderSize = BitConverter.ToUInt32(br_read(4), 0); - Common.SendToDebug("CodeChunk Header Size: " + myCodeChunk.CodeChunkHeaderSize ); - // Read until null - myCodeChunk.Comment = Read_String(); - Common.SendToDebug("Function comment: " + myCodeChunk.Comment); - myCodeChunk.ReturnType = br_read(1)[0]; - Common.SendToDebug("Return type #" + myCodeChunk.ReturnType + ": " + (getLLObjectType(myCodeChunk.ReturnType).ToString())); - - // TODO: How to determine number of codechunks -- does this method work? - myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List(); - byte reader = br_read(1)[0]; + ccount++; + Common.SendToDebug("Reading Code Chunk Argument " + ccount); + LSO_Struct.CodeChunkArgument CCA = new LSO_Struct.CodeChunkArgument(); + CCA.FunctionReturnType = reader; reader = br_read(1)[0]; - - // NOTE ON CODE CHUNK ARGUMENTS - // This determins type definition - int ccount = 0; - while (reader != 0x000) - { - ccount++; - Common.SendToDebug("Reading Code Chunk Argument " + ccount); - LSO_Struct.CodeChunkArgument CCA = new LSO_Struct.CodeChunkArgument(); - CCA.FunctionReturnType = reader; - reader = br_read(1)[0]; - CCA.NullString = reader; - myCodeChunk.CodeChunkArguments.Add(CCA); - Common.SendToDebug("Code Chunk Argument " + ccount + " type: " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType); - } - // Create string array - Type[] MethodArgs = new Type[myCodeChunk.CodeChunkArguments.Count]; - for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) - { - MethodArgs[_ic] = getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType); - Common.SendToDebug("Method argument " + _ic + ": " + getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType).ToString()); - } - // End marker is 0x000 - myCodeChunk.EndMarker = reader; + CCA.NullString = reader; + myCodeChunk.CodeChunkArguments.Add(CCA); + Common.SendToDebug("Code Chunk Argument " + ccount + " type: " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType); + } + // Create string array + Type[] MethodArgs = new Type[myCodeChunk.CodeChunkArguments.Count]; + for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) + { + MethodArgs[_ic] = getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType); + Common.SendToDebug("Method argument " + _ic + ": " + getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType).ToString()); + } + // End marker is 0x000 + myCodeChunk.EndMarker = reader; - // - // Emit: START OF METHOD (FUNCTION) - // + // + // Emit: START OF METHOD (FUNCTION) + // - Common.SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod..."); - MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, - MethodAttributes.Public, - typeof(void), - MethodArgs); - //typeof(void), //getLLObjectType(myCodeChunk.ReturnType), - // new Type[] { typeof(object) }, //); + Common.SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod..."); + MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, + MethodAttributes.Public, + typeof(void), + MethodArgs); + //typeof(void), //getLLObjectType(myCodeChunk.ReturnType), + // new Type[] { typeof(object) }, //); - //Common.SendToDebug("CLR:" + eventname + ":typeBuilder.DefineMethodOverride(methodBuilder..."); - //typeBuilder.DefineMethodOverride(methodBuilder, - // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); + //Common.SendToDebug("CLR:" + eventname + ":typeBuilder.DefineMethodOverride(methodBuilder..."); + //typeBuilder.DefineMethodOverride(methodBuilder, + // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); - // Create the IL generator + // Create the IL generator - Common.SendToDebug("CLR:" + eventname + ":ILGenerator il = methodBuilder.GetILGenerator();"); - ILGenerator il = methodBuilder.GetILGenerator(); + Common.SendToDebug("CLR:" + eventname + ":ILGenerator il = methodBuilder.GetILGenerator();"); + ILGenerator il = methodBuilder.GetILGenerator(); - if (Common.IL_UseTryCatch) - IL_INSERT_TRY(il, eventname); + if (Common.IL_UseTryCatch) + IL_INSERT_TRY(il, eventname); - // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); - //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); - //il.Emit(OpCodes.Call, typeof(Console).GetMethod - // ("WriteLine", new Type[] { typeof(string) })); + // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); + //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); + //il.Emit(OpCodes.Call, typeof(Console).GetMethod + // ("WriteLine", new Type[] { typeof(string) })); - //Common.SendToDebug("STARTUP: il.Emit(OpCodes.Ldc_I4_S, 0);"); + //Common.SendToDebug("STARTUP: il.Emit(OpCodes.Ldc_I4_S, 0);"); - //il.Emit(OpCodes.Ldc_I4_S, 0); - for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) - { - Common.SendToDebug("PARAMS: il.Emit(OpCodes.Ldarg, " + _ic + ");"); - il.Emit(OpCodes.Ldarg, _ic); - } + //il.Emit(OpCodes.Ldc_I4_S, 0); + for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) + { + Common.SendToDebug("PARAMS: il.Emit(OpCodes.Ldarg, " + _ic + ");"); + il.Emit(OpCodes.Ldarg, _ic); + } - // - // CALLING OPCODE PROCESSOR, one command at the time TO GENERATE IL - // - bool FoundRet = false; - while (FoundRet == false) - { - FoundRet = LSL_PROCESS_OPCODE(il); - } + // + // CALLING OPCODE PROCESSOR, one command at the time TO GENERATE IL + // + bool FoundRet = false; + while (FoundRet == false) + { + FoundRet = LSL_PROCESS_OPCODE(il); + } - if (Common.IL_UseTryCatch) - IL_INSERT_END_TRY(il, eventname); + if (Common.IL_UseTryCatch) + IL_INSERT_END_TRY(il, eventname); - // Emit: RETURN FROM METHOD - il.Emit(OpCodes.Ret); + // Emit: RETURN FROM METHOD + il.Emit(OpCodes.Ret); - return; + return; - } + } - private void IL_INSERT_FUNCTIONLIST() - { + private void IL_INSERT_FUNCTIONLIST() + { - Common.SendToDebug("Creating function list"); + Common.SendToDebug("Creating function list"); - string eventname = "GetFunctions"; + string eventname = "GetFunctions"; - Common.SendToDebug("Creating IL " + eventname); - // Define a private String field. - //FieldBuilder myField = myTypeBuilder.DefineField("EventList", typeof(String[]), FieldAttributes.Public); + Common.SendToDebug("Creating IL " + eventname); + // Define a private String field. + //FieldBuilder myField = myTypeBuilder.DefineField("EventList", typeof(String[]), FieldAttributes.Public); - //FieldBuilder mem = typeBuilder.DefineField("mem", typeof(Array), FieldAttributes.Private); + //FieldBuilder mem = typeBuilder.DefineField("mem", typeof(Array), FieldAttributes.Private); - MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, - MethodAttributes.Public, - typeof(string[]), - null); + MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, + MethodAttributes.Public, + typeof(string[]), + null); - //typeBuilder.DefineMethodOverride(methodBuilder, - // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); + //typeBuilder.DefineMethodOverride(methodBuilder, + // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); - ILGenerator il = methodBuilder.GetILGenerator(); + ILGenerator il = methodBuilder.GetILGenerator(); @@ -548,80 +550,80 @@ using System; //initIL.Emit(OpCodes.Newobj, typeof(string[])); - //string[] MyArray = new string[2] { "TestItem1" , "TestItem2" }; + //string[] MyArray = new string[2] { "TestItem1" , "TestItem2" }; - il.DeclareLocal(typeof(string[])); + il.DeclareLocal(typeof(string[])); - //il.Emit(OpCodes.Ldarg_0); - il.Emit(OpCodes.Ldc_I4, EventList.Count); // Specify array length - il.Emit(OpCodes.Newarr, typeof(String)); // create new string array - il.Emit(OpCodes.Stloc_0); // Store array as local variable 0 in stack + //il.Emit(OpCodes.Ldarg_0); + il.Emit(OpCodes.Ldc_I4, EventList.Count); // Specify array length + il.Emit(OpCodes.Newarr, typeof(String)); // create new string array + il.Emit(OpCodes.Stloc_0); // Store array as local variable 0 in stack - for (int lv = 0; lv < EventList.Count; lv++) - { - il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack - il.Emit(OpCodes.Ldc_I4, lv); // Push index position - il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value - il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value - } + for (int lv = 0; lv < EventList.Count; lv++) + { + il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack + il.Emit(OpCodes.Ldc_I4, lv); // Push index position + il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value + il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value + } - - // IL_INSERT_END_TRY(il, eventname); - il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack - il.Emit(OpCodes.Ret); // Return + // IL_INSERT_END_TRY(il, eventname); - } + il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack + il.Emit(OpCodes.Ret); // Return + } - private void IL_INSERT_TRY(ILGenerator il, string eventname) - { - /* - * CLR TRY - */ - //Common.SendToDebug("CLR:" + eventname + ":il.BeginExceptionBlock()"); - il.BeginExceptionBlock(); - // Push "Hello World!" string to stack - //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); - il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname); + private void IL_INSERT_TRY(ILGenerator il, string eventname) + { + /* + * CLR TRY + */ + //Common.SendToDebug("CLR:" + eventname + ":il.BeginExceptionBlock()"); + il.BeginExceptionBlock(); - } - - private void IL_INSERT_END_TRY(ILGenerator il, string eventname) - { - /* - * CATCH - */ - Common.SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));"); - il.BeginCatchBlock(typeof(Exception)); - - // Push "Hello World!" string to stack - Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); - il.Emit(OpCodes.Ldstr, "Execption executing dynamic CLR function " + eventname + ": "); - - //call void [mscorlib]System.Console::WriteLine(string) - Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); - il.Emit(OpCodes.Call, typeof(Console).GetMethod - ("Write", new Type[] { typeof(string) })); - - //callvirt instance string [mscorlib]System.Exception::get_Message() - Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt..."); - il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod - ("get_Message")); - - //call void [mscorlib]System.Console::WriteLine(string) - Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); - il.Emit(OpCodes.Call, typeof(Console).GetMethod - ("WriteLine", new Type[] { typeof(string) })); - - /* - * CLR END TRY - */ - //Common.SendToDebug("CLR:" + eventname + ":il.EndExceptionBlock();"); - il.EndExceptionBlock(); - } + // Push "Hello World!" string to stack + //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); + il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname); + + } + + private void IL_INSERT_END_TRY(ILGenerator il, string eventname) + { + /* + * CATCH + */ + Common.SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));"); + il.BeginCatchBlock(typeof(Exception)); + + // Push "Hello World!" string to stack + Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); + il.Emit(OpCodes.Ldstr, "Execption executing dynamic CLR function " + eventname + ": "); + + //call void [mscorlib]System.Console::WriteLine(string) + Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); + il.Emit(OpCodes.Call, typeof(Console).GetMethod + ("Write", new Type[] { typeof(string) })); + + //callvirt instance string [mscorlib]System.Exception::get_Message() + Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt..."); + il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod + ("get_Message")); + + //call void [mscorlib]System.Console::WriteLine(string) + Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); + il.Emit(OpCodes.Call, typeof(Console).GetMethod + ("WriteLine", new Type[] { typeof(string) })); + + /* + * CLR END TRY + */ + //Common.SendToDebug("CLR:" + eventname + ":il.EndExceptionBlock();"); + il.EndExceptionBlock(); + } } } -- cgit v1.1