Search in sources :

Example 1 with Shape

use of com.oracle.truffle.api.object.Shape in project graal by oracle.

the class ObjectTypeTest method objectTypeRespondsToIsArray.

@Test
public void objectTypeRespondsToIsArray() {
    final Layout layout = Layout.newLayout().build();
    final Shape rootShape = layout.createShape(OBJECT_TYPE);
    final DynamicObject obj = rootShape.newInstance();
    final boolean is = JavaInteropTest.isArray(obj);
    assertFalse("It is not array", is);
}
Also used : Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Layout(com.oracle.truffle.api.object.Layout) Test(org.junit.Test)

Example 2 with Shape

use of com.oracle.truffle.api.object.Shape in project graal by oracle.

the class ImplicitCastTest method testCanAssignIntToDouble.

@Test
public void testCanAssignIntToDouble() {
    final DynamicObject object = CAST_LAYOUT.createCast(14, 14.2);
    final Shape shapeBefore = object.getShape();
    assertTrue(object.set(CastLayout.DOUBLE_VALUE_IDENTIFIER, 14));
    assertEquals(shapeBefore, object.getShape());
}
Also used : Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Test(org.junit.Test)

Example 3 with Shape

use of com.oracle.truffle.api.object.Shape in project graal by oracle.

the class ImplicitCastTest method testCanAssignIntToLong.

@Test
public void testCanAssignIntToLong() {
    final DynamicObject object = CAST_LAYOUT.createCast(14, 14.2);
    final Shape shapeBefore = object.getShape();
    assertTrue(object.set(CastLayout.LONG_VALUE_IDENTIFIER, 14));
    assertEquals(shapeBefore, object.getShape());
}
Also used : Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Test(org.junit.Test)

Example 4 with Shape

use of com.oracle.truffle.api.object.Shape in project graal by oracle.

the class ImplicitCastTest method testOtherInt.

@Test
public void testOtherInt() {
    Shape rootShape = layout.createShape(new ObjectType());
    DynamicObject object = rootShape.newInstance();
    object.define("a", otherVal);
    Location location1 = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(otherPrimClass, getLocationType(location1));
    object.define("a", intVal);
    Location location2 = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(otherPrimClass, getLocationType(location2));
    Assert.assertEquals(otherVal.getClass(), object.get("a").getClass());
    DOTestAsserts.assertSameLocation(location1, location2);
}
Also used : ObjectType(com.oracle.truffle.api.object.ObjectType) Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Location(com.oracle.truffle.api.object.Location) Test(org.junit.Test)

Example 5 with Shape

use of com.oracle.truffle.api.object.Shape in project graal by oracle.

the class ImplicitCastTest method testLocationDecoratorEquals.

@Test
public void testLocationDecoratorEquals() {
    Layout defaultLayout = new DefaultLayoutFactory().createLayout(Layout.newLayout());
    Shape defaultRootShape = defaultLayout.createShape(new ObjectType());
    Shape implicitCastRootShape = layout.createShape(new ObjectType());
    DynamicObject object1 = implicitCastRootShape.newInstance();
    object1.define("a", otherVal);
    Location location1 = object1.getShape().getProperty("a").getLocation();
    // Location of "a" should not change if an Integer is set
    object1.set("a", intVal);
    Assert.assertEquals(location1, object1.getShape().getProperty("a").getLocation());
    DynamicObject object2 = defaultRootShape.newInstance();
    object2.define("a", otherVal);
    Location location2 = object2.getShape().getProperty("a").getLocation();
    // This test relies on the assumption that both locations are of the same class
    Assert.assertEquals(location1.getClass(), location2.getClass());
    Assert.assertNotEquals(location1, location2);
}
Also used : ObjectType(com.oracle.truffle.api.object.ObjectType) Shape(com.oracle.truffle.api.object.Shape) DynamicObject(com.oracle.truffle.api.object.DynamicObject) Layout(com.oracle.truffle.api.object.Layout) DefaultLayoutFactory(com.oracle.truffle.object.basic.DefaultLayoutFactory) Location(com.oracle.truffle.api.object.Location) Test(org.junit.Test)

Aggregations

Shape (com.oracle.truffle.api.object.Shape)18 DynamicObject (com.oracle.truffle.api.object.DynamicObject)16 Test (org.junit.Test)15 Location (com.oracle.truffle.api.object.Location)7 ObjectType (com.oracle.truffle.api.object.ObjectType)7 Layout (com.oracle.truffle.api.object.Layout)5 DefaultLayoutFactory (com.oracle.truffle.object.basic.DefaultLayoutFactory)2 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 DynamicObjectFactory (com.oracle.truffle.api.object.DynamicObjectFactory)1 LocationFactory (com.oracle.truffle.api.object.LocationFactory)1 ObjectLocation (com.oracle.truffle.api.object.ObjectLocation)1 Property (com.oracle.truffle.api.object.Property)1 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1