Search in sources :

Example 16 with JVMType

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

the class InvokeVirtual method effectStack_.

@Override
public JVMInstruction effectStack_(final JVMStack _aJVMStack) {
    for (int _temp1 = 0; _temp1 < _signature.arguments().length; _temp1++) {
        final JVMType _each = _signature.arguments()[(_signature.arguments().length - _temp1) - 1];
        _aJVMStack.popType_(_each);
    }
    _aJVMStack.pop();
    if (!_signature.returnType().isVoidType()) {
        _aJVMStack.push_(_signature.returnType());
    }
    return this;
}
Also used : JVMType(st.gravel.support.compiler.jvm.JVMType)

Example 17 with JVMType

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

the class JVMBlockCompiler method createInit.

public JVMMethod createInit() {
    final List<JVMInstruction>[] _instructions;
    final Load[] _read0;
    final JVMLocalDeclaration[] _locals;
    _instructions = new List[1];
    _read0 = new Load[1];
    _instructions[0] = new java.util.ArrayList();
    _read0[0] = Load.factory.index_type_(0, _block.ownerType());
    for (int _temp1 = 0; _temp1 < _block.copiedVariables().length; _temp1++) {
        final int _i = _temp1 + 1;
        final JVMVariable _elem = _block.copiedVariables()[_temp1];
        _instructions[0].add(_read0[0]);
        _instructions[0].add(Load.factory.index_type_(_i, _elem.type()));
        _instructions[0].add(PutField.factory.ownerType_name_type_(_block.ownerType(), _elem.varName(), _elem.type()));
    }
    _instructions[0].add(_read0[0]);
    _instructions[0].add(InvokeSpecial.factory.init_voidArguments_(this.superType(), new JVMType[] {}));
    _instructions[0].add(Return.factory.basicNew());
    _locals = st.gravel.support.jvm.ArrayExtensions.copyWithFirst_(st.gravel.support.jvm.ArrayExtensions.keysAndValuesCollect_(_block.copiedVariables(), new st.gravel.support.jvm.Block2<JVMLocalDeclaration, Integer, JVMVariable>() {

        @Override
        public JVMLocalDeclaration value_value_(final Integer _i, final JVMVariable _var) {
            return (JVMLocalDeclaration) _var.asLocalDeclaration_(_i);
        }
    }), JVMLocalDeclaration.factory.blockSelf());
    return JVMMethod.factory.name_locals_instructions_isStatic_signature_("<init>", _locals, _instructions[0].toArray(new JVMInstruction[_instructions[0].size()]), false, _block.initSignature());
}
Also used : JVMVariable(st.gravel.support.compiler.jvm.JVMVariable) Load(st.gravel.support.compiler.jvm.Load) JVMType(st.gravel.support.compiler.jvm.JVMType) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) JVMLocalDeclaration(st.gravel.support.compiler.jvm.JVMLocalDeclaration) ArrayList(java.util.ArrayList) List(java.util.List) JVMInstruction(st.gravel.support.compiler.jvm.JVMInstruction)

Example 18 with JVMType

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

the class JVMClassCompiler method compileInit.

public JVMClassCompiler compileInit() {
    final List<JVMInstruction> _instructions;
    _instructions = new java.util.ArrayList();
    _instructions.add(Load.factory.index_type_(0, _ownerType));
    _instructions.add(InvokeSpecial.factory.init_voidArguments_(_superType, new JVMType[] {}));
    _instructions.add(Return.factory.basicNew());
    _jvmMethods.add(JVMMethod.factory.name_locals_instructions_isStatic_signature_("<init>", st.gravel.support.jvm.ArrayFactory.with_(JVMLocalDeclaration.factory.self()), _instructions.toArray(new JVMInstruction[_instructions.size()]), false, JVMMethodType.factory.r_void()));
    return this;
}
Also used : JVMType(st.gravel.support.compiler.jvm.JVMType) JVMInstruction(st.gravel.support.compiler.jvm.JVMInstruction) ArrayList(java.util.ArrayList)

Example 19 with JVMType

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

the class DynamicSend method effectStack_.

@Override
public JVMInstruction effectStack_(final JVMStack _aJVMStack) {
    final JVMType _aReceiverType;
    final JVMType[] _anArray;
    _anArray = st.gravel.support.jvm.ArrayExtensions.reverse(new st.gravel.core.Interval(1, _numArgs).collect_(new st.gravel.support.jvm.Block1<JVMType, Integer>() {

        @Override
        public JVMType value_(final Integer _i) {
            return (JVMType) _aJVMStack.pop();
        }
    }));
    _aReceiverType = _aJVMStack.pop();
    st.gravel.support.jvm.ObjectExtensions.assert_(this, _aReceiverType.isObjectType());
    _aJVMStack.push_(this.type());
    return this.withReceiverType_argumentTypes_(_aReceiverType, _anArray);
}
Also used : BigInteger(java.math.BigInteger) JVMType(st.gravel.support.compiler.jvm.JVMType)

Example 20 with JVMType

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

the class JVMMethodCompiler method visitBlockNode_.

@Override
public JVMMethodCompiler visitBlockNode_(final BlockNode _blockNode) {
    final JVMVariable[] _nCopiedVariables;
    final BlockInnerClass[] _innerClassDefinition;
    _innerClassDefinition = new BlockInnerClass[1];
    _nCopiedVariables = this.copiedVariablesForBlockNode_(_blockNode);
    _innerClassDefinition[0] = this.createBlockInnerClass_copiedVariables_(_blockNode, _nCopiedVariables);
    if (_nCopiedVariables.length == 0) {
        JVMMethodCompiler.this.produceConstant_ifAbsentPut_(_blockNode, new st.gravel.support.jvm.Block0<Object>() {

            @Override
            public Object value() {
                JVMMethodCompiler.this.emit_(NewInstance.factory.type_(_innerClassDefinition[0].ownerType()));
                JVMMethodCompiler.this.emit_(Dup.factory.basicNew());
                return JVMMethodCompiler.this.emit_(InvokeSpecial.factory.init_voidArguments_(_innerClassDefinition[0].ownerType(), new JVMType[] {}));
            }
        });
    } else {
        JVMMethodCompiler.this.emit_(NewInstance.factory.type_(_innerClassDefinition[0].ownerType()));
        JVMMethodCompiler.this.emit_(Dup.factory.basicNew());
        for (final JVMVariable _each : _nCopiedVariables) {
            JVMMethodCompiler.this.produceVarRead_(_each.varName());
            JVMMethodCompiler.this.ensureCast_(_each.type());
        }
        JVMMethodCompiler.this.emit_(InvokeSpecial.factory.init_voidArguments_(_innerClassDefinition[0].ownerType(), st.gravel.support.jvm.ArrayExtensions.collect_(_nCopiedVariables, ((st.gravel.support.jvm.Block1<JVMType, JVMVariable>) (new st.gravel.support.jvm.Block1<JVMType, JVMVariable>() {

            @Override
            public JVMType value_(final JVMVariable _each) {
                return (JVMType) _each.type();
            }
        })))));
    }
    return this;
}
Also used : JVMVariable(st.gravel.support.compiler.jvm.JVMVariable) ArrayList(java.util.ArrayList) List(java.util.List) TypeCast(st.gravel.support.compiler.ast.TypeCast) JVMType(st.gravel.support.compiler.jvm.JVMType) BlockInnerClass(st.gravel.support.compiler.jvm.BlockInnerClass)

Aggregations

JVMType (st.gravel.support.compiler.jvm.JVMType)24 ArrayList (java.util.ArrayList)4 List (java.util.List)3 BigInteger (java.math.BigInteger)2 JVMInstruction (st.gravel.support.compiler.jvm.JVMInstruction)2 JVMLocalDeclaration (st.gravel.support.compiler.jvm.JVMLocalDeclaration)2 JVMVariable (st.gravel.support.compiler.jvm.JVMVariable)2 TypeCast (st.gravel.support.compiler.ast.TypeCast)1 BlockInnerClass (st.gravel.support.compiler.jvm.BlockInnerClass)1 BlockSendArgument (st.gravel.support.compiler.jvm.BlockSendArgument)1 JVMArrayType (st.gravel.support.compiler.jvm.JVMArrayType)1 JVMClass (st.gravel.support.compiler.jvm.JVMClass)1 JVMMethodType (st.gravel.support.compiler.jvm.JVMMethodType)1 Load (st.gravel.support.compiler.jvm.Load)1 ObjectClass (st.gravel.support.jvm.ObjectClass)1