use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method asTime.
@ExportMessage
@TruffleBoundary
static LocalTime asTime(StaticObject receiver, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
receiver.checkNotForeign();
if (isTime(receiver)) {
Meta meta = receiver.getKlass().getMeta();
if (instanceOf(receiver, meta.java_time_LocalTime)) {
byte hour = (byte) meta.java_time_LocalTime_hour.get(receiver);
byte minute = (byte) meta.java_time_LocalTime_minute.get(receiver);
byte second = (byte) meta.java_time_LocalTime_second.get(receiver);
int nano = (int) meta.java_time_LocalTime_nano.get(receiver);
return LocalTime.of(hour, minute, second, nano);
} else if (instanceOf(receiver, meta.java_time_LocalDateTime)) {
StaticObject localTime = (StaticObject) meta.java_time_LocalDateTime_toLocalTime.invokeDirect(receiver);
return asTime(localTime, error);
} else if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
StaticObject localTime = (StaticObject) meta.java_time_ZonedDateTime_toLocalTime.invokeDirect(receiver);
return asTime(localTime, error);
} else if (instanceOf(receiver, meta.java_time_Instant)) {
// return ((Instant) obj).atZone(UTC).toLocalTime();
StaticObject zoneIdUTC = (StaticObject) meta.java_time_ZoneId_of.invokeDirect(null, meta.toGuestString("UTC"));
assert instanceOf(zoneIdUTC, meta.java_time_ZoneId);
StaticObject zonedDateTime = (StaticObject) meta.java_time_Instant_atZone.invokeDirect(receiver, zoneIdUTC);
assert instanceOf(zonedDateTime, meta.java_time_ZonedDateTime);
StaticObject localTime = (StaticObject) meta.java_time_ZonedDateTime_toLocalTime.invokeDirect(zonedDateTime);
assert instanceOf(localTime, meta.java_time_LocalTime);
return asTime(localTime, error);
} else if (instanceOf(receiver, meta.java_util_Date)) {
// return ((Date) obj).toInstant().atZone(UTC).toLocalTime();
int index = meta.java_util_Date_toInstant.getVTableIndex();
Method virtualToInstant = receiver.getKlass().vtableLookup(index);
StaticObject instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
return asTime(instant, error);
}
}
error.enter();
throw UnsupportedMessageException.create();
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method fitsInFloat.
@ExportMessage
static boolean fitsInFloat(StaticObject receiver) {
receiver.checkNotForeign();
if (isNull(receiver)) {
return false;
}
Klass klass = receiver.getKlass();
if (isAtMostFloat(klass)) {
return true;
}
Meta meta = klass.getMeta();
/*
* We might lose precision when we convert an int or a long to a float, however, we still
* perform the conversion. This is consistent with Truffle interop, see GR-22718 for more
* details.
*/
if (klass == meta.java_lang_Integer) {
int content = meta.java_lang_Integer_value.getInt(receiver);
float floatContent = content;
return (int) floatContent == content;
}
if (klass == meta.java_lang_Long) {
long content = meta.java_lang_Long_value.getLong(receiver);
float floatContent = content;
return (long) floatContent == content;
}
if (klass == meta.java_lang_Double) {
double content = meta.java_lang_Double_value.getDouble(receiver);
return !Double.isFinite(content) || (float) content == content;
}
return false;
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method getMembers.
@ExportMessage
@TruffleBoundary
static Object getMembers(StaticObject receiver, @SuppressWarnings("unused") boolean includeInternal) {
receiver.checkNotForeign();
if (isNull(receiver)) {
return EmptyKeysArray.INSTANCE;
}
ArrayList<String> members = new ArrayList<>();
if (receiver.getKlass() == receiver.getKlass().getMeta().java_lang_Class) {
// SVM does not like ArrayList.addAll(). Do manual copy.
for (String s : CLASS_KEYS) {
members.add(s);
}
}
ObjectKlass k = getInteropKlass(receiver);
for (Field f : k.getFieldTable()) {
if (f.isPublic() && !f.isRemoved()) {
members.add(f.getNameAsString());
}
}
for (Method.MethodVersion m : k.getVTable()) {
if (LookupVirtualMethodNode.isCandidate(m.getMethod())) {
// Note: If there are overloading, the same key may appear twice.
// TODO: Cache the keys array in the Klass.
members.add(m.getMethod().getInteropString());
}
}
// SVM does not like ArrayList.toArray(). Do manual copy.
String[] array = new String[members.size()];
int pos = 0;
for (String str : members) {
array[pos++] = str;
}
return new KeysArray(array);
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method isDate.
// endregion ### Members
// region ### Date/time conversions
@ExportMessage
static boolean isDate(StaticObject receiver) {
receiver.checkNotForeign();
if (isNull(receiver)) {
return false;
}
Meta meta = receiver.getKlass().getMeta();
return instanceOf(receiver, meta.java_time_LocalDate) || instanceOf(receiver, meta.java_time_LocalDateTime) || 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 isMemberModifiable.
@ExportMessage
static boolean isMemberModifiable(StaticObject receiver, String member, @Cached @Exclusive LookupInstanceFieldNode lookup) {
receiver.checkNotForeign();
Field f = lookup.execute(getInteropKlass(receiver), member);
if (f != null) {
return !f.isFinalFlagSet();
}
return false;
}
Aggregations