use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method asDate.
@ExportMessage
@TruffleBoundary
static LocalDate asDate(StaticObject receiver, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
receiver.checkNotForeign();
if (isDate(receiver)) {
Meta meta = receiver.getKlass().getMeta();
if (instanceOf(receiver, meta.java_time_LocalDate)) {
int year = (int) meta.java_time_LocalDate_year.get(receiver);
short month = (short) meta.java_time_LocalDate_month.get(receiver);
short day = (short) meta.java_time_LocalDate_day.get(receiver);
return LocalDate.of(year, month, day);
} else if (instanceOf(receiver, meta.java_time_LocalDateTime)) {
StaticObject localDate = (StaticObject) meta.java_time_LocalDateTime_toLocalDate.invokeDirect(receiver);
assert instanceOf(localDate, meta.java_time_LocalDate);
return asDate(localDate, error);
} else if (instanceOf(receiver, meta.java_time_Instant)) {
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 localDate = (StaticObject) meta.java_time_ZonedDateTime_toLocalDate.invokeDirect(zonedDateTime);
assert instanceOf(localDate, meta.java_time_LocalDate);
return asDate(localDate, error);
} else if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
StaticObject localDate = (StaticObject) meta.java_time_ZonedDateTime_toLocalDate.invokeDirect(receiver);
assert instanceOf(localDate, meta.java_time_LocalDate);
return asDate(localDate, error);
} else if (instanceOf(receiver, meta.java_util_Date)) {
// return ((Date) obj).toInstant().atZone(UTC).toLocalDate();
int index = meta.java_util_Date_toInstant.getVTableIndex();
Method virtualToInstant = receiver.getKlass().vtableLookup(index);
StaticObject instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
return asDate(instant, error);
}
}
error.enter();
throw UnsupportedMessageException.create();
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method asTimeZone.
@ExportMessage
@TruffleBoundary
static ZoneId asTimeZone(StaticObject receiver, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
receiver.checkNotForeign();
if (isTimeZone(receiver)) {
Meta meta = receiver.getKlass().getMeta();
if (instanceOf(receiver, meta.java_time_ZoneId)) {
int index = meta.java_time_ZoneId_getId.getVTableIndex();
StaticObject zoneIdEspresso = (StaticObject) receiver.getKlass().vtableLookup(index).invokeDirect(receiver);
String zoneId = Meta.toHostStringStatic(zoneIdEspresso);
return ZoneId.of(zoneId, ZoneId.SHORT_IDS);
} else if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
StaticObject zoneId = (StaticObject) meta.java_time_ZonedDateTime_getZone.invokeDirect(receiver);
return asTimeZone(zoneId, error);
} else if (instanceOf(receiver, meta.java_time_Instant) || instanceOf(receiver, meta.java_util_Date)) {
return ZoneId.of("UTC");
}
}
error.enter();
throw UnsupportedMessageException.create();
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method isDuration.
@ExportMessage
static boolean isDuration(StaticObject receiver) {
receiver.checkNotForeign();
if (isNull(receiver)) {
return false;
}
Meta meta = receiver.getKlass().getMeta();
return instanceOf(receiver, meta.java_time_Duration);
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method isMemberReadable.
@ExportMessage
static boolean isMemberReadable(StaticObject receiver, String member, @Cached @Exclusive LookupInstanceFieldNode lookupField) {
receiver.checkNotForeign();
Field f = lookupField.execute(getInteropKlass(receiver), member);
if (f != null) {
return true;
}
return //
notNull(receiver) && receiver.getKlass() == receiver.getKlass().getMeta().java_lang_Class && (CLASS_TO_STATIC.equals(member) || STATIC_TO_CLASS.equals(member));
}
use of com.oracle.truffle.api.library.ExportMessage in project graal by oracle.
the class EspressoInterop method isTimeZone.
@ExportMessage
static boolean isTimeZone(StaticObject receiver) {
receiver.checkNotForeign();
if (isNull(receiver)) {
return false;
}
Meta meta = receiver.getKlass().getMeta();
return instanceOf(receiver, meta.java_time_ZoneId) || instanceOf(receiver, meta.java_time_Instant) || instanceOf(receiver, meta.java_time_ZonedDateTime) || instanceOf(receiver, meta.java_util_Date);
}
Aggregations