KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > compiler > DefnNodeCompiler


1 /*
2  * DefnNodeCompiler.java
3  *
4  * Created on January 4, 2007, 2:07 AM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

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 /**
17  *
18  * @author headius
19  */

20 public class DefnNodeCompiler implements NodeCompiler {
21     
22     /** Creates a new instance of DefnNodeCompiler */
23     public DefnNodeCompiler() {
24         
25     }
26     
27     public void compile(Node node, Compiler JavaDoc context) {
28         context.lineNumber(node.getPosition());
29         
30         final DefnNode defnNode = (DefnNode)node;
31         
32         ClosureCallback body = new ClosureCallback() {
33             public void compile(Compiler JavaDoc context) {
34                 NodeCompilerFactory.getCompiler(defnNode.getBodyNode()).compile(defnNode.getBodyNode(), context);
35             }
36         };
37         
38         int arity = 0;
39         
40         // FIXME: simple arity check assumes simple arg list; expand to support weirder arg lists
41
arity = ((ArgsNode)defnNode.getArgsNode()).getArgsCount();
42         
43         context.defineNewMethod(defnNode.getName(), arity, defnNode.getScope().getNumberOfVariables(), body);
44     }
45     
46 }
47
Popular Tags