compileMultipleAsgnAssignment(node, context);
}
public void compileMultipleAsgnAssignment(Node node, BodyCompiler context) {
final MultipleAsgnNode multipleAsgnNode = (MultipleAsgnNode) node;
// normal items at the "head" of the masgn
ArrayCallback headAssignCallback = new ArrayCallback() {
public void nextValue(BodyCompiler context, Object sourceArray,
int index) {
ListNode headNode = (ListNode) sourceArray;
Node assignNode = headNode.get(index);
// perform assignment for the next node
compileAssignment(assignNode, context);
}
};
// head items for which we've run out of assignable elements
ArrayCallback headNilCallback = new ArrayCallback() {
public void nextValue(BodyCompiler context, Object sourceArray,
int index) {
ListNode headNode = (ListNode) sourceArray;
Node assignNode = headNode.get(index);
// perform assignment for the next node
context.loadNil();
compileAssignment(assignNode, context);
}
};
CompilerCallback argsCallback = new CompilerCallback() {
public void call(BodyCompiler context) {
Node argsNode = multipleAsgnNode.getArgsNode();
if (argsNode instanceof StarNode) {
// done processing args
} else {
// assign to appropriate variable
compileAssignment(argsNode, context);
}
}
};
if (multipleAsgnNode.getHeadNode() == null) {
if (multipleAsgnNode.getArgsNode() == null) {
throw new NotCompilableException("Something's wrong, multiple assignment with no head or args at: " + multipleAsgnNode.getPosition());
} else {
if (multipleAsgnNode.getArgsNode() instanceof StarNode) {
// do nothing
} else {
context.ensureMultipleAssignableRubyArray(multipleAsgnNode.getHeadNode() != null);
context.forEachInValueArray(0, 0, null, null, null, argsCallback);
}
}
} else {
context.ensureMultipleAssignableRubyArray(multipleAsgnNode.getHeadNode() != null);
if (multipleAsgnNode.getArgsNode() == null) {
context.forEachInValueArray(0, multipleAsgnNode.getHeadNode().size(), multipleAsgnNode.getHeadNode(), headAssignCallback, headNilCallback, null);
} else {
context.forEachInValueArray(0, multipleAsgnNode.getHeadNode().size(), multipleAsgnNode.getHeadNode(), headAssignCallback, headNilCallback, argsCallback);
}
}
}