Search in sources :

Example 1 with JVMField

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

the class JVMBlockCompiler method compileBlock.

public JVMClass compileBlock() {
    final JVMMethod _m;
    final JVMField[] _fields;
    final JVMMethodCompiler _methodCompiler;
    final JVMClass _jvmClass;
    _fields = st.gravel.support.jvm.ArrayExtensions.collect_(_block.copiedVariables(), ((st.gravel.support.jvm.Block1<JVMField, JVMVariable>) (new st.gravel.support.jvm.Block1<JVMField, JVMVariable>() {

        @Override
        public JVMField value_(final JVMVariable _each) {
            return (JVMField) _each.asField_isStatic_(_block.ownerType(), false);
        }
    })));
    _methodCompiler = JVMMethodCompiler.factory.parent_(_parent);
    _methodCompiler.isStatic_(false);
    _m = _methodCompiler.buildBlock_copiedVariables_blockType_(_block.blockNode(), _fields, _block.ownerType());
    _jvmClass = JVMClass.factory.type_superType_fields_methods_astConstants_(_block.ownerType(), this.superType(), _fields, st.gravel.support.jvm.ArrayFactory.with_with_(_m, this.createInit()), new BlockSendArgument[] {});
    if (_block.blockNode().sourcePosition() != null) {
        _jvmClass.source_(_block.blockNode().sourcePosition().sourceFile().name());
    }
    return _jvmClass;
}
Also used : JVMClass(st.gravel.support.compiler.jvm.JVMClass) JVMVariable(st.gravel.support.compiler.jvm.JVMVariable) JVMMethod(st.gravel.support.compiler.jvm.JVMMethod) BlockSendArgument(st.gravel.support.compiler.jvm.BlockSendArgument) JVMField(st.gravel.support.compiler.jvm.JVMField) JVMMethodCompiler(st.gravel.support.compiler.jvm.JVMMethodCompiler)

Example 2 with JVMField

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

the class JVMMethodCompiler method buildBlock_copiedVariables_blockType_.

public JVMMethod buildBlock_copiedVariables_blockType_(final BlockNode _aBlockNode, final JVMField[] _anArray, final JVMDefinedObjectType _blockType) {
    final int _numArgs;
    this.reset();
    _isBlock = true;
    _copiedVariables = new java.util.HashMap<String, JVMField>();
    for (final JVMField _each : _anArray) {
        _copiedVariables.put(_each.varName(), _each);
    }
    _copiedVariablesOwner = this.newTempName();
    this.pushLocal_type_(_copiedVariablesOwner, _blockType);
    for (final VariableDeclarationNode _each : _aBlockNode.arguments()) {
        JVMMethodCompiler.this.pushLocal_(_each.name());
    }
    this.produceBlockBody_(_aBlockNode.body());
    _numArgs = _aBlockNode.arguments().length;
    _methodName = _parent.selectorConverter().functionNameForNumArgs_(_numArgs);
    _signature = JVMMethodType.factory.dynamic_(_numArgs);
    return this.buildMethod();
}
Also used : VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) JVMField(st.gravel.support.compiler.jvm.JVMField) PushString(st.gravel.support.compiler.jvm.PushString)

Example 3 with JVMField

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

the class ASMClassWriter method createBytes.

protected byte[] createBytes() {
    cw = newClassWriter();
    cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, jvmClass.type().className(), null, jvmClass.superType().className(), new String[] { "java/lang/Cloneable" });
    if (jvmClass.source() != null) {
        cw.visitSource(jvmClass.source(), null);
    }
    for (JVMField field : jvmClass.fields()) {
        createField(field);
    }
    for (JVMMethod method : jvmClass.methods()) {
        createMethod(method);
    }
    cw.visitEnd();
    return cw.toByteArray();
}
Also used : JVMMethod(st.gravel.support.compiler.jvm.JVMMethod) JVMField(st.gravel.support.compiler.jvm.JVMField)

Example 4 with JVMField

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

the class JVMMethodCompiler method produceVarRead_.

public JVMMethodCompiler produceVarRead_(final String _aString) {
    final JVMLocalDeclaration _local;
    final JVMField _cv;
    JVMLocalDeclaration _temp1 = _locals.get(_aString);
    _local = ((JVMLocalDeclaration) _temp1);
    if (_local != null) {
        return JVMMethodCompiler.this.emit_(Load.factory.local_(_local));
    }
    _cv = _copiedVariables.get(_aString);
    this.produceVarRead_(_copiedVariablesOwner);
    this.emit_(_cv.asGetField());
    return this;
}
Also used : JVMField(st.gravel.support.compiler.jvm.JVMField) JVMLocalDeclaration(st.gravel.support.compiler.jvm.JVMLocalDeclaration)

Aggregations

JVMField (st.gravel.support.compiler.jvm.JVMField)4 JVMMethod (st.gravel.support.compiler.jvm.JVMMethod)2 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)1 BlockSendArgument (st.gravel.support.compiler.jvm.BlockSendArgument)1 JVMClass (st.gravel.support.compiler.jvm.JVMClass)1 JVMLocalDeclaration (st.gravel.support.compiler.jvm.JVMLocalDeclaration)1 JVMMethodCompiler (st.gravel.support.compiler.jvm.JVMMethodCompiler)1 JVMVariable (st.gravel.support.compiler.jvm.JVMVariable)1 PushString (st.gravel.support.compiler.jvm.PushString)1