Search in sources :

Example 1 with MethodNode

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

the class SystemMappingUpdater method linkMethods_in_identityClass_to_isStatic_.

public ClassPartMapping linkMethods_in_identityClass_to_isStatic_(final MethodNode[] _methods, final Class _javaClass, final Class _identityClass, final ClassPartMapping _cpm, final boolean _isStatic) {
    final ClassPartMapping[] _ecm;
    _ecm = new ClassPartMapping[1];
    _ecm[0] = _cpm;
    for (final MethodNode _m : _methods) {
        final String _fn;
        final java.lang.invoke.MethodHandle _methodHandle;
        final st.gravel.core.Symbol _selector;
        _selector = st.gravel.core.Symbol.value(_m.selector());
        _fn = _selectorConverter.selectorAsFunctionName_(_selector);
        _methodHandle = _compilerTools.methodHandleAt_numArgs_in_identityClass_isStatic_(_fn, _selector.numArgs(), _javaClass, _identityClass, _isStatic);
        _ecm[0] = _ecm[0].withMethodMapping_(((MethodMapping) MethodMapping.factory.methodNode_methodHandle_definingClass_(_m, _methodHandle, _javaClass)));
    }
    return _ecm[0];
}
Also used : ExtensionClassPartMapping(st.gravel.support.compiler.ast.ExtensionClassPartMapping) ClassPartMapping(st.gravel.support.compiler.ast.ClassPartMapping) IdentityClassPartMapping(st.gravel.support.compiler.ast.IdentityClassPartMapping) List(java.util.List) ArrayList(java.util.ArrayList) UnaryMethodNode(st.gravel.support.compiler.ast.UnaryMethodNode) MethodNode(st.gravel.support.compiler.ast.MethodNode)

Example 2 with MethodNode

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

Example 3 with MethodNode

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

the class UpdateClassDescriptorDiff method applyOnClassNode_.

public ClassDescriptionNode applyOnClassNode_(final ClassDescriptionNode _startClassNode) {
    ClassDescriptionNode _classNode;
    _classNode = ((ClassDescriptionNode) st.gravel.support.jvm.ArrayExtensions.inject_into_(_methodNodes, _startClassNode, ((st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, MethodNode>) (new st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, MethodNode>() {

        @Override
        public ClassDescriptionNode value_value_(final ClassDescriptionNode _cn, final MethodNode _m) {
            return (ClassDescriptionNode) _cn.withMethodNode_(_m);
        }
    }))));
    _classNode = ((ClassDescriptionNode) st.gravel.support.jvm.ArrayExtensions.inject_into_(_updatedMethodNodes, _classNode, ((st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, MethodNode>) (new st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, MethodNode>() {

        @Override
        public ClassDescriptionNode value_value_(final ClassDescriptionNode _cn, final MethodNode _m) {
            return (ClassDescriptionNode) _cn.copyReplaceMethodNode_(_m);
        }
    }))));
    return ((ClassDescriptionNode) st.gravel.support.jvm.ArrayExtensions.inject_into_(_deletedSelectors, _classNode, ((st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, String>) (new st.gravel.support.jvm.Block2<ClassDescriptionNode, ClassDescriptionNode, String>() {

        @Override
        public ClassDescriptionNode value_value_(final ClassDescriptionNode _cn, final String _sel) {
            return (ClassDescriptionNode) _cn.copyRemoveSelector_(_sel);
        }
    }))));
}
Also used : MethodNode(st.gravel.support.compiler.ast.MethodNode) ClassDescriptionNode(st.gravel.support.compiler.ast.ClassDescriptionNode)

Example 4 with MethodNode

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

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

the class LiteralBlockSendCallSite method findMethod.

@Override
protected MethodHandle findMethod(Class receiverClass) {
    MethodMapping methodMapping = ImageBootstrapper.systemMapping.methodMappingFor_methodName_(receiverClass, selector);
    if (methodMapping == null) {
        return createDNUHandle(receiverClass).asType(type);
    }
    MethodNode methodNode = methodMapping.methodNode();
    return inlineBlocks(methodNode, ImageBootstrapper.systemMapping.classMappingForJavaClass_(receiverClass).reference(), (JVMNonPrimitiveType) ImageBootstrapper.systemMapping.compilerTools().jvmTypeForClass_(receiverClass));
}
Also used : MethodMapping(st.gravel.support.compiler.ast.MethodMapping) MethodNode(st.gravel.support.compiler.ast.MethodNode)

Aggregations

MethodNode (st.gravel.support.compiler.ast.MethodNode)28 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)10 UnaryMethodNode (st.gravel.support.compiler.ast.UnaryMethodNode)9 HashMap (java.util.HashMap)7 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ExtensionClassPartMapping (st.gravel.support.compiler.ast.ExtensionClassPartMapping)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 BoundVariableDeclarationNode (st.gravel.support.compiler.ast.BoundVariableDeclarationNode)4 ClassNode (st.gravel.support.compiler.ast.ClassNode)4 IdentityClassPartMapping (st.gravel.support.compiler.ast.IdentityClassPartMapping)4 Map (java.util.Map)3 Symbol (st.gravel.core.Symbol)3 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)2 ClassMapping (st.gravel.support.compiler.ast.ClassMapping)2 KeywordMethodNode (st.gravel.support.compiler.ast.KeywordMethodNode)2 MethodMapping (st.gravel.support.compiler.ast.MethodMapping)2 PackageNode (st.gravel.support.compiler.ast.PackageNode)2