Search in sources :

Example 6 with SequenceNode

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

the class IntermediateNodeRewriter method produce_ifTrue_ifFalse_.

public IfTrueIfFalseNode produce_ifTrue_ifFalse_(final Node _receiver, final Expression _trueExpr, final Expression _falseExpr) {
    final BlockNode _trueBlockNode;
    final BlockNode _falseBlockNode;
    if (!_trueExpr.isBlockNode()) {
        return null;
    }
    if (!_falseExpr.isBlockNode()) {
        return null;
    }
    _trueBlockNode = ((BlockNode) _trueExpr);
    _falseBlockNode = ((BlockNode) _falseExpr);
    return IfTrueIfFalseNode.factory.test_trueSequence_falseSequence_returnType_(((Expression) this.visit_(_receiver)), ((SequenceNode) this.visit_(_trueBlockNode.body())), ((SequenceNode) this.visit_(_falseBlockNode.body())), TypeOrNode.factory.left_right_(_trueBlockNode.returnType(), _falseBlockNode.returnType()));
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) Expression(st.gravel.support.compiler.ast.Expression) SequenceNode(st.gravel.support.compiler.ast.SequenceNode)

Example 7 with SequenceNode

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

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

the class NonLocalTempAccessToHolderConverter method visitSequenceNode_.

@Override
public SequenceNode visitSequenceNode_(final SequenceNode _anObject) {
    final SequenceNode[] _node;
    _node = new SequenceNode[1];
    _node[0] = SequenceNode.factory.temporaries_statements_(st.gravel.support.jvm.ArrayExtensions.collect_(_anObject.temporaries(), ((st.gravel.support.jvm.Block1<VariableDeclarationNode, VariableDeclarationNode>) (new st.gravel.support.jvm.Block1<VariableDeclarationNode, VariableDeclarationNode>() {

        @Override
        public VariableDeclarationNode value_(final VariableDeclarationNode _each) {
            _temps.put(_each.name(), VariableScopeAnalyzerStateDefined.factory.basicNew());
            return (VariableDeclarationNode) NonLocalTempAccessToHolderConverter.this.visit_(_each);
        }
    }))), st.gravel.support.jvm.ArrayExtensions.collect_(_anObject.statements(), ((st.gravel.support.jvm.Block1<Statement, Statement>) (new st.gravel.support.jvm.Block1<Statement, Statement>() {

        @Override
        public Statement value_(final Statement _each) {
            return (Statement) NonLocalTempAccessToHolderConverter.this.visit_(_each);
        }
    }))));
    for (final Map.Entry<String, VariableScopeAnalyzerState> _temp1 : _temps.entrySet()) {
        String _varName = _temp1.getKey();
        VariableScopeAnalyzerState _state = _temp1.getValue();
        if (NonLocalTempAccessToHolderConverter.this.needsRewrite_(_state)) {
            _node[0] = ((SequenceNode) VariableToHolderRewriter.factory.varName_(_varName).visit_(_node[0]));
        }
    }
    return _node[0];
}
Also used : VariableScopeAnalyzerState(st.gravel.support.compiler.ast.VariableScopeAnalyzerState) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Statement(st.gravel.support.compiler.ast.Statement) HashMap(java.util.HashMap) Map(java.util.Map) SequenceNode(st.gravel.support.compiler.ast.SequenceNode)

Example 9 with SequenceNode

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

the class Parser method parseBinaryMethod_.

public BinaryMethodNode parseBinaryMethod_(final String _aString) {
    final VariableDeclarationNode _argument;
    final SequenceNode _body;
    final TypeNode _returnType;
    final PragmaNode[][] _pragmas;
    _pragmas = new PragmaNode[1][];
    this.eatWhitespace();
    _argument = this.parseVariableDeclaration();
    _returnType = this.parseReturnType();
    _pragmas[0] = this.readPragmas();
    _body = this.parseSequenceNode_(new st.gravel.support.jvm.Block1<Object, PragmaNode[]>() {

        @Override
        public Object value_(final PragmaNode[] _extraPragmas) {
            return _pragmas[0] = st.gravel.support.jvm.ArrayExtensions.copyWithAll_(_pragmas[0], _extraPragmas);
        }
    });
    return BinaryMethodNode.factory.selector_argument_body_returnType_pragmas_protocol_(_aString, _argument, _body, _returnType, _pragmas[0], null);
}
Also used : TypeCast(st.gravel.support.compiler.ast.TypeCast) ArrayList(java.util.ArrayList) List(java.util.List) PragmaNode(st.gravel.support.compiler.ast.PragmaNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) BlockTypeNode(st.gravel.support.compiler.ast.BlockTypeNode) SelfTypeNode(st.gravel.support.compiler.ast.SelfTypeNode) InstanceTypeNode(st.gravel.support.compiler.ast.InstanceTypeNode) TypeNode(st.gravel.support.compiler.ast.TypeNode) SequenceNode(st.gravel.support.compiler.ast.SequenceNode)

Example 10 with SequenceNode

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

the class Parser method parseUnaryMethod_.

public MethodNode parseUnaryMethod_(final String _aString) {
    final SequenceNode _body;
    final TypeNode _returnType;
    final PragmaNode[][] _pragmas;
    _pragmas = new PragmaNode[1][];
    _returnType = this.parseReturnType();
    _pragmas[0] = this.readPragmas();
    _body = this.parseSequenceNode_(new st.gravel.support.jvm.Block1<Object, PragmaNode[]>() {

        @Override
        public Object value_(final PragmaNode[] _extraPragmas) {
            return _pragmas[0] = st.gravel.support.jvm.ArrayExtensions.copyWithAll_(_pragmas[0], _extraPragmas);
        }
    });
    return UnaryMethodNode.factory.selector_body_returnType_pragmas_protocol_(_aString, _body, _returnType, _pragmas[0], null);
}
Also used : TypeCast(st.gravel.support.compiler.ast.TypeCast) ArrayList(java.util.ArrayList) List(java.util.List) PragmaNode(st.gravel.support.compiler.ast.PragmaNode) BlockTypeNode(st.gravel.support.compiler.ast.BlockTypeNode) SelfTypeNode(st.gravel.support.compiler.ast.SelfTypeNode) InstanceTypeNode(st.gravel.support.compiler.ast.InstanceTypeNode) TypeNode(st.gravel.support.compiler.ast.TypeNode) SequenceNode(st.gravel.support.compiler.ast.SequenceNode)

Aggregations

SequenceNode (st.gravel.support.compiler.ast.SequenceNode)14 BlockNode (st.gravel.support.compiler.ast.BlockNode)9 Expression (st.gravel.support.compiler.ast.Expression)6 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BlockTypeNode (st.gravel.support.compiler.ast.BlockTypeNode)3 InstanceTypeNode (st.gravel.support.compiler.ast.InstanceTypeNode)3 PragmaNode (st.gravel.support.compiler.ast.PragmaNode)3 SelfTypeNode (st.gravel.support.compiler.ast.SelfTypeNode)3 TypeCast (st.gravel.support.compiler.ast.TypeCast)3 TypeNode (st.gravel.support.compiler.ast.TypeNode)3 Statement (st.gravel.support.compiler.ast.Statement)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 VariableNode (st.gravel.support.compiler.ast.VariableNode)1 VariableScopeAnalyzerState (st.gravel.support.compiler.ast.VariableScopeAnalyzerState)1