use of st.gravel.support.compiler.ast.NamespaceNode in project gravel by gravel-st.
the class SystemMapping method namespaceGlobalsAndInitializersDo_.
public SystemMapping namespaceGlobalsAndInitializersDo_(final st.gravel.support.jvm.Block2<Object, AbsoluteReference, SharedDeclarationNode> _aBlock) {
for (final Map.Entry<Reference, NamespaceNode> _temp1 : _systemNode.namespaceNodes().entrySet()) {
Reference _reference = _temp1.getKey();
NamespaceNode _namespaceNode = _temp1.getValue();
for (final SharedDeclarationNode _sharedVariable : _namespaceNode.sharedVariables()) {
_aBlock.value_value_(((AbsoluteReference) _reference).$slash$(st.gravel.core.Symbol.value(_sharedVariable.name())), _sharedVariable);
}
}
return this;
}
use of st.gravel.support.compiler.ast.NamespaceNode in project gravel by gravel-st.
the class PackageNodeMerger method load.
public SystemNode load() {
final Map<Reference, ClassNode>[] _classNodes;
final Map<Reference, ClassDescriptionNode>[] _classDescriptionNodes;
final Map<Reference, NamespaceNode>[] _namespaceNodes;
_classDescriptionNodes = new Map[1];
_classNodes = new Map[1];
_namespaceNodes = new Map[1];
_classNodes[0] = new java.util.HashMap<Reference, ClassNode>();
_namespaceNodes[0] = new java.util.HashMap<Reference, NamespaceNode>();
this.packageClassNodesDo_(new st.gravel.support.jvm.Block1<Object, ClassNode>() {
@Override
public Object value_(final ClassNode _classNode) {
if (!_classNode.isExtension()) {
final Reference _reference;
_reference = _classNode.reference();
if (_classNodes[0].containsKey(_reference)) {
throw new RuntimeException("Class " + _reference.toString() + " defined twice");
}
return _classNodes[0].put(_reference, _classNode);
}
return PackageNodeMerger.this;
}
});
this.packageClassNodesDo_(new st.gravel.support.jvm.Block1<Object, ClassNode>() {
@Override
public Object value_(final ClassNode _classNode) {
if (_classNode.isExtension()) {
final Reference _reference;
_reference = _classNode.reference();
if (!_classNodes[0].containsKey(_reference)) {
throw new RuntimeException("Can\'t extend Class " + _reference.toString() + "; not defined yet");
}
return _classNodes[0].put(_reference, _classNodes[0].get(_reference).mergedWithExtension_(_classNode));
}
return PackageNodeMerger.this;
}
});
_classDescriptionNodes[0] = new java.util.HashMap<Reference, ClassDescriptionNode>();
for (final ClassNode _classNode : _classNodes[0].values()) {
_classDescriptionNodes[0].put(_classNode.reference(), _classNode);
_classDescriptionNodes[0].put(_classNode.metaclassNode().reference(), _classNode.metaclassNode());
}
this.packageNamespaceNodesDo_(new st.gravel.support.jvm.Block1<Object, NamespaceNode>() {
@Override
public Object value_(final NamespaceNode _namespaceNode) {
final Reference _reference;
_reference = _namespaceNode.reference();
if (_namespaceNodes[0].containsKey(_reference)) {
return _namespaceNodes[0].put(_reference, _namespaceNode.mergeWith_(_namespaceNodes[0].get(_reference)));
} else {
return _namespaceNodes[0].put(_reference, _namespaceNode);
}
}
});
for (final Reference _ref : _classNodes[0].keySet()) {
final AbsoluteReference _namespace;
_namespace = _ref.namespace();
NamespaceNode _temp1 = _namespaceNodes[0].get(_namespace);
if (_temp1 == null) {
NamespaceNode _temp2 = NamespaceNode.factory.for_(_namespace);
_namespaceNodes[0].put(_namespace, _temp2);
_temp1 = _temp2;
}
}
return SystemNode.factory.classDescriptionNodes_namespaceNodes_(_classDescriptionNodes[0], _namespaceNodes[0]).flattenTraits();
}
use of st.gravel.support.compiler.ast.NamespaceNode in project gravel by gravel-st.
the class PackageNode method withNamespace_.
public PackageNode withNamespace_(final NamespaceNode _aNamespaceNode) {
final NamespaceNode _current;
final NamespaceNode _merged;
_current = ((NamespaceNode) st.gravel.support.jvm.ArrayExtensions.detect_ifNone_(_namespaces, new st.gravel.support.jvm.Predicate1<NamespaceNode>() {
@Override
public boolean value_(final NamespaceNode _each) {
return st.gravel.support.jvm.ObjectExtensions.equals_(_each.reference(), _aNamespaceNode.reference());
}
}, ((st.gravel.support.jvm.Block0<NamespaceNode>) (new st.gravel.support.jvm.Block0<NamespaceNode>() {
@Override
public NamespaceNode value() {
return (NamespaceNode) null;
}
}))));
_merged = _current == null ? _aNamespaceNode : _current.mergeWith_(_aNamespaceNode);
return this.copy().pvtSetNamespaces_(st.gravel.support.jvm.ArrayExtensions.copyWith_(_namespaces, _merged));
}
use of st.gravel.support.compiler.ast.NamespaceNode in project gravel by gravel-st.
the class DiskClassWriter method write_.
public DiskClassWriter write_(final PackageNode _aPackageNode) {
final java.io.File[] _pkgRoot;
_pkgRoot = new java.io.File[1];
_pkgRoot[0] = new java.io.File(_root, _aPackageNode.name().asString());
_pkgRoot[0].mkdirs();
for (final ClassNode _cl : _aPackageNode.classes()) {
DiskClassWriter.this.writeClass_in_(_cl, _pkgRoot[0]);
}
for (final NamespaceNode _ns : _aPackageNode.namespaces()) {
DiskClassWriter.this.writeNamespace_in_(_ns, _pkgRoot[0]);
}
return this;
}
use of st.gravel.support.compiler.ast.NamespaceNode 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;
}
}
}
Aggregations