use of com.oracle.truffle.object.basic.DefaultLayoutFactory 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);
}
use of com.oracle.truffle.object.basic.DefaultLayoutFactory in project graal by oracle.
the class ShapeTest method testToString.
@Test
public void testToString() {
Layout layout = new DefaultLayoutFactory().createLayout(Layout.newLayout().addAllowedImplicitCast(ImplicitCast.IntToLong));
Shape rootShape = layout.createShape(new ObjectType());
DOTestAsserts.assertShape("{}", rootShape);
Shape aInt = rootShape.defineProperty("a", 1, 0);
DOTestAsserts.assertShape("{\"a\":int@0" + "\n}", aInt);
Shape aObj = aInt.defineProperty("a", new Object(), 0);
DOTestAsserts.assertShape("{\"a\":Object@0" + "\n}", aObj);
Shape aObjBInt = aObj.defineProperty("b", 2, 0);
DOTestAsserts.assertShape("{" + "\"b\":int@1,\n" + "\"a\":Object@0" + "\n}", aObjBInt);
Shape aIntBObj = aInt.defineProperty("b", new Object(), 0);
DOTestAsserts.assertShape("{" + "\"b\":Object@0,\n" + "\"a\":int@0" + "\n}", aIntBObj);
Shape bool = rootShape.addProperty(Property.create("bool", rootShape.allocator().locationForType(boolean.class), 0));
DOTestAsserts.assertShape("{\"bool\":boolean@0\n}", bool);
Shape str = rootShape.addProperty(Property.create("str", rootShape.allocator().locationForType(String.class), 0));
DOTestAsserts.assertShape("{\"str\":Object@0\n}", str);
Shape shapeWithExtArray = aIntBObj.defineProperty("c", true, 0).defineProperty("d", 3.14, 0).defineProperty("e", 1L << 44, 0);
DOTestAsserts.assertShape("{" + "\"e\":long[0],\n" + "\"d\":double@2,\n" + "\"c\":boolean@1,\n" + "\"b\":Object@0,\n" + "\"a\":int@0" + "\n}", shapeWithExtArray);
}
Aggregations