use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class PropertyGenerator method propertyDefinitions.
private OutlinedCall propertyDefinitions(PropertyDefinitionsMethod node, CodeVisitor mv) {
MethodTypeDescriptor methodDescriptor = PropertyDefinitionsCodeVisitor.methodDescriptor(mv);
MethodCode method = codegen.method(mv, "propdef", methodDescriptor);
return outlined(new PropertyDefinitionsCodeVisitor(node, method, mv), body -> {
Variable<OrdinaryObject> object = body.getObjectParameter();
StoreToArray<Object> decorators = this.decorators.from(body.getDecoratorsParameter());
PropertyEvaluation(codegen, node.getProperties(), object, decorators, body);
return Completion.Normal;
});
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class StatementGenerator method statementList.
private OutlinedCall statementList(StatementListMethod node, CodeVisitor mv) {
MethodTypeDescriptor methodDescriptor = StatementListMethodCodeVisitor.methodDescriptor(mv);
MethodCode method = codegen.method(mv, "stmt", methodDescriptor);
return outlined(new StatementListMethodCodeVisitor(node, method, mv), body -> {
return statements(node.getStatements(), body);
});
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class BlockDeclarationInstantiationGenerator method blockInstantiation.
private MethodName blockInstantiation(Node node, Consumer<BlockInstantiationVisitor> compiler) {
MethodCode method = codegen.method("!block", BlockInstantiationVisitor.BlockInstantiation);
BlockInstantiationVisitor body = new BlockInstantiationVisitor(method);
body.lineInfo(node);
body.begin();
compiler.accept(body);
body._return();
body.end();
return method.name();
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class CodeGenerator method classDefinition.
/**
* Compiles a class definition node.
*
* @param node
* the class definition
* @return the class definition method
*/
MethodName classDefinition(ClassDefinition node) {
MethodDefinition constructor = node.getConstructor();
MethodDefinition callConstructor = node.getCallConstructor();
String methodName = newUniqueName(node);
CompletableFuture<String> source = getSource(node);
ClassCompiler compiler;
if (node.getHeritage() == null) {
compiler = ClassCompiler.BaseClass;
} else {
compiler = ClassCompiler.DerivedClass;
}
// instantiation method
MethodCode constructInit = newMethod(scriptFrame(methodName, "_init"), compiler.desc.instantiation);
new FunctionDeclarationInstantiationGenerator(this).generate(constructor, constructInit);
// runtime method
MethodCode constructBody = newMethod(scriptFrame(methodName), compiler.desc.body);
boolean tailConstruct = compiler.body.compile(this, constructor, constructBody);
// construct method
MethodTypeDescriptor constructDesc;
if (tailConstruct) {
constructDesc = FunctionDesc.ConstructorFunctionTailCall.construct;
} else {
constructDesc = compiler.desc.construct;
}
MethodCode constructEntry = newMethod(hiddenFrame(methodName, "_construct"), constructDesc);
FunctionCode construct = new FunctionCode(constructEntry.name(), constructInit.name(), constructBody.name(), tailConstruct);
compiler.construct.compile(this, node, constructEntry, construct);
FunctionCode call;
Function<MethodName, MethodName> debugInfo = null;
if (callConstructor != null) {
FunctionCompiler<MethodDefinition> callCompiler = FunctionCompiler.CallConstructor;
String callMethodName = newUniqueName(callConstructor);
// instantiation method
MethodCode callInit = newMethod(scriptFrame(callMethodName, "_init"), callCompiler.desc.instantiation);
new FunctionDeclarationInstantiationGenerator(this).generate(callConstructor, callInit);
// runtime method
MethodCode callBody = newMethod(scriptFrame(callMethodName), callCompiler.desc.body);
boolean tailCall = callCompiler.body.compile(this, callConstructor, callBody);
// call method
MethodCode callMethod = newMethod(hiddenFrame(methodName, "_call"), callCompiler.desc.call);
call = new FunctionCode(callMethod.name(), callInit.name(), callBody.name(), tailCall);
callCompiler.call.compile(this, callConstructor, callMethod, call);
// debug-info method
if (isEnabled(Compiler.Option.DebugInfo)) {
debugInfo = rt -> {
MethodCode method = newMethod(hiddenFrame(methodName, "_dbg"), MethodDescriptors.DebugInfo);
debugInfo(method, rt, call.entry, call.instantiation, call.body, construct.entry, construct.instantiation, construct.body);
return method.name();
};
}
} else {
// call method
MethodCode callMethod = newMethod(hiddenFrame(methodName, "_call"), compiler.desc.call);
call = new FunctionCode(callMethod.name(), null, null, false);
compiler.call.compile(this, node, callMethod, call);
// debug-info method
if (isEnabled(Compiler.Option.DebugInfo)) {
debugInfo = rt -> {
MethodCode method = newMethod(hiddenFrame(methodName, "_dbg"), MethodDescriptors.DebugInfo);
debugInfo(method, rt, call.entry, construct.entry, construct.instantiation, construct.body);
return method.name();
};
}
}
// runtime-info method
MethodCode runtimeInfo = newMethod(hiddenFrame(methodName, "_rti"), MethodDescriptors.Function_RTI);
new RuntimeInfoGenerator(this).runtimeInfo(constructor, runtimeInfo, call, construct, source.join(), debugInfo);
return runtimeInfo.name();
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class CodeGenerator method compile.
/* ----------------------------------------------------------------------------------------- */
/**
* Compiles a script node.
*
* @param node
* the script node
*/
void compile(Script node) {
// instantiation method
MethodCode scriptInit = newMethod(scriptFrame("~script_init"), MethodDescriptors.Script_Init);
if (!(node.isEvalScript() || node.isScripting())) {
new GlobalDeclarationInstantiationGenerator(this).generate(node, scriptInit);
} else {
new EvalDeclarationInstantiationGenerator(this).generate(node, scriptInit);
}
// runtime method
MethodCode scriptBody = newMethod(scriptFrame("~script_body"), MethodDescriptors.Script_Body);
scriptBody(node, scriptBody);
// entry method (hidden frame)
MethodCode scriptCode = newMethod("!script", MethodDescriptors.Script_Code);
ScriptCodeGenerator.scriptEvaluation(node, scriptCode, scriptInit.name(), scriptBody.name());
// debug-info method
Function<MethodName, MethodName> debugInfo = null;
if (isEnabled(Compiler.Option.DebugInfo)) {
debugInfo = rt -> {
MethodCode method = newMethod("!script_dbg", MethodDescriptors.DebugInfo);
debugInfo(method, rt, scriptCode.name(), scriptInit.name(), scriptBody.name());
return method.name();
};
}
// runtime-info method
MethodCode runtimeInfo = newMethod("!script_rti", MethodDescriptors.Script_RTI);
RuntimeInfoGenerator.runtimeInfo(node, runtimeInfo, scriptCode.name(), debugInfo);
defaultConstructor(Methods.CompiledScript_Constructor, runtimeInfo.name());
}
Aggregations