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