Search in sources :

Example 1 with ClassNode

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

the class ClassBuilder method build.

public Class build() {
    Map<String, String> _properties = new HashMap<>();
    VariableDeclarationNode[] _instVars = instVars.toArray(new VariableDeclarationNode[instVars.size()]);
    VariableDeclarationNode[] _classInstVars = new VariableDeclarationNode[0];
    MethodNode[] _methods = methods.toArray(new MethodNode[methods.size()]);
    MethodNode[] _classMethods = classMethods.toArray(new MethodNode[classMethods.size()]);
    Symbol[] _namespace = new Symbol[] { Symbol.value("ClassBuilder") };
    ClassNode classNode = ClassNode.factory.name_superclassPath_properties_instVars_classInstVars_sharedVariables_methods_classMethods_namespace_isExtension_isTrait_traitUsage_classTraitUsage_(Symbol.value(name), superclassName, _properties, _instVars, _classInstVars, new SharedDeclarationNode[0], _methods, _classMethods, _namespace, false, false, EmptyTraitUsageNode.factory.basicNew(), EmptyTraitUsageNode.factory.basicNew());
    SystemDefinitionNode systemDefinitionNode = ImageBootstrapper.systemMapping.systemDefinitionNode();
    ImageBootstrapper.systemMapping.updateTo_(systemDefinitionNode.withPackageNamed_classNode_(Symbol.value(name), classNode));
    return ImageBootstrapper.systemMapping.classMappingAtReference_(classNode.reference()).identityClass();
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) HashMap(java.util.HashMap) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) Symbol(st.gravel.core.Symbol) SystemDefinitionNode(st.gravel.support.compiler.ast.SystemDefinitionNode)

Example 2 with ClassNode

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

the class DiskClassReader method readClass_packageName_file_namespace_.

public ClassNode readClass_packageName_file_namespace_(final String _aName, final st.gravel.core.Symbol _packageName, final java.io.File _aFilename, final String[] _anArray) {
    final Parser _parser;
    MessageNode _expr;
    ClassNode _cn;
    st.gravel.support.jvm.Block3<ClassNode, ClassNode, MessageNode, Parser> _directive;
    final int _start;
    _cn = ClassNode.factory.name_namespacePath_(st.gravel.core.Symbol.value(_aName), st.gravel.support.jvm.ArrayExtensions.collect_(_anArray, ((st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>) (new st.gravel.support.jvm.Block1<st.gravel.core.Symbol, String>() {

        @Override
        public st.gravel.core.Symbol value_(final String _each) {
            return (st.gravel.core.Symbol) st.gravel.core.Symbol.value(_each);
        }
    }))));
    _parser = Parser.factory.source_sourceFile_(st.gravel.support.jvm.FilenameExtensions.contentsOfEntireFile(_aFilename), SourceFile.factory.directory_name_packageName_(_aFilename.getParent(), _aFilename.getName(), _packageName));
    _start = _parser.position();
    boolean _temp1 = false;
    while (!_temp1) {
        _temp1 = _parser.atEnd();
        if (!_temp1) {
            _expr = ((MessageNode) _parser.parseExpression());
            _directive = DiskClassReader.this.directiveAt_(_expr.selector());
            _cn = _directive.value_value_value_(_cn, _expr, _parser);
            if (!_parser.atEnd()) {
                _parser.parseBang();
            }
        }
    }
    return ((ClassNode) _parser.setSourcePosition_node_(_start, _cn));
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) ArrayList(java.util.ArrayList) List(java.util.List) Parser(st.gravel.support.compiler.ast.Parser) MessageNode(st.gravel.support.compiler.ast.MessageNode)

Example 3 with ClassNode

use of st.gravel.support.compiler.ast.ClassNode 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;
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) NamespaceNode(st.gravel.support.compiler.ast.NamespaceNode)

Example 4 with ClassNode

use of st.gravel.support.compiler.ast.ClassNode 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();
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) NamespaceNode(st.gravel.support.compiler.ast.NamespaceNode) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with ClassNode

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

the class SystemMapping method newClassMappingForJavaClass_.

public ClassMapping newClassMappingForJavaClass_(final Class _receiverClass) {
    final Map<st.gravel.core.Symbol, AbstractMethodMapping>[] _methodMappings;
    final ClassNode _classNode;
    final ClassMapping _superMapping;
    final java.util.Set<st.gravel.core.Symbol>[] _allSelectors;
    _allSelectors = new java.util.Set[1];
    _methodMappings = new Map[1];
    _superMapping = this.bestClassMappingFor_(_receiverClass);
    _allSelectors[0] = _superMapping.allSelectorsIn_(this);
    _methodMappings[0] = new java.util.HashMap<st.gravel.core.Symbol, AbstractMethodMapping>();
    _compilerTools.methodNamesIn_do_(_receiverClass, new st.gravel.support.jvm.Block2<Object, String, Integer>() {

        @Override
        public Object value_value_(final String _methodName, final Integer _numArgs) {
            final st.gravel.core.Symbol _sel;
            _sel = _selectorConverter.functionNameAsSelector_(_methodName);
            if (st.gravel.support.jvm.IntegerExtensions.equals_(_sel.numArgs(), _numArgs) && _allSelectors[0].contains(_sel)) {
                final java.lang.invoke.MethodHandle _methodHandle;
                _methodHandle = _compilerTools.methodHandleAt_numArgs_in_identityClass_isStatic_(_methodName, _sel.numArgs(), _receiverClass, _receiverClass, false);
                if (_methodHandle != null) {
                    return _methodMappings[0].put(_sel, AnonymousMethodMapping.factory.methodHandle_definingClass_(_methodHandle, _receiverClass));
                }
            }
            return SystemMapping.this;
        }
    });
    _classNode = ClassNode.factory.name_superclassPath_properties_instVars_classInstVars_sharedVariables_methods_classMethods_namespace_isExtension_isTrait_traitUsage_classTraitUsage_(_superMapping.classNode().name(), _superMapping.reference().toString(), new java.util.HashMap<String, String>(), new VariableDeclarationNode[] {}, new VariableDeclarationNode[] {}, new SharedDeclarationNode[] {}, new MethodNode[] {}, new MethodNode[] {}, _superMapping.classNode().namespace(), false, false, EmptyTraitUsageNode.factory.basicNew(), EmptyTraitUsageNode.factory.basicNew());
    return ClassMapping.factory.identityMapping_extensions_instVarMappings_classNode_(IdentityClassPartMapping.factory.javaClass_isGenerated_(_receiverClass, false).withMethodMappings_(_methodMappings[0]), new ExtensionClassPartMapping[] {}, new java.util.HashMap<String, InstVarMapping>(), _classNode);
}
Also used : ClassMapping(st.gravel.support.compiler.ast.ClassMapping) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) InstVarMapping(st.gravel.support.compiler.ast.InstVarMapping) MethodNode(st.gravel.support.compiler.ast.MethodNode) VariableDeclarationNode(st.gravel.support.compiler.ast.VariableDeclarationNode) ClassNode(st.gravel.support.compiler.ast.ClassNode) AbstractMethodMapping(st.gravel.support.compiler.ast.AbstractMethodMapping) BigInteger(java.math.BigInteger) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ClassNode (st.gravel.support.compiler.ast.ClassNode)10 HashMap (java.util.HashMap)5 Map (java.util.Map)4 MethodNode (st.gravel.support.compiler.ast.MethodNode)4 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)3 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)3 NamespaceNode (st.gravel.support.compiler.ast.NamespaceNode)3 PackageNode (st.gravel.support.compiler.ast.PackageNode)3 Reference (st.gravel.support.compiler.ast.Reference)3 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Symbol (st.gravel.core.Symbol)2 SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)2 SystemDefinitionNode (st.gravel.support.compiler.ast.SystemDefinitionNode)2 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)1 AbstractMethodMapping (st.gravel.support.compiler.ast.AbstractMethodMapping)1