Search in sources :

Example 6 with BlockNode

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

the class IntermediateNodeRewriter method produce_whileTrue_.

public WhileTrueNode produce_whileTrue_(final Expression _testExpr, final Expression _loopExpr) {
    final BlockNode _testBlockNode;
    final BlockNode _loopBlockNode;
    if (!_testExpr.isBlockNode()) {
        return null;
    }
    if (!_loopExpr.isBlockNode()) {
        return null;
    }
    _testBlockNode = ((BlockNode) _testExpr);
    _loopBlockNode = ((BlockNode) _loopExpr);
    return WhileTrueNode.factory.testSequence_doSequence_(((SequenceNode) this.visit_(_testBlockNode.body())), ((SequenceNode) this.visit_(_loopBlockNode.body())));
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) SequenceNode(st.gravel.support.compiler.ast.SequenceNode)

Example 7 with BlockNode

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

the class IntermediateNodeRewriter method produce_to_by_do_.

public ToDoNode produce_to_by_do_(final Expression _start, final Expression _stop, final Expression _step, final Expression _loopExpr) {
    final BlockNode _loopBlockNode;
    if (!_loopExpr.isBlockNode()) {
        return null;
    }
    if (!_step.isIntegerLiteralNode()) {
        return null;
    }
    _loopBlockNode = ((BlockNode) _loopExpr);
    return ToDoNode.factory.start_stop_step_counterName_doSequence_(((Expression) this.visit_(_start)), ((Expression) this.visit_(_stop)), ((Expression) this.visit_(_step)), _loopBlockNode.arguments()[0].name(), ((SequenceNode) this.visit_(_loopBlockNode.body())));
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) Expression(st.gravel.support.compiler.ast.Expression) SequenceNode(st.gravel.support.compiler.ast.SequenceNode)

Example 8 with BlockNode

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

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

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

the class NonLocalReturnRewriter method visitBlockNode_.

@Override
public BlockNode visitBlockNode_(final BlockNode _anObject) {
    final boolean _old;
    final BlockNode _bn;
    _old = _isInBlockNode;
    _isInBlockNode = true;
    _bn = super.visitBlockNode_(_anObject);
    _isInBlockNode = _old;
    return _bn;
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode)

Aggregations

BlockNode (st.gravel.support.compiler.ast.BlockNode)16 SequenceNode (st.gravel.support.compiler.ast.SequenceNode)10 Expression (st.gravel.support.compiler.ast.Expression)5 JVMVariable (st.gravel.support.compiler.jvm.JVMVariable)3 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ArrayAtNode (st.gravel.support.compiler.ast.ArrayAtNode)1 ArrayAtPutNode (st.gravel.support.compiler.ast.ArrayAtPutNode)1 ArrayLiteralNode (st.gravel.support.compiler.ast.ArrayLiteralNode)1 ArraySizeNode (st.gravel.support.compiler.ast.ArraySizeNode)1 BinaryMessageNode (st.gravel.support.compiler.ast.BinaryMessageNode)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 CharacterLiteralNode (st.gravel.support.compiler.ast.CharacterLiteralNode)1 CreateHolderNode (st.gravel.support.compiler.ast.CreateHolderNode)1