Search in sources :

Example 21 with MethodCode

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

the class CodeGenerator method defaultConstructor.

private void defaultConstructor(MethodName superConstructor, MethodName runtimeInfo) {
    MethodCode constructor = code.newConstructor(Modifier.PUBLIC, MethodDescriptors.DefaultConstructor);
    InstructionVisitor mv = new InstructionVisitor(constructor);
    mv.begin();
    mv.loadThis();
    mv.loadParameter(0, Types.Source);
    mv.invoke(runtimeInfo);
    mv.invoke(superConstructor);
    mv._return();
    mv.end();
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 22 with MethodCode

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

the class ExpressionGenerator method expressionMethod.

private OutlinedCall expressionMethod(ExpressionMethod node, CodeVisitor mv) {
    MethodTypeDescriptor methodDescriptor = ExpressionMethodVisitor.methodDescriptor(mv);
    MethodCode method = codegen.method(mv, "expr", methodDescriptor);
    return outlined(new ExpressionMethodVisitor(node, method, mv), body -> {
        ValType type = node.getExpression().accept(this, body);
        assert type != ValType.Empty;
        body.storeCompletionValue(type);
        return Completion.Normal;
    });
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) ValType(com.github.anba.es6draft.compiler.DefaultCodeGenerator.ValType) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)

Example 23 with MethodCode

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

the class ExpressionGenerator method objectMethodDecorators.

private MethodName objectMethodDecorators(ObjectLiteral node, CodeVisitor parent) {
    MethodTypeDescriptor descriptor = ObjectMethodDecoratorsVisitor.methodDescriptor();
    MethodCode method = codegen.method(parent, "objectdecorators", descriptor);
    ObjectMethodDecoratorsVisitor mv = new ObjectMethodDecoratorsVisitor(method);
    mv.begin();
    Variable<ExecutionContext> cx = mv.getExecutionContext();
    Variable<OrdinaryObject> object = mv.getObject();
    // List of <1..n callable, property key>.
    Variable<Object[]> decorators = mv.getDecorators();
    Variable<Object> propertyKey = mv.newVariable("propertyKey", Object.class);
    Variable<Object> propertyDesc = mv.newVariable("propertyDesc", Object.class);
    Variable<Object> result = mv.newVariable("result", Object.class);
    int index = 0;
    for (MethodDefinition methodDef : DecoratedMethods(node.getProperties())) {
        List<Expression> decoratorsList = methodDef.getDecorators();
        assert !decoratorsList.isEmpty();
        mv.store(propertyKey, mv.arrayElement(decorators, index + decoratorsList.size(), Object.class));
        mv.lineInfo(methodDef);
        mv.invoke(Methods.DecoratorOperations_propertyDescriptor, object, propertyKey, cx);
        mv.store(propertyDesc);
        for (Expression decoratorExpr : decoratorsList) {
            Value<Object> decorator = mv.arrayElement(decorators, index++, Object.class);
            invokeDynamicCall(mv, decoratorExpr, decorator, cx, mv.undefinedValue(), object, propertyKey, propertyDesc);
            mv.store(result);
            Jump isObject = new Jump();
            mv.invoke(Methods.Type_isObject, result);
            mv.ifeq(isObject);
            {
                mv.store(propertyDesc, result);
            }
            mv.mark(isObject);
        }
        Jump isObject = new Jump();
        mv.invoke(Methods.Type_isObject, propertyDesc);
        mv.ifeq(isObject);
        {
            mv.lineInfo(methodDef);
            mv.invoke(Methods.DecoratorOperations_defineProperty, object, propertyKey, propertyDesc, cx);
        }
        mv.mark(isObject);
        // Skip over property key element.
        index += 1;
    }
    mv._return();
    mv.end();
    return method.name();
}
Also used : Jump(com.github.anba.es6draft.compiler.assembler.Jump) ExecutionContext(com.github.anba.es6draft.runtime.ExecutionContext) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) OrdinaryObject(com.github.anba.es6draft.runtime.types.builtins.OrdinaryObject) ArrayObject(com.github.anba.es6draft.runtime.types.builtins.ArrayObject) MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode) MethodTypeDescriptor(com.github.anba.es6draft.compiler.assembler.MethodTypeDescriptor)

Example 24 with MethodCode

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

the class ExpressionGenerator method templateLiteral.

private MethodName templateLiteral(TemplateLiteral node) {
    MethodCode method = codegen.method("!template", Type.methodType(Types.String_));
    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();
    return method.name();
}
Also used : MethodCode(com.github.anba.es6draft.compiler.assembler.Code.MethodCode)

Example 25 with MethodCode

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

the class FunctionCodeGenerator method generateClassCall.

private void generateClassCall(ClassDefinition node) {
    MethodDefinition constructor = node.getConstructor();
    MethodDefinition callConstructor = node.getCallConstructor();
    MethodCode method = codegen.newMethod(constructor, FunctionName.Call);
    InstructionVisitor mv = new CallMethodGenerator(method, targetName(constructor), targetType(constructor));
    mv.lineInfo(callConstructor);
    mv.begin();
    generateFunctionCall(callConstructor, OrdinaryConstructorFunction.class, mv);
    mv.end();
}
Also used : MethodDefinition(com.github.anba.es6draft.ast.MethodDefinition) 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