From 2ca4b2adb80c6fe5edc6386145edd664f01d8ee7 Mon Sep 17 00:00:00 2001 From: Charles Betros Date: Wed, 10 Oct 2018 18:02:57 -0500 Subject: [PATCH] Add comparers for byte and char. --- Demos/ZMachine/ZKernel/ZKernel.csproj | 22 ++++++-- .../ZLibrary/Machine/ZConsoleScreen.cs | 4 +- Demos/ZMachine/ZLibrary/ZDebug.cs | 9 ++-- .../Generic/ComparerHelpersImpl.cs | 54 ++++++++++++------- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/Demos/ZMachine/ZKernel/ZKernel.csproj b/Demos/ZMachine/ZKernel/ZKernel.csproj index 7efe72db41..8d7e8286f4 100644 --- a/Demos/ZMachine/ZKernel/ZKernel.csproj +++ b/Demos/ZMachine/ZKernel/ZKernel.csproj @@ -3,7 +3,7 @@ netcoreapp2.0 cosmos - Bochs + VMware ELF True MethodFooters @@ -19,11 +19,11 @@ <_DebugMode>Source <_IgnoreDebugStubAttribute>False <_PxeInterface>192.168.211.1 - Use Bochs emulator to deploy and debug. - Bochs + Use VMware Player or Workstation to deploy and debug. + VMware Pipe: Cosmos\Serial - True - True + False + False True MethodFooters Use VMware Player or Workstation to deploy and debug. @@ -36,6 +36,18 @@ 192.168.211.1 True True + True + MethodFooters + Use Bochs emulator to deploy and debug. + ISO + Bochs + True + Source + False + Pipe: Cosmos\Serial + 192.168.211.1 + True + True diff --git a/Demos/ZMachine/ZLibrary/Machine/ZConsoleScreen.cs b/Demos/ZMachine/ZLibrary/Machine/ZConsoleScreen.cs index a023b2abc8..e991eed2ba 100644 --- a/Demos/ZMachine/ZLibrary/Machine/ZConsoleScreen.cs +++ b/Demos/ZMachine/ZLibrary/Machine/ZConsoleScreen.cs @@ -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) diff --git a/Demos/ZMachine/ZLibrary/ZDebug.cs b/Demos/ZMachine/ZLibrary/ZDebug.cs index afac5cef33..1642a16976 100644 --- a/Demos/ZMachine/ZLibrary/ZDebug.cs +++ b/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"); @@ -20,7 +21,7 @@ public static void Output(string s) Debugger.Send(s); #else //writer.WriteLine(s); - Debug.WriteLine(s); + //Debug.WriteLine(s); #endif } } diff --git a/source/Cosmos.Core_Plugs/System/Collections/Generic/ComparerHelpersImpl.cs b/source/Cosmos.Core_Plugs/System/Collections/Generic/ComparerHelpersImpl.cs index 929c0cb3b6..1f5e201f93 100644 --- a/source/Cosmos.Core_Plugs/System/Collections/Generic/ComparerHelpersImpl.cs +++ b/source/Cosmos.Core_Plugs/System/Collections/Generic/ComparerHelpersImpl.cs @@ -31,19 +31,25 @@ 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(); - //} mDebugger.Send($"No EqualityComparer for type {aType}"); return null; } @@ -51,48 +57,60 @@ public static object CreateDefaultEqualityComparer(Type aType) public class StringComparer : Comparer { - 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 { - 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 + public class CharEqualityComparer : EqualityComparer + { + public override bool Equals(char x, char y) + { + return x == y; + } + + public override int GetHashCode(char val) + { + return val.GetHashCode(); + } + } + + public class ByteEqualityComparer : EqualityComparer { - 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 + { 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(); } }