Search in sources :

Example 16 with MethodCode

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;
    });
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)

Example 17 with MethodCode

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);
    });
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)

Example 18 with MethodCode

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();
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 19 with MethodCode

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();
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)

Example 20 with MethodCode

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());
}
Also used : MethodName(com.github.anba.es6draft.compiler.assembler.MethodName) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Aggregations

MethodCode (com.github.anba.es6draft.compiler.assembler.Code.MethodCode)46 MethodTypeDescriptor (com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)12 Completion (com.github.anba.es6draft.compiler.StatementGenerator.Completion)8 ExecutionContext (com.github.anba.es6draft.runtime.ExecutionContext)6 OrdinaryObject (com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject)6 GeneratorState (com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)5 MethodName (com.github.anba.es6draft.compiler.assembler.MethodName)4 LexicalEnvironment (com.github.anba.es6draft.runtime.LexicalEnvironment)4 OrdinaryConstructorFunction (com.github.anba.es6draft.runtime.types.builtins.OrdinaryConstructorFunction)4 SwitchClause (com.github.anba.es6draft.ast.SwitchClause)3 Jump (com.github.anba.es6draft.compiler.assembler.Jump)3 LabelState (com.github.anba.es6draft.compiler.CodeVisitor.LabelState)2 ResumptionPoint (com.github.anba.es6draft.runtime.internal.ResumptionPoint)2 ArrayObject (com.github.anba.es6draft.runtime.types.builtins.ArrayObject)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2 ArrayList (java.util.ArrayList)2 MethodDefinition (com.github.anba.es6draft.ast.MethodDefinition)1 ValType (com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType)1 InstanceMethod (com.github.anba.es6draft.runtime.language.ClassOperations.InstanceMethod)1 ScriptObject (com.github.anba.es6draft.runtime.types.ScriptObject)1