Search in sources :

Example 1 with MethodName

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

the class DeclarationBindingInstantiationGenerator method InstantiateGeneratorObject.

/**
     * Emit function call for:
     * {@link ScriptRuntime#InstantiateGeneratorObject(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 generator declaration to instantiate
     * @param mv
     *            the instruction visitor
     */
private void InstantiateGeneratorObject(Variable<ExecutionContext> context, Variable<? extends LexicalEnvironment<?>> env, GeneratorDeclaration f, InstructionVisitor mv) {
    MethodName method = codegen.compile(f);
    mv.load(env);
    mv.load(context);
    mv.invoke(method);
    if (f instanceof LegacyGeneratorDeclaration) {
        mv.invoke(Methods.ScriptRuntime_InstantiateLegacyGeneratorObject);
    } else if (f.isConstructor()) {
        mv.invoke(Methods.ScriptRuntime_InstantiateConstructorGeneratorObject);
    } else {
        mv.invoke(Methods.ScriptRuntime_InstantiateGeneratorObject);
    }
}
Also used : LegacyGeneratorDeclaration(com.github.anba.es6draft.ast.LegacyGeneratorDeclaration) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 2 with MethodName

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

the class DeclarationBindingInstantiationGenerator method InstantiateFunctionObject.

/**
     * Emit function call for:
     * {@link ScriptRuntime#InstantiateFunctionObject(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 InstantiateFunctionObject(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_InstantiateFunctionObject);
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 3 with MethodName

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

the class DefaultCodeGenerator method ClassDefinitionEvaluation.

/**
     * 14.5.14 Runtime Semantics: ClassDefinitionEvaluation
     * 
     * @param def
     *            the class definition node
     * @param className
     *            the class name or {@code null} if not present
     * @param mv
     *            the code visitor
     */
protected final void ClassDefinitionEvaluation(ClassDefinition def, Name className, CodeVisitor mv) {
    mv.enterVariableScope();
    Variable<ArrayList<Callable>> classDecorators = null;
    boolean hasClassDecorators = !def.getDecorators().isEmpty();
    if (hasClassDecorators) {
        classDecorators = newDecoratorVariable("classDecorators", mv);
        evaluateDecorators(classDecorators, def.getDecorators(), mv);
    }
    mv.enterClassDefinition();
    // step 1 (not applicable)
    // steps 2-4
    BlockScope scope = def.getScope();
    assert (scope != null && scope.isPresent()) == (className != null);
    Variable<DeclarativeEnvironmentRecord> classScopeEnvRec = null;
    if (className != null) {
        // stack: [] -> [classScope]
        newDeclarativeEnvironment(scope, mv);
        classScopeEnvRec = mv.newVariable("classScopeEnvRec", DeclarativeEnvironmentRecord.class);
        getEnvRec(classScopeEnvRec, mv);
        // stack: [classScope] -> [classScope]
        Name innerName = scope.resolveName(className, false);
        BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classScopeEnvRec, innerName);
        op.createImmutableBinding(classScopeEnvRec, innerName, true, mv);
        // stack: [classScope] -> []
        pushLexicalEnvironment(mv);
        mv.enterScope(def);
    }
    // steps 5-7
    // stack: [] -> [<constructorParent,proto>]
    Expression classHeritage = def.getHeritage();
    if (classHeritage == null) {
        mv.loadExecutionContext();
        mv.invoke(Methods.ScriptRuntime_getDefaultClassProto);
    } else if (classHeritage instanceof NullLiteral) {
        mv.loadExecutionContext();
        mv.invoke(Methods.ScriptRuntime_getClassProto_Null);
    } else {
        expressionBoxed(classHeritage, mv);
        mv.loadExecutionContext();
        mv.lineInfo(def);
        mv.invoke(Methods.ScriptRuntime_getClassProto);
    }
    // stack: [<constructorParent,proto>] -> [<constructorParent,proto>]
    Variable<OrdinaryObject> proto = mv.newVariable("proto", OrdinaryObject.class);
    mv.dup();
    mv.aload(1, Types.ScriptObject);
    mv.checkcast(Types.OrdinaryObject);
    mv.store(proto);
    // stack: [<constructorParent,proto>] -> [constructorParent, proto]
    mv.aload(0, Types.ScriptObject);
    mv.load(proto);
    // steps 8-9
    // stack: [constructorParent, proto] -> [constructorParent, proto, <rti>]
    MethodDefinition constructor = ConstructorMethod(def);
    assert constructor != null;
    MethodName method = codegen.compile(def);
    // Runtime Semantics: Evaluation -> MethodDefinition
    mv.invoke(method);
    // step 10 (not applicable)
    // steps 11-18
    // stack: [constructorParent, proto, <rti>] -> [F]
    mv.iconst(classHeritage != null);
    mv.loadExecutionContext();
    mv.lineInfo(def);
    mv.invoke(Methods.ScriptRuntime_EvaluateConstructorMethod);
    // stack: [F] -> []
    Variable<OrdinaryConstructorFunction> F = mv.newVariable("F", OrdinaryConstructorFunction.class);
    mv.store(F);
    Variable<ArrayList<Object>> methodDecorators = null;
    boolean hasMethodDecorators = HasDecorators(def);
    if (hasMethodDecorators) {
        methodDecorators = newDecoratorVariable("methodDecorators", mv);
    }
    if (!constructor.getDecorators().isEmpty()) {
        addDecoratorObject(methodDecorators, proto, mv);
        evaluateDecorators(methodDecorators, constructor.getDecorators(), mv);
        addDecoratorKey(methodDecorators, "constructor", mv);
    }
    // steps 19-21
    ClassPropertyEvaluation(codegen, def.getProperties(), F, proto, methodDecorators, mv);
    if (hasClassDecorators) {
        mv.load(F);
        mv.load(classDecorators);
        mv.loadExecutionContext();
        mv.lineInfo(def);
        mv.invoke(Methods.ScriptRuntime_EvaluateClassDecorators);
    }
    if (hasMethodDecorators) {
        mv.load(methodDecorators);
        mv.loadExecutionContext();
        mv.lineInfo(def);
        mv.invoke(Methods.ScriptRuntime_EvaluateClassMethodDecorators);
    }
    // steps 22-23 (moved)
    if (className != null) {
        // stack: [] -> []
        Name innerName = scope.resolveName(className, false);
        BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classScopeEnvRec, innerName);
        op.initializeBinding(classScopeEnvRec, innerName, F, mv);
        mv.exitScope();
        popLexicalEnvironment(mv);
    }
    // stack: [] -> [F]
    mv.load(F);
    mv.exitVariableScope();
    // step 24 (return F)
    mv.exitClassDefinition();
}
Also used : ArrayList(java.util.ArrayList) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) Name(com.github.anba.es6draft.ast.scope.Name) FieldName(com.github.anba.es6draft.compiler.assembler.FieldName) OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Example 4 with MethodName

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

the class BlockDeclarationInstantiationGenerator method generateMethod.

/**
     * stack: [] {@literal ->} []
     * 
     * @param node
     *            the block statement
     * @param cx
     *            the execution context
     * @param env
     *            the lexical environment
     * @param mv
     *            the instruction visitor
     */
void generateMethod(BlockStatement node, Variable<ExecutionContext> cx, Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env, InstructionVisitor mv) {
    List<Declaration> declarations = LexicallyScopedDeclarations(node);
    if (declarations.size() <= METHOD_LIMIT) {
        generate(declarations, cx, env, mv);
    } else {
        for (int i = 0, size = declarations.size(); i < size; i += METHOD_LIMIT) {
            List<Declaration> sublist = declarations.subList(i, Math.min(i + METHOD_LIMIT, size));
            MethodName method = codegen.compile(node, sublist, this);
            mv.load(env);
            mv.load(cx);
            mv.invoke(method);
        }
    }
}
Also used : HoistableDeclaration(com.github.anba.es6draft.ast.HoistableDeclaration) Declaration(com.github.anba.es6draft.ast.Declaration) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 5 with MethodName

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

the class BlockDeclarationInstantiationGenerator method generateMethod.

/**
     * stack: [] {@literal ->} []
     * 
     * @param node
     *            the switch statement
     * @param cx
     *            the execution context
     * @param env
     *            the lexical environment
     * @param mv
     *            the instruction visitor
     */
void generateMethod(SwitchStatement node, Variable<ExecutionContext> cx, Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env, InstructionVisitor mv) {
    List<Declaration> declarations = LexicallyScopedDeclarations(node);
    if (declarations.size() <= METHOD_LIMIT) {
        generate(declarations, cx, env, mv);
    } else {
        for (int i = 0, size = declarations.size(); i < size; i += METHOD_LIMIT) {
            List<Declaration> sublist = declarations.subList(i, Math.min(i + METHOD_LIMIT, size));
            MethodName method = codegen.compile(node, sublist, this);
            mv.load(env);
            mv.load(cx);
            mv.invoke(method);
        }
    }
}
Also used : HoistableDeclaration(com.github.anba.es6draft.ast.HoistableDeclaration) Declaration(com.github.anba.es6draft.ast.Declaration) 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