KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * MultipleAsgnNodeAsgnCompiler.java
3  *
4  * Created on January 31, 2007, 11:16 PM
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 java.util.Collections JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import org.jruby.ast.ListNode;
15 import org.jruby.ast.MultipleAsgnNode;
16 import org.jruby.ast.Node;
17 import org.jruby.ast.StarNode;
18
19 /**
20  *
21  * @author headius
22  */

23 public class MultipleAsgnNodeAsgnCompiler implements NodeCompiler {
24     
25     /** Creates a new instance of MultipleAsgnNodeAsgnCompiler */
26     public MultipleAsgnNodeAsgnCompiler() {
27     }
28     
29     public void compile(Node node, Compiler JavaDoc context) {
30         
31         // FIXME: This is incomplete.
32

33         context.lineNumber(node.getPosition());
34         
35         MultipleAsgnNode multipleAsgnNode = (MultipleAsgnNode)node;
36         
37         int varLen = multipleAsgnNode.getHeadNode() == null ? 0 : multipleAsgnNode.getHeadNode().size();
38         
39         Iterator JavaDoc iter = multipleAsgnNode.getHeadNode() != null ? multipleAsgnNode.getHeadNode().iterator() : Collections.EMPTY_LIST.iterator();
40         
41         { // normal items at the "head" of the masgn
42
ArrayCallback headAssignCallback = new ArrayCallback() {
43                 public void nextValue(Compiler JavaDoc context, Object JavaDoc sourceArray,
44                                       int index) {
45                     ListNode headNode = (ListNode)sourceArray;
46                     Node assignNode = headNode.get(index);
47
48                     // perform assignment for the next node
49
NodeCompilerFactory.getAssignmentCompiler(assignNode).compile(assignNode, context);
50                 }
51             };
52
53             context.ensureRubyArray();
54             context.forEachInValueArray(multipleAsgnNode.getHeadNode().size(), 0, multipleAsgnNode.getHeadNode(), headAssignCallback);
55         }
56         
57         // FIXME: This needs to fit in somewhere
58
//if (callAsProc && iter.hasNext()) {
59
// throw runtime.newArgumentError("Wrong # of arguments (" + valueLen + " for " + varLen + ")");
60
//}
61

62         { // "args node" handling
63
Node argsNode = multipleAsgnNode.getArgsNode();
64             if (argsNode != null) {
65                 if (argsNode instanceof StarNode) {
66                     // no check for '*'
67
} else {
68                     BranchCallback trueBranch = new BranchCallback() {
69                         public void branch(Compiler JavaDoc context) {
70                             
71                         }
72                     };
73                     
74                     // check if the number of variables is exceeded by the number of values in the array
75
// the number of values
76
context.loadRubyArraySize();
77                     context.loadInteger(varLen);
78                     //context.performLTBranch(trueBranch, falseBranch);
79
}
80             }
81         }
82     }
83 }
84
Popular Tags