Delegates issue solved.,

This commit is contained in:
Matthijs ter Woord 2015-09-05 18:11:20 +02:00
parent 3cb082bfbc
commit 44690293e8
5 changed files with 115 additions and 82 deletions

View file

@ -15,13 +15,13 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<Profile>VMware</Profile>
<Profile>Bochs</Profile>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<Framework>MicrosoftNET</Framework>
<UseInternalAssembler>False</UseInternalAssembler>
<EnableGDB>False</EnableGDB>
<DebugMode>Source</DebugMode>
<DebugMode>IL</DebugMode>
<TraceMode>User</TraceMode>
<BuildTarget>PXE</BuildTarget>
<VMWareFlavor>Player</VMWareFlavor>
@ -30,8 +30,8 @@
<VMwareDeploy>ISO</VMwareDeploy>
<IgnoreDebugStubAttribute>False</IgnoreDebugStubAttribute>
<Deployment>ISO</Deployment>
<Launch>VMware</Launch>
<DebugEnabled>True</DebugEnabled>
<Launch>Bochs</Launch>
<DebugEnabled>False</DebugEnabled>
<TraceAssemblies>All</TraceAssemblies>
<PXE_Deployment>PXE</PXE_Deployment>
<PXE_Launch>None</PXE_Launch>
@ -67,8 +67,8 @@
<VMware_Framework>MicrosoftNET</VMware_Framework>
<VMware_UseInternalAssembler>False</VMware_UseInternalAssembler>
<VMware_TraceAssemblies>All</VMware_TraceAssemblies>
<VMware_EnableGDB>False</VMware_EnableGDB>
<VMware_StartCosmosGDB>False</VMware_StartCosmosGDB>
<VMware_EnableGDB>True</VMware_EnableGDB>
<VMware_StartCosmosGDB>True</VMware_StartCosmosGDB>
<ISO_Deployment>ISO</ISO_Deployment>
<ISO_Launch>None</ISO_Launch>
<ISO_DebugEnabled>False</ISO_DebugEnabled>
@ -82,7 +82,7 @@
<ISO_EnableGDB>False</ISO_EnableGDB>
<ISO_StartCosmosGDB>false</ISO_StartCosmosGDB>
<Name>Guess</Name>
<Description>Use VMware Player or Workstation to deploy and debug.</Description>
<Description>Use Bochs emulator to deploy and debug.</Description>
<ISO_Name>User 001</ISO_Name>
<ISO_Description>Creates a bootable ISO image which can be burned to a DVD. After running the selected project, an explorer window will open containing the ISO file. The ISO file can then be burned to a CD or DVD and used to boot a physical or virtual system.</ISO_Description>
<USB_Name>Guess</USB_Name>
@ -136,7 +136,7 @@
<Bochs_Deployment>ISO</Bochs_Deployment>
<Bochs_Launch>Bochs</Bochs_Launch>
<Bochs_ShowLaunchConsole>False</Bochs_ShowLaunchConsole>
<Bochs_DebugEnabled>True</Bochs_DebugEnabled>
<Bochs_DebugEnabled>False</Bochs_DebugEnabled>
<Bochs_StackCorruptionDetectionEnabled>True</Bochs_StackCorruptionDetectionEnabled>
<Bochs_DebugMode>IL</Bochs_DebugMode>
<Bochs_IgnoreDebugStubAttribute>False</Bochs_IgnoreDebugStubAttribute>
@ -150,7 +150,7 @@
<Bochs_TraceAssemblies>All</Bochs_TraceAssemblies>
<Bochs_EnableGDB>False</Bochs_EnableGDB>
<Bochs_StartCosmosGDB>False</Bochs_StartCosmosGDB>
<EnableBochsDebug>False</EnableBochsDebug>
<EnableBochsDebug>True</EnableBochsDebug>
<Bochs_EnableBochsDebug>True</Bochs_EnableBochsDebug>
<PXE_StackCorruptionDetectionEnabled>False</PXE_StackCorruptionDetectionEnabled>
<PXE_EnableBochsDebug>False</PXE_EnableBochsDebug>
@ -181,13 +181,13 @@
<USB_EnableBochsDebug>False</USB_EnableBochsDebug>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<Profile>VMware</Profile>
<Profile>Bochs</Profile>
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
<Framework>MicrosoftNET</Framework>
<UseInternalAssembler>False</UseInternalAssembler>
<EnableGDB>False</EnableGDB>
<DebugMode>Source</DebugMode>
<DebugMode>IL</DebugMode>
<TraceMode>User</TraceMode>
<BuildTarget>PXE</BuildTarget>
<VMWareFlavor>Player</VMWareFlavor>
@ -196,8 +196,8 @@
<VMwareDeploy>ISO</VMwareDeploy>
<IgnoreDebugStubAttribute>False</IgnoreDebugStubAttribute>
<Deployment>ISO</Deployment>
<Launch>VMware</Launch>
<DebugEnabled>True</DebugEnabled>
<Launch>Bochs</Launch>
<DebugEnabled>False</DebugEnabled>
<TraceAssemblies>All</TraceAssemblies>
<PXE_Deployment>PXE</PXE_Deployment>
<PXE_Launch>None</PXE_Launch>
@ -233,8 +233,8 @@
<VMware_Framework>MicrosoftNET</VMware_Framework>
<VMware_UseInternalAssembler>False</VMware_UseInternalAssembler>
<VMware_TraceAssemblies>All</VMware_TraceAssemblies>
<VMware_EnableGDB>False</VMware_EnableGDB>
<VMware_StartCosmosGDB>False</VMware_StartCosmosGDB>
<VMware_EnableGDB>True</VMware_EnableGDB>
<VMware_StartCosmosGDB>True</VMware_StartCosmosGDB>
<ISO_Deployment>ISO</ISO_Deployment>
<ISO_Launch>None</ISO_Launch>
<ISO_DebugEnabled>False</ISO_DebugEnabled>
@ -248,7 +248,7 @@
<ISO_EnableGDB>False</ISO_EnableGDB>
<ISO_StartCosmosGDB>false</ISO_StartCosmosGDB>
<Name>Guess</Name>
<Description>Use VMware Player or Workstation to deploy and debug.</Description>
<Description>Use Bochs emulator to deploy and debug.</Description>
<ISO_Name>User 001</ISO_Name>
<ISO_Description>Creates a bootable ISO image which can be burned to a DVD. After running the selected project, an explorer window will open containing the ISO file. The ISO file can then be burned to a CD or DVD and used to boot a physical or virtual system.</ISO_Description>
<USB_Name>Guess</USB_Name>
@ -308,7 +308,7 @@
<Bochs_Deployment>ISO</Bochs_Deployment>
<Bochs_Launch>Bochs</Bochs_Launch>
<Bochs_ShowLaunchConsole>False</Bochs_ShowLaunchConsole>
<Bochs_DebugEnabled>True</Bochs_DebugEnabled>
<Bochs_DebugEnabled>False</Bochs_DebugEnabled>
<Bochs_StackCorruptionDetectionEnabled>True</Bochs_StackCorruptionDetectionEnabled>
<Bochs_DebugMode>IL</Bochs_DebugMode>
<Bochs_IgnoreDebugStubAttribute>False</Bochs_IgnoreDebugStubAttribute>
@ -322,7 +322,7 @@
<Bochs_TraceAssemblies>All</Bochs_TraceAssemblies>
<Bochs_EnableGDB>False</Bochs_EnableGDB>
<Bochs_StartCosmosGDB>False</Bochs_StartCosmosGDB>
<EnableBochsDebug>False</EnableBochsDebug>
<EnableBochsDebug>True</EnableBochsDebug>
<Bochs_EnableBochsDebug>True</Bochs_EnableBochsDebug>
<PXE_StackCorruptionDetectionEnabled>False</PXE_StackCorruptionDetectionEnabled>
<PXE_EnableBochsDebug>False</PXE_EnableBochsDebug>

View file

@ -5,7 +5,7 @@ using Cosmos.TestRunner;
namespace Cosmos.Compiler.Tests.Bcl.System
{
public static class DelegatesTest
public class DelegatesTest
{
private static int mCount;
@ -14,22 +14,54 @@ namespace Cosmos.Compiler.Tests.Bcl.System
mCount++;
}
private static void IncreaseCounterTwice()
private void IncreaseCounterTwiceFromInstanceMethod()
{
mCount++;
mCount += 2;
}
public static void Execute()
{
TestDelegateWithoutArguments();
TestDelegateWithArguments();
}
private static void TestDelegateWithoutArguments()
{
mCount = 0;
Action xDelegate = IncreaseCounterOnce;
xDelegate();
Assert.AreEqual(1, mCount, "After calling delegate once, Count != 1");
//xDelegate += IncreaseCounterTwice;
//xDelegate();
//Assert.AreEqual(4, mCount, "After calling delegate second time, Count != 4");
var xTestInstance = new DelegatesTest();
xDelegate = xTestInstance.IncreaseCounterTwiceFromInstanceMethod;
mCount = 0;
xDelegate();
Assert.AreEqual(2, mCount, "After calling delegate second time, Count != 2");
}
private static void IncreaseCounter(int number)
{
mCount += number;
}
private void IncreaseCounterFromInstanceMethod(int number)
{
mCount += number;
}
private static void TestDelegateWithArguments()
{
mCount = 0;
Action<int> xDelegate = IncreaseCounter;
xDelegate(2);
Assert.AreEqual(2, mCount, "After calling delegate once, Count != 2");
var xTestInstance = new DelegatesTest();
xDelegate = xTestInstance.IncreaseCounterFromInstanceMethod;
mCount = 0;
xDelegate(3);
Assert.AreEqual(3, mCount, "After calling delegate second time, Count != 3");
}
}
}

View file

@ -20,12 +20,12 @@ namespace Cosmos.TestRunner.Core
// if you're working on the compiler (or other lower parts), you can choose to run the compiler in process
// 1 thing to keep in mind though, is that this only works with 1 kernel at a time!
//engine.RunIL2CPUInProcess = true;
engine.RunWithGDB = false;
//engine.RunWithGDB = true;
engine.AddKernel(typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel).Assembly.Location);
engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location);
engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location);
engine.AddKernel(typeof(Cosmos.Compiler.Tests.SingleEchoTest.Kernel).Assembly.Location);
//engine.AddKernel(typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel).Assembly.Location);
//engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location);
//engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location);
//engine.AddKernel(typeof(Cosmos.Compiler.Tests.SingleEchoTest.Kernel).Assembly.Location);
engine.AddKernel(typeof(Cosmos.Compiler.Tests.Bcl.Kernel).Assembly.Location);
// known bugs, therefor disabled for now:

View file

@ -1,4 +1,4 @@
//#define VMT_DEBUG
#define VMT_DEBUG
using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;

View file

@ -57,63 +57,64 @@ namespace Cosmos.IL2CPU.X86.Plugs.NEW_PLUGS {
new CPU.Comment("ecx = ptr to delegate object");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = Ldarg.GetArgumentDisplacement(xMethodInfo, 0) };//addrof the delegate
new CPU.Comment("ecx points to the size of the delegated methods arguments");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ECX,SourceReg = CPUx86.Registers.ECX,SourceIsIndirect = true };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.ECX,SourceIsIndirect = true };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.ECX, SourceIsIndirect = true, SourceDisplacement = Ldfld.GetFieldOffset(xMethodInfo.MethodBase.DeclaringType, "$$ArgSize$$") };//the size of the arguments to the method? + 12??? -- 12 is the size of the current call stack.. i think
new CPUx86.Xor { DestinationReg = CPUx86.Registers.EDX, SourceReg = CPUx86.Registers.EDX };
;//make sure edx is 0
new CPU.Label(".BEGIN_OF_LOOP");
{
new CPUx86.Compare { DestinationReg = CPUx86.Registers.EDX, SourceReg = CPUx86.Registers.EBX };//are we at the end of this list
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.GreaterThanOrEqualTo, DestinationLabel = ".END_OF_INVOKE_" };//then we better stop
new CPUx86.Pushad();
new CPU.Comment("esi points to where we will copy the methods argumetns from");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.ESP };
new CPU.Comment("edi = ptr to delegate object");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = Ldarg.GetArgumentDisplacement(xMethodInfo, 0) };
new CPUx86.Mov {DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true}; // dereference handle
new CPU.Comment("edi = ptr to delegate object should be a pointer to the delgates context ie (this) for the methods ");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true, SourceDisplacement = Ldfld.GetFieldOffset(xMethodInfo.MethodBase.DeclaringType, "System.Object System.Delegate._target") };
new CPUx86.Compare { DestinationReg = CPUx86.Registers.EDI, SourceValue = 0 };
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.Zero, DestinationLabel = ".NO_THIS" };
new CPUx86.Push { DestinationReg = CPUx86.Registers.EDI };
new CPU.Label(".NO_THIS");
new CPU.Comment("make space for us to copy the arguments too");
new CPUx86.Sub { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.ECX };
new CPU.Comment("move the current delegate to edi");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true }; // dereference
new CPU.Comment("move the methodptr from that delegate to edi ");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true, SourceDisplacement = Ldfld.GetFieldOffset(xMethodInfo.MethodBase.DeclaringType, "System.IntPtr System.Delegate._methodPtr") };//
new CPU.Comment("save methodptr on the stack");
new CPUx86.Push { DestinationReg = CPUx86.Registers.EDI };
new CPU.Comment("move location to copy args to");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.ESP };
//new CPU.Comment("get above the saved methodptr");
//new CPUx86.Sub { DestinationReg = CPUx86.Registers.ESP, SourceValue = 4 };
//we allocated the argsize on the stack once, and it we need to get above the original args
new CPU.Comment("we allocated argsize on the stack once");
new CPU.Comment("add 32 for the Pushad + 16 for the current stack + 4 for the return value");
//uint xToAdd = 32; // skip pushad data
//xToAdd += 4; // method pointer
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.EBP };
new CPUx86.Add { DestinationReg = CPUx86.Registers.ESI, SourceValue = 8 }; // ebp+8 is first argument
new CPUx86.Movs { Size = 8, Prefixes = CPUx86.InstructionPrefixes.Repeat };
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EDI };
new CPU.Label(".BeforeCall");
new CPUx86.Call { DestinationReg = CPUx86.Registers.EDI };
new CPU.Comment("store return -- return stored into edi after popad");
new CPU.Comment("edi = ptr to delegate object");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = Ldarg.GetArgumentDisplacement(xMethodInfo, 0) };
new CPU.Comment("edi = ptr to delegate object should be a pointer to the delgates context ie (this) for the methods ");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true }; // dereference handle
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true, SourceDisplacement = Ldfld.GetFieldOffset(xMethodInfo.MethodBase.DeclaringType, "System.Object System.Delegate._target") };//i really dont get the +12, MtW: that's for the object header
new CPU.Label(".noTHIStoPop");
new CPUx86.Popad();
new CPUx86.INC { DestinationReg = CPUx86.Registers.EDX };
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = 4 };
new CPUx86.Jump { DestinationLabel = ".BEGIN_OF_LOOP" };
new CPUx86.Compare { DestinationReg = CPUx86.Registers.EDX, SourceReg = CPUx86.Registers.EBX };//are we at the end of this list
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.GreaterThanOrEqualTo, DestinationLabel = ".END_OF_INVOKE_" };//then we better stop
new CPUx86.Pushad();
new CPU.Comment("esi points to where we will copy the methods argumetns from");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.ESP };
new CPU.Comment("edi = ptr to delegate object");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = Ldarg.GetArgumentDisplacement(xMethodInfo, 0) };
new CPUx86.Mov {DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true}; // dereference handle
new CPU.Comment("edi = ptr to delegate object should be a pointer to the delgates context ie (this) for the methods ");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true, SourceDisplacement = Ldfld.GetFieldOffset(xMethodInfo.MethodBase.DeclaringType, "System.Object System.Delegate._target") };
new CPUx86.Compare { DestinationReg = CPUx86.Registers.EDI, SourceValue = 0 };
new CPUx86.ConditionalJump { Condition = CPUx86.ConditionalTestEnum.Zero, DestinationLabel = ".NO_THIS" };
new CPUx86.Push { DestinationReg = CPUx86.Registers.EDI };
new CPU.Label(".NO_THIS");
new CPU.Comment("make space for us to copy the arguments too");
new CPUx86.Sub { DestinationReg = CPUx86.Registers.ESP, SourceReg = CPUx86.Registers.ECX };
new CPU.Comment("move the current delegate to edi");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EAX, SourceIsIndirect = true };
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true }; // dereference
new CPU.Comment("move the methodptr from that delegate to edi ");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true, SourceDisplacement = Ldfld.GetFieldOffset(xMethodInfo.MethodBase.DeclaringType, "System.IntPtr System.Delegate._methodPtr") };//
new CPU.Comment("save methodptr on the stack");
new CPUx86.Push { DestinationReg = CPUx86.Registers.EDI };
new CPU.Comment("move location to copy args to");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.ESP };
new CPUx86.Add { DestinationReg = CPUx86.Registers.EDI, SourceValue = 4 };
//new CPU.Comment("get above the saved methodptr");
//new CPUx86.Sub { DestinationReg = CPUx86.Registers.ESP, SourceValue = 4 };
//we allocated the argsize on the stack once, and it we need to get above the original args
new CPU.Comment("we allocated argsize on the stack once");
new CPU.Comment("add 32 for the Pushad + 16 for the current stack + 4 for the return value");
//uint xToAdd = 32; // skip pushad data
//xToAdd += 4; // method pointer
new CPUx86.Mov { DestinationReg = CPUx86.Registers.ESI, SourceReg = CPUx86.Registers.EBP };
new CPUx86.Add { DestinationReg = CPUx86.Registers.ESI, SourceValue = 8 }; // ebp+8 is first argument
new CPUx86.Movs { Size = 8, Prefixes = CPUx86.InstructionPrefixes.Repeat };
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EDI };
new CPU.Label(".BeforeCall");
new CPUx86.Call { DestinationReg = CPUx86.Registers.EDI };
new CPU.Comment("store return -- return stored into edi after popad");
new CPU.Comment("edi = ptr to delegate object");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EBP, SourceIsIndirect = true, SourceDisplacement = Ldarg.GetArgumentDisplacement(xMethodInfo, 0) };
new CPU.Comment("edi = ptr to delegate object should be a pointer to the delgates context ie (this) for the methods ");
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true }; // dereference handle
new CPUx86.Mov { DestinationReg = CPUx86.Registers.EDI, SourceReg = CPUx86.Registers.EDI, SourceIsIndirect = true, SourceDisplacement = Ldfld.GetFieldOffset(xMethodInfo.MethodBase.DeclaringType, "System.Object System.Delegate._target") };//i really dont get the +12, MtW: that's for the object header
new CPU.Label(".noTHIStoPop");
new CPUx86.Popad();
new CPUx86.INC { DestinationReg = CPUx86.Registers.EDX };
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = 4 };
new CPUx86.Jump { DestinationLabel = ".BEGIN_OF_LOOP" };
}
new CPU.Label(".END_OF_INVOKE_");
new CPU.Comment("get the return value");