Search in sources :

Example 1 with ValType

use of com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType in project es6draft by anba.

the class BindingInitializationGenerator method InitializeBoundName.

/**
     * 12.1.5.1 Runtime Semantics: InitializeBoundName(name, value, environment)
     * <p>
     * stack: [value] {@literal ->} []
     * 
     * @param node
     *            the binding identifier
     * @param mv
     *            the code visitor
     */
static <ENVREC extends EnvironmentRecord> void InitializeBoundName(BindingIdentifier node, CodeVisitor mv) {
    IdReferenceOp op = IdReferenceOp.of(node);
    /* steps 1-2 (not applicable) */
    /* step 3 */
    // stack: [value] -> [reference, value]
    ValType refType = op.resolveBinding(node, mv);
    mv.swap(ValType.Any, refType);
    // stack: [reference, value] -> []
    op.putValue(node, ValType.Any, mv);
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)

Example 2 with ValType

use of com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType in project es6draft by anba.

the class ExpressionGenerator method arrayLiteralWithSpread.

/**
     * 12.2.4.1.3 Runtime Semantics: Evaluation<br>
     * 12.2.4.1.2 Runtime Semantics: Array Accumulation
     * 
     * @param node
     *            the array literal
     * @param mv
     *            the expresion visitor
     */
private void arrayLiteralWithSpread(ArrayLiteral node, CodeVisitor mv) {
    // stack: [array, nextIndex]
    int elisionWidth = 0;
    for (Expression element : node.getElements()) {
        if (element instanceof Elision) {
            // Elision
            elisionWidth += 1;
            continue;
        }
        if (elisionWidth != 0) {
            mv.iconst(elisionWidth);
            mv.iadd();
            elisionWidth = 0;
        }
        if (element instanceof SpreadElement) {
            element.accept(this, mv);
        } else {
            // stack: [array, nextIndex] -> [array, nextIndex, array, nextIndex]
            mv.dup2();
            ValType elementType = element.accept(this, mv);
            mv.toBoxed(elementType);
            // stack: [array, nextIndex, array, nextIndex, value] -> [array, nextIndex]
            mv.invoke(Methods.ScriptRuntime_defineProperty__int);
            elisionWidth += 1;
        }
    }
    if (elisionWidth != 0) {
        mv.iconst(elisionWidth);
        mv.iadd();
    }
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)

Example 3 with ValType

use of com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType in project es6draft by anba.

the class ExpressionGenerator method visit.

/**
     * 12.2.4.1.2 Runtime Semantics: Array Accumulation
     */
@Override
public ValType visit(SpreadElement node, CodeVisitor mv) {
    // stack: [array, nextIndex] -> [array, array, nextIndex]
    mv.swap();
    mv.dupX1();
    mv.swap();
    // stack: [array, array, nextIndex] -> [array, array, nextIndex, value]
    Expression spread = node.getExpression();
    ValType spreadType = spread.accept(this, mv);
    mv.toBoxed(spreadType);
    // stack: [array, array, nextIndex, value] -> [array, nextIndex']
    mv.loadExecutionContext();
    mv.lineInfo(node);
    mv.invoke(Methods.ScriptRuntime_ArrayAccumulationSpreadElement);
    return ValType.Any;
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)

Example 4 with ValType

use of com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType in project es6draft by anba.

the class ExpressionGenerator method PerformEval.

/**
     * [18.2.1.1] Direct Call to Eval
     * 
     * @param call
     *            the function call expression
     * @param arguments
     *            the list of function call arguments
     * @param hasThisValue
     *            {@code true} if the thisValue is on the stack
     * @param afterCall
     *            the label after the call instruction
     * @param mv
     *            the code visitor
     */
private void PerformEval(Expression call, List<Expression> arguments, boolean hasThisValue, Jump afterCall, CodeVisitor mv) {
    int evalFlags = EvalFlags.Direct.getValue();
    if (mv.isStrict()) {
        evalFlags |= EvalFlags.Strict.getValue();
    }
    if (mv.isGlobalCode()) {
        evalFlags |= EvalFlags.GlobalCode.getValue();
    }
    if (isGlobalScope(mv.getScope())) {
        evalFlags |= EvalFlags.GlobalScope.getValue();
    }
    if (isGlobalThis(mv.getScope())) {
        evalFlags |= EvalFlags.GlobalThis.getValue();
    }
    if (isEnclosedByWithStatement(mv.getScope())) {
        evalFlags |= EvalFlags.EnclosedByWithStatement.getValue();
    }
    if (!mv.isStrict() && isEnclosedByLexicalDeclaration(mv.getScope())) {
        evalFlags |= EvalFlags.EnclosedByLexicalDeclaration.getValue();
    }
    // stack: [thisValue?, args?, func(Callable)] -> [thisValue?, args?]
    mv.pop();
    // stack: [thisValue?, args?] -> [args?]
    boolean constantArguments = hasConstantArguments(arguments);
    if (hasThisValue) {
        if (constantArguments) {
            // stack: [thisValue] -> []
            mv.pop();
        } else {
            // stack: [thisValue, args] -> [args]
            mv.swap();
            mv.pop();
        }
    }
    if (codegen.isEnabled(CompatibilityOption.Realm)) {
        if (constantArguments) {
            // stack: [] -> [args]
            ArgumentListEvaluation(call, arguments, mv);
        }
        // stack: [args] -> [result]
        mv.loadExecutionContext();
        mv.iconst(evalFlags);
        mv.invoke(Methods.Eval_directEvalWithTranslate);
        mv.goTo(afterCall);
    } else {
        if (arguments.isEmpty()) {
            assert constantArguments : "empty arguments list is constant";
            // stack: [] -> [result]
            mv.loadUndefined();
            mv.goTo(afterCall);
        } else if (hasArguments(arguments)) {
            if (constantArguments) {
                // stack: [] -> [arg_0]
                ValType type = arguments.get(0).accept(this, mv);
                mv.toBoxed(type);
            } else {
                // stack: [args] -> [arg_0]
                mv.iconst(0);
                mv.aaload();
            }
            mv.loadExecutionContext();
            mv.iconst(evalFlags);
            mv.invoke(Methods.Eval_directEval);
            mv.goTo(afterCall);
        } else {
            assert !constantArguments : "spread arguments list is not constant";
            Jump emptyArguments = new Jump();
            mv.dup();
            mv.arraylength();
            mv.ifeq(emptyArguments);
            {
                mv.iconst(0);
                mv.aaload();
                mv.loadExecutionContext();
                mv.iconst(evalFlags);
                mv.invoke(Methods.Eval_directEval);
                mv.goTo(afterCall);
            }
            mv.mark(emptyArguments);
            mv.pop();
            mv.loadUndefined();
            mv.goTo(afterCall);
        }
    }
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType) Jump(com.github.anba.es6draft.compiler.assembler.Jump)

Example 5 with ValType

use of com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType in project es6draft by anba.

the class ExpressionGenerator method visit.

/**
 * 14.4 Generator Function Definitions
 * <p>
 * 14.4.14 Runtime Semantics: Evaluation
 */
@Override
public ValType visit(YieldExpression node, CodeVisitor mv) {
    Expression expr = node.getExpression();
    if (expr != null) {
        ValType type = expr.accept(this, mv);
        mv.toBoxed(type);
    } else {
        mv.loadUndefined();
    }
    if (node.isDelegatedYield()) {
        delegatedYield(node, mv);
    } else {
        yield(node, mv);
    }
    return ValType.Any;
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)

Aggregations

ValType (com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)21 Jump (com.github.anba.es6draft.compiler.assembler.Jump)4 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)3 BlockScope (com.github.anba.es6draft.ast.scope.BlockScope)2 Name (com.github.anba.es6draft.ast.scope.Name)2 SpreadElementMethod (com.github.anba.es6draft.ast.synthetic.SpreadElementMethod)2 MethodCode (com.github.anba.es6draft.compiler.assembler.Code.MethodCode)2 FieldName (com.github.anba.es6draft.compiler.assembler.FieldName)2 MethodTypeDescriptor (com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)2 com.github.anba.es6draft.ast (com.github.anba.es6draft.ast)1 Scope (com.github.anba.es6draft.ast.scope.Scope)1 TopLevelScope (com.github.anba.es6draft.ast.scope.TopLevelScope)1 WithScope (com.github.anba.es6draft.ast.scope.WithScope)1 ExpressionMethod (com.github.anba.es6draft.ast.synthetic.ExpressionMethod)1 EvaluateArrayComprehension (com.github.anba.es6draft.compiler.ArrayComprehensionGenerator.EvaluateArrayComprehension)1 OutlinedCall (com.github.anba.es6draft.compiler.CodeVisitor.OutlinedCall)1 PropertyEvaluation (com.github.anba.es6draft.compiler.PropertyGenerator.PropertyEvaluation)1 Completion (com.github.anba.es6draft.compiler.StatementGenerator.Completion)1 MutableValue (com.github.anba.es6draft.compiler.assembler.MutableValue)1 Type (com.github.anba.es6draft.compiler.assembler.Type)1