Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[interop] Add support for Date/Time/Duration/TimeZone/... interop types #2166

Closed
fniephaus opened this issue Nov 20, 2020 · 4 comments
Closed
Assignees
Labels
Milestone

Comments

@fniephaus
Copy link
Member

TruffleRuby lacks support for some interop types, for example Date:

Interop isDate: (Polyglot eval: 'ruby' string: 'DateTime.now.to_date') "returns `false`"

Some of these types may be implemented in Ruby, so adding interop support could be a bit tricky. In TruffleSqueak, we currently plan to dispatch interop messages directly on the object, so for example Date objects will respond to #isDate and #asDate:.

@eregon
Copy link
Member

eregon commented Nov 20, 2020

It should be fairly easy for Time, which is in core (and considered faster).
Date/DateTime is a stdlib: https://github.com/oracle/truffleruby/blob/master/lib/truffle/date.rb so we'd need to add polyglot_date?/polyglot_time?/etc and polyglot_as_date/polyglot_as_time/etc and implement it there + somehow convert from the very different internal representations.
There are actually quite a lot of date-related messages, notably also isInstant and isTimeZone stuff.
Time is using java.time.ZonedDateTime so hopefully it has all of that easily accessible.

I don't think Ruby has any object representing isDuration. Integer/Float are used instead for durations.

So I'd suggest to try to implement date-related messages for Time first, before trying it for date.rb which seems complicated (maybe some of it could be achieved through DateTime#to_time).

@fniephaus
Copy link
Member Author

Sounds good!

Why prefix interop messages with polyglot_ rather than interop_? If someone looks at interop_time?, for example, it might be clearer that it's an interop message.

@eregon
Copy link
Member

eregon commented Nov 21, 2020

In TruffleRuby, we consider anything named "polyglot" to be public API, and anything named "interop" to be more internal APIs.
Anyway, such methods are not called by the user, but they can be defined by the user, like

def polyglot_has_array_elements?

I'll add support for date/time messages for Ruby's Time.

For Date/DateTime, one can easily workaround by using Date#to_time and DateTime#to_time.

@eregon eregon self-assigned this Nov 21, 2020
@eregon
Copy link
Member

eregon commented Nov 23, 2020

Implemented for Time in 159cee8.

@eregon eregon closed this as completed Nov 23, 2020
@eregon eregon added this to the 21.0.0 milestone Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants