private void exec_step3(ASBinCode.rtData.rtObjectBase rtobject)
        {
            if (constructor == null)
            {
                objectResult = rtobject;
                //objectResult.directSet(rtobject);
                if (callbacker != null)
                {
                    callbacker.call(this);
                    callbacker = null;
                }
            }
            else
            {
                HeapSlot _temp = tempSlot; _temp.directSet(ASBinCode.rtData.rtUndefined.undefined);
                _function_constructor.returnSlot = _temp;
                //_function_constructor.function = (ASBinCode.rtData.rtFunction)TypeConverter.ObjectImplicit_ToPrimitive(constructor).Clone();
                //_function_constructor.function.setThis(rtobject);
                _function_constructor.SetFunction((ASBinCode.rtData.rtFunction)TypeConverter.ObjectImplicit_ToPrimitive(constructor),rtobject);

                BlockCallBackBase cb = player.blockCallBackPool.create();
                cb.args            = cb.cacheObjects; //new object[] { rtobject , _temp };
                cb.cacheObjects[0] = rtobject;
                cb.cacheObjects[1] = _temp;

                cb.setCallBacker(_finalStep);

                _function_constructor.callbacker = cb;
                _function_constructor.call();
                _function_constructor = null;
            }
        }
        public override void executeAsync(RunTimeValueBase thisObj,SLOT[] argements,SLOT resultSlot,object callbacker,object stackframe,SourceToken token,RunTimeScope scope)
        {
            IBlockCallBack cb    = (IBlockCallBack)callbacker;
            StackFrame     frame = (StackFrame)stackframe;

            if (argements[0].getValue().rtType == RunTimeDataType.rt_null)
            {
                if (frame.player.infoOutput != null)
                {
                    frame.player.infoOutput.Info(string.Empty);
                }
                cb.call(cb.args);
                return;
            }

            rtArray array = (rtArray)(argements[0].getValue());

            if (array.innerArray.Count == 0)
            {
                if (frame.player.infoOutput != null)
                {
                    frame.player.infoOutput.Info(string.Empty);
                }
                cb.call(cb.args);
                return;
            }


            BlockCallBackBase sepcb = frame.player.blockCallBackPool.create();

            sepcb.scope   = scope;
            sepcb._intArg = 0;
            sepcb.setCallBacker(null);
            sepcb._intArg2 = 0;

            object[] sendargs = sepcb.cacheObjects;
            sendargs[0] = cb;
            sendargs[1] = array;
            sendargs[2] = frame;
            sendargs[3] = token;
            sendargs[4] = scope;
            sendargs[5] = " ";
            sendargs[6] = new StringBuilder();
            sendargs[7] = resultSlot;
            //sendargs[8] = new rtInt(0);
            sepcb.args = sendargs;

            _SeptoString_CB(sepcb,sendargs);
        }
        private static void _convertCB(BlockCallBackBase sender, object args)
        {
            object[] a = (object[])sender.args;

            if (sender.isSuccess)
            {
                ASBinCode.rtti.Vector_Data vd = (ASBinCode.rtti.Vector_Data)a[0];
                var v    = ((StackFrame)a[5])._tempSlot1.getValue().Clone();             //必须Clone
                var list = (List <RunTimeValueBase>)a[1];
                vd.innnerList.Add((RunTimeValueBase)v);

                sender._intArg = sender._intArg + 1;

                if (sender._intArg >= list.Count)
                {
                    IBlockCallBack cb = (IBlockCallBack)a[4];
                    cb.call(cb.args);
                }
                else
                {
                    OpCast.CastValue(list[sender._intArg],
                                     vd.vector_type, (StackFrame)a[5], (SourceToken)a[2],
                                     (RunTimeScope)a[3], ((StackFrame)a[5])._tempSlot1,
                                     sender, false);
                }
            }
        }
Exemple #4
0
        private static void callfun_cb(BlockCallBackBase sender,object args)
        {
            IBlockCallBack callbacker = sender.cacheObjects[0] as IBlockCallBack;
            StackFrame     frame      = (StackFrame)sender.cacheObjects[1];

            clear_para_slot(frame,sender._intArg);
            if (callbacker != null)
            {
                callbacker.call(callbacker.args);
            }
        }
        private void _movenext_callbacker(BlockCallBackBase sender,object args)
        {
            ASBinCode.rtti.YieldObject yieldObj = (ASBinCode.rtti.YieldObject)sender.args;

            yieldObj._moveNextResultSlot.directSet(yieldObj.argements[yieldObj.argements.Length - 1].getValue());
            yieldObj._moveNextResultSlot = null;

            IBlockCallBack cb = ((IBlockCallBack)yieldObj._callbacker);

            yieldObj._callbacker = null;

            cb.call(cb.args);
        }
Exemple #6
0
        public override void executeAsync(RunTimeValueBase thisObj,SLOT[] argements,
                                          SLOT resultSlot,object callbacker,object stackframe,SourceToken token,RunTimeScope scope)
        {
            IBlockCallBack cb    = (IBlockCallBack)callbacker;
            StackFrame     frame = (StackFrame)stackframe;

            rtArray array = (rtArray)((rtObjectBase)thisObj).value.memberData[0].getValue();

            if (array.innerArray.Count == 0)
            {
                cb.call(cb.args);
                resultSlot.directSet(new rtString(string.Empty));
                return;
            }


            BlockCallBackBase sepcb = frame.player.blockCallBackPool.create();

            sepcb.scope   = scope;
            sepcb._intArg = 0;

            object[] sendargs = sepcb.cacheObjects;
            sendargs[0] = cb;
            sendargs[1] = array;
            sendargs[2] = frame;
            sendargs[3] = token;
            sendargs[4] = scope;
            sendargs[5] = argements[0].getValue();
            sendargs[6] = new StringBuilder();
            sendargs[7] = resultSlot;
            sendargs[8] = new rtInt(0);

            sepcb.args = sendargs;
            sepcb.setCallBacker(D_SeptoString_CB);

            operators.OpCast.CastValue(argements[0].getValue(),RunTimeDataType.rt_string,
                                       frame,token,scope,frame._tempSlot1,sepcb,false);
        }
        private void _ValueToString_CB(BlockCallBackBase sender,object args)
        {
            object[]   receiveArgs = (object[])sender.args;
            StackFrame frame       = (StackFrame)receiveArgs[2];
            rtArray    array       = (rtArray)receiveArgs[1];

            //((rtInt)receiveArgs[8]).value++;
            sender._intArg2++;

            if (sender._intArg2 == 10) //((rtInt)receiveArgs[8]).value == 10)    //堆栈清理,防止溢出...
            {
                sender._intArg2 = 0;   //((rtInt)receiveArgs[8]).value = 0;
                BlockCallBackBase valueCB = frame.player.blockCallBackPool.create();
                valueCB._intArg = sender._intArg; valueCB._intArg2 = 0;
                valueCB.args    = valueCB.copyFromReceiveArgs(receiveArgs);
                valueCB.setCallBacker(_ValueToString_CB);

                frame.player.CallBlankBlock(valueCB);
                return;
            }


            StringBuilder sb    = (StringBuilder)receiveArgs[6];
            SourceToken   token = (SourceToken)receiveArgs[3];

            string aSep = (string)receiveArgs[5];

            sb.Append(

                TypeConverter.ConvertToString(frame._tempSlot1.getValue(),frame,token) == null?"null":
                TypeConverter.ConvertToString(frame._tempSlot1.getValue(),frame,token)

                );
            if (sender._intArg < array.innerArray.Count)
            {
                sb.Append(aSep);


                BlockCallBackBase valueCB = frame.player.blockCallBackPool.create();
                valueCB._intArg = sender._intArg + 1; valueCB._intArg2 = sender._intArg2;
                valueCB.args    = valueCB.copyFromReceiveArgs(receiveArgs);
                valueCB.setCallBacker(_ValueToString_CB);

                var v = array.innerArray[sender._intArg];
                if (v.rtType == RunTimeDataType.rt_void)
                {
                    v = UNDEFINED;
                }

                operators.OpCast.CastValue(v,RunTimeDataType.rt_string,
                                           frame,
                                           (SourceToken)receiveArgs[3],
                                           (RunTimeScope)receiveArgs[4],
                                           frame._tempSlot1,
                                           valueCB,false
                                           );
            }
            else
            {
                //ISLOT result = (ISLOT)receiveArgs[7];

                //result.directSet(new rtString(sb.ToString()));
                if (frame.player.infoOutput != null)
                {
                    frame.player.infoOutput.Info(sb.ToString());
                }
                IBlockCallBack cb = (IBlockCallBack)receiveArgs[0];
                cb.call(cb.args);
            }
        }
Exemple #8
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();
                }
            }
        }
Exemple #9
0
        private static void _ValueToString_CB(BlockCallBackBase sender,object args)
        {
            object[]   receiveArgs = (object[])sender.args;
            StackFrame frame       = (StackFrame)receiveArgs[2];
            rtArray    array       = (rtArray)receiveArgs[1];

            ((rtInt)receiveArgs[8]).value++;

            if (((rtInt)receiveArgs[8]).value == 10)    //堆栈清理,防止溢出...
            {
                ((rtInt)receiveArgs[8]).value = 0;
                BlockCallBackBase valueCB = frame.player.blockCallBackPool.create();
                valueCB._intArg = sender._intArg;
                valueCB.args    = valueCB.copyFromReceiveArgs(receiveArgs);
                valueCB.setCallBacker(D_ValueToString_CB);

                frame.player.CallBlankBlock(valueCB);
                return;
            }


            StringBuilder sb    = (StringBuilder)receiveArgs[6];
            SourceToken   token = (SourceToken)receiveArgs[3];

            string aSep     = (string)receiveArgs[5];
            string toappend = TypeConverter.ConvertToString(frame._tempSlot1.getValue(),frame,token);

            while (true)
            {
                sb.Append(toappend == null ? "null" : toappend);
                if (sender._intArg < array.innerArray.Count)
                {
                    sb.Append(aSep);

                    if (//sender._intArg  < array.innerArray.Count
                        //&&
                        array.innerArray[sender._intArg].rtType < RunTimeDataType.unknown
                        )
                    {
                        toappend = TypeConverter.ConvertToString(array.innerArray[sender._intArg],frame,token);
                        sender._intArg++;
                        continue;
                    }
                    else
                    {
                        BlockCallBackBase valueCB = frame.player.blockCallBackPool.create();
                        valueCB._intArg = sender._intArg + 1;
                        valueCB.args    = valueCB.copyFromReceiveArgs(receiveArgs);
                        valueCB.setCallBacker(D_ValueToString_CB);

                        operators.OpCast.CastValue(array.innerArray[sender._intArg],RunTimeDataType.rt_string,
                                                   frame,
                                                   (SourceToken)receiveArgs[3],
                                                   (RunTimeScope)receiveArgs[4],
                                                   frame._tempSlot1,
                                                   valueCB,false
                                                   );
                        break;
                    }
                }
                else
                {
                    SLOT result = (SLOT)receiveArgs[7];

                    result.directSet(new rtString(sb.ToString()));

                    IBlockCallBack cb = (IBlockCallBack)receiveArgs[0];
                    cb.call(cb.args);
                    break;
                }
            }
        }