Search in sources :

Example 6 with Expression

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

the class LiteralSendInliner method produceBlock_arguments_.

public Statement produceBlock_arguments_(final BlockNode _block, final Expression[] _arguments) {
    final SequenceNode[] _body;
    final Statement[] _stmts;
    final Expression[] _argTemps;
    final VariableNode _result;
    final Statement _lastStatement;
    _body = new SequenceNode[1];
    _body[0] = _block.body();
    if (_body[0].statements().length == 0) {
        return NilLiteralNode.factory.basicNew();
    }
    for (final VariableDeclarationNode _temp : _block.body().temporaries()) {
        _body[0] = ((SequenceNode) VariableRenamer.factory.in_rename_to_(_body[0], _temp.name(), LiteralSendInliner.this.newTempSuggestion_(_temp.name()).name()));
    }
    _argTemps = st.gravel.support.jvm.ArrayExtensions.collect_(_arguments, ((st.gravel.support.jvm.Block1<Expression, Expression>) (new st.gravel.support.jvm.Block1<Expression, Expression>() {

        @Override
        public Expression value_(final Expression _each) {
            if (_each.isVariableNode()) {
                return _each;
            } else {
                final VariableNode _t;
                _t = LiteralSendInliner.this.newTempSuggestion_("extract");
                LiteralSendInliner.this.extraEmit_(LocalWriteNode.factory.name_value_(_t.name(), _each));
                return _t;
            }
        }
    })));
    _stmts = _body[0].statements();
    int _temp1 = (_stmts.length - 1);
    for (int _i = 1; _i <= _temp1; _i++) {
        final Statement _stmt;
        _stmt = _stmts[_i - 1];
        LiteralSendInliner.this.extraEmit_(LiteralSendInliner.this.in_replaceAll_with_(_stmt, _block.arguments(), _argTemps));
    }
    _lastStatement = this.in_replaceAll_with_(_stmts[_stmts.length - 1], _block.arguments(), _argTemps);
    if (_lastStatement.isReturnNode()) {
        return _lastStatement;
    }
    _result = this.newTempSuggestion_("result");
    this.extraEmit_(_result.assign_(((Expression) _lastStatement)));
    return _result;
}
Also used : Statement(st.gravel.support.compiler.ast.Statement) SequenceNode(st.gravel.support.compiler.ast.SequenceNode) VariableNode(st.gravel.support.compiler.ast.VariableNode) Expression(st.gravel.support.compiler.ast.Expression) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode)

Example 7 with Expression

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

the class LiteralSendInliner method visitReturnNode_.

@Override
public Statement visitReturnNode_(final ReturnNode _anObject) {
    final Statement _value;
    _value = ((Statement) this.visit_(_anObject.value()));
    if (_value.isReturnNode()) {
        return _value;
    }
    return ReturnNode.factory.value_(((Expression) _value));
}
Also used : Expression(st.gravel.support.compiler.ast.Expression) Statement(st.gravel.support.compiler.ast.Statement)

Example 8 with Expression

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

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

the class MethodNode method primitiveIn_.

public String[] primitiveIn_(final String _className) {
    final PragmaNode _pragma;
    final Expression _argument;
    final ArrayLiteralNode _arrayNode;
    _pragma = this.primitivePragma();
    if (_pragma == null) {
        return null;
    }
    _argument = _pragma.expression().argument();
    if (_argument.isStringLiteralNode()) {
        return MethodNode.this.localPrimitiveIn_nameNode_(_className, ((StringLiteralNode) _argument));
    }
    if (!_argument.isArrayLiteralNode()) {
        return null;
    }
    _arrayNode = ((ArrayLiteralNode) _argument);
    return st.gravel.support.jvm.ArrayExtensions.collect_(_arrayNode.value(), ((st.gravel.support.jvm.Block1<String, Object>) (new st.gravel.support.jvm.Block1<String, Object>() {

        @Override
        public String value_(final Object _e) {
            final String _str;
            _str = ((String) _e);
            return (String) _str;
        }
    })));
}
Also used : PragmaNode(st.gravel.support.compiler.ast.PragmaNode) Expression(st.gravel.support.compiler.ast.Expression) ArrayLiteralNode(st.gravel.support.compiler.ast.ArrayLiteralNode) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode)

Example 10 with Expression

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

the class Parser method parseBinaryOrUnaryMessage.

public Expression parseBinaryOrUnaryMessage() {
    final Expression _receiver;
    _receiver = this.parseOperand();
    return this.parseBinaryOrUnaryMessage_(_receiver);
}
Also used : Expression(st.gravel.support.compiler.ast.Expression)

Aggregations

Expression (st.gravel.support.compiler.ast.Expression)25 SequenceNode (st.gravel.support.compiler.ast.SequenceNode)7 BlockNode (st.gravel.support.compiler.ast.BlockNode)6 ArrayList (java.util.ArrayList)3 BinaryMessageNode (st.gravel.support.compiler.ast.BinaryMessageNode)3 MessageNode (st.gravel.support.compiler.ast.MessageNode)3 Statement (st.gravel.support.compiler.ast.Statement)3 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)3 ArrayLiteralNode (st.gravel.support.compiler.ast.ArrayLiteralNode)2 StringLiteralNode (st.gravel.support.compiler.ast.StringLiteralNode)2 List (java.util.List)1 ArrayAtNode (st.gravel.support.compiler.ast.ArrayAtNode)1 ArrayAtPutNode (st.gravel.support.compiler.ast.ArrayAtPutNode)1 ArraySizeNode (st.gravel.support.compiler.ast.ArraySizeNode)1 BlockTypeNode (st.gravel.support.compiler.ast.BlockTypeNode)1 BooleanAndNode (st.gravel.support.compiler.ast.BooleanAndNode)1 BooleanLiteralNode (st.gravel.support.compiler.ast.BooleanLiteralNode)1 BooleanOrNode (st.gravel.support.compiler.ast.BooleanOrNode)1 ByteArrayLiteralNode (st.gravel.support.compiler.ast.ByteArrayLiteralNode)1 CascadeNode (st.gravel.support.compiler.ast.CascadeNode)1