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

The following examples show how to use com.oracle.truffle.api.interop.InteropLibrary#fitsInInt() . 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: ClassObject.java    From trufflesqueak with MIT License 6 votes vote down vote up
@Specialization(guards = "arguments.length == 1")
protected static final Object doOneArgument(final ClassObject receiver, final Object[] arguments,
                @Shared("newObjectNode") @Cached final SqueakObjectNewNode newObjectNode,
                @CachedLibrary(limit = "2") final InteropLibrary functions,
                @CachedLibrary(limit = "2") final InteropLibrary initializer,
                @CachedContext(SqueakLanguage.class) final SqueakImageContext theImage) throws UnsupportedTypeException {
    if (functions.fitsInInt(arguments[0])) {
        final AbstractSqueakObjectWithHash newObject;
        try {
            newObject = newObjectNode.execute(theImage, receiver, functions.asInt(arguments[0]));
        } catch (final UnsupportedMessageException e) {
            throw UnsupportedTypeException.create(arguments, "Second argument violates interop contract.");
        }
        initializeObject(arguments, initializer, newObject);
        return newObject;
    } else {
        throw UnsupportedTypeException.create(arguments, "Second argument must be the size as an integer.");
    }
}
 
Example 2
Source File: JavaObjectWrapper.java    From trufflesqueak with MIT License 5 votes vote down vote up
@ExportMessage
protected boolean fitsInInt(@Shared("lib") @CachedLibrary(limit = "LIMIT") final InteropLibrary lib) {
    if (isNumber()) {
        return lib.fitsInInt(wrappedObject);
    } else {
        return false;
    }
}