Search in sources :

Example 1 with Value

use of com.github.anba.es6draft.compiler.assembler.Value in project es6draft by anba.

the class DefaultCodeGenerator method delegatedYield.

/**
     * 14.4 Generator Function Definitions
     * <p>
     * 14.4.14 Runtime Semantics: Evaluation
     * <ul>
     * <li>YieldExpression : yield * AssignmentExpression
     * </ul>
     * <p>
     * stack: [value] {@literal ->} [value']
     * 
     * @param node
     *            the expression node
     * @param mv
     *            the code visitor
     */
protected final void delegatedYield(Expression node, CodeVisitor mv) {
    if (!mv.isAsync()) {
        delegatedYield(node, (iterator, received) -> {
            IteratorNext(node, iterator, received, mv);
        }, (iterator, received) -> {
            mv.loadExecutionContext();
            mv.load(iterator);
            mv.load(received);
            mv.checkcast(Types.ScriptException);
            mv.invoke(Methods.ScriptRuntime_yieldThrowCompletion);
        }, (iterator, received) -> {
            mv.loadExecutionContext();
            mv.load(iterator);
            mv.load(received);
            mv.checkcast(Types.ReturnValue);
            mv.invoke(Methods.ScriptRuntime_yieldReturnCompletion);
        }, mv);
    } else {
        delegatedYield(node, (iterator, received) -> {
            IteratorNext(node, iterator, received, mv);
            await(node, mv);
            // FIXME: spec bug - missing type check
            requireObjectResult(node, "next", mv);
        }, (iterator, received) -> {
            mv.enterVariableScope();
            Variable<Callable> throwMethod = mv.newVariable("throwMethod", Callable.class);
            GetMethod(node, iterator, "throw", mv);
            mv.store(throwMethod);
            Jump noThrow = new Jump(), nextYield = new Jump();
            mv.load(throwMethod);
            mv.ifnull(noThrow);
            {
                InvokeMethod(node, mv, throwMethod, iterator, __ -> {
                    mv.load(received);
                    mv.checkcast(Types.ScriptException);
                    mv.invoke(Methods.ScriptException_getValue);
                });
                await(node, mv);
                requireObjectResult(node, "throw", mv);
                mv.goTo(nextYield);
            }
            mv.mark(noThrow);
            {
                asyncIteratorClose(node, iterator, mv);
                reportPropertyNotCallable(node, "throw", mv);
                mv.athrow();
            }
            mv.mark(nextYield);
            mv.exitVariableScope();
        }, (iterator, received) -> {
            mv.enterVariableScope();
            Variable<Callable> returnMethod = mv.newVariable("returnMethod", Callable.class);
            GetMethod(node, iterator, "return", mv);
            mv.store(returnMethod);
            Jump noReturn = new Jump(), nextYield = new Jump();
            mv.load(returnMethod);
            mv.ifnull(noReturn);
            {
                InvokeMethod(node, mv, returnMethod, iterator, __ -> {
                    mv.load(received);
                    mv.checkcast(Types.ReturnValue);
                    mv.invoke(Methods.ReturnValue_getValue);
                });
                await(node, mv);
                requireObjectResult(node, "return", mv);
                mv.goTo(nextYield);
            }
            mv.mark(noReturn);
            {
                mv.anull();
            }
            mv.mark(nextYield);
            mv.exitVariableScope();
        }, mv);
    }
}
Also used : ModuleEnvironmentRecord(com.github.anba.es6draft.runtime.ModuleEnvironmentRecord) ConstructorMethod(com.github.anba.es6draft.semantics.StaticSemantics.ConstructorMethod) Undefined(com.github.anba.es6draft.runtime.types.Undefined) TryCatchLabel(com.github.anba.es6draft.compiler.assembler.TryCatchLabel) ArrayList(java.util.ArrayList) ModuleScope(com.github.anba.es6draft.ast.scope.ModuleScope) Variable(com.github.anba.es6draft.compiler.assembler.Variable) Type(com.github.anba.es6draft.compiler.assembler.Type) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) WithScope(com.github.anba.es6draft.ast.scope.WithScope) Null(com.github.anba.es6draft.runtime.types.Null) Reference(com.github.anba.es6draft.runtime.types.Reference) Scope(com.github.anba.es6draft.ast.scope.Scope) EnvironmentRecord(com.github.anba.es6draft.runtime.EnvironmentRecord) BiConsumer(java.util.function.BiConsumer) OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) EnumSet(java.util.EnumSet) ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) Jump(com.github.anba.es6draft.compiler.assembler.Jump) GlobalEnvironmentRecord(com.github.anba.es6draft.runtime.GlobalEnvironmentRecord) HasDecorators(com.github.anba.es6draft.semantics.StaticSemantics.HasDecorators) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) ObjectEnvironmentRecord(com.github.anba.es6draft.runtime.ObjectEnvironmentRecord) Consumer(java.util.function.Consumer) com.github.anba.es6draft.ast(com.github.anba.es6draft.ast) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) List(java.util.List) Name(com.github.anba.es6draft.ast.scope.Name) Callable(com.github.anba.es6draft.runtime.types.Callable) FieldName(com.github.anba.es6draft.compiler.assembler.FieldName) ClassPropertyEvaluation(com.github.anba.es6draft.compiler.ClassPropertyGenerator.ClassPropertyEvaluation) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Value(com.github.anba.es6draft.compiler.assembler.Value) Abrupt(com.github.anba.es6draft.ast.AbruptNode.Abrupt) ScriptScope(com.github.anba.es6draft.ast.scope.ScriptScope) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord) Bootstrap(com.github.anba.es6draft.runtime.internal.Bootstrap) Jump(com.github.anba.es6draft.compiler.assembler.Jump) Callable(com.github.anba.es6draft.runtime.types.Callable)

Aggregations

com.github.anba.es6draft.ast (com.github.anba.es6draft.ast)1 Abrupt (com.github.anba.es6draft.ast.AbruptNode.Abrupt)1 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)1 ModuleScope (com.github.anba.es6draft.ast.scope.ModuleScope)1 Name (com.github.anba.es6draft.ast.scope.Name)1 Scope (com.github.anba.es6draft.ast.scope.Scope)1 ScriptScope (com.github.anba.es6draft.ast.scope.ScriptScope)1 WithScope (com.github.anba.es6draft.ast.scope.WithScope)1 ClassPropertyEvaluation (com.github.anba.es6draft.compiler.ClassPropertyGenerator.ClassPropertyEvaluation)1 FieldName (com.github.anba.es6draft.compiler.assembler.FieldName)1 Jump (com.github.anba.es6draft.compiler.assembler.Jump)1 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)1 TryCatchLabel (com.github.anba.es6draft.compiler.assembler.TryCatchLabel)1 Type (com.github.anba.es6draft.compiler.assembler.Type)1 Value (com.github.anba.es6draft.compiler.assembler.Value)1 Variable (com.github.anba.es6draft.compiler.assembler.Variable)1 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)1 EnvironmentRecord (com.github.anba.es6draft.runtime.EnvironmentRecord)1 GlobalEnvironmentRecord (com.github.anba.es6draft.runtime.GlobalEnvironmentRecord)1 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)1