Search in sources :

Example 1 with Invoke

use of st.gravel.support.compiler.jvm.Invoke in project gravel by gravel-st.

the class JVMMethodCompiler method producePrimitive_def_.

public JVMMethodCompiler producePrimitive_def_(final MethodNode _aMethodNode, final String[] _prim) {
    final JVMDefinedObjectType _ownerType;
    final String _name;
    final Invoke _invoke;
    final JVMMethodType[] _staticSignature;
    final int[] _selfOffset;
    _selfOffset = new int[1];
    _staticSignature = new JVMMethodType[1];
    _ownerType = JVMDefinedObjectType.factory.dottedClassName_(_prim[0]);
    _name = _prim[1];
    _invoke = _parent.createInvokeInstruction_name_numArgs_(_ownerType, _name, _aMethodNode.arguments().length);
    if (_invoke == null) {
        JVMMethodCompiler.this.emit_(NewInstance.factory.type_(JVMDefinedObjectType.factory.runtimeException()));
        JVMMethodCompiler.this.emit_(Dup.factory.basicNew());
        JVMMethodCompiler.this.pushString_("Cannot find method " + _ownerType.descriptorString() + ">>" + _name);
        JVMMethodCompiler.this.emit_(InvokeSpecial.factory.init_voidArguments_(JVMDefinedObjectType.factory.runtimeException(), st.gravel.support.jvm.ArrayFactory.with_(JVMDefinedObjectType.factory.string())));
        JVMMethodCompiler.this.emit_(AThrow.factory.basicNew());
        return JVMMethodCompiler.this;
    }
    _staticSignature[0] = _invoke.staticSignature();
    if (_invoke.isInvokeStatic() && st.gravel.support.jvm.IntegerExtensions.equals_(_invoke.signature().numArgs(), _aMethodNode.numArgs())) {
        _selfOffset[0] = 0;
    } else {
        _selfOffset[0] = 1;
        JVMMethodCompiler.this.produceVarRead_("self");
        JVMMethodCompiler.this.ensureCast_(_staticSignature[0].arguments()[0]);
    }
    for (int _temp1 = 0; _temp1 < _aMethodNode.arguments().length; _temp1++) {
        final int _i = _temp1 + 1;
        final VariableDeclarationNode _each = _aMethodNode.arguments()[_temp1];
        JVMMethodCompiler.this.produceVarRead_(_each.name());
        JVMMethodCompiler.this.ensureCast_(_staticSignature[0].arguments()[(_i + (_selfOffset[0])) - 1]);
    }
    this.emit_(_invoke);
    if (_staticSignature[0].returnType().isVoidType()) {
        JVMMethodCompiler.this.produceVarRead_("self");
    } else {
        JVMMethodCompiler.this.ensureCast_(JVMDynamicObjectType.factory.basicNew());
    }
    this.emit_(AReturn.factory.basicNew());
    return this;
}
Also used : VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) JVMDefinedObjectType(st.gravel.support.compiler.jvm.JVMDefinedObjectType) PushString(st.gravel.support.compiler.jvm.PushString) JVMMethodType(st.gravel.support.compiler.jvm.JVMMethodType) Invoke(st.gravel.support.compiler.jvm.Invoke)

Aggregations

VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)1 Invoke (st.gravel.support.compiler.jvm.Invoke)1 JVMDefinedObjectType (st.gravel.support.compiler.jvm.JVMDefinedObjectType)1 JVMMethodType (st.gravel.support.compiler.jvm.JVMMethodType)1 PushString (st.gravel.support.compiler.jvm.PushString)1