use of com.github.anba.es6draft.compiler.assembler.Variable in project es6draft by anba.
the class DefaultCodeGenerator method asyncIteratorClose.
/**
* Emit:
*
* <pre>
* Callable returnMethod = GetMethod(cx, iterator, "return");
* if (returnMethod != null) {
* try {
* returnMethod.call(cx, iterator);
* await;
* } catch (ScriptException e) {
* if (throwable != e) {
* throwable.addSuppressed(e);
* }
* }
* }
* </pre>
*
* @param node
* the ast node
* @param iterator
* the script iterator object
* @param mv
* the code visitor
*/
final void asyncIteratorClose(Node node, Variable<ScriptObject> iterator, Variable<? extends Throwable> throwable, CodeVisitor mv) {
IteratorClose(node, iterator, returnMethod -> {
TryCatchLabel startCatch = new TryCatchLabel();
TryCatchLabel endCatch = new TryCatchLabel(), handlerCatch = new TryCatchLabel();
Jump noException = new Jump();
mv.mark(startCatch);
{
InvokeMethod(node, mv, returnMethod, iterator);
await(node, mv);
mv.pop();
mv.goTo(noException);
}
mv.mark(endCatch);
mv.catchHandler(handlerCatch, Types.ScriptException);
{
mv.enterVariableScope();
Variable<ScriptException> exception = mv.newVariable("exception", ScriptException.class);
mv.store(exception);
mv.load(throwable);
mv.load(exception);
mv.ifacmpeq(noException);
{
mv.load(throwable);
mv.load(exception);
mv.invoke(Methods.Throwable_addSuppressed);
}
mv.exitVariableScope();
}
mv.tryCatch(startCatch, endCatch, handlerCatch, Types.ScriptException);
mv.mark(noException);
}, mv);
}
use of com.github.anba.es6draft.compiler.assembler.Variable in project es6draft by anba.
the class ExpressionGenerator method EvaluateDirectCallEval.
/**
* [12.3.4.3 Runtime Semantics: EvaluateDirectCall( func, thisValue, arguments, tailPosition )]
*
* @param call
* the function call expression
* @param arguments
* the function arguments
* @param hasThisValue
* {@code true} if the thisValue is on the stack
* @param mv
* the code visitor
*/
private ValType EvaluateDirectCallEval(Expression call, List<Expression> arguments, boolean hasThisValue, CodeVisitor mv) {
Jump afterCall = new Jump(), notEval = new Jump();
if (hasThisValue) {
// stack: [func, thisValue] -> [thisValue, func]
mv.swap();
}
/* steps 1-2 (EvaluateDirectCall) */
// stack: [thisValue?, func] -> [thisValue?, args?, func]
boolean constantArguments = hasConstantArguments(arguments);
if (!constantArguments) {
ArgumentListEvaluation(call, arguments, mv);
mv.swap();
}
// Emit line info after evaluating arguments.
mv.lineInfo(call);
/* steps 3-4 (EvaluateDirectCall) */
// stack: [thisValue?, args?, func] -> [thisValue?, args?, func(Callable)]
mv.loadExecutionContext();
mv.invoke(Methods.ScriptRuntime_CheckCallable);
// stack: [thisValue?, args?, func(Callable)] -> [thisValue?, args?, func(Callable)]
mv.dup();
mv.loadExecutionContext();
mv.invoke(Methods.ScriptRuntime_IsBuiltinEval);
mv.ifeq(notEval);
{
PerformEval(call, arguments, hasThisValue, afterCall, mv);
}
mv.mark(notEval);
// stack: [thisValue?, args?, func(Callable)] -> [func(Callable), cx, thisValue, args]
if (constantArguments) {
if (hasThisValue) {
// stack: [thisValue, func(Callable)] -> [...]
mv.loadExecutionContext();
mv.swap1_2();
ArgumentListEvaluation(call, arguments, mv);
} else {
// stack: [func(Callable)] -> [...]
mv.loadExecutionContext();
mv.loadUndefined();
ArgumentListEvaluation(call, arguments, mv);
}
} else {
if (hasThisValue) {
// stack: [thisValue, args, func(Callable)] -> [...]
mv.loadExecutionContext();
mv.swap2();
} else {
// stack: [args, func(Callable)] -> [...]
mv.swap();
mv.loadExecutionContext();
mv.loadUndefined();
mv.swap1_2();
}
}
if (codegen.isEnabled(CompatibilityOption.Realm)) {
// direct-eval fallback hook
Jump noEvalHook = new Jump();
mv.loadExecutionContext();
mv.invoke(Methods.ScriptRuntime_directEvalFallbackHook);
mv.ifnull(noEvalHook);
{
// stack: [func(Callable), cx, thisValue, args] -> [args']
mv.invoke(Methods.ScriptRuntime_directEvalFallbackArguments);
// stack: [args'] -> []
Variable<Object[]> fallbackArguments = mv.newScratchVariable(Object[].class);
mv.store(fallbackArguments);
// stack: [] -> [func(Callable), cx, thisValue, args']
mv.loadExecutionContext();
mv.invoke(Methods.ScriptRuntime_directEvalFallbackHook);
mv.loadExecutionContext();
mv.loadExecutionContext();
mv.invoke(Methods.ScriptRuntime_directEvalFallbackThisArgument);
mv.load(fallbackArguments);
mv.freeVariable(fallbackArguments);
}
mv.mark(noEvalHook);
}
/* steps 5-9 (EvaluateDirectCall) */
if (isTailCall(call, mv)) {
// stack: [func(Callable), cx, thisValue, args'] -> [<func(Callable), thisValue, args>]
mv.invoke(Methods.ScriptRuntime_PrepareForTailCall);
} else {
// stack: [func(Callable), cx, thisValue, args] -> [result]
invokeDynamicCall(mv);
}
mv.mark(afterCall);
return ValType.Any;
}
use of com.github.anba.es6draft.compiler.assembler.Variable in project es6draft by anba.
the class ComprehensionGenerator method visit.
/**
* Runtime Semantics: ComprehensionEvaluation
*/
@Override
public Void visit(Comprehension node, CodeVisitor mv) {
ArrayList<Node> list = new ArrayList<>(node.getList().size() + 1);
list.addAll(node.getList());
list.add(node.getExpression());
elements = list.iterator();
// Create variables early so they'll appear next to each other in the local variable map.
ArrayList<Variable<ScriptIterator<?>>> iters = new ArrayList<>();
for (ComprehensionQualifier e : node.getList()) {
if (e instanceof ComprehensionFor || e instanceof LegacyComprehensionFor) {
Variable<ScriptIterator<?>> iter = mv.newVariable("iter", ScriptIterator.class).uncheckedCast();
iters.add(iter);
}
}
iterators = iters.iterator();
// Start generating code.
elements.next().accept(this, mv);
return null;
}
use of com.github.anba.es6draft.compiler.assembler.Variable 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 */
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);
/* steps 5-6 */
// stack: [ex] -> []
BindingInitialization(codegen, envRec, catchParameter, exception, mv);
}
mv.exitVariableScope();
}
Aggregations