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