use of com.oracle.truffle.espresso.impl.Method 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.espresso.impl.Method in project graal by oracle.
the class MapEntryInterop method writeArrayElement.
@ExportMessage
public static void writeArrayElement(StaticObject receiver, long index, Object value, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws InvalidArrayIndexException {
if (index != 1) {
throw InvalidArrayIndexException.create(index);
}
Meta meta = receiver.getKlass().getMeta();
Method m = doLookup(receiver, meta.java_util_Map_Entry, meta.java_util_Map_Entry_setValue);
try {
invoke.execute(m, receiver, new Object[] { value });
} catch (ArityException | UnsupportedTypeException e) {
throw EspressoError.shouldNotReachHere(e);
}
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class MapInterop method containsKey.
private static boolean containsKey(StaticObject receiver, Object key, InvokeEspressoNode invokeContains) {
Meta meta = receiver.getKlass().getMeta();
Method containsKey = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_containsKey.getITableIndex());
try {
return (boolean) invokeContains.execute(containsKey, receiver, new Object[] { key });
} catch (UnsupportedTypeException | ArityException e) {
throw EspressoError.shouldNotReachHere(e);
}
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class MapInterop method writeHashEntry.
@ExportMessage
public static void writeHashEntry(StaticObject receiver, Object key, Object value, @Cached.Exclusive @Cached InvokeEspressoNode invoke) throws UnknownKeyException {
Meta meta = receiver.getKlass().getMeta();
Method put = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_put.getITableIndex());
try {
invoke.execute(put, receiver, new Object[] { key, value });
} catch (UnsupportedTypeException e) {
throw UnknownKeyException.create(key);
} catch (ArityException e) {
throw EspressoError.shouldNotReachHere(e);
}
}
use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.
the class MapInterop method readHashValue.
@ExportMessage
public static Object readHashValue(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 get = getInteropKlass(receiver).itableLookup(meta.java_util_Map, meta.java_util_Map_get.getITableIndex());
try {
return invoke.execute(get, receiver, new Object[] { key });
} catch (UnsupportedTypeException e) {
throw UnknownKeyException.create(key);
} catch (ArityException e) {
throw EspressoError.shouldNotReachHere(e);
}
}
Aggregations