package com.oracle.truffle.js.nodes.control;
import java.util.Set;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.Tag;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.js.nodes.JavaScriptNode;
import com.oracle.truffle.js.nodes.access.WriteNode;
public final class GeneratorExprBlockNode extends AbstractGeneratorBlockNode {
GeneratorExprBlockNode(JavaScriptNode[] statements, JavaScriptNode readStateNode, WriteNode writeStateNode) {
super(statements, readStateNode, writeStateNode);
}
public static JavaScriptNode create(JavaScriptNode[] statements, JavaScriptNode readStateNode, WriteNode writeStateNode) {
return new GeneratorExprBlockNode(statements, readStateNode, writeStateNode);
}
@Override
public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultException {
int index = getStateAndReset(frame);
assert index < getStatements().length;
return block.executeBoolean(frame, index);
}
@Override
public int executeInt(VirtualFrame frame) throws UnexpectedResultException {
int index = getStateAndReset(frame);
assert index < getStatements().length;
return block.executeInt(frame, index);
}
@Override
public double executeDouble(VirtualFrame frame) throws UnexpectedResultException {
int index = getStateAndReset(frame);
assert index < getStatements().length;
return block.executeDouble(frame, index);
}
@Override
public boolean executeBoolean(VirtualFrame frame, JavaScriptNode node, int index, int argument) throws UnexpectedResultException {
assert index == getStatements().length - 1;
try {
return node.executeBoolean(frame);
} catch (YieldException e) {
setState(frame, index);
throw e;
}
}
@Override
public int executeInt(VirtualFrame frame, JavaScriptNode node, int index, int argument) throws UnexpectedResultException {
assert index == getStatements().length - 1;
try {
return node.executeInt(frame);
} catch (YieldException e) {
setState(frame, index);
throw e;
}
}
@Override
public double executeDouble(VirtualFrame frame, JavaScriptNode node, int index, int argument) throws UnexpectedResultException {
assert index == getStatements().length - 1;
try {
return node.executeDouble(frame);
} catch (YieldException e) {
setState(frame, index);
throw e;
}
}
@Override
protected JavaScriptNode copyUninitialized(Set<Class<? extends Tag>> materializedTags) {
return new GeneratorExprBlockNode(cloneUninitialized(getStatements(), materializedTags), cloneUninitialized(readStateNode, materializedTags),
(WriteNode) cloneUninitialized((JavaScriptNode) writeStateNode, materializedTags));
}
}