Java Code Examples for com.oracle.truffle.api.interop.InteropLibrary#hasArrayElements()

The following examples show how to use com.oracle.truffle.api.interop.InteropLibrary#hasArrayElements() . 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: ShreddedObject.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
public Object readMember(String member,
                @CachedLibrary("this.delegate") InteropLibrary memberInterop) {
    if (memberInterop.isMemberReadable(delegate, member)) {
        try {
            return memberInterop.readMember(delegate, member);
        } catch (UnsupportedMessageException | UnknownIdentifierException e) {
            CompilerDirectives.transferToInterpreter();
            throw new MapException("cannot read 'readable' member: " + e.getMessage());
        }
    } else {
        if (memberInterop.hasArrayElements(delegate)) {
            return new ShreddedObjectMember(delegate, member);
        } else {
            CompilerDirectives.transferToInterpreter();
            throw new MapException("cannot shred object without size and member");
        }
    }
}
 
Example 2
Source File: MapDeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Specialization(limit = "3")
Object doMap(Object source, Type elementType, CUDARuntime runtime,
                @CachedLibrary("source") InteropLibrary interop,
                @CachedContext(GrCUDALanguage.class) @SuppressWarnings("unused") GrCUDAContext context,
                @Cached(value = "createLoop(source)", uncached = "createUncachedLoop(source, context)") CallTarget loop) {

    if (source instanceof DeviceArray && ((DeviceArray) source).getElementType() == elementType) {
        return source;
    }

    if (!interop.hasArrayElements(source)) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAException("cannot map from non-array to DeviceArray");
    }

    long size;
    try {
        size = interop.getArraySize(source);
    } catch (UnsupportedMessageException e) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAException("cannot read array size");
    }
    DeviceArray result = new DeviceArray(runtime, size, elementType);
    loop.call(size, source, result);
    return result;
}
 
Example 3
Source File: HashemHasSizeBuiltin.java    From mr-hashemi with Universal Permissive License v1.0 4 votes vote down vote up
@Specialization(limit = "3")
public boolean hasSize(Object obj, @CachedLibrary("obj") InteropLibrary arrays) {
    return arrays.hasArrayElements(obj);
}
 
Example 4
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 4 votes vote down vote up
@ExportMessage
@TruffleBoundary
protected boolean hasArrayElements(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) {
    return wrappedObject.getClass().isArray() || wrappedObject instanceof TruffleObject && lib.hasArrayElements(wrappedObject);
}