use of com.github.anba.es6draft.compiler.assembler.Jump in project es6draft by anba.
the class DefaultCodeGenerator method delegatedYield.
private void delegatedYield(Expression node, BiConsumer<Variable<ScriptObject>, Variable<Object>> iterNext, BiConsumer<Variable<ScriptObject>, Variable<Object>> iterThrow, BiConsumer<Variable<ScriptObject>, Variable<Object>> iterReturn, CodeVisitor mv) {
Jump iteratorNext = new Jump();
Jump generatorYield = new Jump();
Jump generatorYieldOrReturn = new Jump();
Jump done = new Jump();
mv.lineInfo(node);
mv.enterVariableScope();
Variable<ScriptObject> iterator = mv.newVariable("iterator", ScriptObject.class);
Variable<ScriptObject> innerResult = mv.newVariable("innerResult", ScriptObject.class);
Variable<Object> received = mv.newVariable("received", Object.class);
/* steps 3-4 */
// stack: [value] -> []
mv.loadExecutionContext();
mv.swap();
mv.invoke(Methods.AbstractOperations_GetIterator);
mv.store(iterator);
/* step 5 */
// stack: [] -> []
mv.loadUndefined();
mv.store(received);
/* step 6.a.i-6.a.ii */
// stack: [] -> []
mv.mark(iteratorNext);
iterNext.accept(iterator, received);
mv.store(innerResult);
/* steps 6.a.iii-6.a.v */
// stack: [] -> []
IteratorComplete(node, innerResult, mv);
mv.ifne(done);
/* step 6.a.vi */
// stack: [] -> [Object(innerResult)]
// force stack top to Object-type
mv.mark(generatorYield);
mv.load(innerResult);
mv.checkcast(Types.Object);
mv.suspend();
mv.store(received);
/* step 6.b */
Jump isException = new Jump();
mv.load(received);
mv.instanceOf(Types.ScriptException);
mv.ifeq(isException);
{
/* steps 6.b.iii.1-4, 6.b.iv */
iterThrow.accept(iterator, received);
mv.store(innerResult);
mv.goTo(generatorYieldOrReturn);
}
mv.mark(isException);
/* step 6.c */
mv.load(received);
mv.instanceOf(Types.ReturnValue);
mv.ifeq(iteratorNext);
{
/* steps 6.c.i-vii */
iterReturn.accept(iterator, received);
mv.store(innerResult);
mv.load(innerResult);
mv.ifnonnull(generatorYieldOrReturn);
{
/* step 6.c.iv */
mv.popStack();
mv.returnCompletion(__ -> {
mv.load(received);
mv.checkcast(Types.ReturnValue);
mv.invoke(Methods.ReturnValue_getValue);
});
}
}
mv.mark(generatorYieldOrReturn);
/* steps 6.b.iii.5-6, 6.c.viii-ix */
IteratorComplete(node, innerResult, mv);
mv.ifeq(generatorYield);
/* step 6.b.iii.7, 6.c.x */
mv.popStack();
mv.returnCompletion(__ -> {
IteratorValue(node, innerResult, mv);
});
/* step 6.a.v */
mv.mark(done);
IteratorValue(node, innerResult, mv);
mv.exitVariableScope();
}
use of com.github.anba.es6draft.compiler.assembler.Jump in project es6draft by anba.
the class DefaultCodeGenerator method asyncIteratorClose.
/**
* Emit:
*
* <pre>
* Callable returnMethod = GetMethod(cx, iterator, "return");
* if (returnMethod != null) {
* try {
* returnMethod.call(cx, iterator);
* await;
* } catch (ScriptException e) {
* if (throwable != e) {
* throwable.addSuppressed(e);
* }
* }
* }
* </pre>
*
* @param node
* the ast node
* @param iterator
* the script iterator object
* @param mv
* the code visitor
*/
final void asyncIteratorClose(Node node, Variable<ScriptObject> iterator, Variable<? extends Throwable> throwable, CodeVisitor mv) {
IteratorClose(node, iterator, returnMethod -> {
TryCatchLabel startCatch = new TryCatchLabel();
TryCatchLabel endCatch = new TryCatchLabel(), handlerCatch = new TryCatchLabel();
Jump noException = new Jump();
mv.mark(startCatch);
{
InvokeMethod(node, mv, returnMethod, iterator);
await(node, mv);
mv.pop();
mv.goTo(noException);
}
mv.mark(endCatch);
mv.catchHandler(handlerCatch, Types.ScriptException);
{
mv.enterVariableScope();
Variable<ScriptException> exception = mv.newVariable("exception", ScriptException.class);
mv.store(exception);
mv.load(throwable);
mv.load(exception);
mv.ifacmpeq(noException);
{
mv.load(throwable);
mv.load(exception);
mv.invoke(Methods.Throwable_addSuppressed);
}
mv.exitVariableScope();
}
mv.tryCatch(startCatch, endCatch, handlerCatch, Types.ScriptException);
mv.mark(noException);
}, mv);
}
use of com.github.anba.es6draft.compiler.assembler.Jump in project es6draft by anba.
the class DefaultCodeGenerator method throwAfterResume.
private void throwAfterResume(CodeVisitor mv) {
Jump isException = new Jump();
mv.dup();
mv.instanceOf(Types.ScriptException);
mv.ifeq(isException);
{
mv.checkcast(Types.ScriptException);
mv.athrow();
}
mv.mark(isException);
}
use of com.github.anba.es6draft.compiler.assembler.Jump in project es6draft by anba.
the class EvalDeclarationInstantiationGenerator method createFunctions.
/**
* 18.2.1.2, step 14
*/
private void createFunctions(ArrayDeque<HoistableDeclaration> functionsToInitialize, boolean strict, Variable<ExecutionContext> context, Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> lexEnv, Variable<FunctionObject> fo, Variable<? extends EnvironmentRecord> varEnvRec, InstructionVisitor mv) {
for (HoistableDeclaration f : functionsToInitialize) {
Name fn = BoundName(f);
// stack: [] -> []
InstantiateFunctionObject(context, lexEnv, f, mv);
mv.store(fo);
BindingOp<EnvironmentRecord> op = BindingOp.LOOKUP;
Jump funcAlreadyDeclared = new Jump(), after = new Jump();
op.hasBinding(varEnvRec, fn, mv);
mv.ifne(funcAlreadyDeclared);
{
op.createMutableBinding(varEnvRec, fn, true, mv);
op.initializeBinding(varEnvRec, fn, fo, mv);
mv.goTo(after);
}
mv.mark(funcAlreadyDeclared);
{
op.setMutableBinding(varEnvRec, fn, fo, strict, mv);
}
mv.mark(after);
}
}
use of com.github.anba.es6draft.compiler.assembler.Jump in project es6draft by anba.
the class EvalDeclarationInstantiationGenerator method createVarDeclarations.
/**
* 18.2.1.2, step 15
*/
private void createVarDeclarations(LinkedHashSet<Name> declaredVarNames, Variable<? extends EnvironmentRecord> varEnvRec, Variable<Undefined> undef, InstructionVisitor mv) {
for (Name vn : declaredVarNames) {
BindingOp<EnvironmentRecord> op = BindingOp.LOOKUP;
Jump varAlreadyDeclared = new Jump();
op.hasBinding(varEnvRec, vn, mv);
mv.ifne(varAlreadyDeclared);
{
op.createMutableBinding(varEnvRec, vn, true, mv);
op.initializeBinding(varEnvRec, vn, undef, mv);
}
mv.mark(varAlreadyDeclared);
}
}
Aggregations