1 9 10 package org.jruby.compiler; 11 12 import org.jruby.ast.FCallNode; 13 import org.jruby.ast.IterNode; 14 import org.jruby.ast.Node; 15 import org.jruby.runtime.Arity; 16 17 21 public class FCallNodeCompiler implements NodeCompiler { 22 23 24 public FCallNodeCompiler() { 25 } 26 27 public void compile(Node node, Compiler context) { 28 context.lineNumber(node.getPosition()); 29 30 FCallNode fcallNode = (FCallNode)node; 31 32 if (fcallNode.getIterNode() == null) { 33 if (fcallNode.getArgsNode() != null) { 35 NodeCompiler argsCompiler = NodeCompilerFactory.getArgumentsCompiler(fcallNode.getArgsNode()); 37 38 argsCompiler.compile(fcallNode.getArgsNode(), context); 39 40 context.invokeDynamic(fcallNode.getName(), false, true, null); 41 } else { 42 context.invokeDynamic(fcallNode.getName(), false, false, null); 43 } 44 } else { 45 final IterNode iterNode = (IterNode) fcallNode.getIterNode(); 47 48 final ClosureCallback closureBody = new ClosureCallback() { 50 public void compile(Compiler context) { 51 NodeCompilerFactory.getCompiler(iterNode.getBodyNode()).compile(iterNode.getBodyNode(), context); 52 } 53 }; 54 55 final ClosureCallback closureArg = new ClosureCallback() { 56 public void compile(Compiler context) { 57 context.createNewClosure(iterNode.getScope(), Arity.procArityOf(iterNode.getVarNode()).getValue(), closureBody); 58 } 59 }; 60 61 if (fcallNode.getArgsNode() != null) { 62 NodeCompiler argsCompiler = NodeCompilerFactory.getArgumentsCompiler(fcallNode.getArgsNode()); 64 65 argsCompiler.compile(fcallNode.getArgsNode(), context); 66 67 context.invokeDynamic(fcallNode.getName(), false, true, closureArg); 68 } else { 69 context.invokeDynamic(fcallNode.getName(), false, false, closureArg); 70 } 71 } 72 } 73 74 } 75 | Popular Tags |