Search in sources :

Example 1 with SystemDefinitionNode

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

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

the class ClassDescriptionMirror method compile_classified_.

public Object compile_classified_(String source, String protocol) {
    final MethodNode method = Parser.factory.parseMethod_(source).withProtocol_(protocol);
    ClassDescriptionNode currentClassNode = definitionClassNode();
    final MethodNode current = currentClassNode.methodOrNilAt_(method.selector());
    Symbol targetPackageName = current == null ? definitionClassNode().packageName() : current.packageName();
    if (targetPackageName == null) {
        targetPackageName = definitionClassNode().packageName();
        if (targetPackageName == null) {
            targetPackageName = current.packageName();
        }
    }
    SystemDefinitionNode newSystem = ImageBootstrapper.systemMapping.systemDefinitionNode().copyUpdatePackage_do_(targetPackageName, new Block1<PackageNode, PackageNode>() {

        @Override
        public PackageNode value_(PackageNode packageNode) {
            return packageNode.copyUpdateClassNode_do_(definitionClassNode().reference(), new Block1<ClassNode, ClassNode>() {

                @Override
                public ClassNode value_(ClassNode classNode) {
                    return current == null ? classNode.withMethodNode_(method) : classNode.copyReplaceMethodNode_(method);
                }
            });
        }
    });
    ImageBootstrapper.systemMapping.updateTo_(newSystem);
    return getMethodMirror(Symbol.value(method.selector()));
}
Also used : ClassNode(st.gravel.support.compiler.ast.ClassNode) MethodNode(st.gravel.support.compiler.ast.MethodNode) Symbol(st.gravel.core.Symbol) SystemDefinitionNode(st.gravel.support.compiler.ast.SystemDefinitionNode) PackageNode(st.gravel.support.compiler.ast.PackageNode) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode)

Aggregations

Symbol (st.gravel.core.Symbol)2 ClassNode (st.gravel.support.compiler.ast.ClassNode)2 MethodNode (st.gravel.support.compiler.ast.MethodNode)2 SystemDefinitionNode (st.gravel.support.compiler.ast.SystemDefinitionNode)2 HashMap (java.util.HashMap)1 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)1 PackageNode (st.gravel.support.compiler.ast.PackageNode)1 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)1