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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations