Search in sources :

Example 16 with MethodName

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

the class PropertyGenerator method visit.

/**
     * 14.3.9 Runtime Semantics: PropertyDefinitionEvaluation<br>
     * 14.4.13 Runtime Semantics: PropertyDefinitionEvaluation
     */
@Override
public ValType visit(MethodDefinition node, CodeVisitor mv) {
    MethodName method = codegen.compile(node);
    boolean hasDecorators = !node.getDecorators().isEmpty();
    if (hasDecorators) {
        evaluateDecorators(decorators, node.getDecorators(), mv);
    }
    // stack: [<object>] -> []
    String propName = PropName(node);
    if (propName == null) {
        assert node.getPropertyName() instanceof ComputedPropertyName;
        ValType propKey = node.getPropertyName().accept(this, mv);
        if (hasDecorators) {
            addDecoratorKey(decorators, propKey, mv);
        }
        mv.iconst(node.getAllocation() == MethodDefinition.MethodAllocation.Object);
        mv.invoke(method);
        mv.loadExecutionContext();
        mv.lineInfo(node);
        switch(node.getType()) {
            case AsyncFunction:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionAsync);
                break;
            case AsyncGenerator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionAsyncGenerator);
                break;
            case Function:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinition);
                break;
            case ConstructorGenerator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionConstructorGenerator);
                break;
            case Generator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionGenerator);
                break;
            case Getter:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionGetter);
                break;
            case Setter:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionSetter);
                break;
            case BaseConstructor:
            case DerivedConstructor:
            case CallConstructor:
            default:
                throw new AssertionError("invalid method type");
        }
    } else {
        if (hasDecorators) {
            addDecoratorKey(decorators, propName, mv);
        }
        mv.aconst(propName);
        mv.iconst(node.getAllocation() == MethodDefinition.MethodAllocation.Object);
        mv.invoke(method);
        mv.loadExecutionContext();
        mv.lineInfo(node);
        switch(node.getType()) {
            case AsyncFunction:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionAsync_String);
                break;
            case AsyncGenerator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionAsyncGenerator_String);
                break;
            case Function:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinition_String);
                break;
            case ConstructorGenerator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionConstructorGenerator_String);
                break;
            case Generator:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionGenerator_String);
                break;
            case Getter:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionGetter_String);
                break;
            case Setter:
                mv.invoke(Methods.ScriptRuntime_EvaluatePropertyDefinitionSetter_String);
                break;
            case BaseConstructor:
            case DerivedConstructor:
            case CallConstructor:
            default:
                throw new AssertionError("invalid method type");
        }
    }
    return null;
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) ComputedPropertyName(com.github.anba.es6draft.ast.ComputedPropertyName)

Example 17 with MethodName

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

the class BlockDeclarationInstantiationGenerator method generate.

/**
     * stack: [env] {@literal ->} [env]
     * 
     * @param node
     *            the block statement
     * @param mv
     *            the code visitor
     */
void generate(BlockStatement node, CodeVisitor mv) {
    int declarations = LexicallyDeclaredNames(node).size();
    if (declarations > INLINE_LIMIT) {
        MethodName method = codegen.compile(node, this);
        // stack: [env] -> [env]
        mv.dup();
        mv.loadExecutionContext();
        mv.invoke(method);
    } else {
        generateInline(LexicallyScopedDeclarations(node), mv);
    }
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 18 with MethodName

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

the class DeclarationBindingInstantiationGenerator method InstantiateAsyncFunctionObject.

/**
     * Emit function call for:
     * {@link ScriptRuntime#InstantiateAsyncFunctionObject(LexicalEnvironment, ExecutionContext, RuntimeInfo.Function)}
     * <p>
     * stack: [] {@literal ->} [fo]
     * 
     * @param context
     *            the variable which holds the execution context
     * @param env
     *            the variable which holds the lexical environment
     * @param f
     *            the function declaration to instantiate
     * @param mv
     *            the instruction visitor
     */
private void InstantiateAsyncFunctionObject(Variable<ExecutionContext> context, Variable<? extends LexicalEnvironment<?>> env, AsyncFunctionDeclaration f, InstructionVisitor mv) {
    MethodName method = codegen.compile(f);
    mv.load(env);
    mv.load(context);
    mv.invoke(method);
    mv.invoke(Methods.ScriptRuntime_InstantiateAsyncFunctionObject);
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 19 with MethodName

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

the class DeclarationBindingInstantiationGenerator method InstantiateLegacyFunctionObject.

/**
     * Emit function call for:
     * {@link ScriptRuntime#InstantiateLegacyFunctionObject(LexicalEnvironment, ExecutionContext, RuntimeInfo.Function)}
     * <p>
     * stack: [] {@literal ->} [fo]
     * 
     * @param context
     *            the variable which holds the execution context
     * @param env
     *            the variable which holds the lexical environment
     * @param f
     *            the function declaration to instantiate
     * @param mv
     *            the instruction visitor
     */
private void InstantiateLegacyFunctionObject(Variable<ExecutionContext> context, Variable<? extends LexicalEnvironment<?>> env, FunctionDeclaration f, InstructionVisitor mv) {
    MethodName method = codegen.compile(f);
    mv.load(env);
    mv.load(context);
    mv.invoke(method);
    mv.invoke(Methods.ScriptRuntime_InstantiateLegacyFunctionObject);
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 20 with MethodName

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

the class DeclarationBindingInstantiationGenerator method InstantiateAsyncGeneratorObject.

/**
     * Emit function call for:
     * {@link ScriptRuntime#InstantiateAsyncGeneratorObject(LexicalEnvironment, ExecutionContext, RuntimeInfo.Function)}
     * <p>
     * stack: [] {@literal ->} [fo]
     * 
     * @param context
     *            the variable which holds the execution context
     * @param env
     *            the variable which holds the lexical environment
     * @param f
     *            the function declaration to instantiate
     * @param mv
     *            the instruction visitor
     */
private void InstantiateAsyncGeneratorObject(Variable<ExecutionContext> context, Variable<? extends LexicalEnvironment<?>> env, AsyncGeneratorDeclaration f, InstructionVisitor mv) {
    MethodName method = codegen.compile(f);
    mv.load(env);
    mv.load(context);
    mv.invoke(method);
    mv.invoke(Methods.ScriptRuntime_InstantiateAsyncGeneratorObject);
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Aggregations

MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)27 Declaration (com.github.anba.es6draft.ast.Declaration)2 HoistableDeclaration (com.github.anba.es6draft.ast.HoistableDeclaration)2 LabelState (com.github.anba.es6draft.compiler.CodeVisitor.LabelState)2 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)2 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)2 ComputedPropertyName (com.github.anba.es6draft.ast.ComputedPropertyName)1 LegacyGeneratorDeclaration (com.github.anba.es6draft.ast.LegacyGeneratorDeclaration)1 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)1 Name (com.github.anba.es6draft.ast.scope.Name)1 FieldName (com.github.anba.es6draft.compiler.assembler.FieldName)1 InstructionAssembler (com.github.anba.es6draft.compiler.assembler.InstructionAssembler)1 DeclarativeEnvironmentRecord (com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1 FunctionObject (com.github.anba.es6draft.runtime.types.builtins.FunctionObject)1 OrdinaryConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction)1 ArrayList (java.util.ArrayList)1