use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class CodeGenerator method compile.
private <FUNCTION extends FunctionNode> MethodName compile(FUNCTION node, FunctionCompiler<FUNCTION> compiler) {
CompletableFuture<String> source = getSource(node);
String methodName = newUniqueName(node);
FunctionCode call;
if (node.isInline()) {
// call method
MethodCode callEntry = newMethod(scriptFrame(methodName), compiler.desc.call);
boolean tailCall = compiler.callInline.compile(this, node, callEntry);
call = new FunctionCode(callEntry.name(), null, null, tailCall);
} else {
// instantiation method
MethodCode functionInit = newMethod(scriptFrame(methodName, "_init"), compiler.desc.instantiation);
new FunctionDeclarationInstantiationGenerator(this).generate(node, functionInit);
// runtime method
MethodCode functionBody = newMethod(scriptFrame(methodName), compiler.desc.body);
boolean tailCall = compiler.body.compile(this, node, functionBody);
// call method
MethodCode callEntry = newMethod(hiddenFrame(methodName, "_call"), compiler.desc.call);
call = new FunctionCode(callEntry.name(), functionInit.name(), functionBody.name(), tailCall);
compiler.call.compile(this, node, callEntry, call);
}
FunctionCode construct;
Function<MethodName, MethodName> debugInfo = null;
if (compiler.construct != null) {
// construct method
MethodTypeDescriptor constructDesc;
if (call.tailCall) {
assert node instanceof FunctionDefinition && IsStrict(node);
constructDesc = FunctionDesc.ConstructorFunctionTailCall.construct;
} else {
constructDesc = compiler.desc.construct;
}
if (node.isInline()) {
MethodCode constructEntry = newMethod(scriptFrame(methodName), constructDesc);
boolean tailCall = compiler.constructInline.compile(this, node, constructEntry);
construct = new FunctionCode(constructEntry.name(), null, null, tailCall);
} else {
MethodCode constructEntry = newMethod(hiddenFrame(methodName, "_construct"), constructDesc);
construct = new FunctionCode(constructEntry.name(), call.instantiation, call.body, call.tailCall);
compiler.construct.compile(this, node, constructEntry, construct);
}
// 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, call.instantiation, call.body);
return method.name();
};
}
} else {
construct = null;
// 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);
return method.name();
};
}
}
// runtime-info method
MethodCode runtimeInfo = newMethod(hiddenFrame(methodName, "_rti"), MethodDescriptors.Function_RTI);
new RuntimeInfoGenerator(this).runtimeInfo(node, 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 newMethod.
MethodCode newMethod(String methodName, MethodTypeDescriptor methodDescriptor) {
final int access = Modifier.PUBLIC | Modifier.STATIC;
MethodCode method = code.newMethod(access, methodName, methodDescriptor);
// System.out.printf("add <%s, %s>%n", methodName, method.classCode.className);
return method;
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class CodeGenerator method compile.
/**
* Compiles a module node.
*
* @param node
* the module node
* @param moduleRecord
* the module record
*/
void compile(Module node, SourceTextModuleRecord moduleRecord) {
// instantiation methods
MethodCode moduleInit = newMethod(scriptFrame("~module_init"), MethodDescriptors.Module_Init);
new ModuleDeclarationInstantiationGenerator(this).generate(node, moduleRecord, moduleInit);
// runtime method
MethodCode moduleBody = newMethod(scriptFrame("~module"), MethodDescriptors.Module_Code);
moduleBody(node, moduleBody);
// debug-info method
Function<MethodName, MethodName> debugInfo = null;
if (isEnabled(Compiler.Option.DebugInfo)) {
debugInfo = rt -> {
MethodCode method = newMethod("!module_dbg", MethodDescriptors.DebugInfo);
debugInfo(method, rt, moduleInit.name(), moduleBody.name());
return method.name();
};
}
// runtime-info method
MethodCode runtimeInfo = newMethod("!module_rti", MethodDescriptors.Module_RTI);
RuntimeInfoGenerator.runtimeInfo(node, runtimeInfo, moduleInit.name(), moduleBody.name(), debugInfo);
defaultConstructor(Methods.CompiledModule_Constructor, runtimeInfo.name());
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class ExpressionGenerator method doExpression.
private OutlinedCall doExpression(DoExpression node, CodeVisitor mv) {
if (!codegen.isEnabled(Compiler.Option.NoCompletion)) {
CompletionValueVisitor.performCompletion(node);
}
MethodTypeDescriptor methodDescriptor = DoExpressionCodeVisitor.methodDescriptor(mv);
MethodCode method = codegen.method(mv, "doexpr", methodDescriptor);
return outlined(new DoExpressionCodeVisitor(node, method, mv), body -> {
return statement(node.getStatement(), body);
});
}
use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.
the class ExpressionGenerator method spreadElement.
private OutlinedCall spreadElement(SpreadElementMethod node, CodeVisitor mv) {
MethodTypeDescriptor methodDescriptor = SpreadElementCodeVisitor.methodDescriptor(mv);
MethodCode method = codegen.method(mv, "spread", methodDescriptor);
return outlined(new SpreadElementCodeVisitor(node, method, mv), body -> {
Variable<ArrayObject> array = body.getArrayParameter();
Variable<Integer> index = body.getIndexParameter();
MutableValue<Integer> nextIndex = body.iarrayElement(body.getNextIndexParameter(), 0);
spreadArray(node.getElements(), array, index, body);
body.store(nextIndex, index);
return Completion.Normal;
});
}
Aggregations