}
@SuppressWarnings("unchecked")
public void compileFixnumCase(final Node node, BodyCompiler context) {
List<WhenNode> cases = new ArrayList<WhenNode>();
Node elseBody = null;
// first get all when nodes
for (Node tmpNode = node; tmpNode != null; tmpNode = ((WhenNode)tmpNode).getNextCase()) {
WhenNode whenNode = (WhenNode)tmpNode;
cases.add(whenNode);
if (whenNode.getNextCase() != null) {
// if there's another node coming, make sure it will be a when...
if (whenNode.getNextCase() instanceof WhenNode) {
// normal when, continue
continue;
} else {
// ...or handle it as an else and we're done
elseBody = whenNode.getNextCase();
break;
}
}
}
// sort them based on literal value
Collections.sort(cases, new Comparator() {
public int compare(Object o1, Object o2) {
WhenNode w1 = (WhenNode)o1;
WhenNode w2 = (WhenNode)o2;
Integer value1 = (int)((FixnumNode)((ArrayNode)w1.getExpressionNodes()).get(0)).getValue();
Integer value2 = (int)((FixnumNode)((ArrayNode)w2.getExpressionNodes()).get(0)).getValue();
return value1.compareTo(value2);
}
});
final int[] intCases = new int[cases.size()];
final Node[] bodies = new Node[intCases.length];
// prepare arrays of int cases and code bodies
for (int i = 0 ; i < intCases.length; i++) {
intCases[i] = (int)((FixnumNode)((ArrayNode)cases.get(i).getExpressionNodes()).get(0)).getValue();
bodies[i] = cases.get(i).getBodyNode();
}
final ArrayCallback callback = new ArrayCallback() {
public void nextValue(BodyCompiler context, Object array, int index) {
Node[] bodies = (Node[])array;
if (bodies[index] != null) {
compile(bodies[index], context);
} else {
context.loadNil();
}
}
};
final Node finalElse = elseBody;
final CompilerCallback elseCallback = new CompilerCallback() {
public void call(BodyCompiler context) {
if (finalElse == null) {
context.loadNil();
} else {