コード例 #1
0
        public void Visit(IfStatementNode statement)
        {
            int    labelIndex = _labelCount++;
            string falseLabel = "if_false_" + labelIndex;
            string endLabel   = "if_end_" + labelIndex;

            EmitComment("If: condition");
            statement.Condition.Accept(this);
            EmitComment("If: jump");
            Emit("brfalse", falseLabel);
            EmitComment("If: begin true part");
            statement.ThenBody.Accept(this);
            if (statement.ElseBody != null)
            {
                Emit("br", endLabel);
            }
            EmitComment("If: end true part");
            EmitLabel(falseLabel);
            if (statement.ElseBody != null)
            {
                EmitComment("If: begin false part");
                statement.ElseBody.Accept(this);
                EmitComment("If: end false part");
                EmitLabel(endLabel);
            }
        }
コード例 #2
0
 public void Visit(IfStatementNode statement)
 {
     statement.Condition.Accept(this);
     Emit("if (stack.pop()) {");
     ++_indentationLevel;
     statement.ThenBody.Accept(this);
     --_indentationLevel;
     Emit("}");
     if (statement.ElseBody != null)
     {
         Emit("else {");
         ++_indentationLevel;
         statement.ElseBody.Accept(this);
         --_indentationLevel;
         Emit("}");
     }
 }
コード例 #3
0
 public void Visit(IfStatementNode statement)
 {
     int labelIndex = _labelCount++;
     string falseLabel = "if_false_" + labelIndex;
     string endLabel = "if_end_" + labelIndex;
     EmitComment("If: condition");
     statement.Condition.Accept(this);
     EmitComment("If: jump");
     Emit("ifeq", falseLabel);
     EmitComment("If: begin true part");
     statement.ThenBody.Accept(this);
     if (statement.ElseBody != null)
         Emit("goto", endLabel);
     EmitComment("If: end true part");
     EmitLabel(falseLabel);
     if (statement.ElseBody != null)
     {
         EmitComment("If: begin false part");
         statement.ElseBody.Accept(this);
         EmitComment("If: end false part");
         EmitLabel(endLabel);
     }
 }
コード例 #4
0
 public void Visit(IfStatementNode statement)
 {
     statement.Condition.Accept(this);
     Emit("if (stack.pop()) {");
     ++_indentationLevel;
     statement.ThenBody.Accept(this);
     --_indentationLevel;
     Emit("}");
     if (statement.ElseBody != null)
     {
         Emit("else {");
         ++_indentationLevel;
         statement.ElseBody.Accept(this);
         --_indentationLevel;
         Emit("}");
     }
 }