Search in sources :

Example 11 with BlockNode

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

the class SystemMapping method compileExpression_reference_.

public JVMClass[] compileExpression_reference_(final Node _anExpression, final Reference _aReference) {
    final JVMDefinedObjectType _ownerType;
    final BlockNode _fieldAccessed;
    final BlockInnerClass _aBlockInnerClass;
    final BlockNode _intermediate;
    final BlockNode _holderized;
    final JVMClassCompiler _jvmClassCompiler;
    final JVMClass _blockClass;
    _intermediate = ((BlockNode) IntermediateNodeRewriter.factory.visit_(BlockNode.factory.expression_(_anExpression)));
    _holderized = ((BlockNode) NonLocalTempWritesToHolderConverter.factory.visit_(_intermediate));
    _fieldAccessed = ((BlockNode) VariableAccessToFieldAccessConverter.factory.instVars_owner_ownerReference_(new VariableDeclarationNode[] {}, NilLiteralNode.factory.basicNew(), _aReference).visit_(_holderized));
    _ownerType = JVMDefinedObjectType.factory.dottedClassName_("Expression$" + _compilerTools.nextExtensionPostfix());
    _aBlockInnerClass = BlockInnerClass.factory.ownerType_blockNode_copiedVariables_(_ownerType, _fieldAccessed, new JVMVariable[] {});
    _jvmClassCompiler = JVMClassCompiler.factory.classDescriptionNode_systemNode_systemMappingUpdater_isStatic_(null, _systemNode, this.newSystemMappingUpdater(), false);
    _jvmClassCompiler.ownerType_(JVMDefinedObjectType.factory.dottedClassName_("ExpressionContainer$" + _compilerTools.nextExtensionPostfix()));
    _blockClass = _jvmClassCompiler.compileBlockNoAdd_(_aBlockInnerClass);
    return _jvmClassCompiler.withContainerAndExtraClasses_(_blockClass);
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) JVMClass(st.gravel.support.compiler.jvm.JVMClass) JVMVariable(st.gravel.support.compiler.jvm.JVMVariable) JVMClassCompiler(st.gravel.support.compiler.jvm.JVMClassCompiler) JVMDefinedObjectType(st.gravel.support.compiler.jvm.JVMDefinedObjectType) BlockInnerClass(st.gravel.support.compiler.jvm.BlockInnerClass)

Example 12 with BlockNode

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

the class Parser method parseBlock.

public BlockNode parseBlock() {
    VariableDeclarationNode[] _arguments;
    final BlockNode _bn;
    TypeNode _returnType;
    final int _start;
    _start = st.gravel.support.jvm.ReadStreamExtensions.position(_stream);
    st.gravel.support.jvm.ReadStreamExtensions.next(_stream);
    this.eatWhitespace();
    _arguments = new VariableDeclarationNode[] {};
    if (st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, ':')) {
        boolean _temp1 = true;
        while (_temp1) {
            Parser.this.eatWhitespace();
            _arguments = st.gravel.support.jvm.ArrayExtensions.copyWith_(_arguments, Parser.this.parseVariableDeclaration());
            Parser.this.eatWhitespace();
            _temp1 = st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, ':');
        }
        _returnType = Parser.this.parseReturnType();
        Parser.this.eatWhitespace();
        if (st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, ']')) {
            return BlockNode.factory.arguments_body_returnType_(_arguments, SequenceNode.factory.empty(), _returnType);
        }
        st.gravel.support.jvm.ObjectExtensions.assert_(Parser.this, st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '|'));
    } else {
        _returnType = Parser.this.parseReturnType();
        if (_returnType != null) {
            Parser.this.eatWhitespace();
            st.gravel.support.jvm.ObjectExtensions.assert_(Parser.this, st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, '|'));
        }
    }
    _bn = BlockNode.factory.arguments_body_returnType_(_arguments, this.parseSequenceNode_(new st.gravel.support.jvm.Block1<Object, PragmaNode[]>() {

        @Override
        public Object value_(final PragmaNode[] _extraPragmas) {
            throw new RuntimeException("Extra pragmas not allowed");
        }
    }), _returnType);
    st.gravel.support.jvm.ObjectExtensions.assert_(this, st.gravel.support.jvm.ReadStreamExtensions.peekFor_(_stream, ']'));
    return ((BlockNode) this.setSourcePosition_node_(_start, _bn));
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) 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)

Example 13 with BlockNode

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

the class BlockInliner method renamedBlockNodeFor_.

public BlockNode renamedBlockNodeFor_(final BlockSendArgument _astConstant) {
    final BlockNode[] _blockNode;
    _blockNode = new BlockNode[1];
    _blockNode[0] = _astConstant.blockNode();
    for (final JVMVariable _cv : _astConstant.copiedVariables()) {
        _blockNode[0] = ((BlockNode) BlockInliner.this.renameVariable_from_to_(_blockNode[0], _cv.varName(), _copiedArgRenames.get(_cv.varName())));
    }
    this.log_text_("renamedBlockNode: ", _blockNode[0].sourceString());
    return _blockNode[0];
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) JVMVariable(st.gravel.support.compiler.jvm.JVMVariable)

Example 14 with BlockNode

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

the class IntermediateNodeRewriter method produce$underscore$whileFalse_.

public WhileFalseNode produce$underscore$whileFalse_(final Expression _testExpr) {
    final BlockNode _testBlockNode;
    if (!_testExpr.isBlockNode()) {
        return null;
    }
    _testBlockNode = ((BlockNode) _testExpr);
    return WhileFalseNode.factory.testSequence_doSequence_(((SequenceNode) this.visit_(_testBlockNode.body())), null);
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) SequenceNode(st.gravel.support.compiler.ast.SequenceNode)

Example 15 with BlockNode

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

the class IntermediateNodeRewriter method produce_or_.

public BooleanOrNode produce_or_(final Node _receiver, final Expression _testExpr) {
    final BlockNode _testBlockNode;
    if (!_testExpr.isBlockNode()) {
        return null;
    }
    _testBlockNode = ((BlockNode) _testExpr);
    return BooleanOrNode.factory.left_right_(((Expression) this.visit_(_receiver)), ((SequenceNode) this.visit_(_testBlockNode.body())));
}
Also used : BlockNode(st.gravel.support.compiler.ast.BlockNode) Expression(st.gravel.support.compiler.ast.Expression) SequenceNode(st.gravel.support.compiler.ast.SequenceNode)

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