Ejemplo n.º 1
0
        internal string[] Instructions(LinqList <Local> locals)
        {
            var ret = new List <string>();

            var invoke         = typeof(DelegateType).GetMethod("Invoke");
            var returnType     = invoke.ReturnType;
            var parameterTypes = LinqAlternative.Select(invoke.GetParameters(), s => s.ParameterType).ToArray();

            var dynMethod = new DynamicMethod(Guid.NewGuid().ToString(), returnType, parameterTypes);
            var il        = dynMethod.GetILGenerator();

            var instrs = new StringBuilder();

            for (var i = 0; i < Buffer.Count; i++)
            {
                var x = Buffer[i];

                x(il, true, instrs);
                var line = instrs.ToString().TrimEnd();

                if (line.StartsWith(OpCodes.Ldloc_0.ToString()) ||
                    line.StartsWith(OpCodes.Stloc_0.ToString()))
                {
                    line += " // " + GetInScopeAt(locals, i)[0];
                }

                if (line.StartsWith(OpCodes.Ldloc_1.ToString()) ||
                    line.StartsWith(OpCodes.Stloc_1.ToString()))
                {
                    line += " // " + GetInScopeAt(locals, i)[1];
                }

                if (line.StartsWith(OpCodes.Ldloc_2.ToString()) ||
                    line.StartsWith(OpCodes.Stloc_2.ToString()))
                {
                    line += " // " + GetInScopeAt(locals, i)[2];
                }

                if (line.StartsWith(OpCodes.Ldloc_3.ToString()) ||
                    line.StartsWith(OpCodes.Stloc_3.ToString()))
                {
                    line += " // " + GetInScopeAt(locals, i)[3];
                }

                if (line.StartsWith(OpCodes.Ldloc_S.ToString()) ||
                    line.StartsWith(OpCodes.Stloc_S.ToString()))
                {
                    line += " // " + ExtractLocal(line, locals, i);
                }

                ret.Add(line);
                instrs.Length = 0;
            }

            return(ret.ToArray());
        }
Ejemplo n.º 2
0
        public void Emit(OpCode op, Sigil.Label[] labels, out UpdateOpCodeDelegate update)
        {
            var localOp = op;

            update =
                newOpcode =>
            {
                LengthCache.Clear();

                localOp = newOpcode;
            };

            InstructionSizes.Add(() => InstructionSize.Get(localOp, labels));

            LengthCache.Clear();

            Buffer.Add(
                (il, logOnly, log) =>
            {
                if (!logOnly)
                {
                    var ls = LinqAlternative.Select(labels, l => l.LabelDel(il)).ToArray();
                    il.Emit(localOp, ls);
                }

                log.AppendLine(localOp + " " + Join(", ", ((LinqArray <Label>)labels).AsEnumerable()));
            }
                );

            TraversableBuffer.Add(new BufferedILInstruction {
                IsInstruction = op
            });

            Operations.Add(new Operation <DelegateType> {
                OpCode = op, Parameters = labels
            });
        }
Ejemplo n.º 3
0
 public LinqRoot <V> Select <V>(SigilFunc <T, int, V> p)
 {
     return(LinqAlternative.Select(InnerEnumerable(), p));
 }