public StackSlot(CSWC classfinder,Player player)
        {
            this.player = player;
            store       = new RunTimeValueBase[(int)RunTimeDataType._OBJECT + 1];
            index       = (int)RunTimeDataType.unknown;

            _cache_arraySlot     = new operators.OpAccess_Dot.arraySlot(null,0,classfinder);
            _cache_vectorSlot    = new operators.OpVector.vectorSLot(null,0,classfinder);
            _cache_prototypeSlot = new operators.OpAccess_Dot.prototypeSlot(null,null,null);
            _cache_setthisslot   = new SetThisItemSlot();

            //存储器设置初始值
            for (int i = 0; i < RunTimeDataType._OBJECT + 1; i++)
            {
                RunTimeDataType t = (RunTimeDataType)i;
                if (t != RunTimeDataType.unknown)
                {
                    store[i] = TypeConverter.getDefaultValue(t).getValue(null,null);
                }
            }

            store[RunTimeDataType.rt_array]    = null;
            store[RunTimeDataType.rt_string]   = null;
            store[RunTimeDataType.rt_function] = null;


            _numberValue = (rtNumber)store[RunTimeDataType.rt_number];
            _intValue    = (rtInt)store[RunTimeDataType.rt_int];
            _uintValue   = (rtUInt)store[RunTimeDataType.rt_uint];
            _stringValue = new rtString(string.Empty);

            _functionValue  = new rtFunction(-1,false);
            _functon_result = new rtFunction(-1,false);
        }
 public InterfaceMethodGetter(string name, rtti.Class _class
                              , int refdefinedinblockid
                              ) : base(name, _class, 0, refdefinedinblockid)
 {
     //cache = new WeakReference(null);
     _cachemethod = new rtFunction(-1, false);
 }
        public static void bindFunctionWhenCreate(rtFunction function, StackFrame frame, RunTimeScope scope, int defclassid)
        {
            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 = frame.player.swc.classes[defclassid];                              //obj.value._class;
                            if (cls.staticClass == null)
                            {
                                cls = cls.instanceClass;
                            }
                            if (cls.mainClass != null)
                            {
                                cls = cls.mainClass;
                            }

                            if (frame.player.outpackage_runtimescope.ContainsKey(cls.classid))
                            {
                                var ot = frame.player.outpackage_runtimescope[cls.classid];
                                function.setThis(ot.this_pointer);
                            }
                            else
                            {
                                //***此处只有在$Object启动时发生***
                                function.setThis(obj);
                            }
                        }
                    }
                    else
                    {
                        if (frame.player.infoOutput != null)
                        {
                            frame.player.infoOutput.Warring("当前函数没有this指针。也许不是从文档类启动,而是从包外代码启动的");
                        }
                    }
                }
            }
        }
        public static bool create_paraScope_WithSignature_AllParaOnStack(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope)
        {
            rtFunction function
                = (rtFunction)step.arg1.getValue(frame.scope, frame);

            var functionDefine = frame.player.swc.functions[function.functionId];

            if (frame.baseBottomSlotIndex + frame.call_parameter_slotCount + functionDefine.signature.onStackParameters >= Player.STACKSLOTLENGTH)
            {
                frame.throwError(new error.InternalError(frame.player.swc, step.token, "stack overflow"));
                frame.endStep();
                return(false);
            }

            var funcCaller = frame.player.funcCallerPool.create(frame, step.token);

            funcCaller.SetFunction(function); function.Clear();
            funcCaller.toCallFunc = functionDefine;
            frame.funCaller       = funcCaller;

            frame.call_parameter_slotCount  += functionDefine.signature.onStackParameters;
            funcCaller.onstackparametercount = functionDefine.signature.onStackParameters;
            funcCaller.CallFuncHeap          = Player.emptyMembers;

            var parameters = functionDefine.signature.parameters; int len = parameters.Count; int parast = frame.baseBottomSlotIndex + frame.call_parameter_slotCount;

            for (int i = step.jumoffset; i < len; i++)
            {
                var parameter = parameters[i];
                if (parameter.defaultValue != null)
                {
                    var dv = FunctionCaller.getDefaultParameterValue(parameter.type, parameter.defaultValue.getValue(null, null));

                    frame.stack[parast - i - 1].directSet(dv);
                    //_storeArgementToSlot(i, dv);
                }
                else if (parameter.isPara)
                {
                    frame.stack[parast - i - 1].directSet(new ASBinCode.rtData.rtArray());
                    //_storeArgementToSlot(i, new ASBinCode.rtData.rtArray());
                }
            }



            frame.endStepNoError();
            return(true);
        }
        public static void create_paraScope_Method_NoParameters(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope)
        {
            rtFunction function
                = (rtFunction)((MethodGetterBase)step.arg1).getMethod(frame.scope);

            var functionDefine = frame.player.swc.functions[function.functionId];


            var funcCaller = frame.player.funcCallerPool.create(frame, step.token);

            funcCaller.SetFunction(function); function.Clear();
            funcCaller.toCallFunc   = functionDefine;
            frame.funCaller         = funcCaller;
            funcCaller.CallFuncHeap = Player.emptyMembers;
            frame.endStepNoError();
        }
        public static void create_paraScope_Method(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope)
        {
            rtFunction function
                = (rtFunction)((MethodGetterBase)step.arg1).getMethod(frame.scope);

            var funcCaller = frame.player.funcCallerPool.create(frame, step.token);

            funcCaller.SetFunction(function); function.Clear();
            funcCaller._tempSlot  = frame._tempSlot1;
            funcCaller.toCallFunc = frame.player.swc.functions[function.functionId];
            if (!funcCaller.createParaScope())
            {
                return;
            }

            frame.funCaller = funcCaller;

            //frame.endStep(step);
            frame.endStepNoError();
        }
        public static void create_paraScope_WithSignature(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope)
        {
            rtFunction function
                = (rtFunction)step.arg1.getValue(frame.scope, frame);

            var funcCaller = frame.player.funcCallerPool.create(frame, step.token);

            funcCaller.SetFunction(function);
            funcCaller._tempSlot  = frame._tempSlot1;
            funcCaller.toCallFunc = frame.player.swc.functions[function.functionId];
            if (!funcCaller.createParaScope())
            {
                return;
            }

            frame.funCaller = funcCaller;

            //frame.endStep(step);
            frame.endStepNoError();
        }
        //public override RunTimeValueBase execute(RunTimeValueBase thisObj, SLOT[] argements,object stackframe,  out string errormessage, out int errorno)
        //{


        //    //throw new NotImplementedException();
        //}

        public override void execute3(RunTimeValueBase thisObj,FunctionDefine functionDefine,SLOT returnSlot,SourceToken token,StackFrame stackframe,out bool success)
        {
            rtFunction func = (rtFunction)((rtObjectBase)thisObj).value.memberData[0].getValue();

            var signature = stackframe.player.swc.functions[func.functionId].signature;

            success = true;

            if (signature.parameters.Count == 0)
            {
                returnSlot.setValue(0);
            }
            else if (signature.parameters[signature.parameters.Count - 1].isPara)
            {
                returnSlot.setValue(signature.parameters.Count - 1);
            }
            else
            {
                returnSlot.setValue(signature.parameters.Count);
            }
        }
        public static void create_paraScope(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope)
        {
            RunTimeValueBase rv; rtFunction toclear = null;

            if (step.arg1 is MethodGetterBase)
            {
                rv = ((MethodGetterBase)step.arg1).getMethod(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 (frame.typeconvertoperator != null)
                {
                    frame.endStepNoError();
                    //frame.endStep(step);
                    return;
                }
                else if (frame.typeconvertoperator.targettype.instanceClass == null
                         ||
                         frame.typeconvertoperator.targettype != cls
                         )
                {
                    frame.throwError(new error.InternalError(frame.player.swc, step.token, "类型转换函数发现内部错误"
                                                             ));
                    frame.endStep(step);
                    return;
                }
            }

            if (rv.rtType == frame.player.swc.FunctionClass.getRtType())
            {
                rv = TypeConverter.ObjectImplicit_ToPrimitive((rtObjectBase)rv);
            }

            if (rv.rtType != RunTimeDataType.rt_function)
            {
                frame.throwError(step.token, 0, "value is not a function");
                frame.endStep(step);
            }
            else
            {
                ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)rv;
                var funcCaller = frame.player.funcCallerPool.create(frame, step.token);
                funcCaller.SetFunction(function); if (toclear != null)
                {
                    toclear.Clear();
                }
                funcCaller._tempSlot = frame._tempSlot1;
                funcCaller.loadDefineFromFunction();
                if (!funcCaller.createParaScope())
                {
                    return;
                }

                frame.funCaller = funcCaller;
                frame.endStepNoError();
            }
        }
        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;

                step.reg.getSlot(scope, frame).directSet(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);
                    }
                }

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

                frame.endStepNoError();
            }
        }
        public override void executeAsync(RunTimeValueBase thisObj,SLOT[] argements,SLOT resultSlot,
                                          object callbacker,
                                          object stackframe,
                                          SourceToken token,RunTimeScope scope)
        {
            //base.executeAsync(thisObj, argements, resultSlot, callbacker, stackframe, token, scope);

            var thisArg = argements[0].getValue();


            rtFunction func    = (rtFunction)((rtObjectBase)thisObj).value.memberData[0].getValue();
            rtFunction toApply = (rtFunction)func;            //.Clone();


            if (!func.ismethod)             //方法无法更改this
            {
                if (!(thisArg is rtObjectBase))
                {
                    var player  = ((StackFrame)stackframe).player;
                    var objtype = thisArg.rtType;
                    if (objtype < RunTimeDataType.unknown
                        &&
                        player.swc.primitive_to_class_table[objtype] != null
                        )
                    {
                        FunctionCaller toInsertStack = ((StackFrame)stackframe).player.funcCallerPool.create((StackFrame)(stackframe),token);
                        toInsertStack.callbacker = (IBlockCallBack)callbacker;
                        toInsertStack.SetFunction(toApply);
                        toInsertStack._tempSlot  = ((StackFrame)stackframe)._tempSlot1;
                        toInsertStack.returnSlot = resultSlot;
                        toInsertStack.tag        = argements;

                        stackCallers.Push(toInsertStack);

                        //***转换为对象***
                        OpCast.Primitive_to_Object(thisArg,(StackFrame)stackframe,token,scope,
                                                   ((StackFrame)stackframe)._tempSlot1,
                                                   null,_primitive_toObj);


                        return;
                    }
                    else
                    {
                        var fd    = player.swc.functions[toApply.functionId];
                        var block = player.swc.blocks[fd.blockid];
                        //if (block.isoutclass )将this复位
                        {
                            var oc = player.outpackage_runtimescope[block.define_class_id];
                            toApply.setThis(oc.this_pointer);
                        }
                        //else
                        //{
                        //    caller.function.setThis(null);
                        //}
                    }
                }
                else
                {
                    toApply.setThis((rtObjectBase)thisArg);
                }
            }

            FunctionCaller caller = ((StackFrame)stackframe).player.funcCallerPool.create((StackFrame)(stackframe),token);

            caller.callbacker = (IBlockCallBack)callbacker;
            caller.SetFunction(toApply);
            caller._tempSlot  = ((StackFrame)stackframe)._tempSlot1;
            caller.returnSlot = resultSlot;

            caller.loadDefineFromFunction();
            if (!caller.createParaScope())
            {
                return;
            }



            if (argements[1].getValue().rtType == RunTimeDataType.rt_array)
            {
                rtArray argArray = (rtArray)argements[1].getValue();
                for (int i = 0; i < argArray.innerArray.Count; i++)
                {
                    bool success;
                    caller.pushParameter(argArray.innerArray[i],i,out success);
                }
            }


            caller.call();
        }
 internal FunctionWapper(rtFunction func, Player player)
 {
     this.player   = player;
     this.function = (rtFunction)func.Clone();
 }