1 9 10 package org.jruby.compiler; 11 12 import org.jruby.ast.IfNode; 13 import org.jruby.ast.Node; 14 15 19 public class IfNodeCompiler implements NodeCompiler { 20 21 22 public IfNodeCompiler() { 23 } 24 25 public void compile(Node node, Compiler context) { 26 context.lineNumber(node.getPosition()); 27 28 final IfNode ifNode = (IfNode)node; 29 30 NodeCompilerFactory.getCompiler(ifNode.getCondition()).compile(ifNode.getCondition(), context); 31 32 BranchCallback trueCallback = new BranchCallback() { 33 public void branch(Compiler context) { 34 NodeCompilerFactory.getCompiler(ifNode.getThenBody()).compile(ifNode.getThenBody(), context); 35 } 36 }; 37 38 BranchCallback falseCallback = new BranchCallback() { 39 public void branch(Compiler context) { 40 if (ifNode.getElseBody() != null) { 41 NodeCompilerFactory.getCompiler(ifNode.getElseBody()).compile(ifNode.getElseBody(), context); 42 } else { 43 context.loadNil(); 44 } 45 } 46 }; 47 48 context.performBooleanBranch(trueCallback, falseCallback); 49 } 50 51 } 52 | Popular Tags |