diff --git a/source/Compiler/Compiler/Scanner.cs b/source/Compiler/Compiler/Scanner.cs index 516ac0c56..5686a559a 100644 --- a/source/Compiler/Compiler/Scanner.cs +++ b/source/Compiler/Compiler/Scanner.cs @@ -15,10 +15,10 @@ namespace Cosmos.Compiler /// public partial class Scanner { - private HashSet mMethodNames = new HashSet(StringComparer.InvariantCulture); - private List mMethods = new List(); - private HashSet mTypeNames = new HashSet(StringComparer.InvariantCulture); - private List mTypes = new List(); + private HashSet mMethodsSet = new HashSet(); + private List mMethods = new List(); + private HashSet mTypesSet = new HashSet(); + private List mTypes = new List(); private Func[] mOps; public Func[] Ops @@ -29,14 +29,10 @@ namespace Cosmos.Compiler } set { - if(value != mOps) - { - if(value == null) - { + if(value != mOps) { + if(value == null) { throw new Exception("Cannot set Ops to null"); - } - if(value.Length != 0xFE1F) - { + } else if (value.Length != 0xFE1F) { throw new Exception("Element count mismatch!"); } mOps = value; @@ -51,9 +47,8 @@ namespace Cosmos.Compiler //File.WriteAllLines(@"e:\cosmos.dbg", mMethodNames.ToArray()); } - private void ScanList() - { - // dont use a foreach here, the list will change. + private void ScanList() { + // Cannot use foreach, the list changes as we go for(int i = 0; i < mMethods.Count; i++) { ScanMethod(mMethods[i]); @@ -62,22 +57,16 @@ namespace Cosmos.Compiler private void ScanMethod(MethodBase aMethodBase) { - // pinvoke methods dont have an embedded implementation - if ((aMethodBase.Attributes & MethodAttributes.PinvokeImpl) != 0) - { - // pinvoke - return; - } - else if (aMethodBase.IsAbstract) - { - // abstract methods dont have an implementation - - return; + if ((aMethodBase.Attributes & MethodAttributes.PinvokeImpl) != 0) { + // pinvoke methods dont have an embedded implementation + return; + } else if (aMethodBase.IsAbstract) { + // abstract methods dont have an implementation + return; } var xImplFlags = aMethodBase.GetMethodImplementationFlags(); - if ((xImplFlags & MethodImplAttributes.Native) != 0) - { + if ((xImplFlags & MethodImplAttributes.Native) != 0) { // native implementations cannot be compiled return; } @@ -85,23 +74,26 @@ namespace Cosmos.Compiler try { var xBody = aMethodBase.GetMethodBody(); - if (xBody == null) - { + if (xBody == null) { return; } - using(var xReader = new ILReader(aMethodBase, xBody)) - { - while(xReader.Read()) - { - InstructionCount++; + using(var xReader = new ILReader(aMethodBase, xBody)) { + while(xReader.Read()) { + // Kudzu: + // Uncomment for debugging - has a small but noticable + // impact on runtime. Could be coincidental, but ran + // tests several times with and with out and without + // was consistently 0.5 secs faster on the Atom. + // Does not make much sense though as its only used 13000 + // times or so, so possibly the compiling in is affecting + // some CPU cache hit or other? + //InstructionCount++; var xCreate = mOps[(ushort) xReader.OpCode]; - if(xCreate==null) - { + if(xCreate == null) { LogMissingOp(xReader.OpCode); continue; } var xOp = xCreate(); - QueueMethodCallCount = 0; xOp.Scan(xReader, this); // TEMP //if (xReader.OperandValueMethod!=null) @@ -113,54 +105,36 @@ namespace Cosmos.Compiler //} } } - }catch(Exception E) - { + } catch(Exception E) { throw new Exception("Error getting body!", E); } } - - private int QueueMethodCallCount = 0; - public void QueueMethod(MethodBase aMethod) - { - QueueMethodCallCount++; - var xName = aMethod.GetFullName(); - if (!mMethodNames.Contains(xName)) - { - mMethodNames.Add(xName); - mMethods.Add(aMethod); - QueueType(aMethod.DeclaringType); - } + public void QueueMethod(MethodBase aMethod) { + if (!mMethodsSet.Contains(aMethod)) { + mMethodsSet.Add(aMethod); + mMethods.Add(aMethod); + QueueType(aMethod.DeclaringType); + } } - public void QueueType(Type type) - { - if(type == null) - { - return; - } - if (!mTypeNames.Contains(type.GetFullName())) - { - QueueType(type.BaseType); - foreach ( - var xMethod in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) - { - if (xMethod.DeclaringType != type) - { - continue; - } - if (xMethod.IsVirtual) - { - QueueMethod(xMethod); - } + public void QueueType(Type aType) { + if (aType != null) { + if (!mTypesSet.Contains(aType)) { + mTypesSet.Add(aType); + mTypes.Add(aType); + QueueType(aType.BaseType); + foreach (var xMethod in aType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { + if (xMethod.DeclaringType == aType) { + if (xMethod.IsVirtual) { + QueueMethod(xMethod); + } } - mTypeNames.Add(type.GetFullName()); - mTypes.Add(type); + } } + } } - //private void - public int MethodCount { get diff --git a/source/Playgrounds/Matthijs/TestApp/Program.cs b/source/Playgrounds/Matthijs/TestApp/Program.cs index a0ffede6e..59fb197f7 100644 --- a/source/Playgrounds/Matthijs/TestApp/Program.cs +++ b/source/Playgrounds/Matthijs/TestApp/Program.cs @@ -10,7 +10,6 @@ using System.Collections.ObjectModel; using Cosmos.Compiler; using Cosmos.Compiler.IL; - namespace TestApp { class Program { static void Main(string[] args)