1 9 10 package org.jruby.compiler; 11 12 import org.jruby.ast.ArgsNode; 13 import org.jruby.ast.DefnNode; 14 import org.jruby.ast.Node; 15 16 20 public class DefnNodeCompiler implements NodeCompiler { 21 22 23 public DefnNodeCompiler() { 24 25 } 26 27 public void compile(Node node, Compiler context) { 28 context.lineNumber(node.getPosition()); 29 30 final DefnNode defnNode = (DefnNode)node; 31 32 ClosureCallback body = new ClosureCallback() { 33 public void compile(Compiler context) { 34 NodeCompilerFactory.getCompiler(defnNode.getBodyNode()).compile(defnNode.getBodyNode(), context); 35 } 36 }; 37 38 int arity = 0; 39 40 arity = ((ArgsNode)defnNode.getArgsNode()).getArgsCount(); 42 43 context.defineNewMethod(defnNode.getName(), arity, defnNode.getScope().getNumberOfVariables(), body); 44 } 45 46 } 47 | Popular Tags |