Search in sources :

Example 61 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostProxy method getIterator.

@ExportMessage
@TruffleBoundary
Object getIterator(@CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
    if (proxy instanceof ProxyIterable) {
        Object result = guestToHostCall(library, cache.getIterator, context, proxy);
        Object guestValue = context.toGuestValue(library, result);
        InteropLibrary interop = InteropLibrary.getFactory().getUncached();
        if (!interop.isIterator(guestValue)) {
            throw illegalProxy(context, "getIterator() returned an invalid value %s but must return an iterator.", context.asValue(library, guestValue).toString());
        }
        return guestValue;
    } else {
        throw UnsupportedMessageException.create();
    }
}
Also used : ProxyIterable(org.graalvm.polyglot.proxy.ProxyIterable) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyNativeObject(org.graalvm.polyglot.proxy.ProxyNativeObject) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 62 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostProxy method writeArrayElement.

@ExportMessage
@TruffleBoundary
void writeArrayElement(long index, Object value, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
    if (proxy instanceof ProxyArray) {
        Value castValue = context.asValue(library, value);
        guestToHostCall(library, cache.arraySet, context, proxy, index, castValue);
    } else {
        throw UnsupportedMessageException.create();
    }
}
Also used : ProxyArray(org.graalvm.polyglot.proxy.ProxyArray) Value(org.graalvm.polyglot.Value) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 63 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostProxy method getHashEntriesIterator.

@ExportMessage
@TruffleBoundary
Object getHashEntriesIterator(@CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
    if (proxy instanceof ProxyHashMap) {
        Object result = guestToHostCall(library, cache.getHashEntriesIterator, context, proxy);
        Object guestValue = context.toGuestValue(library, result);
        InteropLibrary interop = InteropLibrary.getFactory().getUncached();
        if (!interop.isIterator(guestValue)) {
            throw illegalProxy(context, "getHashEntriesIterator() returned an invalid value %s but must return an iterator.", context.asValue(library, guestValue).toString());
        }
        return guestValue;
    } else {
        throw UnsupportedMessageException.create();
    }
}
Also used : ProxyHashMap(org.graalvm.polyglot.proxy.ProxyHashMap) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ProxyNativeObject(org.graalvm.polyglot.proxy.ProxyNativeObject) ProxyObject(org.graalvm.polyglot.proxy.ProxyObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 64 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class HostProxy method writeHashEntry.

@ExportMessage
@TruffleBoundary
void writeHashEntry(Object key, Object value, @CachedLibrary("this") InteropLibrary library, @Shared("cache") @Cached(value = "this.context.getGuestToHostCache()", allowUncached = true) GuestToHostCodeCache cache) throws UnsupportedMessageException {
    if (proxy instanceof ProxyHashMap) {
        Value keyValue = this.context.asValue(library, key);
        Value valueValue = this.context.asValue(library, value);
        guestToHostCall(library, cache.putHashEntry, this.context, proxy, keyValue, valueValue);
    } else {
        throw UnsupportedMessageException.create();
    }
}
Also used : ProxyHashMap(org.graalvm.polyglot.proxy.ProxyHashMap) Value(org.graalvm.polyglot.Value) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 65 with ExportMessage

use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.

the class WasmFunctionInstance method execute.

@ExportMessage
Object execute(Object[] arguments, @CachedLibrary("this") InteropLibrary self, @Cached WasmIndirectCallNode callNode) {
    TruffleContext c = getTruffleContext();
    Object prev = c.enter(self);
    try {
        return callNode.execute(target, arguments);
    } finally {
        c.leave(self, prev);
    }
}
Also used : TruffleContext(com.oracle.truffle.api.TruffleContext) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Aggregations

ExportMessage (com.oracle.truffle.api.library.ExportMessage)68 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)24 Meta (com.oracle.truffle.espresso.meta.Meta)24 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)16 Method (com.oracle.truffle.espresso.impl.Method)13 ByteBuffer (java.nio.ByteBuffer)10 ByteOrder (java.nio.ByteOrder)10 Klass (com.oracle.truffle.espresso.impl.Klass)8 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)8 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)8 Value (org.graalvm.polyglot.Value)8 ProxyObject (org.graalvm.polyglot.proxy.ProxyObject)8 ArityException (com.oracle.truffle.api.interop.ArityException)7 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)7 ProxyNativeObject (org.graalvm.polyglot.proxy.ProxyNativeObject)7 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)6 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)5 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)4 Field (com.oracle.truffle.espresso.impl.Field)4 ProxyHashMap (org.graalvm.polyglot.proxy.ProxyHashMap)4