mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-27 22:12:25 +00:00
Merge remote-tracking branch 'refs/remotes/CosmosOS/master' into crypto
This commit is contained in:
commit
f9ea9dea7e
5 changed files with 68 additions and 3 deletions
|
|
@ -93,6 +93,7 @@
|
|||
<Compile Include="System\Int16Test.cs" />
|
||||
<Compile Include="System\Int32Test.cs" />
|
||||
<Compile Include="System\Int64Test.cs" />
|
||||
<Compile Include="System\ObjectTests.cs" />
|
||||
<Compile Include="System\SByteTest.cs" />
|
||||
<Compile Include="System\SingleTest.cs" />
|
||||
<Compile Include="System\StringTest.cs" />
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using Sys = Cosmos.System;
|
|||
namespace Cosmos.Compiler.Tests.Bcl
|
||||
{
|
||||
using Cosmos.Compiler.Tests.Bcl.System;
|
||||
|
||||
|
||||
public class Kernel : Sys.Kernel
|
||||
{
|
||||
protected override void BeforeRun()
|
||||
|
|
@ -23,7 +23,7 @@ namespace Cosmos.Compiler.Tests.Bcl
|
|||
mDebugger.Send("Run");
|
||||
|
||||
CSharp.WhileLoopTests.Execute();
|
||||
|
||||
ObjectTests.Execute();
|
||||
StringTest.Execute();
|
||||
ByteTest.Execute();
|
||||
SByteTest.Execute();
|
||||
|
|
@ -54,4 +54,4 @@ namespace Cosmos.Compiler.Tests.Bcl
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
33
Tests/Cosmos.Compiler.Tests.Bcl/System/ObjectTests.cs
Normal file
33
Tests/Cosmos.Compiler.Tests.Bcl/System/ObjectTests.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using Cosmos.TestRunner;
|
||||
|
||||
namespace Cosmos.Compiler.Tests.Bcl.System
|
||||
{
|
||||
public class ObjectTests
|
||||
{
|
||||
public class MyType
|
||||
{
|
||||
public int IntField;
|
||||
public object ReferenceField;
|
||||
|
||||
public MyType Clone()
|
||||
{
|
||||
return (MyType)MemberwiseClone();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Execute()
|
||||
{
|
||||
var xMyType = new MyType();
|
||||
xMyType.IntField = 42;
|
||||
xMyType.ReferenceField = new object();
|
||||
|
||||
var xCloneType = xMyType.Clone();
|
||||
Assert.AreEqual(xMyType.IntField, xCloneType.IntField, "Cloned object has a different IntField value!");
|
||||
Assert.IsTrue(object.ReferenceEquals(xMyType.ReferenceField, xCloneType.ReferenceField), "References of field aren't the same!");
|
||||
xCloneType.IntField = 56;
|
||||
Assert.AreEqual(xMyType.IntField, 42, "Cloned object is linked to original object!");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -109,6 +109,7 @@
|
|||
<Compile Include="System\IO\PathHelperImpl.cs" />
|
||||
<Compile Include="System\MulticastDelegateImpl.cs" />
|
||||
<Compile Include="System\NormalDelegateImpl.cs" />
|
||||
<Compile Include="System\ObjectImpl.cs" />
|
||||
<Compile Include="System\Runtime\InteropServices\MarshalImpl.cs" />
|
||||
<Compile Include="System\StringImpl.cs" />
|
||||
<Compile Include="GCImplementionImpl.cs" />
|
||||
|
|
|
|||
30
source/Cosmos.Core.Plugs/System/ObjectImpl.cs
Normal file
30
source/Cosmos.Core.Plugs/System/ObjectImpl.cs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
using Cosmos.IL2CPU.Plugs;
|
||||
|
||||
namespace Cosmos.Core.Plugs.System
|
||||
{
|
||||
[Plug(Target = typeof(object))]
|
||||
public class ObjectImpl
|
||||
{
|
||||
public static unsafe uint MemberwiseClone(uint aThis)
|
||||
{
|
||||
// pointers are handles!
|
||||
|
||||
|
||||
var xThisPointer = (uint*)aThis;
|
||||
|
||||
var xSize = xThisPointer[1];
|
||||
|
||||
var xResult = GCImplementionImpl.AllocNewObject(xSize);
|
||||
|
||||
var xThatPointer = (uint*)xResult;
|
||||
var xThatPointerByte = (byte*)xThatPointer[0];
|
||||
var xThisSimplePointer = (uint*)aThis;
|
||||
var xThisPointerByte = (byte*)xThisSimplePointer[0];
|
||||
for (int i = 0; i < xSize; i++)
|
||||
{
|
||||
xThatPointerByte[i] = xThisPointerByte[i];
|
||||
}
|
||||
return xResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue