示例#1
0
 public override void SetArgs(object[] values)
 {
     for (int i = 0; i < values.Length; i++)
     {
         if (values[i] is MethodTasks)
         {
             Method = values[i] as MethodTasks;
         }
     }
     Target = values[1];
     //TODO 其他参数
 }
示例#2
0
        public void TestRun(string code)
        {
            srcCode = code;

            //textEditorControl1.SetHighlighting("CSharp-Mode");
            File.WriteAllText("il.il", code);
            this.textEditorControl1.LoadFile("il.il");

            var func = MethodTasks.Build(code).Compile();

            LoadClr(func);
        }
示例#3
0
        public void LoadClr(MethodTasks method, IEnumerator <object> inputSteps = null)
        {
            method          = method.GetDebuggerMethod();
            BindMethodTasks = method;
            this.clirStackViewUI1.LoadStack(method.Clr.Stack);

            if (inputSteps == null)
            {
                Steps = BindMethodTasks.RunStep(null);
                Steps.MoveNext();
            }
            else
            {
                Steps = inputSteps;
            }
            Log("加载:" + method.Name);

            if (string.IsNullOrEmpty(srcCode))
            {
                StringBuilder sb   = new StringBuilder();
                int           line = 0;
                foreach (var opTask in method.Lines)
                {
                    while (line != opTask.OpCode.LineNum)
                    {
                        sb.AppendLine();
                        line++;
                    }
                    line++;
                    sb.AppendLine(opTask.OpCode.Line);
                }

                srcCode = sb.ToString();

                //textEditorControl1.SetHighlighting("CSharp-Mode");
                File.WriteAllText("il.il", srcCode);
                this.textEditorControl1.LoadFile("il.il");
            }
            LoadView();

            MoveCodeLine();

            this.Text += " " + method;
        }
示例#4
0
文件: App.cs 项目: jkloop45/ApolloClr
        public static void Main()
        {
            var code = @"
	IL_0000: nop
	IL_0001: ldc.i4.1
	IL_0002: stloc.0
	IL_0003: ldc.i4.2
	IL_0004: stloc.1
	IL_0005: ldc.i4.3
	IL_0006: stloc.2
	IL_0007: ldloc.0
	IL_0008: ldloc.1
	IL_0009: add
	IL_000a: ldloc.2
	IL_000b: add
	IL_000c: stloc.3
	IL_000d: ldloc.3
	IL_000e: stloc.s 4
	IL_0010: br.s IL_0012

	IL_0012: ldloc.s 4
	IL_0014: ret
";

            if (true)
            {
                int count = 10000 * 10;
                var sw    = new Stopwatch();
                var func  = MethodTasks.Build(code).Compile();


                sw.Restart();
                sw.Start();
                for (int i = 0; i < count; i++)
                {
                    func.Run();
                }
                sw.Stop();
                Console.WriteLine(sw.ElapsedMilliseconds);
                sw.Restart();
                sw.Start();
                for (int i = 0; i < count; i++)
                {
                    Run1();
                }
                sw.Stop();
                Console.WriteLine(sw.ElapsedMilliseconds);
            }

            jQuery.Ajax(new AjaxOptions
            {
                Url         = "out.il",
                Data        = "",
                ContentType = "application/json; charset=utf-8",
                Success     = delegate(object data, string str, jqXHR jqxhr)
                {
                    //Console.WriteLine(str);

                    var json = data + "";
                    Console.WriteLine("Result:" + json);
                    var result = TypeDefine.AssemblyDefine.ReadAndRun(json, "Test", "RunF1");
                    Console.WriteLine("End:" + Bridge.Html5.JSON.Stringify(result));
                }
            });
        }
示例#5
0
        public override void Run(Action onRunEnd)
        {
            var vs = Clr.Argp;

#if JS
            StackObject ptr = vs;
#else
            var ptr = vs->Ptr;
#endif
            //对值对象 赋值
            if (IsStatic)
            {
                object[] args = new object[ArgCount];
                for (int i = 0; i < ArgCount; i++)
                {
                    args[i] = StackObject.ToObject(vs + i);
                }
                CrossMethodDelegate.SetArgs(args);
            }
            else
            {
                object[] args = new object[ArgCount];
                for (int i = 0; i < ArgCount; i++)
                {
                    if (i == 0)
                    {
                        if (!ptr.IsAllocated || ptr != CrossMethodDelegate.Ptr)
                        {
                            args[ArgCount - 1] = StackObject.ToObject(vs + i);
                        }
                        else
                        {
                            //跳过对象创建
                            //如果在一个对象中重复使用,跳过
                        }
                    }
                    else
                    {
                        args[i - 1] = StackObject.ToObject(vs + i);
                    }
                }
                CrossMethodDelegate.SetArgs(args);
                if (!IsStatic && CrossMethodDelegate.Delegate != null)
                {
                    if (ptr != CrossMethodDelegate.Ptr)
                    {
                        CrossMethodDelegate.Ptr = ptr;
#if BRIDGE
                        CrossMethodDelegate["func"] = CrossMethodDelegate.Delegate.SetTarget(args[ArgCount - 1]);
#else
                        CrossMethodDelegate.Delegate.SetTarget(args[ArgCount - 1]);
#endif
                    }
                }
            }


            CrossMethodDelegate.Run();


            Action endAction = () =>
            {
                if (HaseResult)
                {
                    Clr.ResultPoint = Clr.Csp;
#if JS
                    Clr.ResultPoint.ValueType = StackValueType.Ref;
                    Clr.ResultPoint.Ptr       = StackObject.NewObject(CrossMethodDelegate.Result);
#else
                    Clr.ResultPoint->ValueType = StackValueType.Ref;
                    Clr.ResultPoint->Ptr       = StackObject.NewObject(CrossMethodDelegate.Result);
#endif
                }

                if (onRunEnd != null)
                {
                    onRunEnd();
                }
            };
#if DEBUG
            if (InDebug)
            {
                if (CrossMethodDelegate.Delegate != null && CrossMethodDelegate.Delegate.Target is Delegate)
                {
                    var db = ((CrossMethodDelegate.Delegate.Target as Delegate).Target as DelegateBuild);
                    if (db.Method.InDebug && db.Method.DebugerStep != null)
                    {
                        DebugerStep = db.Method.DebugerStep;

                        this.DebugerMethod = db.Method;
                    }
                }
            }


            if (DebugerStep == null)
#endif
            {
                endAction();
            }
        }