com.oracle.truffle.api.interop.ArityException Java Examples

The following examples show how to use com.oracle.truffle.api.interop.ArityException. 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: ConfiguredKernel.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object execute(Object[] arguments,
                @CachedLibrary(limit = "3") InteropLibrary boolAccess,
                @CachedLibrary(limit = "3") InteropLibrary int8Access,
                @CachedLibrary(limit = "3") InteropLibrary int16Access,
                @CachedLibrary(limit = "3") InteropLibrary int32Access,
                @CachedLibrary(limit = "3") InteropLibrary int64Access,
                @CachedLibrary(limit = "3") InteropLibrary doubleAccess) throws UnsupportedTypeException, ArityException {
    kernel.incrementLaunchCount();
    try (KernelArguments args = kernel.createKernelArguments(arguments, boolAccess, int8Access, int16Access,
                    int32Access, int64Access, doubleAccess)) {
        kernel.getCudaRuntime().cuLaunchKernel(kernel, config, args);
    }
    return this;
}
 
Example #2
Source File: AbstractSqueakObject.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(rewriteOn = RespecializeException.class)
protected static final Object invokeMember(final AbstractSqueakObject receiver, final String member, final Object[] arguments,
                @Shared("lookupNode") @Cached final LookupMethodByStringNode lookupNode,
                @Shared("classNode") @Cached final SqueakObjectClassNode classNode,
                @Exclusive @Cached final WrapToSqueakNode wrapNode,
                @Exclusive @Cached final DispatchUneagerlyNode dispatchNode) throws ArityException {
    final int actualArity = arguments.length;
    final Object methodObject = lookupNode.executeLookup(classNode.executeLookup(receiver), toSelector(member, actualArity));
    if (methodObject == null) {
        CompilerDirectives.transferToInterpreterAndInvalidate();
        /* DoesNotUnderstand, rewrite this specialization. */
        throw new RespecializeException();
    }
    final CompiledMethodObject method = (CompiledMethodObject) methodObject;
    final int expectedArity = method.getNumArgs();
    if (actualArity == expectedArity) {
        return dispatchNode.executeDispatch(method, ArrayUtils.copyWithFirst(wrapNode.executeObjects(arguments), receiver), NilObject.SINGLETON);
    } else {
        throw ArityException.create(1 + expectedArity, 1 + actualArity);
    }
}
 
Example #3
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 #4
Source File: DeviceArrayCopyFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary(limit = "3") InteropLibrary pointerAccess,
                @CachedLibrary(limit = "3") InteropLibrary numElementsAccess) throws UnsupportedTypeException, ArityException, IndexOutOfBoundsException {
    long numElements;
    if (arguments.length == 1) {
        numElements = deviceArray.getArraySize();
    } else if (arguments.length == 2) {
        numElements = extractNumber(arguments[1], "numElements", numElementsAccess);
    } else {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(1, arguments.length);
    }
    long pointer = extractPointer(arguments[0], "fromPointer", pointerAccess);
    if (direction == CopyDirection.FROM_POINTER) {
        deviceArray.copyFrom(pointer, numElements);
    }
    if (direction == CopyDirection.TO_POINTER) {
        deviceArray.copyTo(pointer, numElements);
    }
    return deviceArray;
}
 
Example #5
Source File: Kernel.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
Object execute(Object[] arguments,
                @CachedLibrary(limit = "3") InteropLibrary gridSizeAccess,
                @CachedLibrary(limit = "3") InteropLibrary gridSizeElementAccess,
                @CachedLibrary(limit = "3") InteropLibrary blockSizeAccess,
                @CachedLibrary(limit = "3") InteropLibrary blockSizeElementAccess,
                @CachedLibrary(limit = "3") InteropLibrary sharedMemoryAccess) throws UnsupportedTypeException, ArityException {
    int dynamicSharedMemoryBytes;
    if (arguments.length == 2) {
        dynamicSharedMemoryBytes = 0;
    } else if (arguments.length == 3) {
        // dynamic shared memory specified
        dynamicSharedMemoryBytes = extractNumber(arguments[2], "dynamicSharedMemory", sharedMemoryAccess);
    } else {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(2, arguments.length);
    }

    Dim3 gridSize = extractDim3(arguments[0], "gridSize", gridSizeAccess, gridSizeElementAccess);
    Dim3 blockSize = extractDim3(arguments[1], "blockSize", blockSizeAccess, blockSizeElementAccess);
    KernelConfig config = new KernelConfig(gridSize, blockSize, dynamicSharedMemoryBytes);

    return new ConfiguredKernel(this, config);
}
 
Example #6
Source File: DeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@TruffleBoundary
public Object call(Object[] arguments) throws ArityException, UnsupportedTypeException {
    if (arguments.length < 1) {
        throw ArityException.create(1, arguments.length);
    }
    String typeName = expectString(arguments[0], "first argument of DeviceArray must be string (type name)");
    Type elementType;
    try {
        elementType = Type.fromGrCUDATypeString(typeName);
    } catch (TypeException e) {
        throw new GrCUDAException(e.getMessage());
    }
    if (arguments.length == 1) {
        return new TypedDeviceArrayFunction(runtime, elementType);
    } else {
        return createArray(arguments, 1, elementType, runtime);
    }
}
 
Example #7
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 #8
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 #9
Source File: MapArgObject.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@ExportMessage
@TruffleBoundary
Object execute(Object[] arguments) throws UnsupportedMessageException, UnsupportedTypeException, ArityException {
    if (value instanceof MapArgObjectMember) {
        MapArgObjectMember member = (MapArgObjectMember) value;
        if (MAP.equals(member.name)) {
            checkArity(arguments, 1);
            return new MapArgObject(member.parent).map(arguments[0]);
        } else if (SHRED.equals(member.name)) {
            checkArity(arguments, 0);
            CompilerAsserts.neverPartOfCompilation();
            return new MapArgObject(member.parent).shred();
        } else if (DESCRIBE.equals(member.name)) {
            checkArity(arguments, 0);
            CompilerAsserts.neverPartOfCompilation();
            return new MapArgObject(member.parent).describe();
        } else if (BIND.equals(member.name)) {
            checkArity(arguments, 3);
            return member.parent.bind(arguments[0], arguments[1], arguments[2]);
        }
    }
    CompilerDirectives.transferToInterpreter();
    throw UnsupportedMessageException.create();
}
 
Example #10
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Specialization(guards = "VALUE.equals(member)")
static MapFunctionBase readMemberValue(MapFunction receiver, String member) {
    return new MapFunctionBase(arguments -> {
        if (arguments.length < 1) {
            throw ArityException.create(1, arguments.length);
        }
        String name = checkString(arguments[0], "name of created value expected");
        if (arguments.length == 1) {
            return receiver.value(name);
        } else {
            Object function = arguments[1];
            Object[] args = Arrays.copyOfRange(arguments, 2, arguments.length);
            return receiver.value(name, function, args);
        }
    });
}
 
Example #11
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 #12
Source File: HashemInvokeNode.java    From mr-hashemi with Universal Permissive License v1.0 6 votes vote down vote up
@ExplodeLoop
@Override
public Object executeGeneric(VirtualFrame frame) {
    Object function = functionNode.executeGeneric(frame);

    /*
     * The number of arguments is constant for one invoke node. During compilation, the loop is
     * unrolled and the execute methods of all arguments are inlined. This is triggered by the
     * ExplodeLoop annotation on the method. The compiler assertion below illustrates that the
     * array length is really constant.
     */
    CompilerAsserts.compilationConstant(argumentNodes.length);

    Object[] argumentValues = new Object[argumentNodes.length];
    for (int i = 0; i < argumentNodes.length; i++) {
        argumentValues[i] = argumentNodes[i].executeGeneric(frame);
    }

    try {
        return library.execute(function, argumentValues);
    } catch (ArityException | UnsupportedTypeException | UnsupportedMessageException e) {
        /* Execute was not successful. */
        throw HashemUndefinedNameException.undefinedBebin(this, function);
    }
}
 
Example #13
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 #14
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 #15
Source File: CUDAFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@TruffleBoundary
protected Object call(Object[] arguments) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
    try {
        return function.call(runtime, arguments);
    } catch (InteropException e) {
        throw new GrCUDAException(e);
    }
}
 
Example #16
Source File: TypedMapDeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
public Object execute(Object[] arguments,
                @Cached MapArrayNode mapNode) throws ArityException {
    if (arguments.length != 1) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(1, arguments.length);
    }
    return mapNode.execute(arguments[0], elementType, runtime);
}
 
Example #17
Source File: MapDeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@ExportMessage
public Object execute(Object[] arguments,
                @CachedLibrary(limit = "2") InteropLibrary stringInterop,
                @Cached("createIdentityProfile()") ValueProfile elementTypeStringProfile,
                @Cached("createIdentityProfile()") ValueProfile elementTypeProfile,
                @Cached MapArrayNode mapNode) throws ArityException, UnsupportedTypeException {
    if (arguments.length < 1) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(1, arguments.length);
    }
    String typeName;
    try {
        typeName = elementTypeStringProfile.profile(stringInterop.asString(arguments[0]));
    } catch (UnsupportedMessageException e1) {
        throw UnsupportedTypeException.create(arguments, "first argument of MapDeviceArray must be string (type name)");
    }
    Type elementType;
    try {
        elementType = elementTypeProfile.profile(Type.fromGrCUDATypeString(typeName));
    } catch (TypeException e) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAInternalException(e.getMessage());
    }
    if (arguments.length == 1) {
        return new TypedMapDeviceArrayFunction(runtime, elementType);
    } else {
        if (arguments.length != 2) {
            CompilerDirectives.transferToInterpreter();
            throw ArityException.create(2, arguments.length);
        }
        return mapNode.execute(arguments[1], elementType, runtime);
    }
}
 
Example #18
Source File: GetDeviceFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@TruffleBoundary
public Object call(Object[] arguments) throws UnsupportedTypeException, ArityException {
    checkArgumentLength(arguments, 1);
    int deviceId = expectPositiveInt(arguments[0]);
    return new Device(deviceId, runtime);
}
 
Example #19
Source File: BlockClosureObject.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
public Object execute(final Object[] arguments,
                @Exclusive @Cached final WrapToSqueakNode wrapNode) throws ArityException {
    if (getNumArgs() == arguments.length) {
        final Object[] frameArguments = FrameAccess.newClosureArgumentsTemplate(this, NilObject.SINGLETON, arguments.length);
        for (int i = 0; i < arguments.length; i++) {
            frameArguments[FrameAccess.getArgumentStartIndex() + i] = wrapNode.executeWrap(arguments[i]);
        }
        return getCompiledBlock().getCallTarget().call(frameArguments);
    } else {
        throw ArityException.create((int) getNumArgs(), arguments.length);
    }
}
 
Example #20
Source File: TensorRTRegistry.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected Object call(Object[] arguments) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
    checkArgumentLength(arguments, 3);
    int engineHandle = expectInt(arguments[0]);
    int batchSize = expectInt(arguments[1]);

    // extract pointers from buffers array argument
    Object bufferArg = arguments[2];
    if (!INTEROP.hasArrayElements(bufferArg)) {
        throw UnsupportedMessageException.create();
    }
    int numBuffers = (int) INTEROP.getArraySize(bufferArg);
    try (UnsafeHelper.PointerArray pointerArray = UnsafeHelper.createPointerArray(numBuffers)) {
        if (nfiFunction == null) {
            // load function symbol lazily
            CompilerDirectives.transferToInterpreterAndInvalidate();
            nfiFunction = factory.makeFunction(context.getCUDARuntime(), libraryPath, DEFAULT_LIBRARY_HINT);
        }
        for (int i = 0; i < numBuffers; ++i) {
            try {
                Object buffer = INTEROP.readArrayElement(bufferArg, i);
                if (!(buffer instanceof DeviceArray) && !(buffer instanceof GPUPointer)) {
                    UnsupportedTypeException.create(new Object[]{buffer});
                }
                pointerArray.setValueAt(i, INTEROP.asPointer(buffer));
            } catch (InvalidArrayIndexException e) {
                InvalidArrayIndexException.create(i);
            }
        }
        long stream = 0;
        long eventConsumed = 0;
        Object result = INTEROP.execute(nfiFunction, engineHandle, batchSize, pointerArray.getAddress(), stream, eventConsumed);
        if (!INTEROP.fitsInInt(result)) {
            CompilerDirectives.transferToInterpreter();
            throw new RuntimeException("result of 'enqueue' is not an int");
        }
        return INTEROP.asInt(result) == 1;
    }
}
 
Example #21
Source File: MappedFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected MapBoundArgObjectBase bind(Object argumentSet, Object shreddedArgumentSet, Object valueSet)
                throws UnsupportedMessageException, ArityException, UnsupportedTypeException {
    MapBoundArgObjectBase[] newValues = new MapBoundArgObjectBase[values.length];
    for (int i = 0; i < values.length; i++) {
        newValues[i] = values[i].bind(argumentSet, shreddedArgumentSet, valueSet);
    }
    return new MapBoundArgObjectSize(newValues);
}
 
Example #22
Source File: ShredFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@ExportMessage
@TruffleBoundary
public ShreddedObject execute(Object[] arguments) throws ArityException, UnsupportedTypeException {
    MapFunction.checkArity(arguments, 1);
    return new ShreddedObject(arguments[0]);
}
 
Example #23
Source File: JalangiAdapter.java    From nodeprof.js with Apache License 2.0 5 votes vote down vote up
@TruffleBoundary
private static boolean checkArguments(int count, Object[] arguments, String funcName) throws ArityException {
    if (arguments.length < count) {
        Logger.error("call to " + funcName + " expects " + count + " argument(s)");
        if (!GlobalConfiguration.IGNORE_JALANGI_EXCEPTION) {
            CompilerDirectives.transferToInterpreterAndInvalidate();
            throw ArityException.create(count, arguments.length);
        }
        return false;
    } else if (arguments.length > count) {
        Logger.warning("extra arguments passed to " + funcName);
    }
    return true;
}
 
Example #24
Source File: BoundMethod.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
public Object execute(final Object[] arguments,
                @Cached final WrapToSqueakNode wrapNode,
                @Cached final DispatchUneagerlyNode dispatchNode) throws ArityException {
    final int actualArity = arguments.length;
    final int expectedArity = method.getNumArgs(); // receiver + arguments
    if (actualArity == expectedArity) {
        return dispatchNode.executeDispatch(method, wrapNode.executeObjects(ArrayUtils.copyWithFirst(arguments, receiver)), NilObject.SINGLETON);
    } else {
        throw ArityException.create(expectedArity, actualArity);
    }
}
 
Example #25
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Object bindArgument(Object argument, ArgumentSet argSet, ArgumentSet shreddedArgSet, ArgumentSet valueSet) throws UnsupportedTypeException {
    try {
        if (INTEROP.isMemberInvocable(argument, "bind")) {
            return INTEROP.invokeMember(argument, "bind", argSet, shreddedArgSet, valueSet);
        } else {
            Object readMember = INTEROP.readMember(argument, "bind");
            return INTEROP.execute(readMember, argSet, shreddedArgSet, valueSet);
        }
    } catch (UnsupportedMessageException | UnknownIdentifierException | ArityException e) {
        CompilerDirectives.transferToInterpreter();
        throw new GrCUDAInternalException("unable to bind argument " + argument);
    }
}
 
Example #26
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@ExportMessage
@TruffleBoundary
public MappedFunction execute(Object[] arguments) throws ArityException, UnsupportedTypeException {
    if (arguments.length == 0) {
        throw ArityException.create(1, 0);
    }
    Object function = arguments[0];
    if (!INTEROP.isExecutable(function)) {
        throw UnsupportedTypeException.create(arguments, "expecting executable function as first argument");
    }
    String description = null;
    if (arguments.length > 1) {
        Object last = arguments[arguments.length - 1];
        if (INTEROP.isString(last)) {
            try {
                description = INTEROP.asString(last);
            } catch (UnsupportedMessageException e) {
                throw new GrCUDAInternalException("mismatch between isString and asString");
            }
        }
    }
    Object[] values = new Object[arguments.length - 1 - (description == null ? 0 : 1)];
    ArgumentSet argSet = new ArgumentSet();
    ArgumentSet shreddedArgSet = new ArgumentSet();
    ArgumentSet valueSet = new ArgumentSet();

    for (int i = 0; i < values.length; i++) {
        values[i] = bindArgument(arguments[i + 1], argSet, shreddedArgSet, valueSet);
    }
    Object boundReturn = bindArgument(returnValue, argSet, shreddedArgSet, valueSet);
    int[] shreddedIndexes = new int[shreddedArgSet.nameList.size()];
    for (String name : shreddedArgSet.nameList.getKeys()) {
        shreddedIndexes[shreddedArgSet.nameList.get(name)] = argSet.readMember(name);
    }
    Integer returnValueIndex = valueSet.nameList.get("return");
    return new MappedFunction(function, values, shreddedIndexes, valueSet.nameList.size(), boundReturn, returnValueIndex, description);
}
 
Example #27
Source File: HashemNewObjectBuiltin.java    From mr-hashemi with Universal Permissive License v1.0 5 votes vote down vote up
@Specialization(guards = "!values.isNull(obj)", limit = "3")
public Object newObject(Object obj, @CachedLibrary("obj") InteropLibrary values) {
    try {
        return values.instantiate(obj);
    } catch (UnsupportedTypeException | ArityException | UnsupportedMessageException e) {
        /* Foreign access was not successful. */
        throw HashemUndefinedNameException.undefinedBebin(this, obj);
    }
}
 
Example #28
Source File: MapFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Specialization(guards = "SIZE.equals(member)")
static MapFunctionBase readMemberSize(MapFunction receiver, String member) {
    return new MapFunctionBase(arguments -> {
        if (arguments.length == 0) {
            throw ArityException.create(1, 0);
        }
        try {
            return receiver.size((MapArgObject) arguments[0], Arrays.copyOfRange(arguments, 1, arguments.length, MapArgObject[].class));
        } catch (ClassCastException | ArrayStoreException e) {
            throw UnsupportedTypeException.create(arguments, "expected argument objects");
        }
    });
}
 
Example #29
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 #30
Source File: TypedDeviceArrayFunction.java    From grcuda with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@TruffleBoundary
public Object call(Object[] arguments) throws ArityException, UnsupportedTypeException {
    if (arguments.length < 1) {
        CompilerDirectives.transferToInterpreter();
        throw ArityException.create(1, arguments.length);
    }
    return DeviceArrayFunction.createArray(arguments, 0, elementType, runtime);
}