use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.
the class StatementGenerator method visit.
@Override
public Completion visit(ClassFieldInitializer node, CodeVisitor mv) {
ClassFieldDefinition field = node.getField();
// stack: [] -> [fieldName]
ValType type = expressionBoxed(node.getFieldName(), mv);
// stack: [fieldName] -> [fieldName, value]
Expression initializer = field.getInitializer();
ClassFieldScope scope = node.getScope();
assert (initializer != null) == (scope != null);
if (initializer != null) {
mv.enterScope(node);
if (!scope.isPresent()) {
expressionBoxed(initializer, mv);
} else {
Variable<LexicalEnvironment<?>> env = saveEnvironment(mv);
newClassFieldInitializerEnvironment(env, mv);
if (!scope.varDeclaredNames().isEmpty()) {
Variable<DeclarativeEnvironmentRecord> classFieldEnvRec = mv.newVariable("classFieldEnvRec", DeclarativeEnvironmentRecord.class);
getVariableEnvironmentRecord(classFieldEnvRec, mv);
for (Name varName : scope.varDeclaredNames()) {
BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classFieldEnvRec, varName);
op.createMutableBinding(classFieldEnvRec, varName, false, mv);
op.initializeBinding(classFieldEnvRec, varName, mv.undefinedValue(), mv);
}
}
expressionBoxed(initializer, mv);
setVariableAndLexicalEnvironment(env, mv);
}
mv.exitScope();
if (IsAnonymousFunctionDefinition(initializer)) {
SetFunctionName(initializer, type, mv);
}
} else {
mv.loadUndefined();
}
mv.loadExecutionContext();
mv.lineInfo(node);
mv.invoke(Methods.ClassOperations_DefineField);
return Completion.Normal;
}
use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.
the class StatementGenerator method enterCatchScope.
private void enterCatchScope(CatchClause node, CodeVisitor mv) {
BlockScope scope = node.getScope();
Binding catchParameter = node.getCatchParameter();
/* steps 1-6 */
// stack: [e] -> []
mv.enterVariableScope();
{
Variable<Object> exception = mv.newVariable("exception", Object.class);
mv.invoke(Methods.ScriptException_getValue);
mv.store(exception);
/* step 1 (not applicable) */
/* steps 2-4 */
Variable<DeclarativeEnvironmentRecord> envRec = null;
if (scope.isPresent()) {
/* step 2 */
// stack: [] -> [catchEnv]
newCatchEnvironment(catchParameter, scope, mv);
envRec = mv.newVariable("envRec", DeclarativeEnvironmentRecord.class);
getEnvRec(envRec, mv);
/* step 3 */
if (catchParameter != null) {
for (Name name : BoundNames(catchParameter)) {
BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(envRec, name);
op.createMutableBinding(envRec, name, false, mv);
}
}
/* step 4 */
// stack: [catchEnv] -> []
pushLexicalEnvironment(mv);
}
mv.enterScope(node);
// stack: [ex] -> []
if (catchParameter != null) {
BindingInitialization(codegen, envRec, catchParameter, exception, mv);
}
}
mv.exitVariableScope();
}
use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.
the class StatementGenerator method visit.
/**
* 13.7.4 The for Statement
* <p>
* 13.1.8 Runtime Semantics: Evaluation<br>
* 13.1.7 Runtime Semantics: LabelledEvaluation<br>
* 13.7.4.7 Runtime Semantics: LabelledEvaluation
*/
@Override
public Completion visit(ForStatement node, CodeVisitor mv) {
assert mv.getStackSize() == 0;
boolean perIterationsLets = false;
BlockScope scope = node.getScope();
Node head = node.getHead();
if (head == null) {
// empty
} else if (head instanceof Expression) {
ValType type = expression(((Expression) head).emptyCompletion(), mv);
mv.pop(type);
} else if (head instanceof VariableStatement) {
head.accept(this, mv);
} else {
assert head instanceof LexicalDeclaration;
LexicalDeclaration lexDecl = (LexicalDeclaration) head;
List<Name> boundNames = BoundNames(lexDecl);
boolean isConst = IsConstantDeclaration(lexDecl);
perIterationsLets = !isConst && !boundNames.isEmpty();
if (scope.isPresent()) {
mv.enterVariableScope();
Variable<DeclarativeEnvironmentRecord> envRec = mv.newVariable("envRec", DeclarativeEnvironmentRecord.class);
// stack: [] -> [loopEnv]
newDeclarativeEnvironment(scope, mv);
// stack: [loopEnv] -> [loopEnv]
getEnvRec(envRec, mv);
// stack: [loopEnv] -> [loopEnv]
for (Name dn : boundNames) {
BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(envRec, dn);
if (isConst) {
op.createImmutableBinding(envRec, dn, true, mv);
} else {
op.createMutableBinding(envRec, dn, false, mv);
}
}
// stack: [loopEnv] -> []
pushLexicalEnvironment(mv);
mv.exitVariableScope();
}
mv.enterScope(node);
lexDecl.accept(this, mv);
}
Completion result = ForBodyEvaluation(node, perIterationsLets, mv);
if (head instanceof LexicalDeclaration) {
mv.exitScope();
if (scope.isPresent() && !result.isAbrupt()) {
popLexicalEnvironment(mv);
}
}
return result;
}
use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.
the class StatementGenerator method ForInOfHeadEvaluation.
/**
* 13.7.5.12 Runtime Semantics: ForIn/OfHeadEvaluation (TDZnames, expr, iterationKind, labelSet)
* <p>
* stack: [] {@literal ->} [Iterator]
*
* @param <FORSTATEMENT>
* the for-statement node type
* @param node
* the for-statement node
* @param iterationKind
* the for-statement's iteration kind
* @param lblFail
* the target instruction if the expression node does not produce an object type
* @param mv
* the code visitor
* @return the value type of the expression
*/
private <FORSTATEMENT extends IterationStatement & ForIterationNode> ValType ForInOfHeadEvaluation(FORSTATEMENT node, IterationKind iterationKind, Jump lblFail, CodeVisitor mv) {
/* steps 1-2 */
BlockScope scope = node.getScope();
Node lhs = node.getHead();
List<Name> tdzNames = null;
if (lhs instanceof LexicalDeclaration) {
tdzNames = BoundNames(forDeclarationBinding((LexicalDeclaration) lhs));
assert scope.isPresent() == !tdzNames.isEmpty();
if (scope.isPresent()) {
mv.enterVariableScope();
Variable<DeclarativeEnvironmentRecord> envRec = mv.newVariable("envRec", DeclarativeEnvironmentRecord.class);
// stack: [] -> [TDZ]
newDeclarativeEnvironment(scope, mv);
// stack: [TDZ] -> [TDZ]
getEnvRec(envRec, mv);
// stack: [TDZ] -> [TDZ]
for (Name name : tdzNames) {
BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(envRec, name);
op.createMutableBinding(envRec, name, false, mv);
}
mv.exitVariableScope();
// stack: [TDZ] -> []
pushLexicalEnvironment(mv);
}
mv.enterScope(node);
}
/* steps 3, 5-6 */
Expression expr = node.getExpression();
ValType type = expressionBoxed(expr, mv);
/* step 4 */
if (tdzNames != null) {
mv.exitScope();
if (scope.isPresent()) {
popLexicalEnvironment(mv);
}
}
/* steps 7-8 */
if (iterationKind == IterationKind.Enumerate) {
/* step 7.a */
if (type != ValType.Object) {
Jump loopstart = new Jump();
mv.dup();
isUndefinedOrNull(mv);
mv.ifeq(loopstart);
mv.pop();
mv.goTo(lblFail);
mv.mark(loopstart);
}
/* steps 7.b-c */
mv.loadExecutionContext();
mv.lineInfo(expr);
mv.invoke(Methods.IteratorOperations_enumerate);
} else if (iterationKind == IterationKind.AsyncIterate) {
mv.loadExecutionContext();
mv.lineInfo(expr);
mv.invoke(Methods.IteratorOperations_asyncIterate);
} else {
/* step 8 */
assert iterationKind == IterationKind.Iterate;
mv.loadExecutionContext();
mv.lineInfo(expr);
mv.invoke(Methods.IteratorOperations_iterate);
}
return type;
}
use of com.github.anba.es6draft.ast.scope.Name in project es6draft by anba.
the class StatementGenerator method visit.
/**
* 13.3.1 Let and Const Declarations
* <p>
* 13.3.1.4 Runtime Semantics: Evaluation
*/
@Override
public Completion visit(LexicalDeclaration node, CodeVisitor mv) {
mv.enterVariableScope();
Class<? extends EnvironmentRecord> envRecClass = getEnvironmentRecordClass(mv);
Variable<? extends EnvironmentRecord> envRec = mv.newVariable("envRec", envRecClass);
getLexicalEnvironmentRecord(envRec, mv);
/* steps 1-2 */
for (LexicalBinding lexical : node.getElements()) {
Binding binding = lexical.getBinding();
Expression initializer = lexical.getInitializer();
if (initializer == null) {
// LexicalBinding : BindingIdentifier
assert binding instanceof BindingIdentifier;
Name name = ((BindingIdentifier) binding).getName();
/* steps 1-2 */
assert mv.getScope().isDeclared(name);
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 */
BindingInitialization(codegen, envRec, (BindingPattern) binding, mv);
}
}
mv.exitVariableScope();
/* step 3 */
return Completion.Normal;
}
Aggregations