Search in sources :

Example 6 with MethodCode

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

the class CodeGenerator method scriptBody.

private void scriptBody(Script node) {
    MethodCode method = newMethod(node, ScriptName.Code);
    ScriptCodeVisitor body = new ScriptCodeVisitor(method, node);
    body.lineInfo(node);
    body.begin();
    body.loadUndefined();
    body.storeCompletionValue(ValType.Undefined);
    body.enterScope(node);
    Completion result = statements(node.getStatements(), body);
    body.exitScope();
    if (!result.isAbrupt()) {
        body.loadCompletionValue();
        body._return();
    }
    body.end();
}
Also used : Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 7 with MethodCode

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

the class CodeGenerator method conciseFunctionBody.

private boolean conciseFunctionBody(ArrowFunction node) {
    MethodCode method = newMethod(node, FunctionName.Code);
    FunctionCodeVisitor body = new FunctionCodeVisitor(method, node);
    body.lineInfo(node);
    body.begin();
    // call expression in concise function body is always in tail-call position
    Expression expression = node.getExpression();
    body.enterTailCallPosition(expression);
    body.enterFunction(node);
    expressionBoxed(expression, body);
    body.exitFunction();
    body._return();
    body.end();
    return body.hasTailCalls();
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 8 with MethodCode

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

the class CodeGenerator method compile.

MethodName compile(BlockStatement 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 9 with MethodCode

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

the class CodeGenerator method functionBody.

private boolean functionBody(FunctionNode node) {
    MethodCode method = newMethod(node, FunctionName.Code);
    FunctionCodeVisitor body = new FunctionCodeVisitor(method, node);
    body.lineInfo(node);
    body.begin();
    body.enterFunction(node);
    Completion result = statements(node.getStatements(), body);
    body.exitFunction();
    if (!result.isAbrupt()) {
        // fall-thru, return undefined from function
        body.loadUndefined();
        body._return();
    }
    body.end();
    return body.hasTailCalls();
}
Also used : Completion(com.github.anba.es6draft.compiler.StatementGenerator.Completion) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 10 with MethodCode

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

the class CodeGenerator method generatorComprehensionBody.

private boolean generatorComprehensionBody(GeneratorComprehension node) {
    MethodCode method = newMethod(node, FunctionName.Code);
    GeneratorCodeVisitor body = new GeneratorCodeVisitor(method, node);
    body.lineInfo(node);
    body.begin();
    GeneratorState generatorState = body.generatorPrologue();
    body.enterFunction(node);
    EvaluateGeneratorComprehension(this, node, body);
    body.exitFunction();
    body.loadUndefined();
    body._return();
    body.generatorEpilogue(generatorState);
    body.end();
    return body.hasTailCalls();
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) GeneratorState(com.github.anba.es6draft.compiler.CodeVisitor.GeneratorState)

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