Search in sources :

Example 1 with VariableNode

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

the class ParserTest method testParseVariable.

@Test
public void testParseVariable() {
    final VariableNode _node;
    _node = ((VariableNode) Parser.factory.source_(" foo ").parseExpression());
    assertTrue(st.gravel.support.jvm.ObjectExtensions.equals_(_node.factory(), VariableNode.factory));
    assertEquals((String) "foo", (String) _node.prettySourceString());
}
Also used : VariableNode(st.gravel.support.compiler.ast.VariableNode) NamespacedVariableNode(st.gravel.support.compiler.ast.NamespacedVariableNode) Test(org.junit.Test)

Example 2 with VariableNode

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

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

the class Parser method parseAssignment_.

public AssignmentNode parseAssignment_(final Expression _aNode) {
    final Expression _value;
    st.gravel.support.jvm.ObjectExtensions.assert_(this, _aNode.isAssignable());
    _value = this.parseAssignmentOrExpression();
    return AssignmentNode.factory.variable_value_(((VariableNode) _aNode), _value);
}
Also used : VariableNode(st.gravel.support.compiler.ast.VariableNode) NamespacedVariableNode(st.gravel.support.compiler.ast.NamespacedVariableNode) GenericTypeVariableNode(st.gravel.support.compiler.ast.GenericTypeVariableNode) TypeVariableNode(st.gravel.support.compiler.ast.TypeVariableNode) NamespacedTypeVariableNode(st.gravel.support.compiler.ast.NamespacedTypeVariableNode) Expression(st.gravel.support.compiler.ast.Expression)

Example 4 with VariableNode

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

the class DiskClassWriter method writeClass_in_.

public DiskClassWriter writeClass_in_(final ClassNode _aClassNode, final java.io.File _aFilename) {
    final java.io.File _nsFn;
    final java.io.File _clFn;
    final StringBuilder[] _str;
    final VariableNode[] _reader;
    _reader = new VariableNode[1];
    _str = new StringBuilder[1];
    _nsFn = ((java.io.File) st.gravel.support.jvm.ArrayExtensions.inject_into_(_aClassNode.reference().namespace().path(), _aFilename, ((st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>) (new st.gravel.support.jvm.Block2<java.io.File, java.io.File, st.gravel.core.Symbol>() {

        @Override
        public java.io.File value_value_(final java.io.File _fn, final st.gravel.core.Symbol _each) {
            return (java.io.File) new java.io.File(_fn, _each.asString());
        }
    }))));
    _nsFn.mkdirs();
    _clFn = new java.io.File(_nsFn, _aClassNode.reference().name().asString() + ".st");
    _str[0] = st.gravel.support.jvm.WriteStreamFactory.on_(new String());
    _reader[0] = VariableNode.factory.name_("reader");
    if (_aClassNode.isExtension()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_(_aClassNode.isTrait() ? "extendTrait:" : "extendClass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString())), _str[0]);
    } else {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_(_aClassNode.isTrait() ? "defineTrait:superclass:" : "defineClass:superclass:", DiskClassWriter.this.asLiteralNode_(_aClassNode.name().asString()), DiskClassWriter.this.referenceAsLiteralNode_(_aClassNode.superclassReference())), _str[0]);
        for (final SharedDeclarationNode _sv : _aClassNode.metaclassNode().sharedVariables()) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("defineSharedVariable:init:", DiskClassWriter.this.asLiteralNode_(_sv.name()), DiskClassWriter.this.initializerSource_(_sv.initializer())), _str[0]);
        }
    }
    for (final Node _each : TraitUsageToDirectiveConverter.factory.visit_(_aClassNode.traitUsage())) {
        DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
    }
    for (final Node _each : ClassTraitUsageToDirectiveConverter.factory.visit_(_aClassNode.metaclassNode().traitUsage())) {
        DiskClassWriter.this.writeDirective_on_(_each, _str[0]);
    }
    for (final VariableDeclarationNode _each : _aClassNode.instVars()) {
        if (_each.type() == null) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
        } else {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
        }
    }
    for (final VariableDeclarationNode _each : _aClassNode.metaclassNode().instVars()) {
        if (_each.type() == null) {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassInstVar:", DiskClassWriter.this.asLiteralNode_(_each.name())), _str[0]);
        } else {
            DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("addClassInstVar:type:", DiskClassWriter.this.asLiteralNode_(_each.name()), DiskClassWriter.this.asLiteralNode_(_each.type().sourceString())), _str[0]);
        }
    }
    for (final Map.Entry<String, String> _temp1 : _aClassNode.properties().entrySet()) {
        String _k = _temp1.getKey();
        String _v = _temp1.getValue();
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_with_("propertyAt:put:", DiskClassWriter.this.asLiteralNode_(_k), DiskClassWriter.this.asLiteralNode_(_v)), _str[0]);
    }
    for (final MethodNode _each : _aClassNode.methods()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
        DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
    }
    for (final MethodNode _each : _aClassNode.metaclassNode().methods()) {
        DiskClassWriter.this.writeDirective_on_(_reader[0].send_with_("addClassMethod:", DiskClassWriter.this.asLiteralNode_(_each.protocol())), _str[0]);
        DiskClassWriter.this.writeMethod_on_(_each, _str[0]);
    }
    st.gravel.support.jvm.StringExtensions.writeToFile_(_str[0].toString(), _clFn);
    return this;
}
Also used : VariableNode(st.gravel.support.compiler.ast.VariableNode) NilLiteralNode(st.gravel.support.compiler.ast.NilLiteralNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Node(st.gravel.support.compiler.ast.Node) StringLiteralNode(st.gravel.support.compiler.ast.StringLiteralNode) NamespaceNode(st.gravel.support.compiler.ast.NamespaceNode) ClassNode(st.gravel.support.compiler.ast.ClassNode) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) PackageNode(st.gravel.support.compiler.ast.PackageNode) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) VariableNode(st.gravel.support.compiler.ast.VariableNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

VariableNode (st.gravel.support.compiler.ast.VariableNode)4 Expression (st.gravel.support.compiler.ast.Expression)2 NamespacedVariableNode (st.gravel.support.compiler.ast.NamespacedVariableNode)2 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 ClassNode (st.gravel.support.compiler.ast.ClassNode)1 GenericTypeVariableNode (st.gravel.support.compiler.ast.GenericTypeVariableNode)1 MethodNode (st.gravel.support.compiler.ast.MethodNode)1 NamespaceNode (st.gravel.support.compiler.ast.NamespaceNode)1 NamespacedTypeVariableNode (st.gravel.support.compiler.ast.NamespacedTypeVariableNode)1 NilLiteralNode (st.gravel.support.compiler.ast.NilLiteralNode)1 Node (st.gravel.support.compiler.ast.Node)1 PackageNode (st.gravel.support.compiler.ast.PackageNode)1 SequenceNode (st.gravel.support.compiler.ast.SequenceNode)1 SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)1 Statement (st.gravel.support.compiler.ast.Statement)1 StringLiteralNode (st.gravel.support.compiler.ast.StringLiteralNode)1 TypeVariableNode (st.gravel.support.compiler.ast.TypeVariableNode)1