Skip to content

Commit

Permalink
Some basic improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Jun 23, 2016
1 parent a6afa5b commit 3bc4ea7
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 4 deletions.
14 changes: 14 additions & 0 deletions Tests/Cosmos.Compiler.Tests.Bcl/System/DelegatesTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Cosmos.Debug.Kernel;
using Cosmos.TestRunner;

namespace Cosmos.Compiler.Tests.Bcl.System
Expand All @@ -24,6 +25,7 @@ public static void Execute()
{
TestDelegateWithoutArguments();
TestDelegateWithArguments();
//TestMulticastDelegateWithoutArguments();
}

private static void TestDelegateWithoutArguments()
Expand All @@ -40,6 +42,18 @@ private static void TestDelegateWithoutArguments()
Assert.AreEqual(2, mCount, "After calling delegate second time, Count != 2");
}

private static void TestMulticastDelegateWithoutArguments()
{
var xDebugger = new Debugger("Test", "Delegates");
xDebugger.Send("Start MulticastDelegate test");
mCount = 0;
Action xDelegate = IncreaseCounterOnce;
xDebugger.Send("Adding second handler now");
xDelegate += IncreaseCounterOnce;
xDelegate();
Assert.AreEqual(2, mCount, "After calling multicast delegate once, Count != 2");
}

private static void IncreaseCounter(int number)
{
mCount += number;
Expand Down
3 changes: 3 additions & 0 deletions source/Cosmos.Core.Plugs/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[*.cs]
indent_size = 4

[System/MulticastDelegateImpl.cs]
indent_size = 2
1 change: 1 addition & 0 deletions source/Cosmos.Core.Plugs/Cosmos.Core.Plugs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
<Content Include="ReadMe.html" />
</ItemGroup>
<ItemGroup>
<None Include=".editorconfig" />
<None Include="Cosmos.snk" />
</ItemGroup>
<ItemGroup />
Expand Down
10 changes: 10 additions & 0 deletions source/Cosmos.Core.Plugs/System/DelegateImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,15 @@ public static bool Equals(Delegate aThis, object aThat)
// todo: implement proper Delegate.Equals(object)
return false;
}

public static unsafe bool InternalEqualTypes(uint** a, uint** b)
{
var xTypeA = a[0][0];
var xTypeB = b[0][0];



return xTypeA == xTypeB;
}
}
}
14 changes: 14 additions & 0 deletions source/Cosmos.Core.Plugs/System/MulticastDelegateImpl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;

namespace Cosmos.IL2CPU.Plugs.System {

Expand All @@ -17,5 +18,18 @@ public static bool Equals(MulticastDelegate aThis, object aThat) {
// todo: implement MulticastDelegate.Equals(MulticastDelegate)
return false;
}

public static bool TrySetSlot(MulticastDelegate multicastDelegate, object[] a, int index, object o)
{
if (a[index] == null)
{
a[index] = o;
}
if (a[index] != null)
{
return false;
}
return false;
}
}
}
2 changes: 1 addition & 1 deletion source/Cosmos.IL2CPU/IL/Castclass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )

XS.Label(mReturnNullLabel );
XS.Add(XSRegisters.ESP, 4);
string xAllocInfoLabelName = LabelName.Get( GCImplementationRefs.AllocNewObjectRef );
//string xAllocInfoLabelName = LabelName.Get( GCImplementationRefs.AllocNewObjectRef );
#warning TODO: Emit new exceptions
//new Newobj( Assembler ).Execute( aMethod, aOpCode );

Expand Down
4 changes: 4 additions & 0 deletions source/Cosmos.IL2CPU/ILOpCodes/OpType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public override int GetNumberOfStackPops(MethodBase aMethod)
return 1;
case Code.Sizeof:
return 0;
case Code.Mkrefany:
return 1;
default:
throw new NotImplementedException("OpCode '" + OpCode + "' not implemented! Encountered in method " + aMethod.ToString());
}
Expand Down Expand Up @@ -87,6 +89,8 @@ public override int GetNumberOfStackPushes(MethodBase aMethod)
return 1;
case Code.Sizeof:
return 1;
case Code.Mkrefany:
return 1;
default:
throw new NotImplementedException("OpCode '" + OpCode + "' not implemented!");
}
Expand Down
8 changes: 5 additions & 3 deletions source/Cosmos.IL2CPU/Plugs/System/Threading/Interlocked.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Threading;
using System;
using System.Threading;

namespace Cosmos.IL2CPU.Plugs.System.Threading
{
[Plug(Target=typeof(Interlocked))]
[Plug(Target = typeof(Interlocked))]
public static class InterlockedImpl
{
public static int Decrement(ref int aData) {
public static int Decrement(ref int aData)
{
return aData -= 1;
}
}
Expand Down

0 comments on commit 3bc4ea7

Please sign in to comment.