Search in sources :

Example 1 with FunctionName

use of com.github.anba.es6draft.compiler.CodeGenerator.FunctionName in project es6draft by anba.

the class RuntimeInfoGenerator method runtimeInfo.

private <T extends Node> void runtimeInfo(T def, FunctionNode node, boolean tailCall, boolean tailConstruct, String source, int sourceSplit, BiConsumer<T, FunctionName> debugInfo) {
    FunctionName constructName = tailConstruct ? FunctionName.ConstructTailCall : FunctionName.Construct;
    InstructionAssembler asm = new InstructionAssembler(codegen.newMethod(node, FunctionName.RTI));
    asm.begin();
    asm.invokedynamic("methodInfo", Type.methodType(Types.Object), RUNTIME_INFO_BOOTSTRAP);
    asm.aconst(node.getFunctionName());
    asm.iconst(functionFlags(node, tailCall, tailConstruct));
    asm.iconst(ExpectedArgumentCount(node.getParameters()));
    if (hasMappedOrLegacyArguments(node)) {
        // TODO: Make this a compact string (to save bytecode and memory size)?
        newStringArray(asm, mappedNames(node.getParameters()));
    } else {
        asm.anull();
    }
    asm.aconst(source);
    asm.iconst(sourceSplit);
    if (node.isAsync() || node.isGenerator()) {
        asm.handle(codegen.methodDesc(node, FunctionName.Code));
    } else {
        asm.anull();
    }
    asm.handle(codegen.methodDesc(node, FunctionName.Call));
    if (node.isConstructor()) {
        asm.handle(codegen.methodDesc(node, constructName));
    } else {
        asm.anull();
    }
    if (codegen.isEnabled(Compiler.Option.DebugInfo)) {
        debugInfo.accept(def, constructName);
        asm.handle(codegen.methodDesc(node, FunctionName.DebugInfo));
        asm.invoke(Methods.RTI_newFunctionDebug);
    } else {
        asm.invoke(Methods.RTI_newFunction);
    }
    asm._return();
    asm.end();
}
Also used : FunctionName(com.github.anba.es6draft.compiler.CodeGenerator.FunctionName) InstructionAssembler(com.github.anba.es6draft.compiler.assembler.InstructionAssembler)

Aggregations

FunctionName (com.github.anba.es6draft.compiler.CodeGenerator.FunctionName)1 InstructionAssembler (com.github.anba.es6draft.compiler.assembler.InstructionAssembler)1