Java Code Examples for com.oracle.truffle.api.frame.VirtualFrame#setObject()

The following examples show how to use com.oracle.truffle.api.frame.VirtualFrame#setObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HashemReadLocalVariableNode.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@Specialization(replaces = {"readLong", "readBoolean"})
protected Object readObject(VirtualFrame frame) {
    if (!frame.isObject(getSlot())) {
        /*
         * The FrameSlotKind has been set to Object, so from now on all writes to the local
         * variable will be Object writes. However, now we are in a frame that still has an old
         * non-Object value. This is a slow-path operation: we read the non-Object value, and
         * write it immediately as an Object value so that we do not hit this path again
         * multiple times for the same variable of the same frame.
         */
        CompilerDirectives.transferToInterpreter();
        Object result = frame.getValue(getSlot());
        frame.setObject(getSlot(), result);
        return result;
    }

    return FrameUtil.getObjectSafe(frame, getSlot());
}
 
Example 2
Source File: HashemWriteLocalVariableNode.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
/**
 * Generic write method that works for all possible types.
 * <p>
 * Why is this method annotated with {@link Specialization} and not {@link Fallback}? For a
 * {@link Fallback} method, the Truffle DSL generated code would try all other specializations
 * first before calling this method. We know that all these specializations would fail their
 * guards, so there is no point in calling them. Since this method takes a value of type
 * {@link Object}, it is guaranteed to never fail, i.e., once we are in this specialization the
 * node will never be re-specialized.
 */
@Specialization(replaces = {"writeLong", "writeBoolean"})
protected Object write(VirtualFrame frame, Object value) {
    /*
     * Regardless of the type before, the new and final type of the local variable is Object.
     * Changing the slot kind also discards compiled code, because the variable type is
     * important when the compiler optimizes a method.
     *
     * No-op if kind is already Object.
     */
    frame.getFrameDescriptor().setFrameSlotKind(getSlot(), FrameSlotKind.Object);

    frame.setObject(getSlot(), value);
    return value;
}
 
Example 3
Source File: MapDeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Object execute(VirtualFrame frame) {
    frame.setLong(SIZE_SLOT, (long) frame.getArguments()[0]);
    frame.setLong(INDEX_SLOT, 0);
    frame.setObject(SOURCE_SLOT, frame.getArguments()[1]);
    frame.setObject(RESULT_SLOT, frame.getArguments()[2]);
    loop.executeLoop(frame);
    return NoneValue.get();
}
 
Example 4
Source File: DefineNode.java    From mumbler with GNU General Public License v3.0 5 votes vote down vote up
@Specialization(replaces = {"writeLong", "writeBoolean"})
protected Object write(VirtualFrame virtualFrame, Object value) {
	FrameSlot slot = this.getSlot();
	if (slot.getKind() != FrameSlotKind.Object) {
		CompilerDirectives.transferToInterpreterAndInvalidate();
		slot.setKind(FrameSlotKind.Object);
	}
	virtualFrame.setObject(slot, value);
	return value;
}
 
Example 5
Source File: MumblerContext.java    From mumbler with GNU General Public License v3.0 4 votes vote down vote up
private static void addGlobalFunctions(MumblerLanguage lang, VirtualFrame virtualFrame) {
        FrameDescriptor frameDescriptor = virtualFrame.getFrameDescriptor();
        virtualFrame.setObject(frameDescriptor.addFrameSlot("println"),
                createBuiltinFunction(lang, PrintlnBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("+"),
                createBuiltinFunction(lang, AddBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("-"),
                createBuiltinFunction(lang, SubBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("*"),
                createBuiltinFunction(lang, MulBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("/"),
                createBuiltinFunction(lang, DivBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("%"),
                createBuiltinFunction(lang, ModBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("="),
                createBuiltinFunction(lang, EqualBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("<"),
                createBuiltinFunction(lang, LessThanBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot(">"),
                createBuiltinFunction(lang, GreaterThanBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("list"),
                createBuiltinFunction(lang, ListBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("cons"),
                createBuiltinFunction(lang, ConsBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("car"),
                createBuiltinFunction(lang, CarBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("cdr"),
                createBuiltinFunction(lang, CdrBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("now"),
                createBuiltinFunction(lang, NowBuiltinNodeFactory.getInstance(),
                        virtualFrame));
//        virtualFrame.setObject(frameDescriptor.addFrameSlot("eval"),
//                createBuiltinFunction(EvalBuiltinNodeFactory.getInstance(),
//                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("read"),
                createBuiltinFunction(lang, ReadBuiltinNodeFactory.getInstance(),
                        virtualFrame));
        virtualFrame.setObject(frameDescriptor.addFrameSlot("sleep"),
                createBuiltinFunction(lang, SleepBuiltinNodeFactory.getInstance(),
                        virtualFrame));
    }