}
}
@Override
public void compileIter(Node node, BodyCompiler context) {
final IterNode iterNode = (IterNode)node;
final ArgsNode argsNode = (ArgsNode)iterNode.getVarNode();
// create the closure class and instantiate it
final CompilerCallback closureBody = new CompilerCallback() {
public void call(BodyCompiler context) {
if (iterNode.getBodyNode() != null) {
compile(iterNode.getBodyNode(), context, true);
} else {
context.loadNil();
}
}
};
// create the closure class and instantiate it
final CompilerCallback closureArgs = new CompilerCallback() {
public void call(BodyCompiler context) {
// FIXME: This is temporary since the variable compilers assume we want
// args already on stack for assignment. We just pop and continue with
// 1.9 args logic.
context.consumeCurrentValue(); // args value
context.consumeCurrentValue(); // passed block
if (iterNode.getVarNode() != null) {
if (iterNode instanceof LambdaNode) {
final int required = argsNode.getRequiredArgsCount();
final int opt = argsNode.getOptionalArgsCount();
final int rest = argsNode.getRestArg();
context.getVariableCompiler().checkMethodArity(required, opt, rest);
compileMethodArgs(argsNode, context, true);
} else {
compileMethodArgs(argsNode, context, true);
}
}
}
};
boolean hasMultipleArgsHead = false;
if (iterNode.getVarNode() instanceof MultipleAsgnNode) {
hasMultipleArgsHead = ((MultipleAsgnNode) iterNode.getVarNode()).getHeadNode() != null;
}
NodeType argsNodeId = BlockBody.getArgumentTypeWackyHack(iterNode);
ASTInspector inspector = new ASTInspector();
inspector.inspect(iterNode.getBodyNode());
inspector.inspect(iterNode.getVarNode());
if (argsNodeId == null) {
// no args, do not pass args processor
context.createNewClosure19(iterNode.getPosition().getFile(), iterNode.getPosition().getStartLine(), iterNode.getScope(), Arity.procArityOf(iterNode.getVarNode()).getValue(),
closureBody, null, hasMultipleArgsHead, argsNodeId, RuntimeHelpers.encodeParameterList(argsNode), inspector);
} else {
context.createNewClosure19(iterNode.getPosition().getFile(), iterNode.getPosition().getStartLine(), iterNode.getScope(), Arity.procArityOf(iterNode.getVarNode()).getValue(),
closureBody, closureArgs, hasMultipleArgsHead, argsNodeId, RuntimeHelpers.encodeParameterList(argsNode), inspector);
}
}