Search in sources :

Example 6 with SharedDeclarationNode

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

the class NamespaceNode method mergeWith_.

public NamespaceNode mergeWith_(final NamespaceNode _aNamespaceNode) {
    final List<AbsoluteReference>[] _nPublic;
    final List<AbsoluteReference>[] _nPrivate;
    final Map<String, SharedDeclarationNode>[] _nSharedVariables;
    _nSharedVariables = new Map[1];
    _nPrivate = new List[1];
    _nPublic = new List[1];
    _nPublic[0] = new java.util.ArrayList();
    _nPrivate[0] = new java.util.ArrayList();
    _nSharedVariables[0] = new java.util.HashMap<String, SharedDeclarationNode>();
    for (final AbsoluteReference _each : _aNamespaceNode.publicImports()) {
        if (!_nPublic[0].contains(_each)) {
            _nPublic[0].add(_each);
        }
    }
    for (final AbsoluteReference _each : _publicImports) {
        if (!_nPublic[0].contains(_each)) {
            _nPublic[0].add(_each);
        }
    }
    for (final AbsoluteReference _each : _aNamespaceNode.privateImports()) {
        if (!(_nPublic[0].contains(_each) || _nPrivate[0].contains(_each))) {
            _nPrivate[0].add(_each);
        }
    }
    for (final AbsoluteReference _each : _privateImports) {
        if (!(_nPublic[0].contains(_each) || _nPrivate[0].contains(_each))) {
            _nPrivate[0].add(_each);
        }
    }
    for (final SharedDeclarationNode _each : _sharedVariables) {
        _nSharedVariables[0].put(_each.name(), _each);
    }
    for (final SharedDeclarationNode _each : _aNamespaceNode.sharedVariables()) {
        _nSharedVariables[0].put(_each.name(), _each);
    }
    return this.withPrivateImports_publicImports_sharedVariables_(_nPrivate[0].toArray(new AbsoluteReference[_nPrivate[0].size()]), _nPublic[0].toArray(new AbsoluteReference[_nPublic[0].size()]), _nSharedVariables[0].values().toArray(new SharedDeclarationNode[_nSharedVariables[0].size()]));
}
Also used : AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ArrayList(java.util.ArrayList)

Example 7 with SharedDeclarationNode

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

the class SystemMappingUpdater method link.

public SystemMappingUpdater link() {
    _systemMapping.classMappingsDo_(new st.gravel.support.jvm.Block1<Object, AbstractClassMapping>() {

        @Override
        public Object value_(final AbstractClassMapping _acm) {
            if (_acm.classNode().isMeta()) {
                SystemMappingUpdater.this.initializeClassShareds_(((MetaclassNode) _acm.classNode()));
                return _systemMapping.singletonAtReference_ifAbsentPut_(_acm.reference().nonmeta(), new st.gravel.support.jvm.Block0<Object>() {

                    @Override
                    public Object value() {
                        return _compilerTools.createSingletonForClass_(_acm.identityClass());
                    }
                });
            }
            return SystemMappingUpdater.this;
        }
    });
    _compilerTools.resetCallsites();
    _systemMapping.namespaceGlobalsAndInitializersDo_(new st.gravel.support.jvm.Block2<Object, AbsoluteReference, SharedDeclarationNode>() {

        @Override
        public Object value_value_(final AbsoluteReference _reference, final SharedDeclarationNode _sharedVariable) {
            return _systemMapping.singletonAtReference_initialize_(_reference, _sharedVariable);
        }
    });
    for (final Reference _ref : _toInitialize) {
        _compilerTools.initializeClass_systemMapping_(((ClassMapping) _systemMapping.classMappingAtReference_(_ref)), _systemMapping);
    }
    _toInitialize = new java.util.ArrayList();
    return this;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ClassMapping(st.gravel.support.compiler.ast.ClassMapping) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) ArrayList(java.util.ArrayList) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping)

Example 8 with SharedDeclarationNode

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

the class SystemMapping method namespacedSingletonHolderAtReference_ifAbsent_.

public st.gravel.support.jvm.runtime.AlmostFinalValue namespacedSingletonHolderAtReference_ifAbsent_(final AbsoluteReference _reference, final st.gravel.support.jvm.Block0<st.gravel.support.jvm.runtime.AlmostFinalValue> _aBlock) {
    final Object _temp1 = new Object();
    try {
        final NamespaceNode _nsNode;
        _nsNode = _systemNode.namespaceNodeAt_ifAbsent_(_reference.namespace().namespace(), ((st.gravel.support.jvm.Block0<NamespaceNode>) (new st.gravel.support.jvm.Block0<NamespaceNode>() {

            @Override
            public NamespaceNode value() {
                return (NamespaceNode) null;
            }
        })));
        if (_nsNode != null) {
            _nsNode.allImportsIn_do_(_systemNode, new st.gravel.support.jvm.Block1<Object, NamespaceNode>() {

                @Override
                public Object value_(final NamespaceNode _importNS) {
                    final st.gravel.support.jvm.runtime.AlmostFinalValue _sh;
                    final SharedDeclarationNode _shared;
                    _shared = _importNS.sharedVariableAt_ifAbsent_(_reference.name().asString(), ((st.gravel.support.jvm.Block0<SharedDeclarationNode>) (new st.gravel.support.jvm.Block0<SharedDeclarationNode>() {

                        @Override
                        public SharedDeclarationNode value() {
                            return (SharedDeclarationNode) null;
                        }
                    })));
                    if (_shared != null) {
                        throw new NonLocalReturn(SystemMapping.this.singletonAtReference_initialize_(_importNS.reference().$slash$(_reference.name()), _shared), _temp1);
                    }
                    st.gravel.support.jvm.runtime.AlmostFinalValue _temp2 = _singletonHolders.get(_importNS.reference().$slash$(_reference.name()));
                    _sh = ((st.gravel.support.jvm.runtime.AlmostFinalValue) _temp2);
                    if (_sh != null) {
                        throw new NonLocalReturn(_sh, _temp1);
                    }
                    return SystemMapping.this;
                }
            });
        }
        return _aBlock.value();
    } catch (NonLocalReturn nlr) {
        if (nlr.marker == _temp1) {
            return (st.gravel.support.jvm.runtime.AlmostFinalValue) nlr.returnValue;
        } else {
            throw nlr;
        }
    }
}
Also used : SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) NamespaceNode(st.gravel.support.compiler.ast.NamespaceNode) NonLocalReturn(st.gravel.support.jvm.NonLocalReturn)

Example 9 with SharedDeclarationNode

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

SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)9 HashMap (java.util.HashMap)6 Map (java.util.Map)6 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 NamespaceNode (st.gravel.support.compiler.ast.NamespaceNode)3 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)2 ClassMapping (st.gravel.support.compiler.ast.ClassMapping)2 ClassNode (st.gravel.support.compiler.ast.ClassNode)2 MethodNode (st.gravel.support.compiler.ast.MethodNode)2 Reference (st.gravel.support.compiler.ast.Reference)2 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)2 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AbstractMethodMapping (st.gravel.support.compiler.ast.AbstractMethodMapping)1 InstVarMapping (st.gravel.support.compiler.ast.InstVarMapping)1 NilLiteralNode (st.gravel.support.compiler.ast.NilLiteralNode)1 Node (st.gravel.support.compiler.ast.Node)1