예제 #1
0
        public static string Next(object on, string root, params IEnumerable <string>[] inUse)
        {
            var key = SigilTuple.Create(on, root);

            lock (State)
            {
                int next;
                if (!State.TryGetValue(key, out next))
                {
                    next       = 0;
                    State[key] = next;
                }

                State[key]++;

                var ret = root + next;

                if (LinqAlternative.Any(inUse, a => LinqAlternative.Any(a, x => x == ret)))
                {
                    return(Next(on, root, inUse));
                }

                return(ret);
            }
        }
예제 #2
0
        public static TypeOnStack GetKnownFunctionPointer(CallingConventions conv, Type instanceType, Type returnType, Type[] parameterTypes)
        {
            var key = SigilTuple.Create(conv, instanceType, returnType, parameterTypes);

            TypeOnStack ret;

            lock (KnownFunctionPointerCache)
            {
                if (!KnownFunctionPointerCache.TryGetValue(key, out ret))
                {
                    ret =
                        new TypeOnStack
                    {
                        HasAttachedMethodInfo = true,
                        Type = typeof(NativeIntType),
                        CallingConvention = conv,
                        InstanceType      = instanceType,
                        ReturnType        = returnType,
                        ParameterTypes    = parameterTypes,
                        UsedBy            = new LinqHashSet <SigilTuple <InstructionAndTransitions, int> >()
                    };

                    KnownFunctionPointerCache[key] = ret;
                }
            }

            return(ret);
        }
예제 #3
0
        private static IEnumerable <T> _QuickSort <T, V>(T[] data, int[] ixs, V[] keys, IComparer <V> c)
        {
            var nextYield = 0;

            var stack = new Stack <SigilTuple <int, int> >();

            stack.Push(SigilTuple.Create(0, ixs.Length - 1));
            while (stack.Count > 0)
            {
                var leftRight = stack.Pop();
                var left      = leftRight.Item1;
                var right     = leftRight.Item2;
                if (right > left)
                {
                    int pivot         = left + (right - left) / 2;
                    int pivotPosition = _Partition(ixs, keys, left, right, pivot, c);
                    stack.Push(SigilTuple.Create(pivotPosition + 1, right));
                    stack.Push(SigilTuple.Create(left, pivotPosition - 1));
                }
                else
                {
                    while (nextYield <= right)
                    {
                        yield return(data[ixs[nextYield]]);

                        nextYield++;
                    }
                }
            }
        }
예제 #4
0
        private VerificationResult CompareStacks(Label label, SigilTuple <bool, LinqStack <LinqList <TypeOnStack> > > actual, SigilTuple <bool, LinqStack <LinqList <TypeOnStack> > > expected)
        {
            if (!actual.Item1 && !expected.Item1)
            {
                if (expected.Item2.Count != actual.Item2.Count)
                {
                    // Both stacks are based, so the wrong size is a serious error as well
                    return(VerificationResult.FailureUnderflow(label, expected.Item2.Count));
                }
            }

            for (var i = 0; i < expected.Item2.Count; i++)
            {
                if (i >= actual.Item2.Count && !actual.Item1)
                {
                    // actual is based and expected wanted a value, this is an UNDERFLOW
                    return(VerificationResult.FailureUnderflow(label, expected.Item2.Count));
                }

                var expectedTypes = expected.Item2.ElementAt(i);
                LinqList <TypeOnStack> actualTypes;
                if (i < actual.Item2.Count)
                {
                    actualTypes = actual.Item2.ElementAt(i);
                }
                else
                {
                    // Underflowed, but our actual stack is baseless; so we assume we're good until proven otherwise
                    break;
                }

                bool typesMatch = false;
                foreach (var a in actualTypes.AsEnumerable())
                {
                    foreach (var e in expectedTypes.AsEnumerable())
                    {
                        typesMatch |= e.IsAssignableFrom(a);
                    }
                }

                if (!typesMatch)
                {
                    // Just went through what's on the stack, and we the types are known to not be compatible
                    return(VerificationResult.FailureTypeMismatch(label, actualTypes, expectedTypes));
                }
            }

            return(null);
        }
예제 #5
0
        private SigilTuple <bool, LinqStack <LinqList <TypeOnStack> > > GetCurrentStack()
        {
            SigilTuple <bool, LinqStack <LinqList <TypeOnStack> > > ret = null;

            for (var i = 0; i < CurrentlyInScope.Count; i++)
            {
                var c     = CurrentlyInScope[i];
                var stack = CurrentlyInScopeStacks[i];

                var stackCopy = CopyStack(stack);

                var innerRet = SigilTuple.Create(c.IsBaseless, stackCopy);

                if (ret == null || (innerRet.Item1 && !ret.Item1) || innerRet.Item2.Count > ret.Item2.Count)
                {
                    ret = innerRet;
                }
            }

            return(ret);
        }
예제 #6
0
 /// <summary>
 /// Call to indicate that something on the stack was used
 /// as the #{index}'d (starting at 0) parameter to the {code}
 /// opcode.
 /// </summary>
 public void Mark(InstructionAndTransitions instr, int index)
 {
     UsedBy.Add(SigilTuple.Create(instr, index));
 }