Search in sources :

Example 21 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(ExpressionMethod node, CodeVisitor mv) {
    MethodName method = codegen.compile(node, mv);
    boolean hasResume = node.hasResumePoint();
    // stack: [] -> [result]
    // 0 = hint for stacktraces to omit this frame
    mv.lineInfo(0);
    if (hasResume) {
        mv.callWithSuspend(method);
    } else {
        mv.call(method);
    }
    return ValType.Any;
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 22 with MethodName

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

the class ExpressionGenerator method visit.

/**
     * 12.2.4.1.3 Runtime Semantics: Evaluation<br>
     * 12.2.4.1.2 Runtime Semantics: Array Accumulation
     */
@Override
public ValType visit(SpreadElementMethod node, CodeVisitor mv) {
    MethodName method = codegen.compile(node, mv);
    boolean hasResume = node.hasResumePoint();
    mv.enterVariableScope();
    Variable<ArrayObject> array = mv.newVariable("array", ArrayObject.class);
    Variable<Integer> nextIndex = mv.newVariable("nextIndex", int.class);
    // stack: [array, nextIndex] -> [array]
    mv.store(nextIndex);
    mv.dup();
    mv.store(array);
    // stack: [array] -> [array, nextIndex']
    // 0 = hint for stacktraces to omit this frame
    mv.lineInfo(0);
    if (hasResume) {
        mv.callWithSuspend(method, array, nextIndex);
    } else {
        mv.call(method, array, nextIndex);
    }
    mv.exitVariableScope();
    return ValType.Any;
}
Also used : ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 23 with MethodName

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

the class ExpressionGenerator method visit.

/**
     * 14.4.14 Runtime Semantics: Evaluation
     */
@Override
public ValType visit(GeneratorExpression node, CodeVisitor mv) {
    MethodName method = codegen.compile(node);
    /* steps 1-7/11 */
    mv.invoke(method);
    mv.loadExecutionContext();
    if (node.isConstructor()) {
        mv.invoke(Methods.ScriptRuntime_EvaluateConstructorGeneratorExpression);
    } else {
        mv.invoke(Methods.ScriptRuntime_EvaluateGeneratorExpression);
    }
    /* step 8/12 */
    return ValType.Object;
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 24 with MethodName

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

the class ExpressionGenerator method visit.

/**
     * Extension: 'do' expression
     */
@Override
public ValType visit(DoExpression node, CodeVisitor mv) {
    Entry<MethodName, LabelState> entry = codegen.compile(node, mv);
    MethodName method = entry.getKey();
    LabelState labelState = entry.getValue();
    boolean hasCompletion = labelState.hasReturn() || node.hasCompletion();
    boolean hasResume = node.hasYieldOrAwait();
    boolean hasTarget = hasResume || labelState.size() > 0;
    mv.enterVariableScope();
    Value<Object[]> completion;
    if (hasCompletion) {
        Variable<Object[]> completionVar = mv.newVariable("completion", Object[].class);
        mv.anewarray(1, Types.Object);
        mv.store(completionVar);
        if (node.hasCompletion()) {
            mv.astore(completionVar, 0, mv.undefinedValue());
        }
        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);
    mv.labelSwitch(labelState, target, completionValue, true);
    if (node.hasCompletion()) {
        mv.load(completionValue);
    }
    mv.exitVariableScope();
    return node.hasCompletion() ? ValType.Any : ValType.Empty;
}
Also used : LabelState(com.github.anba.es6draft.compiler.CodeVisitor.LabelState) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 25 with MethodName

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

the class ExpressionGenerator method visit.

/**
     * 14.1.17 Runtime Semantics: Evaluation
     */
@Override
public ValType visit(FunctionExpression node, CodeVisitor mv) {
    MethodName method = codegen.compile(node);
    /* steps 1-5/10 */
    mv.invoke(method);
    mv.loadExecutionContext();
    if (isLegacy(node)) {
        mv.invoke(Methods.ScriptRuntime_EvaluateLegacyFunctionExpression);
    } else {
        mv.invoke(Methods.ScriptRuntime_EvaluateFunctionExpression);
    }
    /* step 6/11 */
    return ValType.Object;
}
Also used : 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