Search in sources :

Example 11 with MethodCode

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

the class CodeGenerator method compile.

MethodName compile(MethodDefinitionsMethod node, boolean hasDecorators, CodeVisitor mv) {
    if (!isCompiled(node)) {
        MethodCode method = newMethod(node);
        MethodDefinitionsCodeVisitor body = new MethodDefinitionsCodeVisitor(node, method, mv);
        body.lineInfo(node);
        body.begin();
        Variable<OrdinaryConstructorFunction> function = body.getFunctionParameter();
        Variable<OrdinaryObject> proto = body.getPrototypeParameter();
        Variable<ArrayList<Object>> decorators = hasDecorators ? body.getDecoratorsParameter() : null;
        ClassPropertyEvaluation(this, node.getProperties(), function, proto, decorators, body);
        body._return();
        body.end();
    }
    return methodDesc(node);
}
Also used : OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayList(java.util.ArrayList) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 12 with MethodCode

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

the class GlobalDeclarationInstantiationGenerator method generate.

void generate(Script script) {
    MethodCode method = codegen.newMethod(script, ScriptName.Init);
    InstructionVisitor mv = new GlobalDeclInitMethodGenerator(method);
    mv.lineInfo(script);
    mv.begin();
    if (VarDeclaredNames(script).isEmpty() && LexicallyDeclaredNames(script).isEmpty() && !hasBlockFunctions(script)) {
        mv._return();
    } else {
        generate(script, mv);
    }
    mv.end();
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 13 with MethodCode

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

the class ExternConstantPool method newMethod.

private <T> ConstantClassAssembler newMethod(String methodName, TypeSpec<T> spec) {
    int modifier = Modifier.PUBLIC | Modifier.STATIC;
    MethodCode method = classCode.newMethod(modifier, methodName, spec.methodDescriptor, null, null);
    return new ConstantClassAssembler(method);
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 14 with MethodCode

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

the class SwitchStatementGenerator method caseSelect.

/**
 * Generates a case-select method.
 *
 * @param caseBlock
 *            the case-block
 * @param switchVarType
 *            the switch-var type
 * @param mv
 *            the code visitor
 * @return the outlined-call object
 */
private OutlinedCall caseSelect(SwitchStatementGenerator.CaseBlock caseBlock, Type switchVarType, CodeVisitor mv) {
    SwitchClause firstClause = caseBlock.clauses.get(0);
    MethodTypeDescriptor methodDescriptor = SwitchSelectCodeVisitor.methodDescriptor(switchVarType, mv);
    MethodCode method = codegen.method(mv, "select", methodDescriptor);
    return outlined(new SwitchSelectCodeVisitor(firstClause, method, mv), body -> {
        Variable<?> switchValue = body.getSwitchValueParameter();
        MutableValue<Integer> switchTarget = body.iarrayElement(body.getSwitchTargetParameter(), 0);
        List<SwitchClause> clauses = caseBlock.clauses;
        int[] switchTargets = caseBlock.switchTargets;
        int numTargets = caseBlock.numTargets();
        Jump[] targetLabels = new Jump[numTargets];
        for (int i = 0; i < targetLabels.length; ++i) {
            targetLabels[i] = new Jump();
        }
        Jump lblExit = new Jump();
        Jump[] labels = new Jump[clauses.size()];
        for (int i = 0; i < clauses.size(); ++i) {
            labels[i] = targetLabels[switchTargets[i] - 1];
        }
        caseSelector(SwitchType.of(clauses)).select(clauses, switchValue, labels, lblExit, body);
        Jump setSwitchTarget = new Jump();
        for (int i = 0; i < targetLabels.length; ++i) {
            // targetLabels[i] is not reachable if only used by the default clause.
            if (targetLabels[i].isTarget()) {
                body.mark(targetLabels[i]);
                body.iconst(i + 1);
                body.goTo(setSwitchTarget);
            }
        }
        if (setSwitchTarget.isTarget()) {
            // stack: [newSwitchTarget] -> []
            body.mark(setSwitchTarget);
            body.store(switchTarget);
        }
        body.mark(lblExit);
        return Completion.Normal;
    });
}
Also used : SwitchClause(com.github.anba.es6draft.ast.SwitchClause) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) Jump(com.github.anba.es6draft.compiler.assembler.Jump) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)

Example 15 with MethodCode

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

the class SwitchStatementGenerator method defaultCaseBlock.

/**
 * Generates a case-block method.
 *
 * @param caseBlock
 *            the case-block
 * @param mv
 *            the code visitor
 * @return the outlined-call object
 */
private OutlinedCall defaultCaseBlock(SwitchStatementGenerator.CaseBlock caseBlock, CodeVisitor mv) {
    SwitchClause firstClause = caseBlock.clauses.get(0);
    MethodTypeDescriptor methodDescriptor = DefaultSwitchBlockCodeVisitor.methodDescriptor(mv);
    MethodCode method = codegen.method(mv, "case", methodDescriptor);
    return outlined(new DefaultSwitchBlockCodeVisitor(firstClause, method, mv), body -> {
        Completion lastResult = Completion.Normal;
        for (SwitchClause clause : caseBlock.clauses) {
            lastResult = clause.accept(this, body);
            if (lastResult.isAbrupt()) {
                break;
            }
        }
        return lastResult;
    });
}
Also used : Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) SwitchClause(com.github.anba.es6draft.ast.SwitchClause) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)

Aggregations

MethodCode (com.github.anba.es6draft.compiler.assembler.Code.MethodCode)46 MethodTypeDescriptor (com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)12 Completion (com.github.anba.es6draft.compiler.StatementGenerator.Completion)8 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)6 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)6 GeneratorState (com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)5 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)4 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)4 OrdinaryConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction)4 SwitchClause (com.github.anba.es6draft.ast.SwitchClause)3 Jump (com.github.anba.es6draft.compiler.assembler.Jump)3 LabelState (com.github.anba.es6draft.compiler.CodeVisitor.LabelState)2 ResumptionPoint (com.github.anba.es6draft.runtime.internal.ResumptionPoint)2 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2 ArrayList (java.util.ArrayList)2 MethodDefinition (com.github.anba.es6draft.ast.MethodDefinition)1 ValType (com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)1 InstanceMethod (com.github.anba.es6draft.runtime.language.ClassOperations.InstanceMethod)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1