Search in sources :

Example 21 with MethodNode

use of st.gravel.support.compiler.ast.MethodNode in project gravel by gravel-st.

the class ClassDescriptionMirror method getMethodMirror.

public MethodMirror getMethodMirror(Object selObject) {
    if (!(selObject instanceof Symbol))
        return null;
    Symbol selector = (Symbol) selObject;
    MethodNode method = getMethodNode(selector);
    if (method == null) {
        return null;
    }
    return new MethodMirror(method, this);
}
Also used : MethodNode(st.gravel.support.compiler.ast.MethodNode) Symbol(st.gravel.core.Symbol)

Example 22 with MethodNode

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

Example 23 with MethodNode

use of st.gravel.support.compiler.ast.MethodNode in project gravel by gravel-st.

the class BlockInliner method buildNonOptimized.

public java.lang.invoke.MethodHandle buildNonOptimized() {
    final MethodNode _node;
    final VariableDeclarationNode[] _arguments;
    final List<Expression>[] _sendArgs;
    _sendArgs = new List[1];
    for (final String _each : _copiedArgumentNames) {
        final String _newTempName;
        _newTempName = BlockInliner.this.newTempName_for_(_each, _methodNode);
        _copiedArgRenames.put(_each, _newTempName);
    }
    _arguments = this.buildMethodNodeArguments_(_methodNode);
    _sendArgs[0] = new java.util.ArrayList();
    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) {
                return _sendArgs[0].add(_arg.asVariableNode());
            } else {
                return _sendArgs[0].add(BlockInliner.this.renamedBlockNodeFor_(_astConstant));
            }
        }
    });
    _node = this.newMethodNode_arguments_body_(_systemMapping.selectorConverter().selectorForNumArgs_(_arguments.length), _arguments, SequenceNode.factory.return_(SelfNode.factory.basicNew().send_withAll_(_methodNode.selector(), _sendArgs[0].toArray(new Expression[_sendArgs[0].size()]))));
    this.log_text_("nonOptimized: ", _node.sourceString());
    return this.compileMethodNode_allowBlockInlining_(this.link_(_node), false);
}
Also used : BlockSendArgument(st.gravel.support.compiler.jvm.BlockSendArgument) ArrayList(java.util.ArrayList) 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) ArrayList(java.util.ArrayList) List(java.util.List)

Example 24 with MethodNode

use of st.gravel.support.compiler.ast.MethodNode in project gravel by gravel-st.

the class MetaclassNode method allMethodsIn_do_.

@Override
public MetaclassNode allMethodsIn_do_(final SystemNode _aSystemNode, final st.gravel.support.jvm.Block1<Object, MethodNode> _aBlock) {
    final ClassDescriptionNode _scn;
    for (final MethodNode _temp1 : _methods) {
        _aBlock.value_(_temp1);
    }
    _scn = this.superclassNodeIn_(_aSystemNode);
    if (_scn == null) {
        return MetaclassNode.this;
    }
    _scn.allMethodsIn_do_(_aSystemNode, _aBlock);
    return this;
}
Also used : MethodNode(st.gravel.support.compiler.ast.MethodNode) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode)

Example 25 with MethodNode

use of st.gravel.support.compiler.ast.MethodNode in project gravel by gravel-st.

the class ClassDescriptionNode method withMethodNode_.

public ClassDescriptionNode withMethodNode_(final MethodNode _aMethodNode) {
    final MethodNode _current;
    _current = this.methodOrNilAt_(_aMethodNode.selector());
    if (_current != null) {
        throw new RuntimeException("Duplicate selector: " + _aMethodNode.selector());
    }
    return this.copy().pvtSetMethods_(st.gravel.support.jvm.ArrayExtensions.copyWith_(_methods, _aMethodNode));
}
Also used : MethodNode(st.gravel.support.compiler.ast.MethodNode)

Aggregations

MethodNode (st.gravel.support.compiler.ast.MethodNode)28 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)10 UnaryMethodNode (st.gravel.support.compiler.ast.UnaryMethodNode)9 HashMap (java.util.HashMap)7 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ExtensionClassPartMapping (st.gravel.support.compiler.ast.ExtensionClassPartMapping)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 BoundVariableDeclarationNode (st.gravel.support.compiler.ast.BoundVariableDeclarationNode)4 ClassNode (st.gravel.support.compiler.ast.ClassNode)4 IdentityClassPartMapping (st.gravel.support.compiler.ast.IdentityClassPartMapping)4 Map (java.util.Map)3 Symbol (st.gravel.core.Symbol)3 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)2 ClassMapping (st.gravel.support.compiler.ast.ClassMapping)2 KeywordMethodNode (st.gravel.support.compiler.ast.KeywordMethodNode)2 MethodMapping (st.gravel.support.compiler.ast.MethodMapping)2 PackageNode (st.gravel.support.compiler.ast.PackageNode)2