Search in sources :

Example 36 with MethodCode

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

the class CodeGenerator method moduleBody.

private void moduleBody(Module node) {
    MethodCode method = newMethod(node, ModuleName.Code);
    ModuleCodeVisitor body = new ModuleCodeVisitor(method, node);
    body.lineInfo(node);
    body.begin();
    body.enterScope(node);
    Completion result = statements(node.getStatements(), body);
    body.exitScope();
    if (!result.isAbrupt()) {
        // Completion values are currently ignored for module code.
        body.loadUndefined();
        body._return();
    }
    body.end();
}
Also used : Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 37 with MethodCode

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

the class CodeGenerator method generatorBody.

private boolean generatorBody(FunctionNode node) {
    MethodCode method = newMethod(node, FunctionName.Code);
    GeneratorCodeVisitor body = new GeneratorCodeVisitor(method, node);
    body.lineInfo(node);
    body.begin();
    GeneratorState generatorState = body.generatorPrologue();
    body.enterFunction(node);
    Completion result = statements(node.getStatements(), body);
    body.exitFunction();
    if (!result.isAbrupt()) {
        // fall-thru, return undefined from function
        body.loadUndefined();
        body._return();
    }
    body.generatorEpilogue(generatorState);
    body.end();
    return body.hasTailCalls();
}
Also used : Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) GeneratorState(com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)

Example 38 with MethodCode

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

the class CodeGenerator method publicStaticMethod.

private MethodCode publicStaticMethod(String methodName, MethodTypeDescriptor methodDescriptor) {
    final int access = Modifier.PUBLIC | Modifier.STATIC;
    MethodCode method = code.newMethod(access, methodName, methodDescriptor);
    // System.out.printf("add <%s, %s>%n", methodName, method.classCode.className);
    assert !methodClasses.containsKey(methodName) : String.format("method '%s' already compiled", methodName);
    methodClasses.put(methodName, method.classCode.classType);
    return method;
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) ResumptionPoint(com.github.anba.es6draft.runtime.internal.ResumptionPoint)

Example 39 with MethodCode

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

the class SwitchStatementGenerator method caseBlock.

/**
 * Generates a case-block method.
 *
 * @param caseBlock
 *            the case-block
 * @param mv
 *            the code visitor
 * @return the outlined-call object
 */
private OutlinedCall caseBlock(SwitchStatementGenerator.CaseBlock caseBlock, CodeVisitor mv) {
    SwitchClause firstClause = caseBlock.clauses.get(0);
    MethodTypeDescriptor methodDescriptor = SwitchBlockCodeVisitor.methodDescriptor(mv);
    MethodCode method = codegen.method(mv, "case", methodDescriptor);
    return outlined(new SwitchBlockCodeVisitor(firstClause, method, mv), body -> {
        Variable<Integer> switchTarget = body.getSwitchTargetParameter();
        List<SwitchClause> clauses = caseBlock.clauses;
        int[] switchTargets = caseBlock.switchTargets;
        int numTargets = caseBlock.numTargets();
        Completion lastResult = Completion.Normal;
        if (numTargets > 1) {
            Jump[] labels = new Jump[numTargets];
            for (int i = 0; i < labels.length; ++i) {
                labels[i] = new Jump();
            }
            Jump defaultInstr = new Jump();
            body.load(switchTarget);
            body.tableswitch(1, numTargets, defaultInstr, labels);
            body.mark(defaultInstr);
            for (int i = 0, lastTarget = 0; i < clauses.size(); ++i) {
                if (lastTarget != switchTargets[i]) {
                    lastTarget = switchTargets[i];
                    body.mark(labels[lastTarget - 1]);
                }
                lastResult = clauses.get(i).accept(this, body);
            }
        } else {
            for (SwitchClause clause : clauses) {
                lastResult = clause.accept(this, body);
            }
        }
        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) Jump(com.github.anba.es6draft.compiler.assembler.Jump) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)

Example 40 with MethodCode

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

the class ClassPropertyGenerator method methodDefinitions.

private OutlinedCall methodDefinitions(MethodDefinitionsMethod node, CodeVisitor mv) {
    MethodTypeDescriptor methodDescriptor = MethodDefinitionsCodeVisitor.methodDescriptor(mv);
    MethodCode method = codegen.method(mv, "mdef", methodDescriptor);
    return outlined(new MethodDefinitionsCodeVisitor(node, method, mv), body -> {
        Variable<OrdinaryConstructorFunction> function = body.getFunctionParameter();
        Variable<OrdinaryObject> proto = body.getPrototypeParameter();
        StoreToArray<Object> staticFields = this.staticFields.from(body.getStaticFieldsParameter());
        StoreToArray<Object> instanceFields = this.instanceFields.from(body.getInstanceFieldsParameter());
        StoreToArray<InstanceMethod> instanceMethods = this.instanceMethods.from(body.getInstanceMethodsParameter());
        StoreToArray<Object> decorators = this.decorators.from(body.getDecoratorsParameter());
        ClassPropertyEvaluation(codegen, classDefinition, node.getProperties(), function, proto, staticFields, instanceFields, instanceMethods, decorators, body);
        return Completion.Normal;
    });
}
Also used : OrdinaryConstructorFunction(com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor) InstanceMethod(com.github.anba.es6draft.runtime.language.ClassOperations.InstanceMethod)

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