Search in sources :

Example 21 with VariableDeclarationNode

use of st.gravel.support.compiler.ast.VariableDeclarationNode 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 22 with VariableDeclarationNode

use of st.gravel.support.compiler.ast.VariableDeclarationNode 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 23 with VariableDeclarationNode

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

the class BlockNode method innerSourceOn_.

@Override
public BlockNode innerSourceOn_(final StringBuilder _aStream) {
    _aStream.append('[');
    if (_arguments.length != 0) {
        for (final VariableDeclarationNode _arg : _arguments) {
            _aStream.append(':');
            _arg.sourceOn_(_aStream);
            _aStream.append(' ');
        }
        _aStream.append('|');
    }
    _body.sourceOn_(_aStream);
    _aStream.append(']');
    return this;
}
Also used : VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode)

Example 24 with VariableDeclarationNode

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

the class DiskClassWriter method writeClass_in_.

public DiskClassWriter writeClass_in_(final ClassNode _aClassNode, final java.io.File _aFilename) {
    final java.io.File _nsFn;
    final java.io.File _clFn;
    final StringBuilder[] _str;
    final VariableNode[] _reader;
    _reader = new VariableNode[1];
    _str = new StringBuilder[1];
    _nsFn = ((java.io.File) st.gravel.support.jvm.ArrayExtensions.inject_into_(_aClassNode.reference().namespace().path(), _aFilename, ((st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>) (new st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>() {

        @Override
        public java.io.File value_value_(final java.io.File _fn, final st.gravel.core.Symbol _each) {
            return (java.io.File) new java.io.File(_fn, _each.asString());
        }
    }))));
    _nsFn.mkdirs();
    _clFn = new java.io.File(_nsFn, _aClassNode.reference().name().asString() + ".st");
    _str[0] = st.gravel.support.jvm.WriteStreamFactory.on_(new String());
    _reader[0] = VariableNode.factory.name_("reader");
    if (_aClassNode.isExtension()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_(_aClassNode.isTrait() ? "extendTrait:" : "extendClass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString())), _str[0]);
    } else {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_(_aClassNode.isTrait() ? "defineTrait:superclass:" : "defineClass:superclass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString()), DiskClassWriter.this.referenceAsLiteralNode_(_aClassNode.superclassReference())), _str[0]);
        for (final SharedDeclarationNode _sv : _aClassNode.metaclassNode().sharedVariables()) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("defineSharedVariable:init:", DiskClassWriter.this.asLiteralNode_(_sv.name()), DiskClassWriter.this.initializerSource_(_sv.initializer())), _str[0]);
        }
    }
    for (final Node _each : TraitUsageToDirectiveConverter.factory.visit_(_aClassNode.traitUsage())) {
        DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
    }
    for (final Node _each : ClassTraitUsageToDirectiveConverter.factory.visit_(_aClassNode.metaclassNode().traitUsage())) {
        DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
    }
    for (final VariableDeclarationNode _each : _aClassNode.instVars()) {
        if (_each.type() == null) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
        } else {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
        }
    }
    for (final VariableDeclarationNode _each : _aClassNode.metaclassNode().instVars()) {
        if (_each.type() == null) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
        } else {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addClassInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
        }
    }
    for (final Map.Entry<String, String> _temp1 : _aClassNode.properties().entrySet()) {
        String _k = _temp1.getKey();
        String _v = _temp1.getValue();
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("propertyAt:put:", DiskClassWriter.this.asLiteralNode_(_k), DiskClassWriter.this.asLiteralNode_(_v)), _str[0]);
    }
    for (final MethodNode _each : _aClassNode.methods()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
        DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
    }
    for (final MethodNode _each : _aClassNode.metaclassNode().methods()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
        DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
    }
    st.gravel.support.jvm.StringExtensions.writeToFile_(_str[0].toString(), _clFn);
    return this;
}
Also used : VariableNode(st.gravel.support.compiler.ast.VariableNode) NilLiteralNode(st.gravel.support.compiler.ast.NilLiteralNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Node(st.gravel.support.compiler.ast.Node) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode) NamespaceNode(st.gravel.support.compiler.ast.NamespaceNode) ClassNode(st.gravel.support.compiler.ast.ClassNode) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) PackageNode(st.gravel.support.compiler.ast.PackageNode) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) VariableNode(st.gravel.support.compiler.ast.VariableNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)24 ArrayList (java.util.ArrayList)6 List (java.util.List)6 MethodNode (st.gravel.support.compiler.ast.MethodNode)6 Statement (st.gravel.support.compiler.ast.Statement)5 HashMap (java.util.HashMap)4 BoundVariableDeclarationNode (st.gravel.support.compiler.ast.BoundVariableDeclarationNode)4 PragmaNode (st.gravel.support.compiler.ast.PragmaNode)4 SequenceNode (st.gravel.support.compiler.ast.SequenceNode)4 TypeNode (st.gravel.support.compiler.ast.TypeNode)4 Map (java.util.Map)3 BlockTypeNode (st.gravel.support.compiler.ast.BlockTypeNode)3 ClassNode (st.gravel.support.compiler.ast.ClassNode)3 InstanceTypeNode (st.gravel.support.compiler.ast.InstanceTypeNode)3 SelfTypeNode (st.gravel.support.compiler.ast.SelfTypeNode)3 BlockSendArgument (st.gravel.support.compiler.jvm.BlockSendArgument)3 Expression (st.gravel.support.compiler.ast.Expression)2 KeywordMethodNode (st.gravel.support.compiler.ast.KeywordMethodNode)2 SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)2 TypeCast (st.gravel.support.compiler.ast.TypeCast)2