private void exec_step1()
        {
            BlockCallBackBase callbacker = player.blockCallBackPool.create();

            callbacker.args = this;

            callbacker.setCallBacker(afterCreateInstanceDataCallBacker);
            callbacker.setWhenFailed(creatorFailed);

            ASBinCode.RunTimeScope objScope;

            makeObj(player,token,_class,callbacker,this,out objScope);
        }
Пример #2
0
        internal void doCall_allcheckpass()
        {
            if (toCallFunc.isYield)
            {
                if (!player.static_instance.ContainsKey(player.swc.YieldIteratorClass.staticClass.classid))
                {
                    if (!InstanceCreator.init_static_class(player.swc.YieldIteratorClass,player,token))
                    {
                        invokerFrame.endStep();

                        if (callbacker != null)
                        {
                            callbacker.noticeRunFailed();
                        }
                        release();


                        return;
                    }
                }

                ASBinCode.rtti.YieldObject yobj = new ASBinCode.rtti.YieldObject(
                    player.swc.YieldIteratorClass);


                CallFuncHeap[CallFuncHeap.Length - 2].directSet(new ASBinCode.rtData.rtInt(1));

                yobj.argements          = CallFuncHeap;
                yobj.function_bindscope = function.bindScope;
                yobj.block          = player.swc.blocks[toCallFunc.blockid];
                yobj.yield_function = toCallFunc;


                ASBinCode.rtData.rtObject rtYield = new ASBinCode.rtData.rtObject(yobj,null);
                yobj.thispointer =
                    (function.this_pointer != null ?
                     function.this_pointer : invokerFrame.scope.this_pointer);

                RunTimeScope scope = new RunTimeScope(null,
                                                      player.swc.YieldIteratorClass.blockid,null,rtYield,RunTimeScopeType.objectinstance);
                rtYield.objScope = scope;

                returnSlot.directSet(rtYield);


                if (callbacker != null)
                {
                    callbacker.call(callbacker.args);
                }
                release();

                return;
            }
            else if (!toCallFunc.isNative)
            {
                if (returnSlot is StackSlot)
                {
                    TypeConverter.setDefaultValueToStackSlot(
                        toCallFunc.signature.returnType,
                        (StackSlot)returnSlot);
                }
                else
                {
                    returnSlot.directSet(
                        TypeConverter.getDefaultValue(toCallFunc.signature.returnType).getValue(null,null));
                }
                if (!ReferenceEquals(callbacker,this))
                {
                    //***执行完成后,先清理参数***
                    BlockCallBackBase cb = player.blockCallBackPool.create();
                    cb.args            = cb.cacheObjects;
                    cb.cacheObjects[0] = callbacker;
                    cb.cacheObjects[1] = invokerFrame;

                    cb.setCallBacker(callfun_cb);
                    cb.setWhenFailed(callfun_failed);
                    cb._intArg            = onstackparametercount;
                    onstackparametercount = 0;

                    player.callBlock(
                        player.swc.blocks[toCallFunc.blockid],
                        CallFuncHeap,
                        returnSlot,
                        function.bindScope,
                        token,cb,function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer,RunTimeScopeType.function);

                    release();
                }
                else
                {
                    player.callBlock(
                        player.swc.blocks[toCallFunc.blockid],
                        CallFuncHeap,
                        returnSlot,
                        function.bindScope,
                        token,callbacker,function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer,RunTimeScopeType.function);
                }
            }
            else
            {
                //if (toCallFunc.native_index <0)
                //{
                //    toCallFunc.native_index = player.swc.nativefunctionNameIndex[toCallFunc.native_name];
                //}

                //var nf = player.swc.nativefunctions[toCallFunc.native_index];
                var nf = player.swc.getNativeFunction(toCallFunc);
                nf.bin = player.swc;

                if (nf.mode == NativeFunctionBase.NativeFunctionMode.normal_0)
                {
                    player._nativefuncCaller = this;

                    string errormsg;
                    int    errorno;
                    var    result = nf.execute(
                        function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer,
                        CallFuncHeap,invokerFrame,
                        out errormsg,
                        out errorno
                        );
                    player._nativefuncCaller = null;
                    if (errormsg == null)
                    {
                        returnSlot.directSet(result);

                        if (callbacker != null)
                        {
                            callbacker.call(callbacker.args);
                        }

                        release();
                    }
                    else
                    {
                        invokerFrame.throwError(
                            token,0,errormsg
                            );

                        invokerFrame.endStep();

                        if (callbacker != null)
                        {
                            callbacker.noticeRunFailed();
                        }
                        release();
                    }
                }
                //else if (nf.mode == NativeFunctionBase.NativeFunctionMode.normal_1)
                //{
                //	player._nativefuncCaller = this;
                //	bool success;

                //	nf.execute2(
                //		function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer,
                //		toCallFunc,
                //		CallFuncHeap,
                //		returnSlot,
                //		token,
                //		invokerFrame,
                //		out success
                //		);
                //	player._nativefuncCaller = null;
                //	if (success)
                //	{
                //		if (callbacker != null)
                //		{
                //			callbacker.call(callbacker.args);
                //		}
                //	}
                //	else
                //	{
                //		invokerFrame.endStep();
                //		if (callbacker != null)
                //		{
                //			callbacker.noticeRunFailed();
                //		}

                //	}

                //	release();


                //}
                else if (nf.mode == NativeFunctionBase.NativeFunctionMode.async_0)
                {
                    nf.executeAsync(function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer,
                                    CallFuncHeap,
                                    returnSlot,
                                    callbacker,
                                    invokerFrame,
                                    token,
                                    function.bindScope
                                    );

                    if (!ReferenceEquals(callbacker,this))
                    {
                        release();
                    }
                }
                else if (nf.mode == NativeFunctionBase.NativeFunctionMode.const_parameter_0)
                {
                    bool success = false;
                    player._nativefuncCaller = this;

                    var nf3 = (nativefuncs.NativeConstParameterFunction)nf;
                    player._executeToken = nf3.getExecToken(toCallFunc.functionid);

                    nf3.execute3(
                        function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer,
                        toCallFunc,
                        returnSlot,
                        token,
                        invokerFrame,
                        out success
                        );

                    player._executeToken     = nativefuncs.NativeConstParameterFunction.ExecuteToken.nulltoken;
                    player._nativefuncCaller = null;
                    ((nativefuncs.NativeConstParameterFunction)nf).clearParameter();

                    clear_para_slot(invokerFrame,onstackparametercount);
                    onstackparametercount = 0;

                    if (success)
                    {
                        var receive_err = player.clear_nativeinvokeraiseerror();
                        if (receive_err != null)
                        {
                            invokerFrame.receiveErrorFromStackFrame(receive_err);
                            if (callbacker != null)
                            {
                                callbacker.noticeRunFailed();
                            }
                        }
                        else if (callbacker != null)
                        {
                            callbacker.call(callbacker.args);
                        }
                    }
                    else
                    {
                        invokerFrame.endStep();
                        if (callbacker != null)
                        {
                            callbacker.noticeRunFailed();
                        }
                    }
                    release();
                }
            }
        }
Пример #3
0
        private void check_para(BlockCallBackBase checkparacb)
        {
            while (check_para_id < pushedArgs)
            {
                var parameter = toCallFunc.signature.parameters;

                RunTimeValueBase argement = getToCheckParameter(check_para_id);

                var argtype    = argement.rtType;
                var targettype = parameter[check_para_id].type;

                if (argtype != targettype
                    &&
                    targettype != RunTimeDataType.rt_void
                    &&
                    !(argtype == RunTimeDataType.rt_null && targettype > RunTimeDataType.unknown)
                    &&
                    !(argtype > RunTimeDataType.unknown && targettype > RunTimeDataType.unknown
                      &&
                      (
                          ClassMemberFinder.check_isinherits(argement,targettype,player.swc)
                          ||
                          ClassMemberFinder.check_isImplements(argement,targettype,player.swc)
                      )
                      )

                    )
                {
                    BlockCallBackBase cb = player.blockCallBackPool.create();
                    cb.args    = argement;
                    cb._intArg = check_para_id;
                    cb.setCallBacker(check_para_callbacker);
                    cb.setWhenFailed(check_para_failed);

                    check_para_id++;

                    OpCast.CastValue(argement,parameter[
                                         cb._intArg].type,

                                     invokerFrame,token,invokerFrame.scope,_tempSlot,cb,false);

                    return;
                }
                else
                {
                    check_para_id++;
                }
            }

            if (pushedArgs < toCallFunc.signature.parameters.Count && !toCallFunc.IsAnonymous)             //匿名函数能跳过参数检查
            {
                for (int i = pushedArgs; i < toCallFunc.signature.parameters.Count; i++)
                {
                    if (toCallFunc.signature.parameters[pushedArgs].defaultValue == null
                        &&
                        !toCallFunc.signature.parameters[pushedArgs].isPara
                        )
                    {
                        invokerFrame.throwArgementException(
                            token,
                            string.Format(
                                "Argument count mismatch on Function/{0}. Expected {1}, got {2}.",
                                player.swc.blocks[toCallFunc.blockid].name,toCallFunc.signature.parameters.Count,pushedArgs
                                )

                            );
                        clear_para_slot(invokerFrame,onstackparametercount); onstackparametercount = 0;
                        //***中断本帧本次代码执行进入try catch阶段
                        invokerFrame.endStep();

                        if (callbacker != null)
                        {
                            callbacker.noticeRunFailed();
                        }
                        release();


                        return;
                    }
                }
            }

            if (!check_return_objtypeisclasscreated())
            {
                return;
            }

            if (checkparacb != null)
            {
                checkparacb.noticeEnd();
            }
            //***全部参数检查通过***
            doCall_allcheckpass();
        }