Search in sources :

Example 11 with ValType

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

the class ExpressionGenerator method visit.

/**
 * 12.2.6 Object Initializer
 * <p>
 * 12.2.6.8 Runtime Semantics: Evaluation
 */
@Override
public ValType visit(ObjectLiteral node, CodeVisitor mv) {
    List<MethodDefinition> decoratedMethods = DecoratedMethods(node.getProperties());
    if (decoratedMethods.isEmpty()) {
        /* step 1 */
        mv.loadExecutionContext();
        mv.get(Fields.Intrinsics_ObjectPrototype);
        mv.invoke(Methods.OrdinaryObject_ObjectCreate);
        /* steps 2-3 */
        PropertyEvaluation(codegen, node.getProperties(), mv);
        /* step 4 */
        return ValType.Object;
    }
    mv.enterVariableScope();
    /* step 1 */
    Variable<OrdinaryObject> object = mv.newVariable("object", OrdinaryObject.class);
    mv.loadExecutionContext();
    mv.get(Fields.Intrinsics_ObjectPrototype);
    mv.invoke(Methods.OrdinaryObject_ObjectCreate);
    mv.store(object);
    int decoratorsCount = decoratedMethods.stream().mapToInt(m -> m.getDecorators().size()).sum();
    int decoratorsLength = decoratorsCount + decoratedMethods.size();
    StoreToArray<Object> methodDecorators = StoreToArray.create("methodDecorators", decoratorsLength, Object[].class, mv);
    /* steps 2-3 */
    PropertyEvaluation(codegen, node.getProperties(), object, methodDecorators, mv);
    MethodName decoratorsMethod = mv.compile(node, this::objectMethodDecorators);
    // 0 = hint for stacktraces to omit this frame
    mv.lineInfo(0);
    mv.invoke(decoratorsMethod, mv.executionContext(), object, methodDecorators.array);
    mv.load(object);
    mv.exitVariableScope();
    /* step 4 */
    return ValType.Object;
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) ListIterator(java.util.ListIterator) MutableValue(com.github.anba.es6draft.compiler.assembler.MutableValue) SIMDType(com.github.anba.es6draft.runtime.objects.simd.SIMDType) EvaluateArrayComprehension(com.github.anba.es6draft.compiler.ArrayComprehensionGenerator.EvaluateArrayComprehension) ArrayList(java.util.ArrayList) Variable(com.github.anba.es6draft.compiler.assembler.Variable) Type(com.github.anba.es6draft.compiler.assembler.Type) Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) WithScope(com.github.anba.es6draft.ast.scope.WithScope) ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType) Scope(com.github.anba.es6draft.ast.scope.Scope) OutlinedCall(com.github.anba.es6draft.compiler.CodeVisitor.OutlinedCall) BigInteger(java.math.BigInteger) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) AbstractOperations(com.github.anba.es6draft.runtime.AbstractOperations) CompatibilityOption(com.github.anba.es6draft.runtime.internal.CompatibilityOption) Parser(com.github.anba.es6draft.parser.Parser) EvalFlags(com.github.anba.es6draft.runtime.objects.Eval.EvalFlags) StaticSemantics(com.github.anba.es6draft.semantics.StaticSemantics) Jump(com.github.anba.es6draft.compiler.assembler.Jump) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) SpreadElementMethod(com.github.anba.es6draft.ast.synthetic.SpreadElementMethod) Objects(java.util.Objects) com.github.anba.es6draft.ast(com.github.anba.es6draft.ast) BlockScope(com.github.anba.es6draft.ast.scope.BlockScope) TopLevelScope(com.github.anba.es6draft.ast.scope.TopLevelScope) CompletionValueVisitor(com.github.anba.es6draft.compiler.completion.CompletionValueVisitor) List(java.util.List) Name(com.github.anba.es6draft.ast.scope.Name) PropertyEvaluation(com.github.anba.es6draft.compiler.PropertyGenerator.PropertyEvaluation) FieldName(com.github.anba.es6draft.compiler.assembler.FieldName) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) Value(com.github.anba.es6draft.compiler.assembler.Value) NativeCalls(com.github.anba.es6draft.runtime.internal.NativeCalls) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) ExpressionMethod(com.github.anba.es6draft.ast.synthetic.ExpressionMethod) Bootstrap(com.github.anba.es6draft.runtime.internal.Bootstrap) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) MethodName(com.github.anba.es6draft.compiler.assembler.MethodName)

Example 12 with ValType

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

the class ExpressionGenerator method visit.

/**
 * 12.3.6.1 Runtime Semantics: ArgumentListEvaluation
 */
@Override
public ValType visit(CallSpreadElement node, CodeVisitor mv) {
    ValType type = node.getExpression().accept(this, mv);
    mv.toBoxed(type);
    mv.loadExecutionContext();
    mv.lineInfo(node);
    mv.invoke(Methods.CallOperations_spreadArray);
    // actually Object[]
    return ValType.Any;
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)

Example 13 with ValType

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

the class ExpressionGenerator method ArrayAccumulationSpreadElement.

private void ArrayAccumulationSpreadElement(SpreadElement spread, CodeVisitor mv) {
    // stack: [array, nextIndex] -> [nextIndex']
    ValType spreadType = spread.accept(this, mv);
    mv.toBoxed(spreadType);
    mv.loadExecutionContext();
    mv.lineInfo(spread);
    mv.invoke(Methods.ArrayOperations_spreadElement);
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)

Example 14 with ValType

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

the class ExpressionGenerator method visit.

/**
 * 12.4.4.1 Runtime Semantics: Evaluation<br>
 * 12.4.5.1 Runtime Semantics: Evaluation<br>
 * 12.4.6.1 Runtime Semantics: Evaluation<br>
 * 12.4.7.1 Runtime Semantics: Evaluation<br>
 */
@Override
public ValType visit(UpdateExpression node, CodeVisitor mv) {
    LeftHandSideExpression expr = (LeftHandSideExpression) node.getOperand();
    ReferenceOp<LeftHandSideExpression> op = ReferenceOp.of(expr);
    ValType type = op.referenceForUpdate(expr, mv, codegen);
    ValType vtype = op.getValue(expr, type, mv);
    vtype = ToNumeric(vtype, mv);
    if (!node.getOperator().isPostfix()) {
        invokeDynamicOperator(node.getOperator(), mv);
        return op.putValue(expr, type, vtype, node.hasCompletion(), mv);
    }
    if (node.hasCompletion()) {
        Value<?> currentValue = op.dupOrStoreValue(type, vtype, mv);
        invokeDynamicOperator(node.getOperator(), mv);
        op.putValue(expr, type, vtype, mv);
        mv.load(currentValue);
        return vtype;
    }
    invokeDynamicOperator(node.getOperator(), mv);
    op.putValue(expr, type, vtype, mv);
    return ValType.Empty;
}
Also used : ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)

Example 15 with ValType

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

the class ExpressionGenerator method visit.

/**
 * 12.15.3 Runtime Semantics: Evaluation
 */
@Override
public ValType visit(CommaExpression node, CodeVisitor mv) {
    assert !node.getOperands().isEmpty() : "empty comma expression";
    int count = node.getOperands().size();
    for (Expression e : node.getOperands()) {
        if (--count == 0) {
            return e.accept(this, mv);
        }
        ValType type = e.emptyCompletion().accept(this, mv);
        mv.pop(type);
    }
    return null;
}
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