Search in sources :

Example 1 with AbstractMethodMapping

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

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

the class SuperCallSite method lookupMethod.

public MethodHandle lookupMethod(Class receiverClass, String selector) {
    Reference reference = Reference.factory.value_(lookupStart);
    AbstractMethodMapping mapping = ImageBootstrapper.systemMapping.superMethodMappingFor_methodName_(reference, selector);
    if (mapping == null) {
        if (selector.equals("doesNotUnderstand_"))
            throw new RuntimeException("Can't find DNU method");
        return wrapDNUHandle(lookupMethod(receiverClass, "doesNotUnderstand_"));
    }
    MethodHandle methodHandle;
    try {
        Method method = MethodTools.searchForMethod(mapping.definingClass(), selector, type.parameterArray(), true);
        if (method != null) {
            return mapping.methodHandle().asType(type);
        }
        methodHandle = lookup.findSpecial(mapping.definingClass(), selector, type.dropParameterTypes(0, 1), lookup.lookupClass());
    } catch (NoSuchMethodException | IllegalAccessException r) {
        try {
            methodHandle = lookup.findStatic(mapping.definingClass(), selector, type);
        } catch (NoSuchMethodException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    return methodHandle.asType(type);
}
Also used : AbstractMethodMapping(st.gravel.support.compiler.ast.AbstractMethodMapping) Reference(st.gravel.support.compiler.ast.Reference) Method(java.lang.reflect.Method) MethodHandle(java.lang.invoke.MethodHandle)

Example 3 with AbstractMethodMapping

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

the class ClassMapping method extensionMethodMappingAt_ifAbsent_.

public AbstractMethodMapping extensionMethodMappingAt_ifAbsent_(final st.gravel.core.Symbol _aSymbol, final st.gravel.support.jvm.Block0<AbstractMethodMapping> _aBlock) {
    for (final ExtensionClassPartMapping _ex : _extensions) {
        final AbstractMethodMapping _m;
        _m = _ex.methodMappingAt_ifAbsent_(_aSymbol, ((st.gravel.support.jvm.Block0<AbstractMethodMapping>) (new st.gravel.support.jvm.Block0<AbstractMethodMapping>() {

            @Override
            public AbstractMethodMapping value() {
                return (AbstractMethodMapping) null;
            }
        })));
        if (_m != null) {
            return _m;
        }
    }
    return _aBlock.value();
}
Also used : AbstractMethodMapping(st.gravel.support.compiler.ast.AbstractMethodMapping) ExtensionClassPartMapping(st.gravel.support.compiler.ast.ExtensionClassPartMapping)

Example 4 with AbstractMethodMapping

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

the class SystemMapping method methodMappingFrom_selector_.

public AbstractMethodMapping methodMappingFrom_selector_(final ClassMapping _classMapping, final st.gravel.core.Symbol _sel) {
    return _classMapping.methodMappingAt_ifAbsent_(_sel, ((st.gravel.support.jvm.Block0<AbstractMethodMapping>) (new st.gravel.support.jvm.Block0<AbstractMethodMapping>() {

        @Override
        public AbstractMethodMapping value() {
            final Reference _superclassReference;
            AbstractMethodMapping _mapping;
            _superclassReference = _classMapping.superclassReferenceForMethodLookup();
            if (_superclassReference == null) {
                _mapping = null;
            } else {
                _mapping = SystemMapping.this.methodMappingFrom_selector_(((ClassMapping) SystemMapping.this.classMappingAtReference_(_superclassReference)), _sel);
            }
            return (AbstractMethodMapping) _mapping;
        }
    })));
}
Also used : AbstractMethodMapping(st.gravel.support.compiler.ast.AbstractMethodMapping) Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference)

Example 5 with AbstractMethodMapping

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

the class SystemMappingUpdater method compiledMethodNodesIn_do_.

public SystemMappingUpdater compiledMethodNodesIn_do_(final Reference _superclassReference, final st.gravel.support.jvm.Block1<Object, MethodNode> _aBlock) {
    final ClassMapping[] _superMapping;
    final Class _sc;
    final java.util.Set<st.gravel.core.Symbol>[] _allSelectors;
    _allSelectors = new java.util.Set[1];
    _superMapping = new ClassMapping[1];
    if (_superclassReference == null) {
        return SystemMappingUpdater.this;
    }
    _superMapping[0] = ((ClassMapping) _systemMapping.classMappingAtReference_(_superclassReference));
    _allSelectors[0] = _superMapping[0].allSelectorsIn_(_systemMapping);
    _sc = _superMapping[0].identityClass();
    _compilerTools.methodNamesIn_do_(_sc, 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 (_allSelectors[0].contains(_sel)) {
                final AbstractMethodMapping _methodMapping;
                _methodMapping = _systemMapping.methodMappingFrom_selector_(_superMapping[0], _sel);
                if ((_methodMapping != null) && (_methodMapping.methodNode() != null)) {
                    return _aBlock.value_(_methodMapping.methodNode());
                }
            }
            return SystemMappingUpdater.this;
        }
    });
    return this;
}
Also used : ClassMapping(st.gravel.support.compiler.ast.ClassMapping) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping) List(java.util.List) ArrayList(java.util.ArrayList) Set(java.util.Set) HashSet(java.util.HashSet) AbstractMethodMapping(st.gravel.support.compiler.ast.AbstractMethodMapping) BigInteger(java.math.BigInteger) JVMClass(st.gravel.support.compiler.jvm.JVMClass)

Aggregations

AbstractMethodMapping (st.gravel.support.compiler.ast.AbstractMethodMapping)6 BigInteger (java.math.BigInteger)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)2 ClassMapping (st.gravel.support.compiler.ast.ClassMapping)2 Reference (st.gravel.support.compiler.ast.Reference)2 MethodHandle (java.lang.invoke.MethodHandle)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)1 ClassNode (st.gravel.support.compiler.ast.ClassNode)1 ExtensionClassPartMapping (st.gravel.support.compiler.ast.ExtensionClassPartMapping)1 InstVarMapping (st.gravel.support.compiler.ast.InstVarMapping)1 MethodNode (st.gravel.support.compiler.ast.MethodNode)1 SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)1 VariableDeclarationNode (st.gravel.support.compiler.ast.VariableDeclarationNode)1