Search in sources :

Example 86 with Node

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());
}
Also used : Node(com.oracle.truffle.api.nodes.Node) Test(org.junit.Test)

Example 87 with Node

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();
    }
}
Also used : UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) Node(com.oracle.truffle.api.nodes.Node) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) Test(org.junit.Test)

Example 88 with Node

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;
}
Also used : CodeTree(com.oracle.truffle.dsl.processor.java.model.CodeTree) DeclaredCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.DeclaredCodeTypeMirror) ArrayCodeTypeMirror(com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror) GeneratedTypeMirror(com.oracle.truffle.dsl.processor.java.model.GeneratedTypeMirror) TypeMirror(javax.lang.model.type.TypeMirror) Node(com.oracle.truffle.api.nodes.Node) ArrayList(java.util.ArrayList) Parameter(com.oracle.truffle.dsl.processor.model.Parameter) CodeTreeBuilder(com.oracle.truffle.dsl.processor.java.model.CodeTreeBuilder)

Example 89 with Node

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);
}
Also used : Node(com.oracle.truffle.api.nodes.Node) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Example 90 with Node

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Node(com.oracle.truffle.api.nodes.Node) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Test(org.junit.Test)

Aggregations

Node (com.oracle.truffle.api.nodes.Node)101 RootNode (com.oracle.truffle.api.nodes.RootNode)65 Test (org.junit.Test)46 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)21 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)21 Source (com.oracle.truffle.api.source.Source)16 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)11 CallTarget (com.oracle.truffle.api.CallTarget)9 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)9 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)8 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)7 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)6 SourceSection (com.oracle.truffle.api.source.SourceSection)6 TestHelper.createNode (com.oracle.truffle.api.dsl.test.TestHelper.createNode)5 ValueNode (com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode)5 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)5 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)5 SLBlockNode (com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)5 LinkedHashMap (java.util.LinkedHashMap)5 TruffleInstrument (com.oracle.truffle.api.instrumentation.TruffleInstrument)4