Search in sources :

Example 11 with Reference

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

the class ImageBootstrapperTest method testLookupClass.

@Test
public void testLookupClass() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    ImageBootstrapper.bootstrap();
    systemMapping = ImageBootstrapper.systemMapping;
    Reference ref = Reference.factory.value_("st.gravel.lang.Message class");
    AbstractClassMapping meta = systemMapping.classMappingAtReference_(ref);
    Object cl = systemMapping.singletonAtReference_(ref.nonmeta());
    Method basicNew = cl.getClass().getMethod("basicNew");
    Object instance = basicNew.invoke(cl);
    Method r_class = instance.getClass().getMethod("r_class");
    Object instanceClass = r_class.invoke(instance);
    assertEquals(meta.identityClass(), instanceClass.getClass());
}
Also used : Reference(st.gravel.support.compiler.ast.Reference) Method(java.lang.reflect.Method) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping) Test(org.junit.Test)

Example 12 with Reference

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

the class MetaclassNode method superclassReferenceForMethodLookup.

@Override
public Reference superclassReferenceForMethodLookup() {
    final Reference _csr;
    _csr = _classNode.superclassReference();
    if (_csr == null) {
        return AbsoluteReference.factory.path_(new st.gravel.core.Symbol[] { st.gravel.core.Symbol.value("st"), st.gravel.core.Symbol.value("gravel"), st.gravel.core.Symbol.value("lang"), st.gravel.core.Symbol.value("Class") });
    }
    return ClassReference.factory.reference_(((AbsoluteReference) _csr));
}
Also used : Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) ClassReference(st.gravel.support.compiler.ast.ClassReference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference)

Example 13 with Reference

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

the class AbstractClassMapping method superclassMappingIn_.

public AbstractClassMapping superclassMappingIn_(final SystemMapping _aSystemMapping) {
    final Reference _superclassReference;
    _superclassReference = this.superclassReference();
    if (_superclassReference == null) {
        return null;
    }
    return _aSystemMapping.classMappingAtReference_(_superclassReference);
}
Also used : Reference(st.gravel.support.compiler.ast.Reference)

Example 14 with Reference

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

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

the class SystemMappingUpdater method link.

public SystemMappingUpdater link() {
    _systemMapping.classMappingsDo_(new st.gravel.support.jvm.Block1<Object, AbstractClassMapping>() {

        @Override
        public Object value_(final AbstractClassMapping _acm) {
            if (_acm.classNode().isMeta()) {
                SystemMappingUpdater.this.initializeClassShareds_(((MetaclassNode) _acm.classNode()));
                return _systemMapping.singletonAtReference_ifAbsentPut_(_acm.reference().nonmeta(), new st.gravel.support.jvm.Block0<Object>() {

                    @Override
                    public Object value() {
                        return _compilerTools.createSingletonForClass_(_acm.identityClass());
                    }
                });
            }
            return SystemMappingUpdater.this;
        }
    });
    _compilerTools.resetCallsites();
    _systemMapping.namespaceGlobalsAndInitializersDo_(new st.gravel.support.jvm.Block2<Object, AbsoluteReference, SharedDeclarationNode>() {

        @Override
        public Object value_value_(final AbsoluteReference _reference, final SharedDeclarationNode _sharedVariable) {
            return _systemMapping.singletonAtReference_initialize_(_reference, _sharedVariable);
        }
    });
    for (final Reference _ref : _toInitialize) {
        _compilerTools.initializeClass_systemMapping_(((ClassMapping) _systemMapping.classMappingAtReference_(_ref)), _systemMapping);
    }
    _toInitialize = new java.util.ArrayList();
    return this;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ClassMapping(st.gravel.support.compiler.ast.ClassMapping) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) SharedDeclarationNode(st.gravel.support.compiler.ast.SharedDeclarationNode) ArrayList(java.util.ArrayList) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping)

Aggregations

Reference (st.gravel.support.compiler.ast.Reference)17 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)11 AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ClassDescriptionNode (st.gravel.support.compiler.ast.ClassDescriptionNode)3 ClassNode (st.gravel.support.compiler.ast.ClassNode)3 MethodHandle (java.lang.invoke.MethodHandle)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 AbstractMethodMapping (st.gravel.support.compiler.ast.AbstractMethodMapping)2 ClassMapping (st.gravel.support.compiler.ast.ClassMapping)2 ClassReference (st.gravel.support.compiler.ast.ClassReference)2 NamespaceNode (st.gravel.support.compiler.ast.NamespaceNode)2 SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)2 JVMDefinedObjectType (st.gravel.support.compiler.jvm.JVMDefinedObjectType)2 ConstantCallSite (java.lang.invoke.ConstantCallSite)1 Constructor (java.lang.reflect.Constructor)1 HashSet (java.util.HashSet)1