diff --git a/source/Indy.IL2CPU.IL.X86/Ldfld.cs b/source/Indy.IL2CPU.IL.X86/Ldfld.cs index 60b3d48a2..7a6597980 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldfld.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldfld.cs @@ -26,9 +26,6 @@ namespace Indy.IL2CPU.IL.X86 { } public override void DoAssemble() { - foreach (var xField in mType.Fields) { - new CPU.Comment(String.Format("{0} -- {1}", xField.Key, xField.Value.ToString())); - } Ldfld(Assembler, mType, mField); } } diff --git a/source/Indy.IL2CPU.IL.X86/Ldsfld.cs b/source/Indy.IL2CPU.IL.X86/Ldsfld.cs index 63af55364..a1ae33327 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldsfld.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldsfld.cs @@ -22,21 +22,21 @@ namespace Indy.IL2CPU.IL.X86 { } public override void DoAssemble() { if (mSize >= 4) { - for (int i = 0; i < (mSize / 4); i++) { + for (int i = 1; i <= (mSize / 4); i++) { // Pop("eax"); // Move(Assembler, "dword [" + mDataName + " + 0x" + (i * 4).ToString("X") + "]", "eax"); - new CPUx86.Pushd("[" + mDataName + " + 0x" + (i * 4).ToString("X") + "]"); + new CPUx86.Pushd("[" + mDataName + " + 0x" + (mSize - (i * 4)).ToString("X") + "]"); } switch (mSize % 4) { case 1: { - new CPUx86.Move(CPUx86.Registers.EAX, "0"); - new CPUx86.Move(CPUx86.Registers.AL, "[" + mDataName + " + 0x" + (mSize - 1).ToString("X") + "]"); + new CPUx86.Move(CPUx86.Registers.EAX, "0"); //mSize - 1 + new CPUx86.Move(CPUx86.Registers.AL, "[" + mDataName + " + 0x" + (0).ToString("X") + "]"); new CPUx86.Push(CPUx86.Registers.EAX); break; } case 2: { new CPUx86.Move(CPUx86.Registers.EAX, "0"); - new CPUx86.Move(CPUx86.Registers.AX, "[" + mDataName + " + 0x" + (mSize - 2).ToString("X") + "]"); + new CPUx86.Move(CPUx86.Registers.AX, "[" + mDataName + " + 0x" + (0).ToString("X") + "]"); new CPUx86.Push(CPUx86.Registers.EAX); break; } diff --git a/source/Indy.IL2CPU.IL.X86/Op.cs b/source/Indy.IL2CPU.IL.X86/Op.cs index 1508c9556..8a1476779 100644 --- a/source/Indy.IL2CPU.IL.X86/Op.cs +++ b/source/Indy.IL2CPU.IL.X86/Op.cs @@ -151,20 +151,20 @@ namespace Indy.IL2CPU.IL.X86 { new CPUx86.Move("ecx", "[ecx]"); } if (aField.Size >= 4) { - for (int i = 0; i < (aField.Size / 4); i++) { - new CPUx86.Move("eax", "[ecx + 0x" + (i * 4).ToString("X") + "]"); + for (int i = 1; i <= (aField.Size / 4); i++) { + new CPUx86.Move("eax", "[ecx + 0x" + (aField.Size - (i * 4)).ToString("X") + "]"); new CPUx86.Pushd("eax"); } switch (aField.Size % 4) { case 1: { new CPUx86.Move("eax", "0"); - new CPUx86.Move("al", "[ecx + 0x" + (aField.Size - 1).ToString("X") + "]"); + new CPUx86.Move("al", "[ecx]"); new CPUx86.Push("eax"); break; } case 2: { new CPUx86.Move("eax", "0"); - new CPUx86.Move("ax", "[ecx + 0x" + (aField.Size - 2).ToString("X") + "]"); + new CPUx86.Move("ax", "[ecx + 0x]"); new CPUx86.Push("eax"); break; } @@ -213,25 +213,27 @@ namespace Indy.IL2CPU.IL.X86 { if (aType.NeedsGC && !aAssembler.InMetalMode) { aExtraOffset = 12; new CPUx86.Pushd("[esp + 4]"); - Ldfld(aAssembler, aType, aField, false); + //Ldfld(aAssembler, aType, aField, false); + new CPUx86.Pop("eax"); + new CPUx86.Pushd("[eax + " + (aField.Offset + aExtraOffset) + "]"); Engine.QueueMethod(GCImplementationRefs.DecRefCountRef); new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.DecRefCountRef)); } new CPUx86.Move("ecx", "[esp + 0x" + xRoundedSize.ToString("X") + "]"); new CPUx86.Add("ecx", "0x" + (aField.Offset + aExtraOffset).ToString("X")); - for (int i = 1; i <= (aField.Size / 4); i++) { + for (int i = 0; i < (aField.Size / 4); i++) { new CPUx86.Pop("eax"); - new Move("dword [ecx + 0x" + (aField.Size - (i * 4)).ToString("X") + "]", "eax"); + new Move("dword [ecx + 0x" + (i * 4).ToString("X") + "]", "eax"); } switch (aField.Size % 4) { case 1: { new CPUx86.Pop("eax"); - new Move("byte [ecx]", "al"); + new Move("byte [ecx + " + ((aField.Size / 4) * 4) + "]", "al"); break; } case 2: { new CPUx86.Pop("eax"); - new Move("word [ecx]", "ax"); + new Move("word [ecx + " + ((aField.Size / 4) * 4) + "]", "ax"); break; } case 0: { diff --git a/source/Indy.IL2CPU.IL.X86/Stloc.cs b/source/Indy.IL2CPU.IL.X86/Stloc.cs index 84e05aecb..cc8627d7b 100644 --- a/source/Indy.IL2CPU.IL.X86/Stloc.cs +++ b/source/Indy.IL2CPU.IL.X86/Stloc.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using Indy.IL2CPU.Assembler; @@ -35,7 +36,7 @@ namespace Indy.IL2CPU.IL.X86 { Engine.QueueMethod(GCImplementationRefs.DecRefCountRef); new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.DecRefCountRef)); } - foreach (string s in mLocal.VirtualAddresses) { + foreach (string s in mLocal.VirtualAddresses.Reverse()) { new CPUx86.Pop(CPUx86.Registers.EAX); new CPUx86.Move("[" + s + "]", "eax"); } diff --git a/source/Indy.IL2CPU.IL.X86/Stsfld.cs b/source/Indy.IL2CPU.IL.X86/Stsfld.cs index 3be053197..cfa2229c0 100644 --- a/source/Indy.IL2CPU.IL.X86/Stsfld.cs +++ b/source/Indy.IL2CPU.IL.X86/Stsfld.cs @@ -31,19 +31,19 @@ namespace Indy.IL2CPU.IL.X86 { Engine.QueueMethod(GCImplementationRefs.DecRefCountRef); new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.DecRefCountRef)); } - for (int i = 1; i <= (mSize / 4); i++) { + for (int i = 0; i < (mSize / 4); i++) { new CPUx86.Pop(CPUx86.Registers.EAX); - new CPUx86.Move("dword [" + mDataName + " + 0x" + (mSize - (i * 4)).ToString("X") + "]", "eax"); + new CPUx86.Move("dword [" + mDataName + " + 0x" + ((i * 4)).ToString("X") + "]", "eax"); } switch (mSize % 4) { case 1: { new CPUx86.Pop(CPUx86.Registers.EAX); - new CPUx86.Move("byte [" + mDataName + "]", "al"); + new CPUx86.Move("byte [" + mDataName + " + " + ((mSize/4)*4) + "]", "al"); break; } case 2: { new CPUx86.Pop(CPUx86.Registers.EAX); - new CPUx86.Move("word [" + mDataName + "]", "ax"); + new CPUx86.Move("word [" + mDataName + " + " + ((mSize / 4) * 4) + "]", "ax"); break; } case 0: { diff --git a/source/Indy.IL2CPU.IL/CustomImplementations/System/UInt32Impl.cs b/source/Indy.IL2CPU.IL/CustomImplementations/System/UInt32Impl.cs index 2aa140d08..b2ab0298d 100644 --- a/source/Indy.IL2CPU.IL/CustomImplementations/System/UInt32Impl.cs +++ b/source/Indy.IL2CPU.IL/CustomImplementations/System/UInt32Impl.cs @@ -12,6 +12,13 @@ namespace Indy.IL2CPU.IL.CustomImplementations.System { } public static string GetNumberString(uint aValue, bool aIsNegative) { + if (aValue == 0) { + if (aIsNegative) { + return "-0"; + } else { + return "0"; + } + } const string xDigits = "0123456789"; char[] xResultChars = new char[11]; int xCurrentPos = 10; diff --git a/source/Indy.IL2CPU/Engine.cs b/source/Indy.IL2CPU/Engine.cs index 0ef3d20d6..55fa8155f 100644 --- a/source/Indy.IL2CPU/Engine.cs +++ b/source/Indy.IL2CPU/Engine.cs @@ -767,11 +767,11 @@ namespace Indy.IL2CPU { // todo: add better detection of implementation state if (xBody != null) { // todo: add support for types which need different stack size - foreach (LocalVariableInfo xLocal in xBody.LocalVariables) { - if (xLocal.LocalType.IsValueType && !xLocal.LocalType.IsPrimitive && !xLocal.LocalType.IsEnum && !xLocal.LocalType.IsPointer) { - throw new Exception("Structs as locals not yet supported!"); - } - } + //foreach (LocalVariableInfo xLocal in xBody.LocalVariables) { + // if (xLocal.LocalType.IsValueType && !xLocal.LocalType.IsPrimitive && !xLocal.LocalType.IsEnum && !xLocal.LocalType.IsPointer) { + // throw new Exception("Structs as locals not yet supported!"); + // } + //} mInstructionsToSkip = 0; mAssembler.StackContents.Clear(); ILReader xReader = new ILReader(xCurrentMethod); @@ -1010,7 +1010,7 @@ namespace Indy.IL2CPU { TypeInformation xTypeInfo; int xObjectStorageSize; SortedList xTypeFields = GetTypeFieldInfo(aType, out xObjectStorageSize); - xTypeInfo = new TypeInformation(xObjectStorageSize, xTypeFields, aType, !aType.IsValueType); + xTypeInfo = new TypeInformation(xObjectStorageSize, xTypeFields, aType, (!aType.IsValueType) && aType.IsClass); return xTypeInfo; } @@ -1138,7 +1138,7 @@ namespace Indy.IL2CPU { if (xFieldType == null) { xFieldType = xField.FieldType; } - if ((!xFieldType.IsValueType && aGCObjects) || (xPlugFieldAttr != null && xPlugFieldAttr.IsExternalValue && aGCObjects)) { + if ((!xFieldType.IsValueType && aGCObjects && xFieldType.IsClass) || (xPlugFieldAttr != null && xPlugFieldAttr.IsExternalValue && aGCObjects)) { continue; } if ((xFieldType.IsClass && !xFieldType.IsValueType) || (xPlugFieldAttr != null && xPlugFieldAttr.IsExternalValue)) { diff --git a/source/MatthijsTest/Program.cs b/source/MatthijsTest/Program.cs index 82e6a3ed0..cb17b1b66 100644 --- a/source/MatthijsTest/Program.cs +++ b/source/MatthijsTest/Program.cs @@ -3,11 +3,9 @@ using System.Collections.Generic; using System.Text; using Cosmos.Build.Windows; -namespace MatthijsTest -{ - class Program - { - #region Cosmos Builder logic +namespace MatthijsTest { + class Program { + #region Cosmos Builder logic // Most users wont touch this. This will call the Cosmos Build tool [STAThread] static void Main(string[] args) { @@ -16,20 +14,78 @@ namespace MatthijsTest } #endregion - public static void Init() - { - Cosmos.Kernel.Boot.Default(); - Cosmos.Kernel.Staging.DefaultStageQueue stages = new Cosmos.Kernel.Staging.DefaultStageQueue(); + public static void Init() { + DoTest(); - // Put any further stages here. + Console.WriteLine("Tests completed, Halting system now"); + while (true) + ; + } - stages.Run(); + private static void DoTest() { + TestStruct xTest = new TestStruct(true); + xTest.Value1 = 1; + xTest.Value2 = 2; + Console.WriteLine("Value1 = " + xTest.Value1); + Console.WriteLine("Value2 = " + xTest.Value2); + Test1(xTest); + Test2(xTest); + mValue = xTest; + Test3(); + Test4(); + var x = new MyTestObj(); + x.mTest = xTest; + x.Test5(); + x.Test6(); + } - // Put your code here. + private static TestStruct mValue; - stages.Teardown(); - while (true) - ; - } - } -} + private static void Test1(TestStruct aTest) { + var xTest = aTest; + Console.WriteLine("Value3 = " + xTest.Value1); + Console.WriteLine("Value4 = " + xTest.Value2); + } + + private static void Test2(TestStruct aTest2) { + Console.WriteLine("Value5 = " + aTest2.Value1); + Console.WriteLine("Value6 = " + aTest2.Value2); + } + + private static void Test3() { + Console.WriteLine("Value7 = " + mValue.Value1); + Console.WriteLine("Value8 = " + mValue.Value2); + } + + private static void Test4() { + var xValue = mValue; + Console.WriteLine("Value9 = " + xValue.Value1); + Console.WriteLine("ValueA = " + xValue.Value2); + } + + public class MyTestObj { + public TestStruct mTest; + + public void Test5() { + System.Diagnostics.Debugger.Break(); + Console.WriteLine("ValueB = " + mTest.Value1); + Console.WriteLine("ValueC = " + mTest.Value2); + } + + public void Test6() { + var xValue = mTest; + Console.WriteLine("ValueD = " + xValue.Value1); + Console.WriteLine("ValueE = " + xValue.Value2); + } + } + } + + public struct TestStruct { + public uint Value1; + public uint Value2; + public TestStruct(bool aIsTest) { + Value1 = 0; + Value2 = 0; + } + } +} \ No newline at end of file