Search in sources :

Example 1 with FrameSlot

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

the class BytecodeInterpreterPartialEvaluationTest method instArraySimpleIfProgram.

@Test
public void instArraySimpleIfProgram() {
    FrameDescriptor fd = new FrameDescriptor();
    FrameSlot valueSlot = fd.addFrameSlot("value", FrameSlotKind.Int);
    FrameSlot returnSlot = fd.addFrameSlot("return", FrameSlotKind.Int);
    Inst[] inst = new Inst[] { /* 0: */
    new Inst.Const(valueSlot, 1, 1), /* 1: */
    new Inst.IfZero(valueSlot, 2, 4), /* 2: */
    new Inst.Const(returnSlot, 41, 3), /* 3: */
    new Inst.Return(), /* 4: */
    new Inst.Const(returnSlot, 42, 5), /* 5: */
    new Inst.Return() };
    assertPartialEvalEqualsAndRunsCorrect(new InstArrayProgram("instArraySimpleIfProgram", inst, returnSlot, fd));
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) Test(org.junit.Test)

Example 2 with FrameSlot

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

the class FrameDescriptorTest method shallowCopy.

@Test
public void shallowCopy() {
    Object defaultValue = "default";
    FrameDescriptor d = new FrameDescriptor(defaultValue);
    s1 = d.addFrameSlot("v1", "i1", FrameSlotKind.Boolean);
    s2 = d.addFrameSlot("v2", "i2", FrameSlotKind.Float);
    assertEquals(2, d.getSize());
    final FrameSlot first = d.getSlots().get(1);
    assertEquals(first.getInfo(), "i2");
    assertEquals(first.getKind(), FrameSlotKind.Float);
    assertEquals(first.getIndex(), 1);
    FrameDescriptor copy = d.shallowCopy();
    assertEquals(2, copy.getSize());
    final FrameSlot firstCopy = copy.getSlots().get(1);
    assertEquals("Info is copied", firstCopy.getInfo(), "i2");
    assertEquals("Kind is copied", firstCopy.getKind(), FrameSlotKind.Float);
    assertEquals(firstCopy.getIndex(), 1);
    firstCopy.setKind(FrameSlotKind.Int);
    assertEquals("Kind is changed", firstCopy.getKind(), FrameSlotKind.Int);
    assertEquals("Kind is changed in original too!", first.getKind(), FrameSlotKind.Int);
}
Also used : FrameDescriptor(com.oracle.truffle.api.frame.FrameDescriptor) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) Test(org.junit.Test)

Example 3 with FrameSlot

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

the class DefaultScope method getVariables.

private static Object getVariables(RootNode root, Frame frame) {
    List<? extends FrameSlot> slots;
    if (frame == null) {
        slots = root.getFrameDescriptor().getSlots();
    } else {
        slots = frame.getFrameDescriptor().getSlots();
        // Filter out slots with null values:
        List<FrameSlot> nonNulls = null;
        int lastI = 0;
        for (int i = 0; i < slots.size(); i++) {
            FrameSlot slot = slots.get(i);
            if (frame.getValue(slot) == null || isInternal(slot)) {
                if (nonNulls == null) {
                    nonNulls = new ArrayList<>(slots.size());
                }
                nonNulls.addAll(slots.subList(lastI, i));
                lastI = i + 1;
            }
        }
        if (nonNulls != null) {
            if (lastI < slots.size()) {
                nonNulls.addAll(slots.subList(lastI, slots.size()));
            }
            slots = nonNulls;
        }
    }
    Map<String, FrameSlot> slotsMap;
    if (slots.isEmpty()) {
        slotsMap = Collections.emptyMap();
    } else if (slots.size() == 1) {
        FrameSlot slot = slots.get(0);
        slotsMap = Collections.singletonMap(Objects.toString(slot.getIdentifier()), slot);
    } else {
        slotsMap = new LinkedHashMap<>(slots.size());
        for (FrameSlot slot : slots) {
            slotsMap.put(Objects.toString(slot.getIdentifier()), slot);
        }
    }
    return new VariablesMapObject(slotsMap, frame);
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with FrameSlot

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

the class SLHelloEqualsWorldBuiltin method change.

@Specialization
@TruffleBoundary
public String change() {
    FrameInstance frameInstance = Truffle.getRuntime().getCallerFrame();
    Frame frame = frameInstance.getFrame(FrameAccess.READ_WRITE);
    FrameSlot slot = frame.getFrameDescriptor().findOrAddFrameSlot("hello");
    frame.setObject(slot, "world");
    return "world";
}
Also used : Frame(com.oracle.truffle.api.frame.Frame) FrameSlot(com.oracle.truffle.api.frame.FrameSlot) FrameInstance(com.oracle.truffle.api.frame.FrameInstance) Specialization(com.oracle.truffle.api.dsl.Specialization) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 5 with FrameSlot

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

the class SLNodeFactory method createRead.

/**
 * Returns a {@link SLReadLocalVariableNode} if this read is a local variable or a
 * {@link SLFunctionLiteralNode} if this read is global. In SL, the only global names are
 * functions.
 *
 * @param nameNode The name of the variable/function being read
 * @return either:
 *         <ul>
 *         <li>A SLReadLocalVariableNode representing the local variable being read.</li>
 *         <li>A SLFunctionLiteralNode representing the function definition.</li>
 *         <li>null if nameNode is null.</li>
 *         </ul>
 */
public SLExpressionNode createRead(SLExpressionNode nameNode) {
    if (nameNode == null) {
        return null;
    }
    String name = ((SLStringLiteralNode) nameNode).executeGeneric(null);
    final SLExpressionNode result;
    final FrameSlot frameSlot = lexicalScope.locals.get(name);
    if (frameSlot != null) {
        /* Read of a local variable. */
        result = SLReadLocalVariableNodeGen.create(frameSlot);
    } else {
        /* Read of a global name. In our language, the only global names are functions. */
        result = new SLFunctionLiteralNode(language, name);
    }
    result.setSourceSection(nameNode.getSourceCharIndex(), nameNode.getSourceLength());
    return result;
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) SLFunctionLiteralNode(com.oracle.truffle.sl.nodes.expression.SLFunctionLiteralNode) SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) SLStringLiteralNode(com.oracle.truffle.sl.nodes.expression.SLStringLiteralNode)

Aggregations

FrameSlot (com.oracle.truffle.api.frame.FrameSlot)47 LLVMExpressionNode (com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode)12 PrimitiveType (com.oracle.truffle.llvm.runtime.types.PrimitiveType)11 PointerType (com.oracle.truffle.llvm.runtime.types.PointerType)10 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)7 TypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.TypeDescriptor)7 ReturnTypeDescriptor (cz.cuni.mff.d3s.trupple.parser.identifierstable.types.subroutine.ReturnTypeDescriptor)7 StructureType (com.oracle.truffle.llvm.runtime.types.StructureType)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Type (com.oracle.truffle.llvm.runtime.types.Type)5 CallTarget (com.oracle.truffle.api.CallTarget)4 TruffleRuntime (com.oracle.truffle.api.TruffleRuntime)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 Phi (com.oracle.truffle.llvm.parser.LLVMPhiManager.Phi)3 LLVMArithmeticInstructionType (com.oracle.truffle.llvm.parser.instructions.LLVMArithmeticInstructionType)3 LLVMConversionType (com.oracle.truffle.llvm.parser.instructions.LLVMConversionType)3 SymbolImpl (com.oracle.truffle.llvm.parser.model.SymbolImpl)3 LexicalException (cz.cuni.mff.d3s.trupple.parser.exceptions.LexicalException)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2