Exemple #1
0
        internal override void Compile(CompileParameter param)
        {
            if (Init != null)
            {
                Init.Compile(param.SetLHS(false));
            }

            LoopBeginCmdID = param.CS.CurrCmdID;

            Command jzCmd = null;

            if (Condition != null)
            {
                Condition.Compile(param.SetLHS(false));

                jzCmd = param.CS.Add(new Command(Opcode.JZ, -1))
                        .SetCodePos(Pos)
                        .SetComment("for condition");
            }

            Body.Compile(param.SetLHS(false));

            if (Post != null)
            {
                Post.Compile(param.SetLHS(false));
            }


            param.CS.Add(new Command(Opcode.JMP, LoopBeginCmdID))
            .SetCodePos(Pos)
            .SetComment("for loop");

            // false body跳入
            if (jzCmd != null)
            {
                jzCmd.DataA = param.CS.CurrCmdID;
            }

            LoopEndCmdID = param.CS.CurrCmdID;
        }