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