Search in sources :

Example 71 with FrameDescriptor

use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.

the class FrameSlotTypeSpecializationTest method test.

@Test
public void test() {
    TruffleRuntime runtime = Truffle.getRuntime();
    FrameDescriptor frameDescriptor = new FrameDescriptor();
    FrameSlot slot = frameDescriptor.addFrameSlot("localVar", FrameSlotKind.Int);
    TestRootNode rootNode = new TestRootNode(frameDescriptor, new IntAssignLocal(slot, new StringTestChildNode()), new IntReadLocal(slot));
    CallTarget target = runtime.createCallTarget(rootNode);
    Assert.assertEquals(FrameSlotKind.Int, slot.getKind());
    Object result = target.call();
    Assert.assertEquals("42", result);
    Assert.assertEquals(FrameSlotKind.Object, slot.getKind());
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) CallTarget(com.oracle.truffle.api.CallTarget) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Example 72 with FrameDescriptor

use of com.oracle.truffle.api.frame.FrameDescriptor in project graal by oracle.

the class FrameTest method test.

@Test
public void test() throws SecurityException, IllegalArgumentException {
    TruffleRuntime runtime = Truffle.getRuntime();
    FrameDescriptor frameDescriptor = new FrameDescriptor();
    String varName = "localVar";
    FrameSlot slot = frameDescriptor.addFrameSlot(varName, FrameSlotKind.Int);
    TestRootNode rootNode = new TestRootNode(frameDescriptor, new AssignLocal(slot), new ReadLocal(slot));
    CallTarget target = runtime.createCallTarget(rootNode);
    Object result = target.call();
    Assert.assertEquals(42, result);
    frameDescriptor.removeFrameSlot(varName);
    boolean slotMissing = false;
    try {
        result = target.call();
    } catch (IllegalArgumentException iae) {
        slotMissing = true;
    }
    Assert.assertTrue(slotMissing);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) CallTarget(com.oracle.truffle.api.CallTarget) TruffleRuntime(com.oracle.truffle.api.TruffleRuntime) Test(org.junit.Test)

Aggregations

FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)72 Test (org.junit.Test)61 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)50 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)43 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)14 ConstantTestNode (org.graalvm.compiler.truffle.test.nodes.ConstantTestNode)14 RootNode (com.oracle.truffle.api.nodes.RootNode)12 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)9 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)7 AddTestNode (org.graalvm.compiler.truffle.test.nodes.AddTestNode)7 BlockTestNode (org.graalvm.compiler.truffle.test.nodes.BlockTestNode)6 Assumption (com.oracle.truffle.api.Assumption)5 CallTarget (com.oracle.truffle.api.CallTarget)5 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)3 LoadLocalTestNode (org.graalvm.compiler.truffle.test.nodes.LoadLocalTestNode)3 NestedExplodedLoopTestNode (org.graalvm.compiler.truffle.test.nodes.NestedExplodedLoopTestNode)3 StoreLocalTestNode (org.graalvm.compiler.truffle.test.nodes.StoreLocalTestNode)3 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 WeakReference (java.lang.ref.WeakReference)2 List (java.util.List)2