Search in sources :

Example 6 with ValType

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

the class ExpressionGenerator method expressionMethod.

private OutlinedCall expressionMethod(ExpressionMethod node, CodeVisitor mv) {
    MethodTypeDescriptor methodDescriptor = ExpressionMethodVisitor.methodDescriptor(mv);
    MethodCode method = codegen.method(mv, "expr", methodDescriptor);
    return outlined(new ExpressionMethodVisitor(node, method, mv), body -> {
        ValType type = node.getExpression().accept(this, body);
        assert type != ValType.Empty;
        body.storeCompletionValue(type);
        return Completion.Normal;
    });
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)

Example 7 with ValType

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

the class ExpressionGenerator method EvaluateNew.

/**
 * [12.3.3.1.1 Runtime Semantics: EvaluateNew(thisCall, constructProduction, arguments)]
 *
 * @param node
 *            the <code>NewExpression</code> node
 * @param mv
 *            the code visitor
 * @return the returned value type
 */
private ValType EvaluateNew(NewExpression node, CodeVisitor mv) {
    /* steps 1-2 (not applicable) */
    /* steps 3-5 */
    ValType type = node.getExpression().accept(this, mv);
    mv.toBoxed(type);
    mv.loadExecutionContext();
    /* steps 6-7 */
    ArgumentListEvaluation(node, node.getArguments(), mv);
    /* steps 8-9 */
    mv.lineInfo(node);
    invokeDynamicConstruct(mv);
    return ValType.Object;
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)

Example 8 with ValType

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

the class ExpressionGenerator method visit.

/**
 * 12.13 Conditional Operator ( ? : )
 * <p>
 * 12.13.3 Runtime Semantics: Evaluation
 */
@Override
public ValType visit(ConditionalExpression node, CodeVisitor mv) {
    Jump l0 = new Jump(), l1 = new Jump();
    /* steps 1-2 */
    testExpressionBailout(node.getTest(), l0, mv);
    /* step 3 */
    ValType typeThen = node.getThen().accept(this, mv);
    if (typeThen.isJavaPrimitive()) {
        // Try to avoid boxing if then-and-otherwise are both compatible primitive types.
        ValType expected = expressionType(node.getOtherwise());
        boolean sameType = typeThen == expected;
        if (sameType || (typeThen.isNumber() && expected.isNumber())) {
            if (!sameType) {
                ToNumber(typeThen, mv);
            }
            mv.goTo(l1);
            mv.mark(l0);
            ValType typeOtherwise = node.getOtherwise().accept(this, mv);
            assert expected == typeOtherwise : String.format("expected=%s, got=%s", expected, typeOtherwise);
            if (!sameType) {
                ToNumber(typeOtherwise, mv);
            }
            mv.mark(l1);
            return sameType ? typeThen : ValType.Number;
        }
    }
    mv.toBoxed(typeThen);
    mv.goTo(l1);
    /* step 4 */
    mv.mark(l0);
    ValType typeOtherwise = node.getOtherwise().accept(this, mv);
    mv.toBoxed(typeOtherwise);
    mv.mark(l1);
    return typeThen == typeOtherwise ? typeThen : ValType.Any;
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType) Jump(com.github.anba.es6draft.compiler.assembler.Jump)

Example 9 with ValType

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

the class ExpressionGenerator method visit.

/**
     * Extension: 'let' expression
     */
@Override
public ValType visit(LetExpression node, CodeVisitor mv) {
    BlockScope scope = node.getScope();
    if (scope.isPresent()) {
        mv.enterVariableScope();
        Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = mv.newVariable("env", LexicalEnvironment.class).uncheckedCast();
        Variable<DeclarativeEnvironmentRecord> envRec = mv.newVariable("envRec", DeclarativeEnvironmentRecord.class);
        newDeclarativeEnvironment(scope, mv);
        mv.store(env);
        getEnvRec(env, envRec, mv);
        for (LexicalBinding lexical : node.getBindings()) {
            Binding binding = lexical.getBinding();
            Expression initializer = lexical.getInitializer();
            for (Name name : BoundNames(binding)) {
                BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(envRec, name);
                op.createMutableBinding(envRec, name, false, mv);
            }
            if (initializer == null) {
                // LexicalBinding : BindingIdentifier
                assert binding instanceof BindingIdentifier;
                Name name = ((BindingIdentifier) binding).getName();
                /* steps 1-2 */
                // stack: [] -> []
                InitializeBoundNameWithUndefined(envRec, name, mv);
            } else if (binding instanceof BindingIdentifier) {
                // LexicalBinding : BindingIdentifier Initializer
                Name name = ((BindingIdentifier) binding).getName();
                /* steps 1-7 */
                InitializeBoundNameWithInitializer(codegen, envRec, name, initializer, mv);
            } else {
                // LexicalBinding : BindingPattern Initializer
                assert binding instanceof BindingPattern;
                /* steps 1-3 */
                expressionBoxed(initializer, mv);
                /* steps 4-5 */
                BindingInitializationGenerator.BindingInitialization(codegen, envRec, (BindingPattern) binding, mv);
            }
        }
        mv.load(env);
        pushLexicalEnvironment(mv);
        mv.exitVariableScope();
    }
    mv.enterScope(node);
    ValType type = node.getExpression().accept(this, mv);
    mv.exitScope();
    if (scope.isPresent()) {
        popLexicalEnvironment(mv);
    }
    return type;
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) Name(com.github.anba.es6draft.ast.scope.Name) FieldName(com.github.anba.es6draft.compiler.assembler.FieldName) LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) DeclarativeEnvironmentRecord(com.github.anba.es6draft.runtime.DeclarativeEnvironmentRecord)

Example 10 with ValType

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

the class ExpressionGenerator method nativeCallArgument.

private Type nativeCallArgument(Expression argument, CodeVisitor mv) {
    if (argument instanceof CallSpreadElement) {
        CallSpreadElement spread = (CallSpreadElement) argument;
        ValType type = spread.getExpression().accept(this, mv);
        mv.toBoxed(type);
        mv.loadExecutionContext();
        mv.lineInfo(spread);
        mv.invoke(Methods.CallOperations_nativeCallSpreadArray);
        return Types.Object_;
    }
    return argument.accept(this, mv).toType();
}
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