1 9 10 package org.jruby.compiler; 11 12 import org.jruby.ast.Node; 13 import org.jruby.ast.WhileNode; 14 15 19 public class WhileNodeCompiler implements NodeCompiler { 20 21 22 public WhileNodeCompiler() { 23 } 24 25 public void compile(Node node, Compiler context) { 26 context.lineNumber(node.getPosition()); 27 28 final WhileNode whileNode = (WhileNode)node; 29 30 BranchCallback condition = new BranchCallback() { 31 public void branch(Compiler context) { 32 NodeCompilerFactory.getCompiler(whileNode.getConditionNode()).compile(whileNode.getConditionNode(), context); 33 } 34 }; 35 36 BranchCallback body = new BranchCallback() { 37 public void branch(Compiler context) { 38 if (whileNode.getBodyNode() == null) { 41 context.loadNil(); 42 return; 43 } 44 NodeCompilerFactory.getCompiler(whileNode.getBodyNode()).compile(whileNode.getBodyNode(), context); 45 } 46 }; 47 48 context.performBooleanLoop(condition, body, whileNode.evaluateAtStart()); 49 } 50 51 } 52 | Popular Tags |