use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method isTime.
@ExportMessage
static boolean isTime(StaticObject receiver) {
receiver.checkNotForeign();
if (isNull(receiver)) {
return false;
}
Meta meta = receiver.getKlass().getMeta();
return instanceOf(receiver, meta.java_time_LocalTime) || instanceOf(receiver, meta.java_time_Instant) || instanceOf(receiver, meta.java_time_ZonedDateTime) || instanceOf(receiver, meta.java_util_Date);
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method asDuration.
@ExportMessage
static Duration asDuration(StaticObject receiver, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
receiver.checkNotForeign();
if (isDuration(receiver)) {
Meta meta = receiver.getKlass().getMeta();
// Avoid expensive calls to Duration.{getSeconds/getNano} by extracting the private
// fields directly.
long seconds = (long) meta.java_time_Duration_seconds.get(receiver);
int nanos = (int) meta.java_time_Duration_nanos.get(receiver);
return Duration.ofSeconds(seconds, nanos);
}
error.enter();
throw UnsupportedMessageException.create();
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method fitsInDouble.
@ExportMessage
static boolean fitsInDouble(StaticObject receiver) {
receiver.checkNotForeign();
if (isNull(receiver)) {
return false;
}
Klass klass = receiver.getKlass();
Meta meta = klass.getMeta();
if (isAtMostInt(klass) || klass == meta.java_lang_Double) {
return true;
}
if (klass == meta.java_lang_Long) {
long content = meta.java_lang_Long_value.getLong(receiver);
double doubleContent = content;
return (long) doubleContent == content;
}
if (klass == meta.java_lang_Float) {
float content = meta.java_lang_Float_value.getFloat(receiver);
return !Float.isFinite(content) || (double) content == content;
}
return false;
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class MapEntryInterop method readArrayElement.
@ExportMessage
public static Object readArrayElement(StaticObject receiver, long index, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws InvalidArrayIndexException {
Meta meta = receiver.getKlass().getMeta();
Method m;
if (index == 0) {
m = doLookup(receiver, meta.java_util_Map_Entry, meta.java_util_Map_Entry_getKey);
} else if (index == 1) {
m = doLookup(receiver, meta.java_util_Map_Entry, meta.java_util_Map_Entry_getValue);
} else {
throw InvalidArrayIndexException.create(index);
}
try {
return invoke.execute(m, receiver, EMPTY_ARRAY);
} catch (ArityException | UnsupportedTypeException e) {
throw EspressoError.shouldNotReachHere(e);
}
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class MapInterop method removeHashEntry.
@ExportMessage
public static void removeHashEntry(StaticObject receiver, Object key, @Cached.Exclusive @Cached InvokeEspressoNode invoke, @Cached.Shared("contains") @Cached InvokeEspressoNode contains) throws UnsupportedMessageException, UnknownKeyException {
if (!isHashEntryReadable(receiver, key, contains)) {
throw UnsupportedMessageException.create();
}
Meta meta = receiver.getKlass().getMeta();
Method remove = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_remove.getITableIndex());
try {
invoke.execute(remove, receiver, new Object[] { key });
} catch (UnsupportedTypeException e) {
throw UnknownKeyException.create(key);
} catch (ArityException e) {
throw EspressoError.shouldNotReachHere(e);
}
}
Aggregations