private static void _do_clear_thispointer(Player player,
                                           ASBinCode.rtData.rtFunction function, StackFrame frame, RunTimeValueBase outscope)
 {
     if (!function.ismethod)
     {
         function.setThis(outscope);
     }
 }
        //class funbacker : IBlockCallBack
        //{
        //    public object args
        //    {
        //        get
        //        ;

        //        set
        //        ;
        //    }

        //    public void call(object args)
        //    {
        //        object[] a = (object[])args;
        //        ((StackFrame)a[0]).endStep((OpStep)a[1]);
        //    }
        //}


        public static void exec_return(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope)
        {
            RunTimeValueBase result = step.arg1.getValue(frame.scope, frame);

            if (result.rtType == RunTimeDataType.rt_function)
            {
                ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)result;
                if (!function.ismethod)//闭包
                {
                    function.setThis(null);
                }
            }

            frame.returnSlot.directSet(result);
            frame.endStep(step);
        }
        public static void exec_yieldreturn(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            RunTimeValueBase result = step.arg1.getValue(scope, frame);

            if (result.rtType == RunTimeDataType.rt_function)
            {
                ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)result;
                if (!function.ismethod)//闭包
                {
                    function.setThis(null);
                }
            }

            scope.memberData[scope.memberData.Length - 2].directSet(new rtInt(frame.codeLinePtr + 1));
            scope.memberData[scope.memberData.Length - 1].directSet(rtBoolean.True);

            frame.returnSlot.directSet(result);
            frame.endStep(step);

            //退出当前调用 *** yield语句不可能包含在try中,所以直接移动到最后一行退出即可
            frame.codeLinePtr = frame.block.instructions.Length;
        }
        public static void bind(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope)
        {
            var rv = step.arg1.getValue(frame.scope, frame);

            if (rv.rtType != RunTimeDataType.rt_function)
            {
                frame.throwError(
                    step.token, 0, "value is not a function");
                frame.endStep(step);
                return;
            }
            else
            {
                ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)rv;

                if (function.bindScope == null
                    ||
                    function.bindScope.blockId == frame.scope.blockId
                    )
                {
                    function.bind(frame.scope);
                }

                if (!function.ismethod)
                {
                    if (function.this_pointer == null)
                    {
                        var s = frame.scope;
                        if (s.this_pointer != null && s.this_pointer is rtObjectBase)
                        {
                            rtObjectBase obj = (rtObjectBase)s.this_pointer;

                            if (obj.value is Global_Object)
                            {
                                function.setThis(obj);
                            }
                            else
                            {
                                var cls = obj.value._class;
                                if (cls.staticClass == null)
                                {
                                    cls = cls.instanceClass;
                                }
                                if (cls.mainClass != null)
                                {
                                    cls = cls.mainClass;
                                }

                                var ot = frame.player.outpackage_runtimescope[cls.classid];
                                function.setThis(ot.this_pointer);
                            }
                        }
                        else
                        {
                            if (frame.player.infoOutput != null)
                            {
                                frame.player.infoOutput.Warring("当前函数没有this指针。也许不是从文档类启动,而是从包外代码启动的");
                            }
                        }
                    }
                }
                frame.endStepNoError();
            }
        }
        //private static void _do_clear_thispointer(Player player,
        //    ASBinCode.rtData.rtFunction function, StackFrame frame,RunTimeValueBase outscope)
        //{

        //    if (!function.ismethod)
        //    {
        //        function.setThis(outscope);
        //    }
        //}

        public static void clear_thispointer(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope)
        {
            RunTimeValueBase rv;
            rtFunction       toclear = null;

            if (step.arg1 is MethodGetterBase)
            {
                rv      = ((ClassMethodGetter)step.arg1).getMethodForClearThis(frame.scope);
                toclear = (rtFunction)rv;
            }
            else
            {
                rv = step.arg1.getValue(frame.scope, frame);
            }

            if (rv.rtType > RunTimeDataType.unknown && ClassMemberFinder.check_isinherits(rv, RunTimeDataType._OBJECT + 2, frame.player.swc))
            {
                //***说明要调用强制类型转换***
                ASBinCode.rtti.Class cls = ((rtObjectBase)rv).value._class;

                if (cls.explicit_from != null)
                {
                    var member = (MethodGetterBase)cls.explicit_from.bindField;
                    var func   = member.getValue(((rtObjectBase)rv).objScope, null);

                    step.reg.getSlot(scope, frame).directSet(func);
                }
                else if (cls.implicit_from != null)
                {
                    var member = (MethodGetterBase)cls.implicit_from.bindField;
                    var func   = member.getValue(((rtObjectBase)rv).objScope, null);

                    step.reg.getSlot(scope, frame).directSet(func);
                }
                else
                {
                    frame.typeconvertoperator            = new typeConvertOperator();
                    frame.typeconvertoperator.targettype = cls;

                    step.reg.getSlot(scope, frame).directSet(rv);
                }

                if (toclear != null)
                {
                    toclear.Clear();
                }

                frame.endStepNoError();
                //frame.endStep(step);
                return;
            }


            if (rv.rtType != RunTimeDataType.rt_function)
            {
                frame.throwError(
                    step.token, 0, "value is not a function");
                if (toclear != null)
                {
                    toclear.Clear();
                }

                frame.endStep(step);
                return;
            }
            else
            {
                ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)rv;



                if (!function.ismethod)
                {
                    int          classid = ((ASBinCode.rtData.rtInt)step.arg2.getValue(scope, frame)).value;
                    RunTimeScope o;
                    if (frame.player.outpackage_runtimescope.TryGetValue(classid, out o))
                    {
                        //_do_clear_thispointer(frame.player, (ASBinCode.rtData.rtFunction)step.reg.getValue(scope, frame), frame, o.this_pointer);
                        function.setThis(o.this_pointer);
                    }
                }

                step.reg.getSlot(scope, frame).directSet(rv);


                if (toclear != null)
                {
                    toclear.Clear();
                }

                frame.endStepNoError();
            }
        }