Search in sources :

Example 1 with JVMInstruction

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

the class JVMMethodCompiler method newFrame_.

public Frame newFrame_(final st.gravel.support.jvm.Block0<Object> _aBlock) {
    final JVMStack _oldStack;
    final List<JVMInstruction> _oldInstructions;
    final Frame _frame;
    final Map<String, JVMLocalDeclaration> _oldLocals;
    _oldStack = _stack;
    _oldInstructions = _instructions;
    _oldLocals = _locals;
    this.reset();
    _locals = st.gravel.support.jvm.DictionaryExtensions.copy(_oldLocals);
    _aBlock.value();
    _frame = Frame.factory.instructions_endStack_(_instructions.toArray(new JVMInstruction[_instructions.size()]), _stack);
    _stack = _oldStack;
    _instructions = _oldInstructions;
    _locals = _oldLocals;
    return _frame;
}
Also used : Frame(st.gravel.support.compiler.jvm.Frame) JVMLocalDeclaration(st.gravel.support.compiler.jvm.JVMLocalDeclaration) PushString(st.gravel.support.compiler.jvm.PushString) JVMStack(st.gravel.support.compiler.jvm.JVMStack) JVMInstruction(st.gravel.support.compiler.jvm.JVMInstruction)

Example 2 with JVMInstruction

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

the class JVMClassCompiler method compileClone.

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

Example 3 with JVMInstruction

use of st.gravel.support.compiler.jvm.JVMInstruction 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 4 with JVMInstruction

use of st.gravel.support.compiler.jvm.JVMInstruction 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 5 with JVMInstruction

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

the class JVMClassCompiler method addInvokeSuper_functionName_numArgs_superReference_superSig_.

public JVMClassCompiler addInvokeSuper_functionName_numArgs_superReference_superSig_(final String _name, final String _functionName, final int _numArgs, final String _superReference, final JVMMethodType _superSig) {
    final List<JVMInstruction> _instructions;
    _instructions = new java.util.ArrayList();
    for (int _i = 0; _i <= _numArgs; _i++) {
        _instructions.add(Load.factory.index_type_(_i, JVMDynamicObjectType.factory.basicNew()));
    }
    _instructions.add(DynamicSuperSend.factory.functionName_numArgs_superReference_(_functionName, _numArgs, _superReference));
    _instructions.add(AReturn.factory.basicNew());
    _jvmMethods.add(JVMMethod.factory.name_locals_instructions_isStatic_signature_(_name, JVMLocalDeclaration.factory.localsForSignature_(_superSig.arguments()), _instructions.toArray(new JVMInstruction[_instructions.size()]), true, _superSig));
    return this;
}
Also used : JVMInstruction(st.gravel.support.compiler.jvm.JVMInstruction) ArrayList(java.util.ArrayList)

Aggregations

JVMInstruction (st.gravel.support.compiler.jvm.JVMInstruction)8 ArrayList (java.util.ArrayList)5 JVMLocalDeclaration (st.gravel.support.compiler.jvm.JVMLocalDeclaration)4 Frame (st.gravel.support.compiler.jvm.Frame)2 JVMStack (st.gravel.support.compiler.jvm.JVMStack)2 JVMType (st.gravel.support.compiler.jvm.JVMType)2 PushString (st.gravel.support.compiler.jvm.PushString)2 BigInteger (java.math.BigInteger)1 List (java.util.List)1 Label (org.objectweb.asm.Label)1 JVMVariable (st.gravel.support.compiler.jvm.JVMVariable)1 Load (st.gravel.support.compiler.jvm.Load)1