Search in sources :

Example 1 with JVMMethodType

use of st.gravel.support.compiler.jvm.JVMMethodType 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)

Example 2 with JVMMethodType

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

the class JavaSystemMappingCompilerTools method createInvoke.

private Invoke createInvoke(Invoke_Factory invokeFactory, JVMDefinedObjectType _type, String _name, Method method) {
    JVMType[] arguments = ArrayExtensions.collect_(method.getParameterTypes(), new Block1<JVMType, Class<?>>() {

        @Override
        public JVMType value_(Class<?> arg1) {
            return jvmTypeForClass_(arg1);
        }
    });
    JVMMethodType _aJVMMethodType = JVMMethodType.factory.returnType_arguments_(jvmTypeForClass_(method.getReturnType()), arguments);
    return invokeFactory.ownerType_name_signature_(_type, _name, _aJVMMethodType);
}
Also used : JVMType(st.gravel.support.compiler.jvm.JVMType) JVMClass(st.gravel.support.compiler.jvm.JVMClass) ObjectClass(st.gravel.support.jvm.ObjectClass) JVMMethodType(st.gravel.support.compiler.jvm.JVMMethodType)

Example 3 with JVMMethodType

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

the class JVMMethodCompiler method produceSuperSend_.

public JVMMethodCompiler produceSuperSend_(final MessageNode _messageNode) {
    final st.gravel.core.Symbol _selector;
    final SuperNode _superNode;
    final String _functionName;
    String _superFN;
    _superNode = ((SuperNode) _messageNode.receiver());
    this.produceVarRead_("self");
    for (final Node _arg : _messageNode.arguments()) {
        JVMMethodCompiler.this.visit_(_arg);
    }
    _selector = st.gravel.core.Symbol.value(_messageNode.selector());
    _functionName = _parent.selectorConverter().selectorAsFunctionName_(_selector);
    if (_isBlock) {
        final JVMMethodType _superSig;
        JVMMethodCompiler.this.ensureCast_(_parent.selfType());
        _superFN = "access$" + _functionName;
        _superSig = JVMMethodType.factory.dynamic_(_messageNode.numArgs()).copyWithFirst_(_parent.selfType());
        JVMMethodCompiler.this.emit_(InvokeStatic.factory.ownerType_name_signature_(_parent.ownerType(), _superFN, _superSig));
        _parent.addInvokeSuper_functionName_numArgs_superReference_superSig_(_superFN, _functionName, _selector.numArgs(), _superNode.reference().toString(), _superSig);
    } else {
        JVMMethodCompiler.this.emit_(DynamicSuperSend.factory.functionName_numArgs_superReference_(_functionName, _selector.numArgs(), _superNode.reference().toString()));
    }
    return this;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) TypeCast(st.gravel.support.compiler.ast.TypeCast) SuperNode(st.gravel.support.compiler.ast.SuperNode) MessageNode(st.gravel.support.compiler.ast.MessageNode) LocalReadNode(st.gravel.support.compiler.ast.LocalReadNode) ArrayAtPutNode(st.gravel.support.compiler.ast.ArrayAtPutNode) FieldReadNode(st.gravel.support.compiler.ast.FieldReadNode) ReturnNode(st.gravel.support.compiler.ast.ReturnNode) IfTrueIfFalseNode(st.gravel.support.compiler.ast.IfTrueIfFalseNode) HolderDeclarationNode(st.gravel.support.compiler.ast.HolderDeclarationNode) ByteArrayLiteralNode(st.gravel.support.compiler.ast.ByteArrayLiteralNode) DoubleLiteralNode(st.gravel.support.compiler.ast.DoubleLiteralNode) BlockNode(st.gravel.support.compiler.ast.BlockNode) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) LocalWriteNode(st.gravel.support.compiler.ast.LocalWriteNode) NilLiteralNode(st.gravel.support.compiler.ast.NilLiteralNode) GlobalReadNode(st.gravel.support.compiler.ast.GlobalReadNode) Node(st.gravel.support.compiler.ast.Node) ReferenceLiteralNode(st.gravel.support.compiler.ast.ReferenceLiteralNode) ArraySizeNode(st.gravel.support.compiler.ast.ArraySizeNode) ToDoNode(st.gravel.support.compiler.ast.ToDoNode) FloatLiteralNode(st.gravel.support.compiler.ast.FloatLiteralNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) SelfNode(st.gravel.support.compiler.ast.SelfNode) CharacterLiteralNode(st.gravel.support.compiler.ast.CharacterLiteralNode) InstanceCreationNode(st.gravel.support.compiler.ast.InstanceCreationNode) CascadeNode(st.gravel.support.compiler.ast.CascadeNode) ArrayAtNode(st.gravel.support.compiler.ast.ArrayAtNode) WhileFalseNode(st.gravel.support.compiler.ast.WhileFalseNode) SymbolLiteralNode(st.gravel.support.compiler.ast.SymbolLiteralNode) WriteHolderNode(st.gravel.support.compiler.ast.WriteHolderNode) BinaryMessageNode(st.gravel.support.compiler.ast.BinaryMessageNode) FieldWriteNode(st.gravel.support.compiler.ast.FieldWriteNode) ReadHolderNode(st.gravel.support.compiler.ast.ReadHolderNode) SuperNode(st.gravel.support.compiler.ast.SuperNode) CreateHolderNode(st.gravel.support.compiler.ast.CreateHolderNode) IsNilNode(st.gravel.support.compiler.ast.IsNilNode) NamespacedVariableNode(st.gravel.support.compiler.ast.NamespacedVariableNode) BooleanAndNode(st.gravel.support.compiler.ast.BooleanAndNode) BooleanOrNode(st.gravel.support.compiler.ast.BooleanOrNode) SequenceNode(st.gravel.support.compiler.ast.SequenceNode) GlobalWriteNode(st.gravel.support.compiler.ast.GlobalWriteNode) IntegerLiteralNode(st.gravel.support.compiler.ast.IntegerLiteralNode) ArrayLiteralNode(st.gravel.support.compiler.ast.ArrayLiteralNode) BooleanLiteralNode(st.gravel.support.compiler.ast.BooleanLiteralNode) IdentityComparisonNode(st.gravel.support.compiler.ast.IdentityComparisonNode) WhileTrueNode(st.gravel.support.compiler.ast.WhileTrueNode) FixedPointLiteralNode(st.gravel.support.compiler.ast.FixedPointLiteralNode) NonLocalReturnNode(st.gravel.support.compiler.ast.NonLocalReturnNode) PushString(st.gravel.support.compiler.jvm.PushString) JVMMethodType(st.gravel.support.compiler.jvm.JVMMethodType)

Aggregations

JVMMethodType (st.gravel.support.compiler.jvm.JVMMethodType)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ArrayAtNode (st.gravel.support.compiler.ast.ArrayAtNode)1 ArrayAtPutNode (st.gravel.support.compiler.ast.ArrayAtPutNode)1 ArrayLiteralNode (st.gravel.support.compiler.ast.ArrayLiteralNode)1 ArraySizeNode (st.gravel.support.compiler.ast.ArraySizeNode)1 BinaryMessageNode (st.gravel.support.compiler.ast.BinaryMessageNode)1 BlockNode (st.gravel.support.compiler.ast.BlockNode)1 BooleanAndNode (st.gravel.support.compiler.ast.BooleanAndNode)1 BooleanLiteralNode (st.gravel.support.compiler.ast.BooleanLiteralNode)1 BooleanOrNode (st.gravel.support.compiler.ast.BooleanOrNode)1 ByteArrayLiteralNode (st.gravel.support.compiler.ast.ByteArrayLiteralNode)1 CascadeNode (st.gravel.support.compiler.ast.CascadeNode)1 CharacterLiteralNode (st.gravel.support.compiler.ast.CharacterLiteralNode)1 CreateHolderNode (st.gravel.support.compiler.ast.CreateHolderNode)1 DoubleLiteralNode (st.gravel.support.compiler.ast.DoubleLiteralNode)1 FieldReadNode (st.gravel.support.compiler.ast.FieldReadNode)1 FieldWriteNode (st.gravel.support.compiler.ast.FieldWriteNode)1 FixedPointLiteralNode (st.gravel.support.compiler.ast.FixedPointLiteralNode)1