use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class ValidTruffleObject15Test method expectTypeError.
@Test(expected = UnsupportedTypeException.class)
public void expectTypeError() throws UnknownIdentifierException, UnsupportedTypeException, UnsupportedMessageException {
ValidTruffleObject15 object = new ValidTruffleObject15();
Node read = Message.WRITE.createNode();
ForeignAccess.sendWrite(read, object, new UnknownObject(), new UnknownObject());
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class ValidTruffleObject15Test method expectUnsupportedSpecializationException.
@Test(expected = UnsupportedSpecializationException.class)
public void expectUnsupportedSpecializationException() {
ValidTruffleObject15 object = new ValidTruffleObject15();
Node read = Message.WRITE.createNode();
try {
ForeignAccess.sendWrite(read, object, "name", new UnknownObject());
} catch (UnknownIdentifierException e) {
Assert.fail();
} catch (UnsupportedMessageException e) {
Assert.fail();
} catch (UnsupportedTypeException e) {
Assert.fail();
}
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class FlatNodeGenFactory method persistCache.
private Collection<IfTriple> persistCache(FrameState frameState, SpecializationData specialization, CacheExpression cache, CodeTree cacheValue) {
String name = createFieldName(specialization, cache.getParameter());
LocalVariable local = frameState.get(name);
CodeTree value;
if (local != null) {
// already initialized and stored don't use init.
value = local.createReference();
} else if (cacheValue == null) {
return Collections.emptyList();
} else {
value = cacheValue;
}
TypeMirror type = cache.getParameter().getType();
String frameStateInitialized = name + "$initialized";
if (frameState.getBoolean(frameStateInitialized, false)) {
return Collections.emptyList();
} else {
frameState.setBoolean(frameStateInitialized, true);
}
List<IfTriple> triples = new ArrayList<>();
CodeTreeBuilder builder = new CodeTreeBuilder(null);
Parameter parameter = cache.getParameter();
boolean useSpecializationClass = useSpecializationClass(specialization);
if (!useSpecializationClass || frameState.getBoolean(createSpecializationClassPersisted(specialization), false)) {
String insertTarget;
if (useSpecializationClass) {
insertTarget = createSpecializationLocalName(specialization);
} else {
insertTarget = "super";
}
TypeMirror nodeType = context.getType(Node.class);
TypeMirror nodeArrayType = context.getType(Node[].class);
boolean isNode = ElementUtils.isAssignable(parameter.getType(), nodeType);
boolean isNodeInterface = isNode || ElementUtils.isAssignable(type, context.getType(NodeInterface.class));
boolean isNodeArray = ElementUtils.isAssignable(type, nodeArrayType);
boolean isNodeInterfaceArray = isNodeArray || isNodeInterfaceArray(type);
if (isNodeInterface || isNodeInterfaceArray) {
builder = new CodeTreeBuilder(null);
String fieldName = createFieldName(specialization, cache.getParameter()) + "__";
String insertName = useSpecializationClass ? useInsertAccessor(specialization, !isNodeInterface) : "insert";
final TypeMirror castType;
if (isNodeInterface) {
if (isNode) {
castType = null;
} else {
castType = nodeType;
}
} else {
assert isNodeInterfaceArray;
if (isNodeArray) {
castType = null;
} else {
castType = nodeArrayType;
}
}
if (castType == null) {
CodeTreeBuilder noCast = new CodeTreeBuilder(null);
noCast.startCall(insertTarget, insertName);
noCast.tree(value);
noCast.end();
value = noCast.build();
} else {
builder.declaration(cache.getExpression().getResolvedType(), fieldName, value);
builder.startIf().string(fieldName).instanceOf(castType).end().startBlock();
builder.startStatement().startCall(insertTarget, insertName);
builder.startGroup().cast(castType).string(fieldName).end();
builder.end().end();
builder.end();
value = CodeTreeBuilder.singleString(fieldName);
}
}
}
builder.startStatement();
builder.tree(createCacheReference(frameState, specialization, cache.getParameter())).string(" = ").tree(value);
builder.end();
triples.add(new IfTriple(builder.build(), null, null));
return triples;
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class OverloadedTest method testNarrowing.
@Test
public void testNarrowing() throws InteropException {
Node n = Message.createInvoke(1).createNode();
Num num = new Num();
TruffleObject numobj = JavaInterop.asTruffleObject(num);
ForeignAccess.sendInvoke(n, numobj, "f", 42.5f);
assertEquals("float", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "f", 42.5d);
assertEquals("float", num.parameter);
}
use of com.oracle.truffle.api.nodes.Node in project graal by oracle.
the class OverloadedTest method testOverloadingNumber.
@Test
public void testOverloadingNumber() throws InteropException {
Node n = Message.createInvoke(1).createNode();
Num num = new Num();
TruffleObject numobj = JavaInterop.asTruffleObject(num);
ForeignAccess.sendInvoke(n, numobj, "x", new UnboxableToInt(21));
assertEquals("int", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "x", JavaInterop.asTruffleObject(new AtomicInteger(22)));
assertEquals("Number", num.parameter);
ForeignAccess.sendInvoke(n, numobj, "x", JavaInterop.asTruffleObject(BigInteger.TEN));
assertEquals("BigInteger", num.parameter);
}
Aggregations