use of com.github.anba.es6draft.compiler.assembler.MethodName in project es6draft by anba.
the class DeclarationBindingInstantiationGenerator method InstantiateGeneratorObject.
/**
* Emit function call for:
* {@link ScriptRuntime#InstantiateGeneratorObject(LexicalEnvironment, ExecutionContext, RuntimeInfo.Function)}
* <p>
* stack: [] {@literal ->} [fo]
*
* @param context
* the variable which holds the execution context
* @param env
* the variable which holds the lexical environment
* @param f
* the generator declaration to instantiate
* @param mv
* the instruction visitor
*/
private void InstantiateGeneratorObject(Variable<ExecutionContext> context, Variable<? extends LexicalEnvironment<?>> env, GeneratorDeclaration f, InstructionVisitor mv) {
MethodName method = codegen.compile(f);
mv.load(env);
mv.load(context);
mv.invoke(method);
if (f instanceof LegacyGeneratorDeclaration) {
mv.invoke(Methods.ScriptRuntime_InstantiateLegacyGeneratorObject);
} else if (f.isConstructor()) {
mv.invoke(Methods.ScriptRuntime_InstantiateConstructorGeneratorObject);
} else {
mv.invoke(Methods.ScriptRuntime_InstantiateGeneratorObject);
}
}
use of com.github.anba.es6draft.compiler.assembler.MethodName in project es6draft by anba.
the class DeclarationBindingInstantiationGenerator method InstantiateFunctionObject.
/**
* Emit function call for:
* {@link ScriptRuntime#InstantiateFunctionObject(LexicalEnvironment, ExecutionContext, RuntimeInfo.Function)}
* <p>
* stack: [] {@literal ->} [fo]
*
* @param context
* the variable which holds the execution context
* @param env
* the variable which holds the lexical environment
* @param f
* the function declaration to instantiate
* @param mv
* the instruction visitor
*/
private void InstantiateFunctionObject(Variable<ExecutionContext> context, Variable<? extends LexicalEnvironment<?>> env, FunctionDeclaration f, InstructionVisitor mv) {
MethodName method = codegen.compile(f);
mv.load(env);
mv.load(context);
mv.invoke(method);
mv.invoke(Methods.ScriptRuntime_InstantiateFunctionObject);
}
use of com.github.anba.es6draft.compiler.assembler.MethodName in project es6draft by anba.
the class DefaultCodeGenerator method ClassDefinitionEvaluation.
/**
* 14.5.14 Runtime Semantics: ClassDefinitionEvaluation
*
* @param def
* the class definition node
* @param className
* the class name or {@code null} if not present
* @param mv
* the code visitor
*/
protected final void ClassDefinitionEvaluation(ClassDefinition def, Name className, CodeVisitor mv) {
mv.enterVariableScope();
Variable<ArrayList<Callable>> classDecorators = null;
boolean hasClassDecorators = !def.getDecorators().isEmpty();
if (hasClassDecorators) {
classDecorators = newDecoratorVariable("classDecorators", mv);
evaluateDecorators(classDecorators, def.getDecorators(), mv);
}
mv.enterClassDefinition();
// step 1 (not applicable)
// steps 2-4
BlockScope scope = def.getScope();
assert (scope != null && scope.isPresent()) == (className != null);
Variable<DeclarativeEnvironmentRecord> classScopeEnvRec = null;
if (className != null) {
// stack: [] -> [classScope]
newDeclarativeEnvironment(scope, mv);
classScopeEnvRec = mv.newVariable("classScopeEnvRec", DeclarativeEnvironmentRecord.class);
getEnvRec(classScopeEnvRec, mv);
// stack: [classScope] -> [classScope]
Name innerName = scope.resolveName(className, false);
BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classScopeEnvRec, innerName);
op.createImmutableBinding(classScopeEnvRec, innerName, true, mv);
// stack: [classScope] -> []
pushLexicalEnvironment(mv);
mv.enterScope(def);
}
// steps 5-7
// stack: [] -> [<constructorParent,proto>]
Expression classHeritage = def.getHeritage();
if (classHeritage == null) {
mv.loadExecutionContext();
mv.invoke(Methods.ScriptRuntime_getDefaultClassProto);
} else if (classHeritage instanceof NullLiteral) {
mv.loadExecutionContext();
mv.invoke(Methods.ScriptRuntime_getClassProto_Null);
} else {
expressionBoxed(classHeritage, mv);
mv.loadExecutionContext();
mv.lineInfo(def);
mv.invoke(Methods.ScriptRuntime_getClassProto);
}
// stack: [<constructorParent,proto>] -> [<constructorParent,proto>]
Variable<OrdinaryObject> proto = mv.newVariable("proto", OrdinaryObject.class);
mv.dup();
mv.aload(1, Types.ScriptObject);
mv.checkcast(Types.OrdinaryObject);
mv.store(proto);
// stack: [<constructorParent,proto>] -> [constructorParent, proto]
mv.aload(0, Types.ScriptObject);
mv.load(proto);
// steps 8-9
// stack: [constructorParent, proto] -> [constructorParent, proto, <rti>]
MethodDefinition constructor = ConstructorMethod(def);
assert constructor != null;
MethodName method = codegen.compile(def);
// Runtime Semantics: Evaluation -> MethodDefinition
mv.invoke(method);
// step 10 (not applicable)
// steps 11-18
// stack: [constructorParent, proto, <rti>] -> [F]
mv.iconst(classHeritage != null);
mv.loadExecutionContext();
mv.lineInfo(def);
mv.invoke(Methods.ScriptRuntime_EvaluateConstructorMethod);
// stack: [F] -> []
Variable<OrdinaryConstructorFunction> F = mv.newVariable("F", OrdinaryConstructorFunction.class);
mv.store(F);
Variable<ArrayList<Object>> methodDecorators = null;
boolean hasMethodDecorators = HasDecorators(def);
if (hasMethodDecorators) {
methodDecorators = newDecoratorVariable("methodDecorators", mv);
}
if (!constructor.getDecorators().isEmpty()) {
addDecoratorObject(methodDecorators, proto, mv);
evaluateDecorators(methodDecorators, constructor.getDecorators(), mv);
addDecoratorKey(methodDecorators, "constructor", mv);
}
// steps 19-21
ClassPropertyEvaluation(codegen, def.getProperties(), F, proto, methodDecorators, mv);
if (hasClassDecorators) {
mv.load(F);
mv.load(classDecorators);
mv.loadExecutionContext();
mv.lineInfo(def);
mv.invoke(Methods.ScriptRuntime_EvaluateClassDecorators);
}
if (hasMethodDecorators) {
mv.load(methodDecorators);
mv.loadExecutionContext();
mv.lineInfo(def);
mv.invoke(Methods.ScriptRuntime_EvaluateClassMethodDecorators);
}
// steps 22-23 (moved)
if (className != null) {
// stack: [] -> []
Name innerName = scope.resolveName(className, false);
BindingOp<DeclarativeEnvironmentRecord> op = BindingOp.of(classScopeEnvRec, innerName);
op.initializeBinding(classScopeEnvRec, innerName, F, mv);
mv.exitScope();
popLexicalEnvironment(mv);
}
// stack: [] -> [F]
mv.load(F);
mv.exitVariableScope();
// step 24 (return F)
mv.exitClassDefinition();
}
use of com.github.anba.es6draft.compiler.assembler.MethodName in project es6draft by anba.
the class BlockDeclarationInstantiationGenerator method generateMethod.
/**
* stack: [] {@literal ->} []
*
* @param node
* the block statement
* @param cx
* the execution context
* @param env
* the lexical environment
* @param mv
* the instruction visitor
*/
void generateMethod(BlockStatement node, Variable<ExecutionContext> cx, Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env, InstructionVisitor mv) {
List<Declaration> declarations = LexicallyScopedDeclarations(node);
if (declarations.size() <= METHOD_LIMIT) {
generate(declarations, cx, env, mv);
} else {
for (int i = 0, size = declarations.size(); i < size; i += METHOD_LIMIT) {
List<Declaration> sublist = declarations.subList(i, Math.min(i + METHOD_LIMIT, size));
MethodName method = codegen.compile(node, sublist, this);
mv.load(env);
mv.load(cx);
mv.invoke(method);
}
}
}
use of com.github.anba.es6draft.compiler.assembler.MethodName in project es6draft by anba.
the class BlockDeclarationInstantiationGenerator method generateMethod.
/**
* stack: [] {@literal ->} []
*
* @param node
* the switch statement
* @param cx
* the execution context
* @param env
* the lexical environment
* @param mv
* the instruction visitor
*/
void generateMethod(SwitchStatement node, Variable<ExecutionContext> cx, Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env, InstructionVisitor mv) {
List<Declaration> declarations = LexicallyScopedDeclarations(node);
if (declarations.size() <= METHOD_LIMIT) {
generate(declarations, cx, env, mv);
} else {
for (int i = 0, size = declarations.size(); i < size; i += METHOD_LIMIT) {
List<Declaration> sublist = declarations.subList(i, Math.min(i + METHOD_LIMIT, size));
MethodName method = codegen.compile(node, sublist, this);
mv.load(env);
mv.load(cx);
mv.invoke(method);
}
}
}
Aggregations