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

The following examples show how to use com.oracle.truffle.api.interop.InteropLibrary#execute() . 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: CallNode.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Specialization
Object doDefault(VirtualFrame frame,
                @CachedLibrary(limit = "2") InteropLibrary interop,
                @CachedContext(GrCUDALanguage.class) GrCUDAContext context) {
    String[] functionName = identifier.getIdentifierName();
    Namespace namespace = context.getRootNamespace();
    Optional<Object> maybeFunction = namespace.lookup(functionName);
    if (!maybeFunction.isPresent() || !(maybeFunction.get() instanceof Function)) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAException("function '" + GrCUDAException.format(functionName) + "' not found", this);
    }
    Function function = (Function) maybeFunction.get();
    Object[] argumentValues = new Object[argumentNodes.length];
    for (int i = 0; i < argumentNodes.length; i++) {
        argumentValues[i] = argumentNodes[i].execute(frame);
    }
    try {
        return interop.execute(function, argumentValues);
    } catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAException(e.getMessage(), this);
    }
}
 
Example 2
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Specialization(guards = "cachedReceiver == receiver", limit = "1")
static Object executeCached(@SuppressWarnings("unused") MappedFunction receiver, Object[] arguments,
                @Cached("receiver") MappedFunction cachedReceiver,
                @CachedLibrary("cachedReceiver.function") InteropLibrary functionInterop,
                @CachedLibrary("cachedReceiver.returnValue") InteropLibrary resultInterop,
                @Cached(value = "createInterop(cachedReceiver)") InteropLibrary[] valueInterop)
                throws IllegalStateException, UnsupportedTypeException, ArityException, UnsupportedMessageException {
    Object[] shredded = createShredded(cachedReceiver.shreddedArguments, arguments);
    Object[] values = new Object[receiver.valueCount];
    ArgumentArray wrappedArguments = new ArgumentArray(arguments);
    ArgumentArray wrappedShreddedArguments = new ArgumentArray(shredded);
    ArgumentArray wrappedValueArguments = new ArgumentArray(values);
    Object[] mappedArguments = mapArguments(valueInterop, cachedReceiver, wrappedArguments, wrappedShreddedArguments, wrappedValueArguments);
    Object result = functionInterop.execute(cachedReceiver.function, mappedArguments);
    return processResult(receiver, resultInterop, values, wrappedArguments, wrappedShreddedArguments, wrappedValueArguments, result);
}
 
Example 3
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary("this.parent") InteropLibrary parentInterop,
                @CachedLibrary(limit = "2") InteropLibrary memberInterop) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
    if (arguments.length != 3) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(3, arguments.length);
    }
    Object value = parentInterop.execute(parent, arguments);
    try {
        return memberInterop.readMember(value, name);
    } catch (UnsupportedMessageException | UnknownIdentifierException e) {
        CompilerDirectives.transferToInterpreter();
        throw new MapException("cannot read member '" + name + "' from argument " + parent);
    }
}
 
Example 4
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary("this.parent") InteropLibrary parentInterop,
                @CachedLibrary(limit = "2") InteropLibrary elementInterop) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
    if (arguments.length != 3) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(3, arguments.length);
    }
    Object value = parentInterop.execute(parent, arguments);
    try {
        return elementInterop.readArrayElement(value, index);
    } catch (UnsupportedMessageException | InvalidArrayIndexException e) {
        CompilerDirectives.transferToInterpreter();
        throw new MapException("cannot read element '" + index + "' from argument " + parent);
    }
}
 
Example 5
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary("this.parent") InteropLibrary parentInterop,
                @CachedLibrary("this.function") InteropLibrary mapInterop) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
    if (arguments.length != 3) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(3, arguments.length);
    }
    Object value = parentInterop.execute(parent, arguments);
    try {
        return mapInterop.execute(function, value);
    } catch (UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new MapException("cannot map argument " + parent);
    }
}
 
Example 6
Source File: AbstractOSProcessPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
protected final long setValue(final InteropLibrary lib, final long id, final long value) {
    try {
        return (int) lib.execute(sysCallObject, (int) id, (int) value);
    } catch (final UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        throw PrimitiveFailed.andTransferToInterpreterWithError(e);
    }
}
 
Example 7
Source File: AbstractOSProcessPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
protected final long getValue(final InteropLibrary lib, final long id) {
    try {
        return (int) lib.execute(sysCallObject, (int) id);
    } catch (final UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        throw PrimitiveFailed.andTransferToInterpreterWithError(e);
    }
}
 
Example 8
Source File: AbstractOSProcessPlugin.java    From trufflesqueak with MIT License 5 votes vote down vote up
protected final long getValue(final InteropLibrary lib) {
    try {
        return (int) lib.execute(sysCallObject);
    } catch (final UnsupportedMessageException | UnsupportedTypeException | ArityException e) {
        throw PrimitiveFailed.andTransferToInterpreterWithError(e);
    }
}
 
Example 9
Source File: DeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object invokeMember(String memberName,
                Object[] arguments,
                @CachedLibrary("this") InteropLibrary interopRead,
                @CachedLibrary(limit = "1") InteropLibrary interopExecute)
                throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    return interopExecute.execute(interopRead.readMember(this, memberName), arguments);
}
 
Example 10
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Object processResult(MappedFunction receiver, InteropLibrary resultInterop, Object[] values, ArgumentArray wrappedArguments, ArgumentArray wrappedShreddedArguments,
                ArgumentArray wrappedValueArguments, Object result) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
    if (receiver.returnValueIndex != null) {
        values[receiver.returnValueIndex] = result;
    }
    return resultInterop.execute(receiver.returnValue, wrappedArguments, wrappedShreddedArguments, wrappedValueArguments);
}
 
Example 11
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary("this.parent") InteropLibrary parentInterop) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
    if (arguments.length != 3) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(3, arguments.length);
    }
    return new ShreddedObject(parentInterop.execute(parent, arguments));
}
 
Example 12
Source File: Device.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object invokeMember(String memberName,
                Object[] arguments,
                @CachedLibrary("this") InteropLibrary interopRead,
                @CachedLibrary(limit = "1") InteropLibrary interopExecute)
                throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    return interopExecute.execute(interopRead.readMember(this, memberName), arguments);
}
 
Example 13
Source File: MultiDimDeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object invokeMember(String memberName,
                Object[] arguments,
                @CachedLibrary("this") InteropLibrary interopRead,
                @CachedLibrary(limit = "1") InteropLibrary interopExecute)
                throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    return interopExecute.execute(interopRead.readMember(this, memberName), arguments);
}
 
Example 14
Source File: DeviceArray.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
Object invokeMember(String memberName,
                Object[] arguments,
                @CachedLibrary("this") InteropLibrary interopRead,
                @CachedLibrary(limit = "1") InteropLibrary interopExecute)
                throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    return interopExecute.execute(interopRead.readMember(this, memberName), arguments);
}
 
Example 15
Source File: MapArgObject.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@ExportMessage
Object invokeMember(String member, Object[] arguments,
                @CachedLibrary("this") InteropLibrary interopRead,
                @CachedLibrary(limit = "1") InteropLibrary interopExecute) throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    return interopExecute.execute(interopRead.readMember(this, member), arguments);
}
 
Example 16
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@ExportMessage
Object invokeMember(String member, Object[] arguments,
                @CachedLibrary("this") InteropLibrary interopRead,
                @CachedLibrary(limit = "1") InteropLibrary interopExecute) throws UnsupportedTypeException, ArityException, UnsupportedMessageException, UnknownIdentifierException {
    return interopExecute.execute(interopRead.readMember(this, member), arguments);
}
 
Example 17
Source File: Namespace.java    From grcuda with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@ExportMessage
public Object invokeMember(String member, Object[] arguments,
                @CachedLibrary(limit = "2") InteropLibrary callLibrary)
                throws UnsupportedMessageException, ArityException, UnknownIdentifierException, UnsupportedTypeException {
    return callLibrary.execute(readMember(member), arguments);
}