Search in sources :

Example 1 with AbstractClassMapping

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

the class ObjectExtensions method inheritsFrom_.

public static boolean inheritsFrom_(ObjectClass receiver, Object arg) {
    ClassMapping cm = ImageBootstrapper.systemMapping.classMappingForJavaClass_(receiver.getClass());
    ClassMapping other = ImageBootstrapper.systemMapping.classMappingForJavaClass_(arg.getClass());
    AbstractClassMapping sm = cm;
    while (sm != null) {
        sm = sm.superclassMappingIn_(ImageBootstrapper.systemMapping);
        if (sm == other)
            return true;
    }
    return false;
}
Also used : ClassMapping(st.gravel.support.compiler.ast.ClassMapping) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping)

Example 2 with AbstractClassMapping

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

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

the class SystemMapping method subclassMappingsFor_do_.

public SystemMapping subclassMappingsFor_do_(final Reference _aReference, final st.gravel.support.jvm.Block1<Object, AbstractClassMapping> _aBlock) {
    final java.util.Set<AbstractClassMapping> _c;
    if (_subclassMappingsCache == null) {
        SystemMapping.this.buildSubclassMappingsCache();
    }
    java.util.Set<AbstractClassMapping> _temp1 = _subclassMappingsCache.get(_aReference);
    _c = ((java.util.Set<AbstractClassMapping>) _temp1);
    if (_c == null) {
        return null;
    }
    for (final AbstractClassMapping _temp2 : _c) {
        _aBlock.value_(_temp2);
    }
    return this;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping)

Example 4 with AbstractClassMapping

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

Example 5 with AbstractClassMapping

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

the class SystemMapping method buildSubclassMappingsCache.

public SystemMapping buildSubclassMappingsCache() {
    _subclassMappingsCache = new java.util.HashMap<Reference, java.util.Set<AbstractClassMapping>>();
    for (final AbstractClassMapping _each : _classMappingsByReference.values()) {
        final Reference _scr;
        _scr = _each.superclassReference();
        if (_scr != null) {
            java.util.Set<AbstractClassMapping> _temp1 = _subclassMappingsCache.get(_scr);
            if (_temp1 == null) {
                java.util.Set<AbstractClassMapping> _temp2 = new java.util.HashSet();
                _subclassMappingsCache.put(_scr, _temp2);
                _temp1 = _temp2;
            }
            _temp1.add(_each);
        }
    }
    return this;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Reference(st.gravel.support.compiler.ast.Reference) AbsoluteReference(st.gravel.support.compiler.ast.AbsoluteReference) AbstractClassMapping(st.gravel.support.compiler.ast.AbstractClassMapping) HashSet(java.util.HashSet)

Aggregations

AbstractClassMapping (st.gravel.support.compiler.ast.AbstractClassMapping)5 Reference (st.gravel.support.compiler.ast.Reference)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 AbsoluteReference (st.gravel.support.compiler.ast.AbsoluteReference)2 ClassMapping (st.gravel.support.compiler.ast.ClassMapping)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Test (org.junit.Test)1 SharedDeclarationNode (st.gravel.support.compiler.ast.SharedDeclarationNode)1