Search in sources :

Example 1 with BlockSendArgument

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

the class BlockInliner method buildMethodNodeArguments_.

public VariableDeclarationNode[] buildMethodNodeArguments_(final MethodNode _node) {
    final List<VariableDeclarationNode>[] _arguments;
    _arguments = new List[1];
    _arguments[0] = new java.util.ArrayList();
    st.gravel.support.jvm.ArrayExtensions.with_do_(_astConstants, _node.arguments(), new st.gravel.support.jvm.Block2<Object, BlockSendArgument, VariableDeclarationNode>() {

        @Override
        public Object value_value_(final BlockSendArgument _astConstant, final VariableDeclarationNode _arg) {
            if (_astConstant == null) {
                return _arguments[0].add(_arg);
            }
            return BlockInliner.this;
        }
    });
    for (final String _each : _copiedArgumentNames) {
        _arguments[0].add(BlockInliner.this.variableDeclarationNodeFor_(_each));
    }
    return _arguments[0].toArray(new VariableDeclarationNode[_arguments[0].size()]);
}
Also used : BlockSendArgument(st.gravel.support.compiler.jvm.BlockSendArgument) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) BoundVariableDeclarationNode(st.gravel.support.compiler.ast.BoundVariableDeclarationNode) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with BlockSendArgument

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

the class JVMClassCompiler method addASTConstant_.

public String addASTConstant_(final BlockSendArgument _aBlockSendArgument) {
    final BlockSendArgument _bsa;
    _bsa = _aBlockSendArgument.withName_(this.newConstantName());
    _astConstants.add(_bsa);
    return _bsa.name();
}
Also used : BlockSendArgument(st.gravel.support.compiler.jvm.BlockSendArgument)

Example 3 with BlockSendArgument

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

the class JVMClassCompiler method compileAstInit.

public JVMClassCompiler compileAstInit() {
    final List<JVMInstruction>[] _instructions;
    final int[] _i;
    _i = new int[1];
    _instructions = new List[1];
    _instructions[0] = new java.util.ArrayList();
    _i[0] = 0;
    for (final BlockSendArgument _each : _astConstants) {
        final JVMType _type;
        _type = JVMDynamicObjectType.factory.basicNew();
        _instructions[0].add(ALoad.factory.index_type_(_i[0], _type));
        _instructions[0].add(PutStatic.factory.ownerType_name_type_(_ownerType, _each.name(), _type));
        _i[0] = ((_i[0]) + 1);
        _fields.add(JVMField.factory.ownerType_varName_type_isStatic_(_ownerType, _each.name(), _type, true));
    }
    _instructions[0].add(Return.factory.basicNew());
    _jvmMethods.add(JVMMethod.factory.name_locals_instructions_isStatic_signature_("_astinit", new JVMLocalDeclaration[] {}, _instructions[0].toArray(new JVMInstruction[_instructions[0].size()]), true, JVMMethodType.factory.voidDynamic_(_astConstants.size())));
    return this;
}
Also used : BlockSendArgument(st.gravel.support.compiler.jvm.BlockSendArgument) JVMLocalDeclaration(st.gravel.support.compiler.jvm.JVMLocalDeclaration) JVMType(st.gravel.support.compiler.jvm.JVMType) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with BlockSendArgument

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

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

the class BlockInliner method buildOptimized.

public java.lang.invoke.MethodHandle buildOptimized() {
    final MethodNode[] _node;
    MethodNode _inlined;
    final VariableDeclarationNode[] _arguments;
    final String _selector;
    _node = new MethodNode[1];
    this.log_text_("methodNode: ", _methodNode.sourceString());
    _node[0] = this.link_(_methodNode);
    this.log_text_("linked methodNode: ", _node[0].sourceString());
    for (final String _each : _copiedArgumentNames) {
        final String _newTempName;
        _newTempName = BlockInliner.this.newTempName_for_(_each, _node[0]);
        _copiedArgRenames.put(_each, _newTempName);
    }
    _arguments = this.buildMethodNodeArguments_(_node[0]);
    _selector = _systemMapping.selectorConverter().selectorForNumArgs_(_arguments.length);
    this.log_text_("selector: ", _selector);
    _node[0] = this.newMethodNode_arguments_body_(_selector, _arguments, _node[0].body()).withNlrMarker_(_node[0].nlrMarker());
    this.log_text_("node: ", _node[0].sourceString());
    st.gravel.support.jvm.ArrayExtensions.with_do_(_astConstants, _methodNode.arguments(), new st.gravel.support.jvm.Block2<Object, BlockSendArgument, VariableDeclarationNode>() {

        @Override
        public Object value_value_(final BlockSendArgument _astConstant, final VariableDeclarationNode _arg) {
            if (_astConstant != null) {
                BlockInliner.this.log_text_("block " + _arg.name() + ": ", _astConstant.blockNode().sourceString());
                return _node[0] = ((MethodNode) VariableNodeReplacer.factory.in_replace_with_(_node[0], _arg.name(), BlockInliner.this.renamedBlockNodeFor_(_astConstant)));
            }
            return BlockInliner.this;
        }
    });
    _inlined = LiteralSendInliner.factory.inline_(_node[0]);
    _inlined = this.link_(_inlined);
    this.log_text_("inlined: ", _inlined.sourceString());
    return this.compileMethodNode_(_inlined);
}
Also used : KeywordMethodNode(st.gravel.support.compiler.ast.KeywordMethodNode) UnaryMethodNode(st.gravel.support.compiler.ast.UnaryMethodNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) BoundVariableDeclarationNode(st.gravel.support.compiler.ast.BoundVariableDeclarationNode) BlockSendArgument(st.gravel.support.compiler.jvm.BlockSendArgument)

Aggregations

BlockSendArgument (st.gravel.support.compiler.jvm.BlockSendArgument)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BoundVariableDeclarationNode (st.gravel.support.compiler.ast.BoundVariableDeclarationNode)3 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)3 KeywordMethodNode (st.gravel.support.compiler.ast.KeywordMethodNode)2 MethodNode (st.gravel.support.compiler.ast.MethodNode)2 UnaryMethodNode (st.gravel.support.compiler.ast.UnaryMethodNode)2 JVMClass (st.gravel.support.compiler.jvm.JVMClass)1 JVMField (st.gravel.support.compiler.jvm.JVMField)1 JVMLocalDeclaration (st.gravel.support.compiler.jvm.JVMLocalDeclaration)1 JVMMethod (st.gravel.support.compiler.jvm.JVMMethod)1 JVMMethodCompiler (st.gravel.support.compiler.jvm.JVMMethodCompiler)1 JVMType (st.gravel.support.compiler.jvm.JVMType)1 JVMVariable (st.gravel.support.compiler.jvm.JVMVariable)1