Example #1
0
        public static void exec_try_write_prop(StackFrame frame,OpStep step,RunTimeScope scope)
        {
            StackSlot slot = (StackSlot)((StackSlotAccessor)step.arg1).getSlot(scope,frame);

            if (slot.stackObjects.propGetSet != null)
            {
                OpAssigning._doPropAssigning(slot.stackObjects.propGetSet,frame,step,frame.player,scope,
                                             slot.stackObjects.propBindObj
                                             ,
                                             slot.getValue()
                                             ,
                                             slot
                                             );
            }
            else if (slot.stackObjects._temp_try_write_setthisitem != null)
            {
                SetThisItemSlot sslot = (SetThisItemSlot)slot.stackObjects._temp_try_write_setthisitem;
                slot.stackObjects._temp_try_write_setthisitem = null;

                OpAssigning._doSetThisItem(
                    sslot.bindObj,
                    slot.getValue(),
                    sslot.setindex,
                    slot,frame,step
                    );
            }
            else
            {
                //frame.endStep(step);
                frame.endStepNoError();
            }
        }
Example #2
0
        public static void exec_delete(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            {
                StackSlot slot = (StackSlot)((StackSlotAccessor)step.arg1).getSlot(scope, frame);

                var ls = slot.getLinkSlot();

                if (ls is DynamicPropertySlot)
                {
                    DynamicPropertySlot link = (DynamicPropertySlot)ls;
                    if (link._canDelete)
                    {
                        ((ASBinCode.rtti.DynamicObject)link.obj.value).deleteProperty(link._propname);
                    }
                    else
                    {
                        if (link.backup != null)
                        {
                            link.directSet(link.backup);
                        }
                    }
                }
                else if (ls is DictionarySlot)
                {
                    DictionarySlot link = (DictionarySlot)ls;
                    ((ASBinCode.rtti.DictionaryObject)link.obj.value).RemoveKey(link._key);
                }
                else if (ls is OpAccess_Dot.arraySlot) //(slot.fromArray != null)
                {
                    //slot.directSet(rtUndefined.undefined);
                    //bool success;
                    //slot.assign(rtUndefined.undefined,out success);

                    ((OpAccess_Dot.arraySlot)ls).delete();


                    //slot.fromArray.innerArray[slot.fromArrayIndex] = rtUndefined.undefined;
                }
                else if (ls is OpAccess_Dot.prototypeSlot)
                {   //原型链对象,不可删除
                }
                else if (ls is OpVector.vectorSLot)
                {
                    //数组链接,跳过
                }
                else
                {
                    frame.throwError(
                        step.token, 0,
                        "动态属性才能被delete"
                        );
                }

                slot.linkTo(null);

                frame.endStep(step);
            }
        }
        public static void exec_push(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            var o = (ASBinCode.rtti.Vector_Data)((ASBinCode.rtti.HostedObject)((rtObjectBase)step.arg1.getValue(scope, frame)).value).hosted_object;

            o.innnerList.Add((RunTimeValueBase)step.arg2.getValue(scope, frame).Clone());            //直接对容器赋值,必须Clone

            //frame.endStep(step);
            frame.endStepNoError();
        }
        private static void _tonumber_cb(BlockCallBackBase sender, object args)
        {
            StackFrame frame = (StackFrame)sender.args;
            OpStep     step  = sender.step;

            step.reg.getSlot(sender.scope, frame).setValue(frame._tempSlot1.getValue().toNumber());
            //frame.endStep(step);
            frame.endStepNoError();
        }
        public static void enumerator_current(StackFrame frame,OpStep step,RunTimeScope scope)
        {
            //StackSlot slot = (StackSlot)((Register)step.arg1).getSlot(scope);

            rtObjectBase        save    = (rtObjectBase)(step.arg1).getValue(scope,frame);
            HostedDynamicObject saveObj = (HostedDynamicObject)save.value;

            IEnumerator <RunTimeValueBase> enumerator = saveObj.hosted_object as IEnumerator <RunTimeValueBase>;


            //IEnumerator<RunTimeValueBase> enumerator = scope.cache_enumerator as  IEnumerator<RunTimeValueBase>;
            if (enumerator != null)
            {
                step.reg.getSlot(scope,frame).directSet(enumerator.Current);
            }
            else
            {
                if (saveObj.hosted_object is rtObjectBase)  //是否是接口
                {
                    var movenext = ClassMemberFinder.find(frame.player.swc.IEnumeratorInterface,"current",frame.player.swc.IEnumeratorInterface);
                    var method   =
                        ((ClassPropertyGetter)movenext.bindField).getter.getMethod(((rtObjectBase)saveObj.hosted_object));

                    //***调用方法***
                    var funCaller = frame.player.funcCallerPool.create(frame,step.token);
                    //funCaller.releaseAfterCall = true;
                    funCaller.SetFunction((ASBinCode.rtData.rtFunction)method); ((ASBinCode.rtData.rtFunction)method).Clear();
                    funCaller.loadDefineFromFunction();
                    if (!funCaller.createParaScope())
                    {
                        return;
                    }

                    funCaller._tempSlot  = step.reg.getSlot(scope,frame);
                    funCaller.returnSlot = step.reg.getSlot(scope,frame);

                    BlockCallBackBase cb = frame.player.blockCallBackPool.create();
                    cb.setCallBacker(D_enumerator_operator_callbacker);
                    cb.step = step;
                    cb.args = frame;

                    funCaller.callbacker = cb;
                    funCaller.call();

                    return;
                }
            }

            frame.endStep(step);
        }
Example #6
0
        private static void build_dot_name(CompileEnv env, ASTool.AS3.Expr.AS3ExprStep step, RightValueBase v1)
        {
            ASBinCode.StackSlotAccessor eax = env.createASTRegister(step.Arg1.Reg);
            eax.setEAXTypeWhenCompile(RunTimeDataType.rt_void);

            OpStep op = new OpStep(OpCode.access_dot_byname, new SourceToken(step.token.line, step.token.ptr, step.token.sourceFile));

            op.reg      = eax; eax._isDotAccessTarget = true;
            op.regType  = eax.valueType;
            op.arg1     = v1;
            op.arg1Type = v1.valueType;
            op.arg2     = new ASBinCode.rtData.RightValue(
                new ASBinCode.rtData.rtString(step.Arg3.Data.Value.ToString()));
            op.arg2Type = RunTimeDataType.rt_string;
            env.block.opSteps.Add(op);
        }
Example #7
0
        /// <summary>
        /// Called when the create workspace command reply is received.
        /// </summary>
        private void HandleCreateKwsCmdResult(KcdQuery query)
        {
            if (m_kcdQuery != query)
            {
                return;
            }
            m_kcdQuery = null;
            Debug.Assert(m_step == OpStep.CreateReply);

            try
            {
                AnpMsg res = query.Res;

                // Failure.
                if (res.Type != KAnp.KANP_RES_MGT_KWS_CREATED)
                {
                    throw EAnpException.FromKAnpReply(res);
                }

                // Parse the reply.
                UInt64 externalID = res.Elements[0].UInt64;
                String emailID    = res.Elements[1].String;

                // Validate that the KCD is not screwing with us. This can
                // happen if the KCD state has been reverted.
                if (Wm.GetKwsByExternalID(Kws.Kcd.KcdID, externalID) != null)
                {
                    throw new Exception("duplicate " + KwmStrings.Kws + " external ID");
                }

                // Update the workspace credentials.
                Creds.ExternalID = externalID;
                Creds.EmailID    = emailID;

                // Wait for login.
                m_step = OpStep.LoggingIn;
                Kws.Sm.SetLoginType(KwsLoginType.Cached);
                Kws.Sm.SetSpawnStep(KwsSpawnTaskStep.Login);
            }

            catch (Exception ex)
            {
                HandleFailure(ex);
            }
        }
        public static void enumerator_close(StackFrame frame,OpStep step,RunTimeScope scope)
        {
            //StackSlot slot = (StackSlot)((Register)step.arg1).getSlot(scope);

            rtObjectBase        save    = (rtObjectBase)(step.arg1).getValue(scope,frame);
            HostedDynamicObject saveObj = (HostedDynamicObject)save.value;

            //if (scope.cache_enumerator != null)
            {
                IEnumerator <RunTimeValueBase> enumerator = saveObj.hosted_object as IEnumerator <RunTimeValueBase>;
                if (enumerator != null)
                {
                    enumerator.Dispose();
                }

                saveObj.hosted_object = null;
            }
            frame.endStep(step);
        }
        public void clear()
        {
            token             = null;
            _class            = null;
            step              = null;
            callbacker        = null;
            constructorCaller = null;
            objectResult      = null;

            constructor           = null;
            _function_constructor = null;
            objectStoreToSlot     = null;

            toNoticeFailed1 = null;
            toNoticeFailed2 = null;


            tempSlot.directSet(ASBinCode.rtData.rtUndefined.undefined);
        }
        public static void exec_GetValue(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            ASBinCode.rtti.Vector_Data vector =
                (ASBinCode.rtti.Vector_Data)((ASBinCode.rtti.HostedObject)((rtObjectBase)step.arg1.getValue(scope, frame)).value).hosted_object;

            int idx = TypeConverter.ConvertToInt(step.arg2.getValue(scope, frame));

            if (idx < 0 || idx >= vector.innnerList.Count)
            {
                frame.throwError(step.token, 1125,
                                 "The index " + idx + " is out of range " + vector.innnerList.Count + ".");
                frame.endStep(step);
            }
            else
            {
                step.reg.getSlot(scope, frame).directSet(vector.innnerList[idx]);
                frame.endStepNoError();
            }
        }
        private void build_void(CompileEnv env, RightValueBase cls, ASTool.AS3.Expr.AS3ExprStep step, Builder builder)
        {
            OpStep opnewclass = new OpStep(OpCode.new_instance_class,
                                           new SourceToken(step.token.line, step.token.ptr, step.token.sourceFile));

            opnewclass.arg1     = cls;
            opnewclass.arg1Type = RunTimeDataType.rt_void;
            StackSlotAccessor _eax = env.createASTRegister(step.Arg1.Reg);

            _eax.setEAXTypeWhenCompile(RunTimeDataType.rt_void);
            opnewclass.reg     = _eax;
            opnewclass.regType = RunTimeDataType.rt_void;


            OpStep opMakeArgs = new OpStep(OpCode.prepare_constructor_class_argement, new SourceToken(step.token.line, step.token.ptr, step.token.sourceFile));

            opMakeArgs.arg1     = cls;
            opMakeArgs.arg1Type = RunTimeDataType.rt_void;
            env.block.opSteps.Add(opMakeArgs);

            if (step.Arg3 != null)
            {
                List <ASTool.AS3.Expr.AS3DataStackElement> args
                    = (List <ASTool.AS3.Expr.AS3DataStackElement>)step.Arg3.Data.Value;
                for (int i = 0; i < args.Count; i++)
                {
                    ASTool.AS3.Expr.AS3DataStackElement argData = args[i];
                    RightValueBase arg = builds.ExpressionBuilder.getRightValue(env, argData, step.token, builder);
                    //***参数准备***
                    OpStep opPushArgs = new OpStep(OpCode.push_parameter_class, new SourceToken(step.token.line, step.token.ptr, step.token.sourceFile));
                    opPushArgs.arg1     = arg;
                    opPushArgs.arg1Type = arg.valueType;
                    opPushArgs.arg2     = new ASBinCode.rtData.RightValue(new ASBinCode.rtData.rtInt(i));
                    opPushArgs.arg2Type = RunTimeDataType.rt_int;
                    env.block.opSteps.Add(opPushArgs);
                }
            }



            env.block.opSteps.Add(opnewclass);
        }
        public void buildAS3YieldBreak(CompileEnv env, ASTool.AS3.AS3YieldBreak as3yieldbreak, Builder builder)
        {
            if (builder.buildingfunctons.Count > 0)
            {
                ASTool.AS3.AS3Function as3function = builder.buildingfunctons.Peek();
                if (as3function.IsConstructor)
                {
                    throw new BuildException(as3yieldbreak.Token.line, as3yieldbreak.Token.ptr, as3yieldbreak.Token.sourceFile,
                                             "构造函数不能用yield");
                }

                OpStep opyieldbreak = new OpStep(OpCode.yield_break, new SourceToken(as3yieldbreak.Token.line, as3yieldbreak.Token.ptr, as3yieldbreak.Token.sourceFile));
                env.block.opSteps.Add(opyieldbreak);
            }
            else
            {
                throw new BuildException(as3yieldbreak.Token.line, as3yieldbreak.Token.ptr, as3yieldbreak.Token.sourceFile,
                                         "yield break 只能在函数中");
            }
        }
Example #13
0
        /// <summary>
        /// Send the workspace creation command if we are ready to.
        /// </summary>
        private void SendCreateKwsCmdIfNeeded()
        {
            if (DoneFlag || m_step != OpStep.Connecting || Kws.Kcd.ConnStatus != KcdConnStatus.Connected)
            {
                return;
            }

            m_step = OpStep.CreateReply;
            AnpMsg cmd = Wm.NewKcdCmd(Kws.Kcd.MinorVersion, KAnp.KANP_CMD_MGT_CREATE_KWS);

            cmd.AddString(Creds.KwsName);
            cmd.AddBin(Creds.Ticket);
            cmd.AddUInt32(Convert.ToUInt32(Creds.PublicFlag));
            cmd.AddUInt32(Convert.ToUInt32(Creds.SecureFlag));
            if (cmd.Minor >= 4)
            {
                cmd.AddUInt32(Convert.ToUInt32(Creds.ThinKfsFlag));
            }
            m_kcdQuery = Kws.PostKcdCmd(cmd, HandleCreateKwsCmdResult);
        }
        public static void exec_link(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            StackSlot l = (StackSlot)step.reg.getSlot(scope, frame);

            int classid = ((ASBinCode.rtData.rtInt)step.arg2.getValue(scope, frame)).value;

            var outscope = frame.player.outpackage_runtimescope[classid];

            SLOT outpackagescopeslot = ((VariableBase)step.arg1).getSlot(outscope,null);

            StackSlotAccessor register = (StackSlotAccessor)step.reg;

            if (register._isassigntarget || register._hasUnaryOrShuffixOrDelete)
            {
                l.linkTo(outpackagescopeslot);
            }
            else
            {
                l.directSet(outpackagescopeslot.getValue());
            }
            frame.endStep(step);
        }
Example #15
0
        public override void Start()
        {
            try
            {
                // Make sure we can login on the KPS.
                if (!KwmCfg.Cur.CanLoginOnKps())
                {
                    throw new EAnpExInvalidKpsConfig();
                }

                // Get a ticket.
                m_step = OpStep.TicketReply;
                WmLoginTicketQuery ticketQuery = new WmLoginTicketQuery();
                m_kmodQuery = ticketQuery;
                ticketQuery.Submit(Wm.KmodBroker, KwmCfg.Cur, OnKmodTicketResult);
            }

            catch (Exception ex)
            {
                HandleFailure(ex);
            }
        }
        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 void build_class(CompileEnv env,
                                ASBinCode.rtti.Class _class,
                                ASTool.Token token, Builder builder,
                                StackSlotAccessor outeax,
                                List <ASTool.AS3.Expr.AS3DataStackElement> args
                                )
        {
            //***查找构造函数**
            if (_class.constructor != null)
            {
                MethodGetterBase field = (MethodGetterBase)_class.constructor.bindField; //(Field)builder._classbuildingEnv[_class].block.scope.members[_class.constructor.index];
                int blockid            = field.refdefinedinblockid;

                var signature =
                    builder.dictSignatures[blockid][field];

                FuncCallBuilder funcbuilder = new FuncCallBuilder();
                funcbuilder.createParaOp(args, signature, token, env, field, builder, true, _class);
            }
            else
            {
                OpStep opMakeArgs = new OpStep(OpCode.prepare_constructor_argement,
                                               new SourceToken(token.line, token.ptr, token.sourceFile));
                opMakeArgs.arg1     = new ASBinCode.rtData.RightValue(new ASBinCode.rtData.rtInt(_class.classid));
                opMakeArgs.arg1Type = RunTimeDataType.rt_int;
                env.block.opSteps.Add(opMakeArgs);
            }

            OpStep op = new OpStep(OpCode.new_instance, new SourceToken(token.line, token.ptr, token.sourceFile));

            op.arg1     = new RightValue(new rtInt(_class.classid));
            op.arg1Type = _class.getRtType();

            outeax.setEAXTypeWhenCompile(_class.getRtType());
            op.reg     = outeax;
            op.regType = _class.getRtType();

            env.block.opSteps.Add(op);
        }
Example #18
0
        /// <summary>
        /// Called when the create workspace command reply is received.
        /// </summary>
        private void HandleCreateKwsCmdResult(KcdQuery query)
        {
            if (m_kcdQuery != query) return;
            m_kcdQuery = null;
            Debug.Assert(m_step == OpStep.CreateReply);

            try
            {
                AnpMsg res = query.Res;

                // Failure.
                if (res.Type != KAnp.KANP_RES_MGT_KWS_CREATED) throw EAnpException.FromKAnpReply(res);

                // Parse the reply.
                UInt64 externalID = res.Elements[0].UInt64;
                String emailID = res.Elements[1].String;

                // Validate that the KCD is not screwing with us. This can
                // happen if the KCD state has been reverted.
                if (Wm.GetKwsByExternalID(Kws.Kcd.KcdID, externalID) != null)
                    throw new Exception("duplicate " + KwmStrings.Kws + " external ID");

                // Update the workspace credentials.
                Creds.ExternalID = externalID;
                Creds.EmailID = emailID;

                // Wait for login.
                m_step = OpStep.LoggingIn;
                Kws.Sm.SetLoginType(KwsLoginType.Cached);
                Kws.Sm.SetSpawnStep(KwsSpawnTaskStep.Login);
            }

            catch (Exception ex)
            {
                HandleFailure(ex);
            }
        }
Example #19
0
        public override void Start()
        {
            try
            {
                // Make sure we can login on the KPS.
                if (!KwmCfg.Cur.CanLoginOnKps()) throw new EAnpExInvalidKpsConfig();

                // Get a ticket.
                m_step = OpStep.TicketReply;
                WmLoginTicketQuery ticketQuery = new WmLoginTicketQuery();
                m_kmodQuery = ticketQuery;
                ticketQuery.Submit(Wm.KmodBroker, KwmCfg.Cur, OnKmodTicketResult);
            }

            catch (Exception ex)
            {
                HandleFailure(ex);
            }
        }
        public static void forin_get_enumerator(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            var player = frame.player;

            SLOT slot = step.reg.getSlot(scope,frame);

            ASBinCode.rtti.HostedDynamicObject saveObj = new HostedDynamicObject(player.swc.ObjectClass);
            rtObject save = new rtObject(saveObj,null);

            slot.directSet(save);

            var obj = step.arg1.getValue(scope,frame);

            if (obj.rtType > RunTimeDataType.unknown)
            {
                rtObject rtObj = (rtObject)obj;

                if (ClassMemberFinder.isInherits(rtObj.value._class,
                                                 player.swc.primitive_to_class_table[RunTimeDataType.rt_array]))
                {
                    rtArray arr = (rtArray)rtObj.value.memberData[0].getValue();
                    saveObj.hosted_object = getArrayForIn(arr.innerArray);
                }
                else if (player.swc.dict_Vector_type.ContainsKey(rtObj.value._class))
                {
                    saveObj.hosted_object = getArrayForIn(((Vector_Data)((HostedObject)rtObj.value).hosted_object).innnerList);
                }
                else if (ClassMemberFinder.isImplements(rtObj.value._class,player.swc.IEnumerableInterface))
                {
                    //***调用getIEnumerator方法****
                    var movenext = ClassMemberFinder.find(
                        frame.player.swc.IEnumerableInterface,"getEnumerator",
                        frame.player.swc.IEnumerableInterface);

                    var method = ((InterfaceMethodGetter)movenext.bindField).getMethod(
                        rtObj);

                    //***调用方法***
                    var funCaller = player.funcCallerPool.create(frame,step.token);
                    //funCaller.releaseAfterCall = true;
                    funCaller.SetFunction((rtFunction)method); ((rtFunction)method).Clear();
                    funCaller.loadDefineFromFunction();
                    if (!funCaller.createParaScope())
                    {
                        return;
                    }

                    funCaller._tempSlot  = frame._tempSlot1;
                    funCaller.returnSlot = frame._tempSlot1;

                    BlockCallBackBase cb = frame.player.blockCallBackPool.create();
                    cb.setCallBacker(D_getEnumerator_callbacker);
                    cb.step  = step;
                    cb.args  = frame;
                    cb.scope = scope;

                    funCaller.callbacker = cb;
                    funCaller.call();

                    return;
                }
                else if (ClassMemberFinder.isImplements(
                             rtObj.value._class,player.swc.IEnumeratorInterface))
                {
                    saveObj.hosted_object = rtObj;
                }
                else
                {
                    IEnumerator <RunTimeValueBase> forinenum = getForinIEnumerator(player,rtObj.value,frame,step,scope);
                    saveObj.hosted_object = forinenum;
                }
            }

            frame.endStep();
        }
        public static void enumerator_movenext(StackFrame frame,OpStep step,RunTimeScope scope)
        {
            //StackSlot slot = (StackSlot)((Register)step.arg1).getSlot(scope);


            rtObjectBase        save    = (rtObjectBase)(step.arg1).getValue(scope,frame);
            HostedDynamicObject saveObj = (HostedDynamicObject)save.value;

            IEnumerator <RunTimeValueBase> enumerator = saveObj.hosted_object as IEnumerator <RunTimeValueBase>;


            if (enumerator != null) //&& enumerator.MoveNext() )//slot.cache_enumerator !=null && slot.cache_enumerator.MoveNext())
            {
                try
                {
                    if (enumerator.MoveNext())
                    {
                        step.reg.getSlot(scope,frame).setValue(rtBoolean.True);
                    }
                    else
                    {
                        step.reg.getSlot(scope,frame).setValue(rtBoolean.False);
                    }
                }
                catch (ASRunTimeException ex)
                {
                    step.reg.getSlot(scope,frame).setValue(rtBoolean.False);
                    frame.throwAneException(step.token,ex.Message + "\n" + ex.AS3StackTrace);
                    return;
                }
            }
            else
            {
                if (saveObj.hosted_object is rtObjectBase)  //是否是接口
                {
                    var movenext = ClassMemberFinder.find(frame.player.swc.IEnumeratorInterface,"moveNext",frame.player.swc.IEnumeratorInterface);
                    var method   = ((InterfaceMethodGetter)movenext.bindField).getMethod(
                        (((rtObjectBase)saveObj.hosted_object)));

                    //***调用方法***
                    var funCaller = frame.player.funcCallerPool.create(frame,step.token);
                    //funCaller.releaseAfterCall = true;
                    funCaller.SetFunction((ASBinCode.rtData.rtFunction)method); ((ASBinCode.rtData.rtFunction)method).Clear();
                    funCaller.loadDefineFromFunction();
                    if (!funCaller.createParaScope())
                    {
                        return;
                    }

                    funCaller._tempSlot  = step.reg.getSlot(scope,frame);
                    funCaller.returnSlot = step.reg.getSlot(scope,frame);

                    BlockCallBackBase cb = frame.player.blockCallBackPool.create();
                    cb.setCallBacker(D_enumerator_operator_callbacker);
                    cb.step = step;
                    cb.args = frame;

                    funCaller.callbacker = cb;
                    funCaller.call();

                    return;
                }
                else
                {
                    step.reg.getSlot(scope,frame).setValue(rtBoolean.False);
                }
            }

            frame.endStep(step);
        }
        private void build_class(CompileEnv env,
                                 ASBinCode.rtti.Class _class,
                                 ASTool.AS3.Expr.AS3ExprStep step, Builder builder)
        {
            //***参数检查***



            List <ASTool.AS3.Expr.AS3DataStackElement> args;

            if (!step.Arg2.IsReg && step.Arg2.Data.FF1Type == ASTool.AS3.Expr.FF1DataValueType.as3_vector)
            {
                ASTool.AS3.AS3Vector vector = (ASTool.AS3.AS3Vector)step.Arg2.Data.Value;



                if (vector.Constructor == null)
                {
                    args = new List <ASTool.AS3.Expr.AS3DataStackElement>();
                }
                else
                {
                    if (vector.isInitData)
                    {
                        args = new List <ASTool.AS3.Expr.AS3DataStackElement>();
                    }
                    else
                    {
                        args = (List <ASTool.AS3.Expr.AS3DataStackElement>)vector.Constructor.Data.Value;
                    }
                }
            }
            else
            {
                if (step.Arg3 != null)
                {
                    args = (List <ASTool.AS3.Expr.AS3DataStackElement>)step.Arg3.Data.Value;
                }
                else
                {
                    args = new List <ASTool.AS3.Expr.AS3DataStackElement>();
                }
            }

            StackSlotAccessor insEax = env.createASTRegister(step.Arg1.Reg);

            build_class(env, _class, step.token, builder,
                        insEax,
                        args
                        );

            if (!step.Arg2.IsReg && step.Arg2.Data.FF1Type == ASTool.AS3.Expr.FF1DataValueType.as3_vector)
            {
                ASTool.AS3.AS3Vector vector = (ASTool.AS3.AS3Vector)step.Arg2.Data.Value;
                if (vector.Constructor != null && vector.isInitData)
                {
                    //***追加初始化Vector***
                    var initdata = (List <ASTool.AS3.Expr.AS3DataStackElement>)vector.Constructor.Data.Value;

                    var vt = builder.bin.dict_Vector_type[_class];

                    for (int i = 0; i < initdata.Count; i++)
                    {
                        var d = ExpressionBuilder.getRightValue(env, initdata[i], step.token, builder);

                        if (!ASRuntime.TypeConverter.testImplicitConvert(d.valueType, vt, builder))
                        {
                            throw(new BuildException(new BuildError(step.token.line, step.token.ptr, step.token.sourceFile,
                                                                    "不能将[" + d.valueType + "]类型存入Vector.<" + vt + ">")));
                        }

                        if (d.valueType != vt)
                        {
                            d = ExpressionBuilder.addCastOpStep(env, d, vt,
                                                                new SourceToken(step.token.line, step.token.ptr, step.token.sourceFile)
                                                                , builder);
                        }

                        OpStep oppush = new OpStep(OpCode.vector_push, new SourceToken(step.token.line, step.token.ptr, step.token.sourceFile));
                        oppush.reg      = null;
                        oppush.regType  = RunTimeDataType.unknown;
                        oppush.arg1     = insEax;
                        oppush.arg1Type = insEax.valueType;
                        oppush.arg2     = d;
                        oppush.arg2Type = d.valueType;

                        env.block.opSteps.Add(oppush);
                    }



                    //throw new NotImplementedException();
                }
            }


            ////***查找构造函数**
            //if (_class.constructor != null)
            //{
            //    ClassMethodGetter field = (ClassMethodGetter)_class.constructor.bindField; //(Field)builder._classbuildingEnv[_class].block.scope.members[_class.constructor.index];
            //    int blockid = field.refdefinedinblockid;

            //    var signature =
            //            builder.dictSignatures[blockid][field];
            //    //***参数检查***
            //    List<ASTool.AS3.Expr.AS3DataStackElement> args;
            //    if (step.Arg3 != null)
            //    {
            //        args = (List<ASTool.AS3.Expr.AS3DataStackElement>)step.Arg3.Data.Value;
            //    }
            //    else
            //    {
            //        args = new List<ASTool.AS3.Expr.AS3DataStackElement>();
            //    }
            //    FuncCallBuilder funcbuilder = new FuncCallBuilder();
            //    funcbuilder.createParaOp(args, signature, step, env, field, builder, true, _class);
            //}
            //else
            //{
            //    OpStep opMakeArgs = new OpStep(OpCode.prepare_constructor_argement,
            //        new SourceToken(step.token.line, step.token.ptr, step.token.sourceFile));
            //    opMakeArgs.arg1 = new ASBinCode.rtData.RightValue(new ASBinCode.rtData.rtInt(_class.classid));
            //    opMakeArgs.arg1Type = RunTimeDataType.rt_int;
            //    env.block.opSteps.Add(opMakeArgs);
            //}

            //OpStep op = new OpStep(OpCode.new_instance, new SourceToken(step.token.line, step.token.ptr, step.token.sourceFile));
            //op.arg1 = new RightValue(new rtInt(_class.classid));
            //op.arg1Type = _class.getRtType();
            //Register eax = env.createASTRegister(step.Arg1.Reg.ID);
            //eax.setEAXTypeWhenCompile(_class.getRtType());
            //op.reg = eax;
            //op.regType = _class.getRtType();

            //env.block.opSteps.Add(op);
        }
        public void build_class(CompileEnv env,
                                ASBinCode.rtti.Class _class,
                                ASTool.Token token, Builder builder,
                                StackSlotAccessor outeax,
                                List <ASTool.AS3.Expr.AS3DataStackElement> args
                                )
        {
            var _cls = _class;

            if (_cls.staticClass == null)
            {
                _cls = _cls.instanceClass;
            }
            if (_cls.isLink_System)
            {
                OpStep stepInitClass = new OpStep(OpCode.init_staticclass,
                                                  new SourceToken(token.line, token.ptr, token.sourceFile));
                stepInitClass.arg1 = new ASBinCode.rtData.RightValue(
                    new ASBinCode.rtData.rtInt(_cls.classid));
                stepInitClass.arg1Type = _cls.staticClass.getRtType();
                env.block.opSteps.Add(stepInitClass);
            }

            //***查找构造函数**
            if (_class.constructor != null)
            {
                MethodGetterBase field = (MethodGetterBase)_class.constructor.bindField; //(Field)builder._classbuildingEnv[_class].block.scope.members[_class.constructor.index];
                int blockid            = field.refdefinedinblockid;

                var signature =
                    builder.dictSignatures[blockid][field];

                FuncCallBuilder funcbuilder = new FuncCallBuilder();
                OpStep          opMakeArgs  = null;
                funcbuilder.createParaOp(out opMakeArgs, args, signature, token, env, field, builder, true, _class);

                if (_cls.isLink_System)
                {
                    if (signature.parameters.Count == 0)
                    {
                        opMakeArgs.opCode    = OpCode.prepare_constructor_argement_linksystem;
                        opMakeArgs.memregid1 = 0;
                    }
                    else
                    {
                        bool canconvert = true;
                        for (int i = 0; i < signature.parameters.Count; i++)
                        {
                            if (signature.parameters[i].defaultValue != null || signature.parameters[i].isPara)
                            {
                                canconvert = false;
                            }
                        }
                        if (canconvert)
                        {
                            opMakeArgs.opCode    = OpCode.prepare_constructor_argement_linksystem;
                            opMakeArgs.memregid1 = (short)signature.parameters.Count;
                        }
                    }
                }
            }
            else
            {
                OpStep opMakeArgs = new OpStep(OpCode.prepare_constructor_argement,
                                               new SourceToken(token.line, token.ptr, token.sourceFile));
                opMakeArgs.arg1     = new ASBinCode.rtData.RightValue(new ASBinCode.rtData.rtInt(_class.classid));
                opMakeArgs.arg1Type = RunTimeDataType.rt_int;
                env.block.opSteps.Add(opMakeArgs);

                if (_cls.isLink_System)
                {
                    opMakeArgs.opCode    = OpCode.prepare_constructor_argement_linksystem;
                    opMakeArgs.memregid1 = 0;
                }
            }

            OpStep op = new OpStep(OpCode.new_instance, new SourceToken(token.line, token.ptr, token.sourceFile));

            op.arg1     = new RightValue(new rtInt(_class.classid));
            op.arg1Type = _class.getRtType();

            outeax.setEAXTypeWhenCompile(_class.getRtType());
            op.reg     = outeax;
            op.regType = _class.getRtType();

            env.block.opSteps.Add(op);
        }
        private static IEnumerator <RunTimeValueBase> getForEach_IEnumerator(
            Player player,ASBinCode.rtti.Object obj,StackFrame frame,OpStep step,RunTimeScope scope,
            Dictionary <object,object> visited = null
            )
        {
            if (obj is ASBinCode.rtti.DynamicObject)
            {
                ASBinCode.rtti.DynamicObject dobj = (ASBinCode.rtti.DynamicObject)obj;
                {
                    var k = dobj.eachSlot();
                    while (k.MoveNext())
                    {
                        var c = k.Current;
                        DynamicPropertySlot ds = c as DynamicPropertySlot;
                        if (c != null)
                        {
                            yield return(ds.getValue()); //new rtString(ds._propname);
                        }
                    }
                }

                if (obj is DictionaryObject)
                {
                    DictionaryObject dictObj = (DictionaryObject)obj;
                    var k = dictObj.eachDictSlot();
                    while (k.MoveNext())
                    {
                        var            c  = k.Current;
                        DictionarySlot ds = c as DictionarySlot;
                        if (c != null)
                        {
                            yield return(ds.getValue()); //ds._key.key;
                        }
                    }
                }

                if (visited == null)
                {
                    visited = new Dictionary <object,object>();
                }
                //***再到原型链中查找
                if (dobj._prototype_ != null)
                {
                    var protoObj = dobj._prototype_;
                    //****_prototype_的类型,只可能是Function对象或Class对象
                    if (protoObj._class.classid == player.swc.FunctionClass.classid) //Function
                    {
                        dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[1].getValue()).value;

                        if (visited.ContainsKey(dobj))
                        {
                            yield break;
                        }
                        visited.Add(dobj,null);

                        var res = getForEach_IEnumerator(player,dobj,frame,step,scope,visited);
                        while (res.MoveNext())
                        {
                            yield return(res.Current);
                        }
                    }
                    else if (protoObj._class.classid == 1) //搜索到根Object
                    {
                        //***根Object有继承自Class的prototype,再没有就没有了
                        dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[0].getValue()).value;
                        {
                            var k = dobj.eachSlot();
                            while (k.MoveNext())
                            {
                                var c = k.Current;
                                DynamicPropertySlot ds = c as DynamicPropertySlot;
                                if (c != null)
                                {
                                    yield return(ds.getValue()); //new rtString(ds._propname);
                                }
                            }
                        }
                        yield break;
                    }
                    else if (protoObj._class.staticClass == null)
                    {
                        dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[0].getValue()).value;
                        var res = getForEach_IEnumerator(player,dobj,frame,step,scope);
                        while (res.MoveNext())
                        {
                            yield return(res.Current);
                        }
                    }
                    else
                    {
                        frame.throwError((new error.InternalError(frame.player.swc,step.token,
                                                                  "遭遇了异常的_prototype_"
                                                                  )));
                        yield break;
                    }
                }
            }
            else if (obj is ASBinCode.rtti.Object)
            {
                //***处理.net IEnumerable***
                System.Collections.IEnumerator enumerator = null;
                if (obj is LinkSystemObject)
                {
                    var od = ((LinkSystemObject)obj).GetLinkData();
                    if (od is System.Collections.IEnumerable)
                    {
                        enumerator = ((System.Collections.IEnumerable)od).GetEnumerator();
                    }
                    else
                    {
                        enumerator = od as System.Collections.IEnumerator;
                    }
                }

                if (enumerator != null)
                {
                    var e = enumerator;
                    while (e.MoveNext())
                    {
                        int slotidx = frame.baseBottomSlotIndex;
                        if (slotidx >= Player.STACKSLOTLENGTH)
                        {
                            throw new ASRunTimeException("stack overflow",frame.player.stackTrace(0));
                        }
                        var tempslot = frame.stack[slotidx];
                        try
                        {
                            player.linktypemapper.storeLinkObject_ToSlot(e.Current,RunTimeDataType.rt_void,frame._tempSlot2,player.swc,player);
                        }
                        finally
                        {
                            tempslot.clear();
                        }

                        yield return(frame._tempSlot2.getValue());
                    }
                }
                else
                {
                    var dobj = ((ASBinCode.rtti.DynamicObject)
                                frame.player.static_instance[obj._class.staticClass.classid].value);

                    dobj = (ASBinCode.rtti.DynamicObject)((rtObjectBase)dobj.memberData[0].getValue()).value;
                    var res = getForEach_IEnumerator(player,dobj,frame,step,scope);
                    while (res.MoveNext())
                    {
                        yield return(res.Current);
                    }
                }
            }

            yield break;
        }
Example #25
0
        public static void _doSetThisItem(ASBinCode.rtData.rtObjectBase thisObj,
                                          RunTimeValueBase v,RunTimeValueBase index,StackSlot slot,StackFrame frame,OpStep step
                                          )
        {
            //***读取setter***
            RunTimeValueBase func;

            func = ((MethodGetterBase)thisObj.value._class.set_this_item.bindField).getMethod(
                thisObj
                );

            //***调用设置器***

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

            funCaller.SetFunction((ASBinCode.rtData.rtFunction)func); ((ASBinCode.rtData.rtFunction)func).Clear();
            funCaller.loadDefineFromFunction();
            if (!funCaller.createParaScope())
            {
                return;
            }

            //funCaller.releaseAfterCall = true;

            bool success;

            funCaller.pushParameter(v,0,out success);

            if (!success)
            {
                frame.endStep(step);
                return;
            }

            funCaller.pushParameter(index,1,out success);
            if (!success)
            {
                frame.endStep(step);
                return;
            }

            funCaller._tempSlot  = frame._tempSlot1;
            funCaller.returnSlot = frame._tempSlot1;

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

            cb.setCallBacker(_setthisitem_callbacker);
            cb.step = step;
            cb.args = frame;


            funCaller.callbacker = cb;
            funCaller.call();

            return;
        }
Example #26
0
        public static void _doPropAssigning(ClassPropertyGetter prop,StackFrame frame,
                                            OpStep step,Player player,RunTimeScope scope,
                                            ASBinCode.rtData.rtObjectBase bindobj,RunTimeValueBase v,StackSlot sslot)
        {
            do
            {
                if (prop.setter == null)
                {
                    frame.throwError(
                        step.token,0,"Illegal write to read-only property "
                        );
                    break;
                }
                //检查访问权限
                CodeBlock block = player.swc.blocks[scope.blockId];
                Class     finder;
                if (block.isoutclass)
                {
                    var c = prop._class;
                    if (c.instanceClass != null)
                    {
                        c = c.instanceClass;
                    }
                    if (c.mainClass != null)
                    {
                        c = c.mainClass;
                    }

                    if (block.define_class_id == c.classid)
                    {
                        finder = player.swc.classes[block.define_class_id];
                    }
                    else
                    {
                        finder = null;
                    }
                }
                else
                {
                    finder = player.swc.classes[block.define_class_id];
                }

                var setter = ClassMemberFinder.find(prop._class,prop.setter.name,finder);
                if (setter == null || setter.bindField != prop.setter)
                {
                    frame.throwError(
                        step.token,0,"Illegal write to read-only property "
                        );
                    break;
                }

                //***读取setter***
                RunTimeValueBase func;

                if (sslot.stackObjects.superPropBindClass != null)
                {
                    func = ((MethodGetterBase)setter.bindField).getSuperMethod(
                        bindobj.objScope,
                        sslot.stackObjects.superPropBindClass
                        );
                }
                else
                {
                    func = ((MethodGetterBase)setter.bindField).getMethod(
                        bindobj
                        );
                }
                //***调用设置器***

                var funCaller = frame.player.funcCallerPool.create(frame,step.token);
                funCaller.SetFunction((ASBinCode.rtData.rtFunction)func); ((ASBinCode.rtData.rtFunction)func).Clear();
                funCaller.loadDefineFromFunction();
                if (!funCaller.createParaScope())
                {
                    return;
                }

                //funCaller.releaseAfterCall = true;

                bool success;
                funCaller.pushParameter(v,0,out success);
                if (!success)
                {
                    frame.endStep(step);
                    return;
                }

                funCaller._tempSlot  = frame._tempSlot1;
                funCaller.returnSlot = frame._tempSlot1;

                BlockCallBackBase cb = frame.player.blockCallBackPool.create();
                cb.setCallBacker(_assign_callbacker);
                cb.step = step;
                cb.args = frame;

                funCaller.callbacker = cb;
                funCaller.call();

                return;
            } while (false);


            frame.endStep(step);
        }
        private static IEnumerator <RunTimeValueBase> getForinIEnumerator(
            Player player,ASBinCode.rtti.Object obj,StackFrame frame,OpStep step,RunTimeScope scope,
            Dictionary <object,object> visited = null
            )
        {
            if (obj is ASBinCode.rtti.DynamicObject)
            {
                ASBinCode.rtti.DynamicObject dobj = (ASBinCode.rtti.DynamicObject)obj;
                {
                    var k = dobj.eachSlot();
                    while (k.MoveNext())
                    {
                        var c = k.Current;
                        DynamicPropertySlot ds = c as DynamicPropertySlot;
                        if (c != null)
                        {
                            yield return(new rtString(ds._propname));
                        }
                    }
                }

                if (obj is DictionaryObject)
                {
                    DictionaryObject dictObj = (DictionaryObject)obj;
                    var k = dictObj.eachDictSlot();
                    while (k.MoveNext())
                    {
                        var            c  = k.Current;
                        DictionarySlot ds = c as DictionarySlot;
                        if (c != null)
                        {
                            yield return(ds._key.key);
                        }
                    }
                }
                if (visited == null)
                {
                    visited = new Dictionary <object,object>();
                }
                //***再到原型链中查找
                if (dobj._prototype_ != null)
                {
                    var protoObj = dobj._prototype_;
                    //****_prototype_的类型,只可能是Function对象或Class对象
                    if (protoObj._class.classid == player.swc.FunctionClass.classid) //Function
                    {
                        dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[1].getValue()).value;
                        if (visited.ContainsKey(dobj))
                        {
                            yield break;
                        }
                        visited.Add(dobj,null);

                        var res = getForinIEnumerator(player,dobj,frame,step,scope,visited);
                        while (res.MoveNext())
                        {
                            yield return(res.Current);
                        }
                    }
                    else if (protoObj._class.classid == 1) //搜索到根Object
                    {
                        //***根Object有继承自Class的prototype,再没有就没有了
                        dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[0].getValue()).value;
                        {
                            var k = dobj.eachSlot();
                            while (k.MoveNext())
                            {
                                var c = k.Current;
                                DynamicPropertySlot ds = c as DynamicPropertySlot;
                                if (c != null)
                                {
                                    yield return(new rtString(ds._propname));
                                }
                            }
                        }
                        yield break;
                    }
                    else if (protoObj._class.staticClass == null)
                    {
                        dobj = (DynamicObject)((rtObjectBase)protoObj.memberData[0].getValue()).value;
                        var res = getForinIEnumerator(player,dobj,frame,step,scope);
                        while (res.MoveNext())
                        {
                            yield return(res.Current);
                        }
                    }
                    else
                    {
                        frame.throwError((new error.InternalError(frame.player.swc,step.token,
                                                                  "遭遇了异常的_prototype_"
                                                                  )));
                        yield break;
                    }
                }
            }
            else if (obj is ASBinCode.rtti.Object)
            {
                var dobj = ((ASBinCode.rtti.DynamicObject)
                            frame.player.static_instance[obj._class.staticClass.classid].value);

                dobj = (ASBinCode.rtti.DynamicObject)((rtObjectBase)dobj.memberData[0].getValue()).value;
                var res = getForinIEnumerator(player,dobj,frame,step,scope);
                while (res.MoveNext())
                {
                    yield return(res.Current);
                }
            }

            yield break;
        }
        public void buildAS3Break(CompileEnv env, ASTool.AS3.AS3Break as3break)
        {
            if (string.IsNullOrEmpty(as3break.breakFlag))
            {
                //throw new BuildException(as3break.Token.line, as3break.Token.ptr, as3break.Token.sourceFile,
                //                    "语句关联break尚未实现");
                //***向上查找

                //int l = 0;
                Stack <string> flagstack = new Stack <string>();

                for (int i = env.block.opSteps.Count - 1; i >= 0; i--)
                {
                    var s = env.block.opSteps[i];
                    if (s.opCode == OpCode.flag)
                    {
                        if (s.flag.StartsWith("LOOP_END_") || s.flag.StartsWith("SWITCH_END_"))
                        {
                            flagstack.Push(s.flag);
                            //l--;
                        }

                        if (s.flag.StartsWith("LOOP_START_") || s.flag.StartsWith("SWITCH_START_"))
                        {
                            if (flagstack.Count == 0)
                            {
                                string header = null;
                                if (s.flag.StartsWith("LOOP_START_"))
                                {
                                    header = "LOOP_END_";
                                }
                                else
                                {
                                    header = "SWITCH_END_";
                                }

                                string id = s.flag.Substring(header.Length + 2);

                                //label标记跳转
                                OpStep op = new OpStep(OpCode.jmp, new SourceToken(as3break.Token.line, as3break.Token.ptr, as3break.Token.sourceFile));
                                op.reg     = null;
                                op.regType = RunTimeDataType.unknown;
                                op.arg1    = new ASBinCode.rtData.RightValue(
                                    new ASBinCode.rtData.rtString(header + id));
                                op.arg1Type = RunTimeDataType.rt_string;
                                op.arg2     = null;
                                op.arg2Type = RunTimeDataType.unknown;

                                env.block.opSteps.Add(op);

                                return;
                            }
                            else
                            {
                                string p = flagstack.Pop();
                                if ((p.StartsWith("LOOP_END_") && s.flag.StartsWith("LOOP_START_"))
                                    ||
                                    (p.StartsWith("SWITCH_END_") && s.flag.StartsWith("SWITCH_START_")))

                                {
                                }
                                else
                                {
                                    throw new BuildException(as3break.Token.line, as3break.Token.ptr, as3break.Token.sourceFile, "switch或loop开关不匹配");
                                }
                                //l++;
                            }
                        }
                    }
                }

                throw new BuildException(as3break.Token.line, as3break.Token.ptr, as3break.Token.sourceFile,
                                         "break的关联块未找到");
            }
            else
            {
                //语句块break

                int l = 0;
                for (int i = 0; i < env.block.opSteps.Count; i++)
                {
                    var s = env.block.opSteps[i];
                    if (s.opCode == OpCode.flag)
                    {
                        if (s.flag == "Label" + env.labelblocks + "_End_" + as3break.breakFlag)
                        {
                            l--;
                        }
                        else if (s.flag == "Label" + env.labelblocks + "_Start_" + as3break.breakFlag)
                        {
                            l++;
                        }
                    }
                }
                if (l < 1)
                {
                    throw new BuildException(as3break.Token.line, as3break.Token.ptr, as3break.Token.sourceFile,
                                             "break的关联标记[" + as3break.breakFlag + "]未找到");
                }

                //label标记跳转
                OpStep op = new OpStep(OpCode.jmp, new SourceToken(as3break.Token.line, as3break.Token.ptr, as3break.Token.sourceFile));
                op.reg     = null;
                op.regType = RunTimeDataType.unknown;
                op.arg1    = new ASBinCode.rtData.RightValue(
                    new ASBinCode.rtData.rtString("Label" + env.labelblocks + "_End_" + as3break.breakFlag));
                op.arg1Type = RunTimeDataType.rt_string;
                op.arg2     = null;
                op.arg2Type = RunTimeDataType.unknown;

                env.block.opSteps.Add(op);
            }
        }
Example #29
0
        public static void _do_prop_read(
            ClassPropertyGetter prop,StackFrame frame,OpStep step,Player player,RunTimeScope scope,
            ASBinCode.rtData.rtObjectBase propBindObj,Class superPropBindClass
            )
        {
            do
            {
                //***调用访问器。***

                if (prop.getter == null)
                {
                    frame.throwError(
                        step.token,0,"Illegal read of write-only property"
                        );
                    break;
                }
                //检查访问权限
                CodeBlock block = player.swc.blocks[scope.blockId];
                Class     finder;
                if (block.isoutclass)
                {
                    var c = prop._class;
                    if (c.instanceClass != null)
                    {
                        c = c.instanceClass;
                    }
                    if (c.mainClass != null)
                    {
                        c = c.mainClass;
                    }

                    if (block.define_class_id == c.classid)
                    {
                        finder = player.swc.classes[block.define_class_id];
                    }
                    else
                    {
                        finder = null;
                    }
                }
                else
                {
                    finder = player.swc.classes[block.define_class_id];
                }

                var getter = ClassMemberFinder.find(prop._class,prop.getter.name,finder);
                if (getter == null || getter.bindField != prop.getter)
                {
                    frame.throwError(
                        step.token,0,"Illegal read of write-only property"
                        );
                    break;
                }

                //***读取getter***


                RunTimeValueBase func;

                if (superPropBindClass != null)
                {
                    func = ((MethodGetterBase)getter.bindField).getSuperMethod(
                        //propslot.bindObj.objScope
                        propBindObj.objScope,
                        superPropBindClass

                        );
                }
                else
                {
                    func = ((MethodGetterBase)getter.bindField).getMethod(
                        //propslot.bindObj.objScope
                        propBindObj
                        );
                }

                //***调用访问器***

                var funCaller = player.funcCallerPool.create(frame,step.token);
                //funCaller.releaseAfterCall = true;
                funCaller.SetFunction((ASBinCode.rtData.rtFunction)func); ((ASBinCode.rtData.rtFunction)func).Clear();

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

                funCaller._tempSlot  = frame._tempSlot1;
                funCaller.returnSlot = step.reg.getSlot(scope,frame);

                ((StackSlot)funCaller.returnSlot).stackObjects.propGetSet  = prop; ((StackSlot)funCaller.returnSlot).refPropChanged = true;
                ((StackSlot)funCaller.returnSlot).stackObjects.propBindObj = propBindObj;


                BlockCallBackBase cb = frame.player.blockCallBackPool.create();
                cb.setCallBacker(D_getter_callbacker);
                cb.step = step;
                cb.args = frame;

                funCaller.callbacker = cb;
                funCaller.call();

                return;
            } while (false);


            frame.endStep(step);
        }
Example #30
0
        public static void exec_try_read_prop(StackFrame frame, OpStep step, RunTimeScope scope)
        {
            ASBinCode.SLOT slot = ((StackSlotAccessor)step.arg1).getSlot(scope,frame);

            if (slot.isPropGetterSetter)
            {
                ((StackSlot)slot).linkTo(null);
                _do_prop_read(

                    ((StackSlot)slot).stackObjects.propGetSet,
                    frame,step,frame.player,scope,((StackSlot)slot).stackObjects.propBindObj,((StackSlot)slot).stackObjects.superPropBindClass
                    );
            }
            else if (slot.isSetThisItem)
            {
                SetThisItemSlot sslot = (SetThisItemSlot)((StackSlot)slot).getLinkSlot();

                ((StackSlot)slot).linkTo(null);

                //***调用索引器get***
                RunTimeValueBase func;
                var rtObj  = sslot.bindObj;
                var player = frame.player;
                var v2     = sslot.setindex;
                func = ((MethodGetterBase)sslot.get_this_item.bindField).getMethod(
                    rtObj
                    );

                var funCaller = player.funcCallerPool.create(frame,step.token);
                funCaller.SetFunction((ASBinCode.rtData.rtFunction)func); ((ASBinCode.rtData.rtFunction)func).Clear();
                funCaller.loadDefineFromFunction();
                if (!funCaller.createParaScope())
                {
                    return;
                }

                //funCaller.releaseAfterCall = true;

                bool success;
                funCaller.pushParameter(v2,0,out success);
                if (!success)
                {
                    frame.endStep(step);
                    return;
                }

                funCaller._tempSlot  = frame._tempSlot1;
                funCaller.returnSlot = step.reg.getSlot(scope,frame);

                StackSlot ret = (StackSlot)funCaller.returnSlot;
                ret.stackObjects._temp_try_write_setthisitem = ret._cache_setthisslot; ret.refPropChanged = true;
                ret._cache_setthisslot.bindObj       = rtObj;
                ret._cache_setthisslot.setindex      = v2;
                ret._cache_setthisslot.set_this_item = sslot.set_this_item;

                BlockCallBackBase cb = frame.player.blockCallBackPool.create();
                cb.setCallBacker(D_get_this_item_callbacker);
                cb.step = step;
                cb.args = frame;

                funCaller.callbacker = cb;
                funCaller.call();

                return;
            }
            else
            {
                SLOT regslot = step.reg.getSlot(scope,frame);

                StackSlot d = regslot as StackSlot;
                StackSlot s = slot as StackSlot;

                if (d != null && s != null && s.getLinkSlot() != null)
                {
                    d.linkTo(s.getLinkSlot());
                    s.linkTo(null);
                }
                else
                {
                    regslot.directSet(slot.getValue());
                }
                //frame.endStep(step);
                frame.endStepNoError();
            }
        }
Example #31
0
        /// <summary>
        /// Called when the KMOD ticket query results are available.
        /// </summary>
        private void OnKmodTicketResult(WmLoginTicketQuery query)
        {
            if (m_kmodQuery != query) return;
            m_kmodQuery = null;
            Debug.Assert(m_step == OpStep.TicketReply);

            try
            {
                // Update the registry information.
                query.UpdateRegistry();

                // Generic failure.
                if (query.Res != WmLoginTicketQueryRes.OK) throw new Exception(query.OutDesc);

                // We cannot create a workspace.
                if (!KwmCfg.Cur.CanCreateKws()) throw new EAnpExInvalidKpsConfig();

                // Update the credentials.
                Creds.Ticket = query.Ticket.BinaryTicket;
                Creds.UserName = query.Ticket.AnpTicket.Elements[0].String;
                Creds.UserEmailAddress = query.Ticket.AnpTicket.Elements[1].String;

                // Set the KCD address.
                if (KwmCfg.Cur.CustomKcdFlag) Creds.KcdAddress = KwmCfg.Cur.CustomKcdAddress;
                else Creds.KcdAddress = KwmCfg.Cur.KpsKcdAddr;
                if (Creds.KcdAddress == "") throw new Exception("invalid KCD address");

                // Create the workspace object.
                Kws = Wm.CreateWorkspace(Creds);
                RegisterToKws();

                // Start the spawn operation and wait for the connection.
                m_step = OpStep.Connecting;
                Kws.Sm.RequestTaskSwitch(KwsTask.Spawn);
                SendCreateKwsCmdIfNeeded();
            }

            catch (Exception ex)
            {
                HandleFailure(ex);
            }
        }
Example #32
0
        public void buildAS3IF(CompileEnv env, ASTool.AS3.AS3IF as3if, Builder builder)
        {
            if (!string.IsNullOrEmpty(as3if.label))
            {
                //**包装一个block**
                ASTool.AS3.AS3Block tempblock = new ASTool.AS3.AS3Block(as3if.Token);
                tempblock.CodeList = new List <ASTool.AS3.IAS3Stmt>();
                tempblock.CodeList.Add(as3if);
                tempblock.label = as3if.label;
                as3if.label     = null;
                builder.buildStmt(env, tempblock);
            }
            else
            {
                //***先编译条件***
                builder.buildStmt(env, as3if.Condition);
                //**取判断条件***
                ASTool.AS3.AS3Expression expr = as3if.Condition.as3exprlist[as3if.Condition.as3exprlist.Count - 1];

                //if true goto TRUE_LBL
                //***
                //goto IF_END_LBL
                //TRUE_LBL
                //***
                //IF_END_LBL


                string truelabel = env.makeLabel("IF_TRUE");
                string endlabel  = env.makeLabel("IF_END");

                {
                    ASTool.AS3.AS3StmtExpressions conditionsJump = new ASTool.AS3.AS3StmtExpressions(as3if.Condition.Token);
                    ASTool.AS3.AS3Expression      expression     = new ASTool.AS3.AS3Expression(as3if.Condition.Token);
                    expression.exprStepList = new ASTool.AS3.Expr.AS3ExprStepList();
                    ASTool.AS3.Expr.AS3ExprStep step = new ASTool.AS3.Expr.AS3ExprStep(as3if.Token);
                    step.Type   = ASTool.AS3.Expr.OpType.IF_GotoFlag;
                    step.OpCode = truelabel;
                    step.Arg1   = expr.Value;
                    expression.exprStepList.Add(step);

                    conditionsJump.as3exprlist = new List <ASTool.AS3.AS3Expression>();
                    conditionsJump.as3exprlist.Add(expression);
                    builder.buildStmt(env, conditionsJump);
                }
                {
                    //false部分
                    if (as3if.FalsePass != null)
                    {
                        for (int i = 0; i < as3if.FalsePass.Count; i++)
                        {
                            builder.buildStmt(env, as3if.FalsePass[i]);
                        }
                    }

                    //跳转到end;
                    ASTool.AS3.AS3StmtExpressions jumptoend = new ASTool.AS3.AS3StmtExpressions(as3if.Token);
                    jumptoend.as3exprlist = new List <ASTool.AS3.AS3Expression>();

                    ASTool.AS3.AS3Expression expression = new ASTool.AS3.AS3Expression(as3if.Token);
                    expression.exprStepList = new ASTool.AS3.Expr.AS3ExprStepList();

                    ASTool.AS3.Expr.AS3ExprStep step = new ASTool.AS3.Expr.AS3ExprStep(as3if.Token);
                    step.Type   = ASTool.AS3.Expr.OpType.GotoFlag;
                    step.OpCode = endlabel;
                    expression.exprStepList.Add(step);

                    jumptoend.as3exprlist.Add(expression);
                    builder.buildStmt(env, jumptoend);

                    //**写入true标记
                    OpStep lbl_true = new OpStep(OpCode.flag, new SourceToken(as3if.Token.line, as3if.Token.ptr, as3if.Token.sourceFile));
                    lbl_true.flag = truelabel;
                    env.block.opSteps.Add(lbl_true);
                }
                {
                    //true部分
                    if (as3if.TruePass != null)
                    {
                        for (int i = 0; i < as3if.TruePass.Count; i++)
                        {
                            builder.buildStmt(env, as3if.TruePass[i]);
                        }
                    }

                    //**写入end标记
                    OpStep lbl_end = new OpStep(OpCode.flag, new SourceToken(as3if.Token.line, as3if.Token.ptr, as3if.Token.sourceFile));
                    lbl_end.flag = endlabel;
                    env.block.opSteps.Add(lbl_end);
                }
            }
        }
Example #33
0
        /// <summary>
        /// Send the workspace creation command if we are ready to.
        /// </summary>
        private void SendCreateKwsCmdIfNeeded()
        {
            if (DoneFlag || m_step != OpStep.Connecting || Kws.Kcd.ConnStatus != KcdConnStatus.Connected) return;

            m_step = OpStep.CreateReply;
            AnpMsg cmd = Wm.NewKcdCmd(Kws.Kcd.MinorVersion, KAnp.KANP_CMD_MGT_CREATE_KWS);
            cmd.AddString(Creds.KwsName);
            cmd.AddBin(Creds.Ticket);
            cmd.AddUInt32(Convert.ToUInt32(Creds.PublicFlag));
            cmd.AddUInt32(Convert.ToUInt32(Creds.SecureFlag));
            if (cmd.Minor >= 4) cmd.AddUInt32(Convert.ToUInt32(Creds.ThinKfsFlag));
            m_kcdQuery = Kws.PostKcdCmd(cmd, HandleCreateKwsCmdResult);
        }
        public void buildAS3Continue(CompileEnv env, ASTool.AS3.AS3Continue as3continue, Builder builder)
        {
            if (string.IsNullOrEmpty(as3continue.continueFlag))
            {
                int l = 0;

                for (int i = env.block.opSteps.Count - 1; i >= 0; i--)
                {
                    var s = env.block.opSteps[i];
                    if (s.opCode == OpCode.flag)
                    {
                        if (s.flag.StartsWith("LOOP_END_"))
                        {
                            l--;
                        }

                        if (s.flag.StartsWith("LOOP_START_"))
                        {
                            if (l == 0)
                            {
                                string id = s.flag.Substring(11);

                                //label标记跳转
                                OpStep op = new OpStep(OpCode.jmp, new SourceToken(as3continue.Token.line, as3continue.Token.ptr, as3continue.Token.sourceFile));
                                op.reg     = null;
                                op.regType = RunTimeDataType.unknown;
                                op.arg1    = new ASBinCode.rtData.RightValue(
                                    new ASBinCode.rtData.rtString("LOOP_CONTINUE_" + id));

                                op.arg1Type = RunTimeDataType.rt_string;
                                op.arg2     = null;
                                op.arg2Type = RunTimeDataType.unknown;

                                env.block.opSteps.Add(op);

                                return;
                            }
                            else
                            {
                                l++;
                            }
                        }
                    }
                }

                throw new BuildException(as3continue.Token.line, as3continue.Token.ptr, as3continue.Token.sourceFile,
                                         "continue的关联块未找到");
            }
            else
            {
                //命名label的continue;
                int l     = 0;
                int stidx = 0;
                for (int i = 0; i < env.block.opSteps.Count; i++)
                {
                    var s = env.block.opSteps[i];
                    if (s.opCode == OpCode.flag)
                    {
                        if (s.flag == "LOOP_LABEL_END_" + as3continue.continueFlag)
                        {
                            l--;
                        }
                        else if (s.flag == "LOOP_LABEL_START_" + as3continue.continueFlag)
                        {
                            l++;
                            stidx = i;
                        }
                    }
                }
                if (l < 1)
                {
                    throw new BuildException(as3continue.Token.line, as3continue.Token.ptr, as3continue.Token.sourceFile,
                                             "continue的关联标记[" + as3continue.continueFlag + "]未找到");
                }

                //**查找关联的循环**
                for (int i = stidx; i < env.block.opSteps.Count; i++)
                {
                    var s = env.block.opSteps[i];
                    if (s.opCode == OpCode.flag)
                    {
                        if (s.flag.StartsWith("LOOP_START_"))
                        {
                            string id = s.flag.Substring(11);

                            //label标记跳转
                            OpStep op = new OpStep(OpCode.jmp, new SourceToken(as3continue.Token.line, as3continue.Token.ptr, as3continue.Token.sourceFile));
                            op.reg     = null;
                            op.regType = RunTimeDataType.unknown;
                            op.arg1    = new ASBinCode.rtData.RightValue(
                                new ASBinCode.rtData.rtString("LOOP_CONTINUE_" + id));

                            op.arg1Type = RunTimeDataType.rt_string;
                            op.arg2     = null;
                            op.arg2Type = RunTimeDataType.unknown;

                            env.block.opSteps.Add(op);

                            return;
                        }
                    }
                }

                throw new BuildException(as3continue.Token.line, as3continue.Token.ptr, as3continue.Token.sourceFile,
                                         "continue的关联标记[" + as3continue.continueFlag + "]未找到");
            }
        }