use of com.github.anba.es6draft.runtime.LexicalEnvironment in project es6draft by anba.
the class ComprehensionGenerator method visit.
/**
* Runtime Semantics: ComprehensionEvaluation
*/
@Override
public Void visit(LegacyComprehension 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 (Name name : LexicallyDeclaredNames(node.getScope())) {
BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(envRec, name);
op.createMutableBinding(envRec, name, false, mv);
InitializeBoundNameWithUndefined(envRec, name, mv);
}
mv.load(env);
pushLexicalEnvironment(mv);
mv.exitVariableScope();
}
mv.enterScope(node);
visit((Comprehension) node, mv);
mv.exitScope();
if (scope.isPresent()) {
popLexicalEnvironment(mv);
}
return null;
}
use of com.github.anba.es6draft.runtime.LexicalEnvironment 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.runtime.LexicalEnvironment in project es6draft by anba.
the class CodeGenerator method compile.
MethodName compile(BlockStatement node, List<Declaration> declarations, BlockDeclarationInstantiationGenerator generator) {
MethodCode method = newMethod2(node);
BlockDeclInitVisitor body = new BlockDeclInitVisitor(method);
body.lineInfo(node);
body.begin();
Variable<ExecutionContext> cx = body.getExecutionContext();
Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = body.getLexicalEnvironment();
generator.generateMethod(declarations, cx, env, body);
body._return();
body.end();
return methodDesc(node, method.methodName);
}
use of com.github.anba.es6draft.runtime.LexicalEnvironment in project es6draft by anba.
the class StatementGenerator method visitTryFinally.
/**
* 13.15.8 Runtime Semantics: Evaluation<br>
*
* <code>try-finally</code>
*
* @param node
* the try-statement
* @param mv
* the code visitor
* @return the completion value
*/
private Completion visitTryFinally(TryStatement node, CodeVisitor mv) {
TryCatchLabel startFinally = new TryCatchLabel(), endFinally = new TryCatchLabel();
TryCatchLabel handlerFinally = new TryCatchLabel();
TryCatchLabel handlerFinallyStackOverflow = new TryCatchLabel();
Jump noException = new Jump();
mv.enterVariableScope();
Variable<LexicalEnvironment<?>> savedEnv = saveEnvironment(mv);
MutableValue<Object> completion = mv.enterFinallyScoped(node);
/* step 1 */
// Emit try-block
mv.mark(startFinally);
Completion tryResult = emitTryBlock(node, noException, mv);
mv.mark(endFinally);
// Restore temporary abrupt targets
List<TempLabel> tempLabels = mv.exitFinallyScoped();
/* step 2 */
// Emit finally-block
Completion finallyResult = emitFinallyBlock(node, savedEnv, completion, tryResult, Completion.Abrupt, handlerFinally, handlerFinallyStackOverflow, noException, tempLabels, mv);
mv.exitVariableScope();
mv.tryCatch(startFinally, endFinally, handlerFinally, Types.ScriptException);
mv.tryCatch(startFinally, endFinally, handlerFinallyStackOverflow, Types.Error);
/* steps 3-6 */
return finallyResult.then(tryResult);
}
use of com.github.anba.es6draft.runtime.LexicalEnvironment 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;
}
Aggregations