public static Vertex yield(Graph graph, Block block, Collection<IRubyObject> args, boolean expanded, Vertex returnVertex) {
if (block == null) {
return Vertex.EMPTY;
}
Ruby runtime = graph.getRuntime();
Context context = runtime.getContext();
Node varNode = block.getVarNode();
boolean noargblock = false;
MultipleAsgnNode masgn = null;
int preCount = 0;
boolean isRest = false;
Node rest = null;
ListNode pre = null;
Vertex vertex = graph.createFreeVertex();
if (varNode == null || varNode instanceof ZeroArgNode) {
noargblock = true;
} else if (varNode instanceof MultipleAsgnNode) {
masgn = (MultipleAsgnNode) varNode;
preCount = masgn.getPreCount();
isRest = masgn.getRest() != null;
rest = masgn.getRest();
pre = masgn.getPre();
}
if (args != null && !args.isEmpty()) {
for (IRubyObject value : args) {
pushLoopFrame(context, block.getFrame(), returnVertex, vertex);
context.pushScope(block.getScope());
if (noargblock) {}
else if (masgn != null) {
Array array;
if (!expanded) {
// FIXME to_ary
if (value instanceof Array) {
array = (Array) value;
} else {
array = createArray(graph, new Vertex[] { graph.createFreeSingleTypeVertex(value) });
}
} else {
if (value instanceof Array) {
array = (Array) value;
} else {
array = createArray(graph, new Vertex[] { graph.createFreeSingleTypeVertex(value) });
}
}
multipleAssign(graph, masgn, array);
} else {
assign(graph, varNode, graph.createFreeSingleTypeVertex(value));
}
if (block.getBodyNode() != null) {
Vertex v = graph.createVertex(block.getBodyNode());
graph.addEdgeAndPropagate(v, vertex);
}
context.popScope();
popLoopFrame(context);
}
} else {
pushLoopFrame(context, block.getFrame(), returnVertex, vertex);
context.pushScope(block.getScope());
if (block.getBodyNode() != null) {
Vertex v = graph.createVertex(block.getBodyNode());
graph.addEdgeAndPropagate(v, vertex);
}
context.popScope();
popLoopFrame(context);
}
return vertex;
}