Skip to content

Commit

Permalink
Add comparers for byte and char.
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed Oct 10, 2018
1 parent 04e45a7 commit 2ca4b2a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 29 deletions.
22 changes: 17 additions & 5 deletions Demos/ZMachine/ZKernel/ZKernel.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifier>cosmos</RuntimeIdentifier>
<Profile>Bochs</Profile>
<Profile>VMware</Profile>
<BinFormat>ELF</BinFormat>
<StackCorruptionDetectionEnabled>True</StackCorruptionDetectionEnabled>
<StackCorruptionDetectionLevel>MethodFooters</StackCorruptionDetectionLevel>
Expand All @@ -19,11 +19,11 @@
<_DebugMode>Source</_DebugMode>
<_IgnoreDebugStubAttribute>False</_IgnoreDebugStubAttribute>
<_PxeInterface>192.168.211.1</_PxeInterface>
<Description>Use Bochs emulator to deploy and debug.</Description>
<Launch>Bochs</Launch>
<Description>Use VMware Player or Workstation to deploy and debug.</Description>
<Launch>VMware</Launch>
<VisualStudioDebugPort>Pipe: Cosmos\Serial</VisualStudioDebugPort>
<EnableGDB>True</EnableGDB>
<StartCosmosGDB>True</StartCosmosGDB>
<EnableGDB>False</EnableGDB>
<StartCosmosGDB>False</StartCosmosGDB>
<VMware_StackCorruptionDetectionEnabled>True</VMware_StackCorruptionDetectionEnabled>
<VMware_StackCorruptionDetectionLevel>MethodFooters</VMware_StackCorruptionDetectionLevel>
<VMware_Description>Use VMware Player or Workstation to deploy and debug.</VMware_Description>
Expand All @@ -36,6 +36,18 @@
<VMware_PxeInterface>192.168.211.1</VMware_PxeInterface>
<VMware_EnableGDB>True</VMware_EnableGDB>
<VMware_StartCosmosGDB>True</VMware_StartCosmosGDB>
<Bochs_StackCorruptionDetectionEnabled>True</Bochs_StackCorruptionDetectionEnabled>
<Bochs_StackCorruptionDetectionLevel>MethodFooters</Bochs_StackCorruptionDetectionLevel>
<Bochs_Description>Use Bochs emulator to deploy and debug.</Bochs_Description>
<Bochs_Deployment>ISO</Bochs_Deployment>
<Bochs_Launch>Bochs</Bochs_Launch>
<Bochs_DebugEnabled>True</Bochs_DebugEnabled>
<Bochs_DebugMode>Source</Bochs_DebugMode>
<Bochs_IgnoreDebugStubAttribute>False</Bochs_IgnoreDebugStubAttribute>
<Bochs_VisualStudioDebugPort>Pipe: Cosmos\Serial</Bochs_VisualStudioDebugPort>
<Bochs_PxeInterface>192.168.211.1</Bochs_PxeInterface>
<Bochs_EnableGDB>True</Bochs_EnableGDB>
<Bochs_StartCosmosGDB>True</Bochs_StartCosmosGDB>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Demos/ZMachine/ZLibrary/Machine/ZConsoleScreen.cs
Expand Up @@ -129,8 +129,8 @@ public class ZConsoleScreen : IZScreen
public ZConsoleScreen(ZMachine aMachine)
{
_machine = aMachine;
_consoles.Add(new VirtualConsole(19, 60, 1, 0));
_consoles.Add(new VirtualConsole(1, 60, 0,0));
_consoles.Add(new VirtualConsole(19, 70, 1, 0));
_consoles.Add(new VirtualConsole(1, 70, 0,0));
}

public string ReadLine(string aInitialValue, int aTimeout, ushort timeoutRoutine, byte[] terminatingKeys, out byte terminator)
Expand Down
9 changes: 5 additions & 4 deletions Demos/ZMachine/ZLibrary/ZDebug.cs
@@ -1,12 +1,13 @@
using System.Diagnostics;
#define COSMOSDEBUG
using System.Diagnostics;

namespace ZLibrary
{
public static class ZDebug
{
public static bool Enable = true;
public static bool Enable = false;

#if COSMOS
#if COSMOSDEBUG
private static Cosmos.Debug.Kernel.Debugger Debugger = new Cosmos.Debug.Kernel.Debugger("", "");
#else
//private static StreamWriter writer = new StreamWriter("log.txt");
Expand All @@ -20,7 +21,7 @@ public static void Output(string s)
Debugger.Send(s);
#else
//writer.WriteLine(s);
Debug.WriteLine(s);
//Debug.WriteLine(s);
#endif
}
}
Expand Down
Expand Up @@ -31,68 +31,86 @@ public static object CreateDefaultEqualityComparer(Type aType)
return new StringEqualityComparer();
}

if (aType == typeof(char))
{
return new CharEqualityComparer();
}

if (aType == typeof(int))
{
return new Int32EqualityComparer();
}

if (aType == typeof(byte))
{
return new ByteEqualityComparer();
}

// TODO: Nullable<>

// TODO: Enum (Comparer is special to avoid boxing)

//else
//{
// xResult = new ObjectComparer<object>();
//}
mDebugger.Send($"No EqualityComparer for type {aType}");
return null;
}
}

public class StringComparer : Comparer<string>
{
private readonly Debugger mDebugger = new Debugger("Core", "String Comparer");

public override int Compare(string x, string y)
{
mDebugger.Send("StringComparer.Compare");

throw new NotImplementedException();
}
}

public class StringEqualityComparer : EqualityComparer<string>
{
private readonly Debugger mDebugger = new Debugger("Core", "String Equality Comparer");

public override bool Equals(string x, string y)
{
mDebugger.Send("StringEqualityComparer.Equals");
return String.Equals(x, y);
}

public override int GetHashCode(string obj)
{
mDebugger.Send("StringEqualityComparer.GetHashCode");

return obj.GetHashCode();
}
}

public class Int32EqualityComparer : EqualityComparer<int>
public class CharEqualityComparer : EqualityComparer<char>
{
public override bool Equals(char x, char y)
{
return x == y;
}

public override int GetHashCode(char val)
{
return val.GetHashCode();
}
}

public class ByteEqualityComparer : EqualityComparer<byte>
{
private readonly Debugger mDebugger = new Debugger("Core", "Int32 Equality Comparer");
public override bool Equals(byte x, byte y)
{
return x == y;
}

public override int GetHashCode(byte val)
{
return val.GetHashCode();
}
}

public class Int32EqualityComparer : EqualityComparer<int>
{
public override bool Equals(int x, int y)
{
mDebugger.Send("Int32EqualityComparer.Equals");
return x == y;
}

public override int GetHashCode(int val)
{
mDebugger.Send("Int32EqualityComparer.GetHashCode");

return val.GetHashCode();
}
}
Expand Down

0 comments on commit 2ca4b2a

Please sign in to comment.