Search in sources :

Example 1 with MessageNode

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

the class DiskClassReader method readClass_packageName_file_namespace_.

public ClassNode readClass_packageName_file_namespace_(final String _aName, final st.gravel.core.Symbol _packageName, final java.io.File _aFilename, final String[] _anArray) {
    final Parser _parser;
    MessageNode _expr;
    ClassNode _cn;
    st.gravel.support.jvm.Block3<ClassNode, ClassNode, MessageNode, Parser> _directive;
    final int _start;
    _cn = ClassNode.factory.name_namespacePath_(st.gravel.core.Symbol.value(_aName), st.gravel.support.jvm.ArrayExtensions.collect_(_anArray, ((st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>) (new st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>() {

        @Override
        public st.gravel.core.Symbol value_(final String _each) {
            return (st.gravel.core.Symbol) st.gravel.core.Symbol.value(_each);
        }
    }))));
    _parser = Parser.factory.source_sourceFile_(st.gravel.support.jvm.FilenameExtensions.contentsOfEntireFile(_aFilename), SourceFile.factory.directory_name_packageName_(_aFilename.getParent(), _aFilename.getName(), _packageName));
    _start = _parser.position();
    boolean _temp1 = false;
    while (!_temp1) {
        _temp1 = _parser.atEnd();
        if (!_temp1) {
            _expr = ((MessageNode) _parser.parseExpression());
            _directive = DiskClassReader.this.directiveAt_(_expr.selector());
            _cn = _directive.value_value_value_(_cn, _expr, _parser);
            if (!_parser.atEnd()) {
                _parser.parseBang();
            }
        }
    }
    return ((ClassNode) _parser.setSourcePosition_node_(_start, _cn));
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) ArrayList(java.util.ArrayList) List(java.util.List) Parser(st.gravel.support.compiler.ast.Parser) MessageNode(st.gravel.support.compiler.ast.MessageNode)

Example 2 with MessageNode

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

the class JVMMethodCompiler method produceMessageSend_.

public JVMMethodCompiler produceMessageSend_(final MessageNode _messageNode) {
    final st.gravel.core.Symbol _selector;
    if (_parent.allowBlockInlining() && (st.gravel.support.jvm.ArrayExtensions.anySatisfy_(_messageNode.arguments(), new st.gravel.support.jvm.Predicate1<Expression>() {

        @Override
        public boolean value_(final Expression _e) {
            return _e.isBlockNode();
        }
    }) && (!st.gravel.support.jvm.ArrayExtensions.anySatisfy_(_messageNode.arguments(), new st.gravel.support.jvm.Predicate1<Expression>() {

        @Override
        public boolean value_(final Expression _e) {
            return _e.isBlockNode() && _e.allNodesContains_(((st.gravel.support.jvm.Block1<Boolean, Node>) (new st.gravel.support.jvm.Block1<Boolean, Node>() {

                @Override
                public Boolean value_(final Node _n) {
                    return (boolean) _n.isSuperNode();
                }
            })));
        }
    })))) {
        return JVMMethodCompiler.this.produceBlockInlineMessageSend_(_messageNode);
    }
    for (final Expression _arg : _messageNode.arguments()) {
        JVMMethodCompiler.this.visit_(_arg);
        JVMMethodCompiler.this.ensureCast_(JVMDynamicObjectType.factory.basicNew());
    }
    _selector = st.gravel.core.Symbol.value(_messageNode.selector());
    this.emit_(DynamicMessageSend.factory.functionName_numArgs_(_parent.selectorConverter().selectorAsFunctionName_(_selector), _selector.numArgs()));
    return this;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) TypeCast(st.gravel.support.compiler.ast.TypeCast) Expression(st.gravel.support.compiler.ast.Expression) MessageNode(st.gravel.support.compiler.ast.MessageNode) LocalReadNode(st.gravel.support.compiler.ast.LocalReadNode) ArrayAtPutNode(st.gravel.support.compiler.ast.ArrayAtPutNode) FieldReadNode(st.gravel.support.compiler.ast.FieldReadNode) ReturnNode(st.gravel.support.compiler.ast.ReturnNode) IfTrueIfFalseNode(st.gravel.support.compiler.ast.IfTrueIfFalseNode) HolderDeclarationNode(st.gravel.support.compiler.ast.HolderDeclarationNode) ByteArrayLiteralNode(st.gravel.support.compiler.ast.ByteArrayLiteralNode) DoubleLiteralNode(st.gravel.support.compiler.ast.DoubleLiteralNode) BlockNode(st.gravel.support.compiler.ast.BlockNode) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) LocalWriteNode(st.gravel.support.compiler.ast.LocalWriteNode) NilLiteralNode(st.gravel.support.compiler.ast.NilLiteralNode) GlobalReadNode(st.gravel.support.compiler.ast.GlobalReadNode) Node(st.gravel.support.compiler.ast.Node) ReferenceLiteralNode(st.gravel.support.compiler.ast.ReferenceLiteralNode) ArraySizeNode(st.gravel.support.compiler.ast.ArraySizeNode) ToDoNode(st.gravel.support.compiler.ast.ToDoNode) FloatLiteralNode(st.gravel.support.compiler.ast.FloatLiteralNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) SelfNode(st.gravel.support.compiler.ast.SelfNode) CharacterLiteralNode(st.gravel.support.compiler.ast.CharacterLiteralNode) InstanceCreationNode(st.gravel.support.compiler.ast.InstanceCreationNode) CascadeNode(st.gravel.support.compiler.ast.CascadeNode) ArrayAtNode(st.gravel.support.compiler.ast.ArrayAtNode) WhileFalseNode(st.gravel.support.compiler.ast.WhileFalseNode) SymbolLiteralNode(st.gravel.support.compiler.ast.SymbolLiteralNode) WriteHolderNode(st.gravel.support.compiler.ast.WriteHolderNode) BinaryMessageNode(st.gravel.support.compiler.ast.BinaryMessageNode) FieldWriteNode(st.gravel.support.compiler.ast.FieldWriteNode) ReadHolderNode(st.gravel.support.compiler.ast.ReadHolderNode) SuperNode(st.gravel.support.compiler.ast.SuperNode) CreateHolderNode(st.gravel.support.compiler.ast.CreateHolderNode) IsNilNode(st.gravel.support.compiler.ast.IsNilNode) NamespacedVariableNode(st.gravel.support.compiler.ast.NamespacedVariableNode) BooleanAndNode(st.gravel.support.compiler.ast.BooleanAndNode) BooleanOrNode(st.gravel.support.compiler.ast.BooleanOrNode) SequenceNode(st.gravel.support.compiler.ast.SequenceNode) GlobalWriteNode(st.gravel.support.compiler.ast.GlobalWriteNode) IntegerLiteralNode(st.gravel.support.compiler.ast.IntegerLiteralNode) ArrayLiteralNode(st.gravel.support.compiler.ast.ArrayLiteralNode) BooleanLiteralNode(st.gravel.support.compiler.ast.BooleanLiteralNode) IdentityComparisonNode(st.gravel.support.compiler.ast.IdentityComparisonNode) WhileTrueNode(st.gravel.support.compiler.ast.WhileTrueNode) FixedPointLiteralNode(st.gravel.support.compiler.ast.FixedPointLiteralNode) NonLocalReturnNode(st.gravel.support.compiler.ast.NonLocalReturnNode)

Example 3 with MessageNode

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

the class JVMMethodCompiler method produceBlockInlineMessageSend_.

public JVMMethodCompiler produceBlockInlineMessageSend_(final MessageNode _messageNode) {
    final st.gravel.core.Symbol _selector;
    final String[][] _blockSendConstants;
    final int[] _passedNumArgs;
    final JVMVariable[][] _argumentsToCopy;
    _argumentsToCopy = new JVMVariable[1][];
    _blockSendConstants = new String[1][];
    _passedNumArgs = new int[1];
    _blockSendConstants[0] = new String[] {};
    _argumentsToCopy[0] = new JVMVariable[] {};
    _passedNumArgs[0] = 0;
    for (final Node _arg : _messageNode.arguments()) {
        if (_arg.isBlockNode()) {
            final BlockNode _blockNode;
            final JVMVariable[] _nCopiedVariables;
            _blockNode = ((BlockNode) _arg);
            _nCopiedVariables = JVMMethodCompiler.this.copiedVariablesForBlockNode_(_blockNode);
            for (final JVMVariable _each : _nCopiedVariables) {
                if (!st.gravel.support.jvm.ArrayExtensions.includes_(_argumentsToCopy[0], _each)) {
                    _argumentsToCopy[0] = st.gravel.support.jvm.ArrayExtensions.copyWith_(_argumentsToCopy[0], _each);
                }
            }
            _blockSendConstants[0] = st.gravel.support.jvm.ArrayExtensions.copyWith_(_blockSendConstants[0], JVMMethodCompiler.this.addASTConstant_(BlockSendArgument.factory.blockNode_copiedVariables_(_blockNode, _nCopiedVariables)));
        } else {
            _passedNumArgs[0] = ((_passedNumArgs[0]) + 1);
            JVMMethodCompiler.this.visit_(_arg);
            JVMMethodCompiler.this.ensureCast_(JVMDynamicObjectType.factory.basicNew());
            _blockSendConstants[0] = st.gravel.support.jvm.ArrayExtensions.copyWith_(_blockSendConstants[0], null);
        }
    }
    for (final JVMVariable _each : _argumentsToCopy[0]) {
        JVMMethodCompiler.this.produceVarRead_(_each.varName());
        JVMMethodCompiler.this.ensureCast_(_each.type());
    }
    _selector = st.gravel.core.Symbol.value(_messageNode.selector());
    this.emit_(DynamicLiteralBlockMessageSend.factory.functionName_numArgs_blockSendConstants_constantOwner_copiedArguments_(_parent.selectorConverter().selectorAsFunctionName_(_selector), ((_passedNumArgs[0]) + _argumentsToCopy[0].length), _blockSendConstants[0], _parent.ownerType(), st.gravel.support.jvm.ArrayExtensions.collect_(_argumentsToCopy[0], ((st.gravel.support.jvm.Block1<String, JVMVariable>) (new st.gravel.support.jvm.Block1<String, JVMVariable>() {

        @Override
        public String value_(final JVMVariable _each) {
            return (String) _each.varName();
        }
    })))));
    return this;
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) ArrayList(java.util.ArrayList) List(java.util.List) TypeCast(st.gravel.support.compiler.ast.TypeCast) JVMVariable(st.gravel.support.compiler.jvm.JVMVariable) MessageNode(st.gravel.support.compiler.ast.MessageNode) LocalReadNode(st.gravel.support.compiler.ast.LocalReadNode) ArrayAtPutNode(st.gravel.support.compiler.ast.ArrayAtPutNode) FieldReadNode(st.gravel.support.compiler.ast.FieldReadNode) ReturnNode(st.gravel.support.compiler.ast.ReturnNode) IfTrueIfFalseNode(st.gravel.support.compiler.ast.IfTrueIfFalseNode) HolderDeclarationNode(st.gravel.support.compiler.ast.HolderDeclarationNode) ByteArrayLiteralNode(st.gravel.support.compiler.ast.ByteArrayLiteralNode) DoubleLiteralNode(st.gravel.support.compiler.ast.DoubleLiteralNode) BlockNode(st.gravel.support.compiler.ast.BlockNode) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) LocalWriteNode(st.gravel.support.compiler.ast.LocalWriteNode) NilLiteralNode(st.gravel.support.compiler.ast.NilLiteralNode) GlobalReadNode(st.gravel.support.compiler.ast.GlobalReadNode) Node(st.gravel.support.compiler.ast.Node) ReferenceLiteralNode(st.gravel.support.compiler.ast.ReferenceLiteralNode) ArraySizeNode(st.gravel.support.compiler.ast.ArraySizeNode) ToDoNode(st.gravel.support.compiler.ast.ToDoNode) FloatLiteralNode(st.gravel.support.compiler.ast.FloatLiteralNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) SelfNode(st.gravel.support.compiler.ast.SelfNode) CharacterLiteralNode(st.gravel.support.compiler.ast.CharacterLiteralNode) InstanceCreationNode(st.gravel.support.compiler.ast.InstanceCreationNode) CascadeNode(st.gravel.support.compiler.ast.CascadeNode) ArrayAtNode(st.gravel.support.compiler.ast.ArrayAtNode) WhileFalseNode(st.gravel.support.compiler.ast.WhileFalseNode) SymbolLiteralNode(st.gravel.support.compiler.ast.SymbolLiteralNode) WriteHolderNode(st.gravel.support.compiler.ast.WriteHolderNode) BinaryMessageNode(st.gravel.support.compiler.ast.BinaryMessageNode) FieldWriteNode(st.gravel.support.compiler.ast.FieldWriteNode) ReadHolderNode(st.gravel.support.compiler.ast.ReadHolderNode) SuperNode(st.gravel.support.compiler.ast.SuperNode) CreateHolderNode(st.gravel.support.compiler.ast.CreateHolderNode) IsNilNode(st.gravel.support.compiler.ast.IsNilNode) NamespacedVariableNode(st.gravel.support.compiler.ast.NamespacedVariableNode) BooleanAndNode(st.gravel.support.compiler.ast.BooleanAndNode) BooleanOrNode(st.gravel.support.compiler.ast.BooleanOrNode) SequenceNode(st.gravel.support.compiler.ast.SequenceNode) GlobalWriteNode(st.gravel.support.compiler.ast.GlobalWriteNode) IntegerLiteralNode(st.gravel.support.compiler.ast.IntegerLiteralNode) ArrayLiteralNode(st.gravel.support.compiler.ast.ArrayLiteralNode) BooleanLiteralNode(st.gravel.support.compiler.ast.BooleanLiteralNode) IdentityComparisonNode(st.gravel.support.compiler.ast.IdentityComparisonNode) WhileTrueNode(st.gravel.support.compiler.ast.WhileTrueNode) FixedPointLiteralNode(st.gravel.support.compiler.ast.FixedPointLiteralNode) NonLocalReturnNode(st.gravel.support.compiler.ast.NonLocalReturnNode) PushString(st.gravel.support.compiler.jvm.PushString)

Example 4 with MessageNode

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

the class JVMMethodCompiler method visitCascadeNode_.

@Override
public JVMMethodCompiler visitCascadeNode_(final CascadeNode _cascadeNode) {
    this.visit_(_cascadeNode.receiver());
    for (final MessageNode _message : st.gravel.support.jvm.ArrayExtensions.copyWithoutLast(_cascadeNode.messages())) {
        JVMMethodCompiler.this.emit_(Dup.factory.basicNew());
        JVMMethodCompiler.this.produceMessageSend_(_message);
        JVMMethodCompiler.this.emit_(Pop.factory.basicNew());
    }
    MessageNode[] _temp1 = _cascadeNode.messages();
    this.produceMessageSend_(_temp1[_temp1.length - 1]);
    return this;
}
Also used : MessageNode(st.gravel.support.compiler.ast.MessageNode) BinaryMessageNode(st.gravel.support.compiler.ast.BinaryMessageNode)

Example 5 with MessageNode

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

the class MessageSendRewriter method visitKeywordMessageNode_.

@Override
public Statement visitKeywordMessageNode_(final KeywordMessageNode _anObject) {
    final st.gravel.core.Symbol _selector;
    final st.gravel.support.jvm.Block1<Statement, MessageNode> _res;
    _selector = st.gravel.core.Symbol.value(_anObject.selector());
    st.gravel.support.jvm.Block1<Statement, MessageNode> _temp1 = _specialSelectors.get(_selector);
    _res = ((st.gravel.support.jvm.Block1<Statement, MessageNode>) _temp1);
    if (_res != null) {
        final Statement _trans;
        _trans = _res.value_(_anObject);
        if (_trans != null) {
            return _trans;
        }
    }
    return super.visitKeywordMessageNode_(_anObject);
}
Also used : BinaryMessageNode(st.gravel.support.compiler.ast.BinaryMessageNode) MessageNode(st.gravel.support.compiler.ast.MessageNode) UnaryMessageNode(st.gravel.support.compiler.ast.UnaryMessageNode) KeywordMessageNode(st.gravel.support.compiler.ast.KeywordMessageNode) Statement(st.gravel.support.compiler.ast.Statement)

Aggregations

MessageNode (st.gravel.support.compiler.ast.MessageNode)11 BinaryMessageNode (st.gravel.support.compiler.ast.BinaryMessageNode)8 ArrayList (java.util.ArrayList)5 List (java.util.List)4 KeywordMessageNode (st.gravel.support.compiler.ast.KeywordMessageNode)4 ArrayAtNode (st.gravel.support.compiler.ast.ArrayAtNode)3 ArrayAtPutNode (st.gravel.support.compiler.ast.ArrayAtPutNode)3 ArrayLiteralNode (st.gravel.support.compiler.ast.ArrayLiteralNode)3 ArraySizeNode (st.gravel.support.compiler.ast.ArraySizeNode)3 BlockNode (st.gravel.support.compiler.ast.BlockNode)3 BooleanAndNode (st.gravel.support.compiler.ast.BooleanAndNode)3 BooleanLiteralNode (st.gravel.support.compiler.ast.BooleanLiteralNode)3 BooleanOrNode (st.gravel.support.compiler.ast.BooleanOrNode)3 ByteArrayLiteralNode (st.gravel.support.compiler.ast.ByteArrayLiteralNode)3 CascadeNode (st.gravel.support.compiler.ast.CascadeNode)3 CharacterLiteralNode (st.gravel.support.compiler.ast.CharacterLiteralNode)3 CreateHolderNode (st.gravel.support.compiler.ast.CreateHolderNode)3 DoubleLiteralNode (st.gravel.support.compiler.ast.DoubleLiteralNode)3 Expression (st.gravel.support.compiler.ast.Expression)3 FieldReadNode (st.gravel.support.compiler.ast.FieldReadNode)3