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);
}
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);
}
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();
}
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;
}
})));
}
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;
}
Aggregations