Search in sources :

Example 11 with MethodName

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

the class ExpressionGenerator method visit.

/**
     * 12.2.7.2 Runtime Semantics: Evaluation
     */
@Override
public ValType visit(GeneratorComprehension node, CodeVisitor mv) {
    MethodName method = codegen.compile(node);
    /* steps 1-8 */
    mv.invoke(method);
    mv.loadExecutionContext();
    if (node.getComprehension() instanceof LegacyComprehension) {
        mv.invoke(Methods.ScriptRuntime_EvaluateLegacyGeneratorComprehension);
    } else if (node.isConstructor()) {
        mv.invoke(Methods.ScriptRuntime_EvaluateConstructorGeneratorComprehension);
    } else {
        mv.invoke(Methods.ScriptRuntime_EvaluateGeneratorComprehension);
    }
    /* step 9 */
    return ValType.Object;
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 12 with MethodName

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

the class ExpressionGenerator method visit.

@Override
public ValType visit(AsyncArrowFunction node, CodeVisitor mv) {
    MethodName method = codegen.compile(node);
    /* steps 1-4 */
    mv.invoke(method);
    mv.loadExecutionContext();
    mv.invoke(Methods.ScriptRuntime_EvaluateAsyncArrowFunction);
    /* step 5 */
    return ValType.Object;
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 13 with MethodName

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

the class StatementGenerator method visit.

@Override
public Completion visit(StatementListMethod node, CodeVisitor mv) {
    Entry<MethodName, LabelState> entry = codegen.compile(node, mv);
    MethodName method = entry.getKey();
    LabelState labelState = entry.getValue();
    boolean hasCompletion = labelState.hasReturn() || (mv.hasCompletion() && node.hasCompletionValue());
    boolean hasResume = node.hasResumePoint();
    boolean hasTarget = hasResume || labelState.hasTargetInstruction();
    mv.enterVariableScope();
    Value<Object[]> completion;
    if (hasCompletion) {
        Variable<Object[]> completionVar = mv.newVariable("completion", Object[].class);
        mv.anewarray(1, Types.Object);
        mv.store(completionVar);
        if (mv.hasCompletion()) {
            mv.astore(completionVar, 0, mv.completionValue());
        }
        completion = completionVar;
    } else {
        completion = mv.anullValue();
    }
    MutableValue<Integer> target = hasTarget ? mv.newVariable("target", int.class) : new PopStoreValue<>();
    // stack: [] -> []
    // 0 = hint for stacktraces to omit this frame
    mv.lineInfo(0);
    if (hasResume) {
        mv.callWithSuspendInt(method, target, completion);
    } else {
        mv.callWithResult(method, target, completion);
    }
    Value<Object> completionValue = mv.arrayElement(completion, 0, Object.class);
    if (node.hasCompletionValue()) {
        mv.storeCompletionValue(completionValue);
    }
    mv.labelSwitch(labelState, target, completionValue, false);
    mv.exitVariableScope();
    return labelState.completion;
}
Also used : LabelState(com.github.anba.es6draft.compiler.CodeVisitor.LabelState) ScriptObject(com.github.anba.es6draft.runtime.types.ScriptObject) FunctionObject(com.github.anba.es6draft.runtime.types.builtins.FunctionObject) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 14 with MethodName

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

the class RuntimeInfoGenerator method debugInfo.

private void debugInfo(MethodCode code, MethodName... names) {
    InstructionAssembler asm = new InstructionAssembler(code);
    asm.begin();
    asm.anew(Types.DebugInfo, Methods.DebugInfo_init);
    for (MethodName name : names) {
        asm.dup();
        asm.handle(name);
        asm.invoke(Methods.DebugInfo_addMethod);
    }
    asm._return();
    asm.end();
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) InstructionAssembler(com.github.anba.es6draft.compiler.assembler.InstructionAssembler)

Example 15 with MethodName

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

the class PropertyGenerator method visit.

@Override
public ValType visit(PropertyDefinitionsMethod node, CodeVisitor mv) {
    MethodName method = codegen.compile(node, decorators != null, mv);
    boolean hasResume = node.hasResumePoint();
    mv.enterVariableScope();
    Variable<OrdinaryObject> object = mv.newVariable("object", OrdinaryObject.class);
    // stack: [<object>] -> []
    mv.store(object);
    // stack: [] -> []
    // 0 = hint for stacktraces to omit this frame
    mv.lineInfo(0);
    if (hasResume) {
        mv.callWithSuspend(method, object, decoratorsOrNull(mv));
    } else {
        mv.call(method, object, decoratorsOrNull(mv));
    }
    mv.exitVariableScope();
    return null;
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) 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