Search in sources :

Example 1 with MethodCode

use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.

the class CodeGenerator method compile.

Entry<MethodName, LabelState> compile(DoExpression node, CodeVisitor mv) {
    if (!isCompiled(node)) {
        if (!isEnabled(Compiler.Option.NoCompletion)) {
            CompletionValueVisitor.performCompletion(node);
        }
        MethodCode method = newMethod(mv.getTopLevelNode(), node);
        DoExpressionCodeVisitor body = new DoExpressionCodeVisitor(node, method, mv);
        body.lineInfo(node);
        // force line-number entry
        body.nop();
        body.begin();
        GeneratorState generatorState = null;
        if (node.hasYieldOrAwait()) {
            generatorState = body.generatorPrologue();
        }
        body.labelPrologue();
        Completion result = statement(node.getStatement(), body);
        if (!result.isAbrupt()) {
            // fall-thru, return `0`.
            body.iconst(0);
            body._return();
        }
        LabelState labelState = body.labelEpilogue(result);
        if (generatorState != null) {
            body.generatorEpilogue(generatorState);
        }
        body.end();
        doExpressionCompletions.put(node, labelState);
    }
    return new SimpleImmutableEntry<>(methodDesc(node), doExpressionCompletions.get(node));
}
Also used : Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) LabelState(com.github.anba.es6draft.compiler.CodeVisitor.LabelState) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) GeneratorState(com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)

Example 2 with MethodCode

use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.

the class CodeGenerator method compile.

void compile(TemplateLiteral node) {
    if (!isCompiled(node)) {
        MethodCode method = newMethod(node);
        InstructionVisitor body = new InstructionVisitor(method);
        body.lineInfo(node);
        body.begin();
        List<TemplateCharacters> strings = TemplateStrings(node);
        body.anewarray(strings.size() * 2, Types.String);
        for (int i = 0, size = strings.size(); i < size; ++i) {
            TemplateCharacters e = strings.get(i);
            int index = i << 1;
            body.astore(index, e.getValue());
            body.astore(index + 1, e.getRawValue());
        }
        body._return();
        body.end();
    }
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) ResumptionPoint(com.github.anba.es6draft.runtime.internal.ResumptionPoint)

Example 3 with MethodCode

use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.

the class CodeGenerator method compile.

MethodName compile(SwitchStatement node, BlockDeclarationInstantiationGenerator generator) {
    if (!isCompiled(node)) {
        MethodCode method = newMethod(node);
        BlockDeclInitVisitor body = new BlockDeclInitVisitor(method);
        body.lineInfo(node);
        body.begin();
        Variable<ExecutionContext> cx = body.getExecutionContext();
        Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = body.getLexicalEnvironment();
        generator.generateMethod(node, cx, env, body);
        body._return();
        body.end();
    }
    return methodDesc(node);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 4 with MethodCode

use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.

the class CodeGenerator method compile.

MethodName compile(PropertyDefinitionsMethod node, boolean hasDecorators, CodeVisitor mv) {
    if (!isCompiled(node)) {
        MethodCode method = newMethod(node);
        PropertyDefinitionsCodeVisitor body = new PropertyDefinitionsCodeVisitor(node, method, mv);
        body.lineInfo(node);
        body.begin();
        Variable<OrdinaryObject> object = body.getObjectParameter();
        Variable<ArrayList<Object>> decorators = hasDecorators ? body.getDecoratorsParameter() : null;
        PropertyGenerator propgen = propertyGenerator(decorators);
        for (PropertyDefinition property : node.getProperties()) {
            body.load(object);
            property.accept(propgen, body);
        }
        body._return();
        body.end();
    }
    return methodDesc(node);
}
Also used : OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayList(java.util.ArrayList) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 5 with MethodCode

use of com.github.anba.es6draft.compiler.assembler.Code.MethodCode in project es6draft by anba.

the class CodeGenerator method compile.

MethodName compile(SwitchStatement node, List<Declaration> declarations, BlockDeclarationInstantiationGenerator generator) {
    MethodCode method = newMethod2(node);
    BlockDeclInitVisitor body = new BlockDeclInitVisitor(method);
    body.lineInfo(node);
    body.begin();
    Variable<ExecutionContext> cx = body.getExecutionContext();
    Variable<LexicalEnvironment<DeclarativeEnvironmentRecord>> env = body.getLexicalEnvironment();
    generator.generateMethod(declarations, cx, env, body);
    body._return();
    body.end();
    return methodDesc(node, method.methodName);
}
Also used : ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) LexicalEnvironment(com.github.anba.es6draft.runtime.LexicalEnvironment) 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