Search in sources :

Example 6 with ObjectType

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

the class ImplicitCastTest method testIntOtherObject.

@Test
public void testIntOtherObject() {
    Shape rootShape = layout.createShape(new ObjectType());
    DynamicObject object = rootShape.newInstance();
    object.define("a", intVal);
    object.define("a", otherVal);
    object.define("a", "");
    Location location = object.getShape().getProperty("a").getLocation();
    Assert.assertEquals(Object.class, getLocationType(location));
    Assert.assertEquals(String.class, object.get("a").getClass());
}
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 7 with ObjectType

use of com.oracle.truffle.api.object.ObjectType 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);
}
Also used : ObjectType(com.oracle.truffle.api.object.ObjectType) Shape(com.oracle.truffle.api.object.Shape) Layout(com.oracle.truffle.api.object.Layout) DefaultLayoutFactory(com.oracle.truffle.object.basic.DefaultLayoutFactory) Test(org.junit.Test)

Example 8 with ObjectType

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

the class LayoutParser method parseGuard.

private void parseGuard(ExecutableElement methodElement) {
    if (methodElement.getParameters().size() != 1) {
        processor.reportError(methodElement, "@Layout guard methods must have just one parameter");
    }
    final VariableElement parameter = methodElement.getParameters().get(0);
    final TypeMirror type = parameter.asType();
    final String parameterName = parameter.getSimpleName().toString();
    final String expectedParameterName;
    if (isSameType(type, DynamicObject.class)) {
        hasDynamicObjectGuard = true;
        expectedParameterName = "object";
    } else if (isSameType(type, ObjectType.class)) {
        hasObjectTypeGuard = true;
        expectedParameterName = "objectType";
    } else if (isSameType(type, Object.class)) {
        hasObjectGuard = true;
        expectedParameterName = "object";
    } else {
        processor.reportError(methodElement, "@Layout guard method with unknown parameter type %s - don't know how to guard on this", type);
        expectedParameterName = null;
    }
    if (expectedParameterName != null && !matches(parameterName, expectedParameterName)) {
        processor.reportError(methodElement, "@Layout guard method should have a parameter named %s", expectedParameterName);
    }
}
Also used : ObjectType(com.oracle.truffle.api.object.ObjectType) TypeMirror(javax.lang.model.type.TypeMirror) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

ObjectType (com.oracle.truffle.api.object.ObjectType)8 Shape (com.oracle.truffle.api.object.Shape)7 Test (org.junit.Test)7 DynamicObject (com.oracle.truffle.api.object.DynamicObject)6 Location (com.oracle.truffle.api.object.Location)6 Layout (com.oracle.truffle.api.object.Layout)2 DefaultLayoutFactory (com.oracle.truffle.object.basic.DefaultLayoutFactory)2 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1