Search in sources :

Example 1 with GeneratorState

use of com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState in project es6draft by anba.

the class CodeGenerator method compile.

Entry<MethodName, LabelState> compile(DoExpression node, CodeVisitor mv) {
    if (!isCompiled(node)) {
        if (!isEnabled(Compiler.Option.NoCompletion)) {
            CompletionValueVisitor.performCompletion(node);
        }
        MethodCode method = newMethod(mv.getTopLevelNode(), node);
        DoExpressionCodeVisitor body = new DoExpressionCodeVisitor(node, method, mv);
        body.lineInfo(node);
        // force line-number entry
        body.nop();
        body.begin();
        GeneratorState generatorState = null;
        if (node.hasYieldOrAwait()) {
            generatorState = body.generatorPrologue();
        }
        body.labelPrologue();
        Completion result = statement(node.getStatement(), body);
        if (!result.isAbrupt()) {
            // fall-thru, return `0`.
            body.iconst(0);
            body._return();
        }
        LabelState labelState = body.labelEpilogue(result);
        if (generatorState != null) {
            body.generatorEpilogue(generatorState);
        }
        body.end();
        doExpressionCompletions.put(node, labelState);
    }
    return new SimpleImmutableEntry<>(methodDesc(node), doExpressionCompletions.get(node));
}
Also used : Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) LabelState(com.github.anba.es6draft.compiler.CodeVisitor.LabelState) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) GeneratorState(com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)

Example 2 with GeneratorState

use of com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState in project es6draft by anba.

the class CodeGenerator method generatorComprehensionBody.

private boolean generatorComprehensionBody(GeneratorComprehension 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);
    EvaluateGeneratorComprehension(this, node, body);
    body.exitFunction();
    body.loadUndefined();
    body._return();
    body.generatorEpilogue(generatorState);
    body.end();
    return body.hasTailCalls();
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) GeneratorState(com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)

Example 3 with GeneratorState

use of com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState in project es6draft by anba.

the class CodeGenerator method compile.

Entry<MethodName, LabelState> compile(StatementListMethod node, CodeVisitor mv) {
    if (!isCompiled(node)) {
        MethodCode method = newMethod(mv.getTopLevelNode(), node);
        StatementListMethodCodeVisitor body = new StatementListMethodCodeVisitor(node, method, mv);
        body.lineInfo(node);
        // force line-number entry
        body.nop();
        body.begin();
        GeneratorState generatorState = null;
        if (node.hasResumePoint()) {
            generatorState = body.generatorPrologue();
        }
        body.labelPrologue();
        Completion result = statements(node.getStatements(), body);
        if (!result.isAbrupt()) {
            // fall-thru, return `0`.
            body.iconst(0);
            body._return();
        }
        LabelState labelState = body.labelEpilogue(result);
        if (generatorState != null) {
            body.generatorEpilogue(generatorState);
        }
        body.end();
        statementCompletions.put(node, labelState);
    }
    return new SimpleImmutableEntry<>(methodDesc(node), statementCompletions.get(node));
}
Also used : Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) LabelState(com.github.anba.es6draft.compiler.CodeVisitor.LabelState) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) GeneratorState(com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)

Example 4 with GeneratorState

use of com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState in project es6draft by anba.

the class CodeGenerator method conciseAsyncFunctionBody.

private boolean conciseAsyncFunctionBody(AsyncArrowFunction 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);
    expressionBoxed(node.getExpression(), body);
    body.exitFunction();
    body._return();
    body.generatorEpilogue(generatorState);
    body.end();
    return body.hasTailCalls();
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) GeneratorState(com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)

Example 5 with GeneratorState

use of com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState 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)

Aggregations

GeneratorState (com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)5 MethodCode (com.github.anba.es6draft.compiler.assembler.Code.MethodCode)5 Completion (com.github.anba.es6draft.compiler.StatementGenerator.Completion)3 LabelState (com.github.anba.es6draft.compiler.CodeVisitor.LabelState)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2