示例#1
0
        /// <summary>
        /// 创建一个值类型的新对象或新实例,并将对象引用(O 类型)推送到计算堆栈上。
        /// </summary>
        /// <param name="type"></param>
        public void Newobj(string instance, string @return, MethodTasks task)
        {
            if (task.Clr.ArgsVarCount > 0)
            {
                //初始化
                task.Clr.Argp->ValueType = StackValueType.Ref;
                var clrObj = new ClrObject();
                task.InitMember(clrObj);

                task.Clr.Argp->SetValue(StackValueType.Ref, clrObj);
            }

            task.Run();
            EvaluationStack_Push(task.Clr.ResultPoint);
        }
示例#2
0
        /// <summary>
        /// "IL_0009" : "call" "int32" "ApolloClr.Program::fib(int32)" null
        /// 调用由传递的方法说明符指示的方法
        /// </summary>
        public void Call(string retType, string method, MethodTasks task)
        {
            //如果有新的层级进来
            if (!task.IsEnd)
            {
                var newtask = task.Clone();

                //获取空余方法
                //从堆栈拷贝参数
                if (newtask.Clr.ArgsVarCount > 0)
                {
                    CopyToArgs(newtask.Clr);
                }

                newtask.Run(() =>
                {
                    //如果有返回
                    if (newtask.Clr.RetResult)
                    {
                        //压入返回值
                        EvaluationStack_Push(newtask.Clr.ResultPoint);
                    }
                });
            }
            else
            {
                if (task.Clr.ArgsVarCount > 0)
                {
                    CopyToArgs(task.Clr);
                }
                //如果是非静态
                //把先吧对象压入栈

                //克隆 对战 并 运行
                task.Run(() =>
                {
                    //如果有返回
                    if (task.Clr.RetResult)
                    {
                        //压入返回值
                        EvaluationStack_Push(task.Clr.ResultPoint);
                    }
                });
            }
        }
示例#3
0
        /// <summary>
        /// 创建一个值类型的新对象或新实例,并将对象引用(O 类型)推送到计算堆栈上。
        /// </summary>
        /// <param name="type"></param>
        public void Newobj(string instance, string @return, MethodTasks task)
        {
            int begin = 1;

            if ((task is CrossMethod) && (task as CrossMethod).CrossMethodDelegate is DelegateBuild)
            {
                begin = 0;
            }
            else
            {
                if (task.Clr.ArgsVarCount > 0)
                {
                    //初始化

                    var clrObj = new ClrObject();
                    task.InitMember(clrObj);

                    task.Clr.Argp->SetValue(StackValueType.Ref, clrObj, true);
                }
            }

            if (task.Clr.ArgsVarCount > 0)
            {
                var vs = EvaluationStack_Pop(task.Clr.ArgsVarCount - begin);

                for (int i = 0; i < task.Clr.ArgsVarCount - begin; i++)
                {
                    *(task.Clr.Argp + i + begin) = *(vs + i);
                    (task.Clr.Argp + i + begin)->Fix();
                }
            }

            task.Run(() =>
            {
                EvaluationStack_Push(task.Clr.ResultPoint);
            });
        }
示例#4
0
        static unsafe void Main(string[] args)
        {
            int count = 10000 * 1000;

            var sw = new Stopwatch();


            long p1   = 0;
            long p2   = 0;
            var  code = @"
	
    // [99 9 - 99 10]
    IL_0000: nop          

    // [100 13 - 100 23]
    IL_0001: ldc.i4.1     
    IL_0002: stloc.0      // i

    // [101 13 - 101 23]
    IL_0003: ldc.i4.2     
    IL_0004: stloc.1      // j

    // [102 13 - 102 23]
    IL_0005: ldc.i4.3     
    IL_0006: stloc.2      // k

    // [103 13 - 103 36]
    IL_0007: ldloc.0      // i
    IL_0008: ldloc.1      // j
    IL_0009: add          
    IL_000a: ldloc.2      // k
    IL_000b: add          
    IL_000c: stloc.3      // answer

    // [104 13 - 104 27]
    IL_000d: ldloc.3      // answer
    IL_000e: stloc.s      V_4
    IL_0010: br.s         IL_0012

    // [105 9 - 105 10]
    IL_0012: ldloc.s      V_4
    IL_0014: ret          
	IL_0017: ret
";
            {
#if JS
                TypeDefine.AssemblyDefine.ReadAndRun(AppDomain.CurrentDomain.BaseDirectory + "TestLib.dll", "Test", "ClassRun");
#endif

                //Test.RunArray();
                TypeDefine.AssemblyDefine.ReadAndRun(AppDomain.CurrentDomain.BaseDirectory + "TestLib.dll", "Test",
                                                     "EventTest");

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


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

                p1 = sw.ElapsedMilliseconds;
                Console.WriteLine(sw.ElapsedMilliseconds);
            }

            {
                sw.Restart();
                sw.Start();
                for (int i = 0; i < count; i++)
                {
                    Run1();
                }

                sw.Stop();
                Console.WriteLine(sw.ElapsedMilliseconds);
                p2 = sw.ElapsedMilliseconds;
            }

            Console.WriteLine("P1/P2:" + p1 * 1.0f / p2);
            Console.ReadLine();
        }
示例#5
0
 /// <summary>
 /// 对对象调用后期绑定方法,并且将返回值推送到计算堆栈上。
 /// </summary>
 public void Callvirt(string instance, string @return, MethodTasks task)
 {
     Call(null, null, task);
 }
示例#6
0
 /// <summary>
 /// 将指向实现特定方法的本机代码的非托管指针(native int 类型)推送到计算堆栈上。
 /// </summary>
 public void Ldftn(string retType, string method, MethodTasks task)
 {
     EvaluationStack_Push(task);
 }
示例#7
0
        static unsafe void Main(string[] args)
        {
            int count = 10000 * 1000;

            var sw = new Stopwatch();


            long p1   = 0;
            long p2   = 0;
            var  code = @"
	IL_0000: ldarg.0
	IL_0001: ldc.i4.2
	IL_0002: bge.s IL_0006

	IL_0004: ldarg.0
	IL_0005: ret

	IL_0006: ldarg.0
	IL_0007: ldc.i4.1
	IL_0008: sub
	IL_0009: call int32 ApolloClr.Program::fib(int32)
	IL_000e: ldarg.0
	IL_000f: ldc.i4.2
	IL_0010: sub
	IL_0011: call int32 ApolloClr.Program::fib(int32)
	IL_0016: add
	IL_0017: ret
";
            {
#if JS
                TypeDefine.AssemblyDefine.ReadAndRun(AppDomain.CurrentDomain.BaseDirectory + "TestLib.dll", "Test", "ClassRun");
#endif

                //Test.RunArray();
                TypeDefine.AssemblyDefine.ReadAndRun(AppDomain.CurrentDomain.BaseDirectory + "TestLib.dll", "Test",
                                                     "ClassRun");

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


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

                p1 = sw.ElapsedMilliseconds;
                Console.WriteLine(sw.ElapsedMilliseconds);
            }

            {
                sw.Restart();
                sw.Start();
                for (int i = 0; i < count; i++)
                {
                    Run1();
                }

                sw.Stop();
                Console.WriteLine(sw.ElapsedMilliseconds);
                p2 = sw.ElapsedMilliseconds;
            }

            Console.WriteLine("P1/P2:" + p1 * 1.0f / p2);
            Console.ReadLine();
        }
示例#8
0
        public virtual IEnumerator <object> RunStep(Action onRunEnd)
        {
            PC    = 0;
            IsEnd = false;



            while (PC < End)
            {
                //try
                //{

                var line = Lines[PC];


                MethodTasks stepinMethodTasks = null;
                if (line.GetType().Name == typeof(OpCodeTask <, ,>).Name)
                {
                    if (line.GetType().GetField("V3") != null)
                    {
                        var obj = line.GetType().GetField("V3").GetValue(line);
                        if (obj is MethodTasks)
                        {
                            stepinMethodTasks         = obj as MethodTasks;
                            stepinMethodTasks.InDebug = true;
                        }
                    }
                }

                line.Run();

                if (stepinMethodTasks != null && stepinMethodTasks.DebugerStep != null)
                {
                    while (stepinMethodTasks.DebugerStep.MoveNext())
                    {
                        yield return(stepinMethodTasks);
                    }
                }

                //}
                //catch (Exception ex)
                //{
                //    Clr.EvaluationStack_Push(0);
                //    ThrowAction(ex, -1);
                //}

                PC++;
                yield return(this);
            }

            IsEnd = true;
            //Console.WriteLine("==========Run End===========:" + Name);
            if (TrowException != null && !IsCatched)
            {
                //如果发现跳出之后依然有异常抛出
                throw TrowException;
            }

            if (onRunEnd != null)
            {
                onRunEnd();
            }
            yield return(this);
        }