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));
}
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);
}
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);
}
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";
}
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;
}
Aggregations