コード例 #1
0
ファイル: ControlFlow.cs プロジェクト: MasterQ32/LoLa-csharp
        public override void Emit(CodeWriter writer)
        {
            Condition.Emit(writer);
            var endLabel = new Label();

            if (this.FalseBody == null)
            {
                // single body
                writer.JumpWhenFalse(endLabel);
                TrueBody.Emit(writer);
            }
            else
            {
                // double body
                var falseLabel = new Label();

                writer.JumpWhenFalse(falseLabel);
                TrueBody.Emit(writer);
                writer.Jump(endLabel);

                writer.DefineLabel(falseLabel);

                FalseBody.Emit(writer);
            }
            writer.DefineLabel(endLabel);
        }
コード例 #2
0
        public override string WriteLua(int indentLevel)
        {
            StringBuilder str = new StringBuilder();

            if (IsElseIf)
            {
                str.Append($"elseif {Condition} then\n");
            }
            else
            {
                str.Append($"if {Condition} then\n");
            }
            if (TrueBody != null)
            {
                str.Append(TrueBody.PrintBlock(indentLevel).AddIndent());
            }
            if (FalseBody != null)
            {
                str.Append("\n");
                // Check for elseif
                if (FalseBody.Instructions.Count() == 1 && FalseBody.Instructions.First() is IfStatement s && s.Follow == null)
                {
                    s.IsElseIf = true;
                    str.Append(FalseBody.PrintBlock(indentLevel));
                }
                else
                {
                    for (int i = 0; i < indentLevel; i++)
                    {
                        str.Append("\t");
                    }
                    str.Append("else\n");
                    str.Append(FalseBody.PrintBlock(indentLevel).AddIndent());
                }
            }
コード例 #3
0
ファイル: nodes.expressions.cs プロジェクト: RenolY2/ssc
        public override void Compile(sunCompiler compiler)
        {
            Condition.Compile(compiler);
            var falsePrologue = new sunJumpNotEqualSite(compiler.Binary);

            TrueBody.Compile(compiler);
            var trueEpilogue = new sunJumpSite(compiler.Binary);

            falsePrologue.Relocate();
            FalseBody.Compile(compiler);
            trueEpilogue.Relocate();
        }
コード例 #4
0
        public override void Compile(sunCompiler compiler)
        {
            Condition.Compile(compiler);
            var trueBodyEpilogue = new sunJumpNotEqualSite(compiler.Binary);

            TrueBody.Compile(compiler);
            var falseBody = FalseBody;

            if (falseBody != null)
            {
                var falseBodyEpilogue = new sunJumpSite(compiler.Binary);
                trueBodyEpilogue.Relocate();
                falseBody.Compile(compiler);
                falseBodyEpilogue.Relocate();
            }
            else
            {
                trueBodyEpilogue.Relocate();
            }
        }
コード例 #5
0
ファイル: nodes.expressions.cs プロジェクト: RenolY2/ssc
 sunExpressionFlags sunTerm.GetExpressionFlags(sunContext context)
 {
     return(Condition.Analyze(context) | TrueBody.Analyze(context) | FalseBody.Analyze(context));
 }
コード例 #6
0
 public override string ToString()
 {
     return($"if ({Condition.ToString()}) {TrueBody.ToString()}");
 }