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