Designing an intuitive language-agnostic integration of foreign objects in Ruby
GraalVM enables all Truffle languages to interoperate with each other and call each other, through a set of traits exposed in Truffle’s
InteropLibrary. There are many such traits: array elements, hash entries, buffer elements, executable, instantiable, members, iterator, iterable, exception, pointer, meta object, source location, identity, number, string, boolean, etc. This interoperability API is probably the richest available today, but it needs to be integrated deeply in languages so that it is natural to use and does not require special calls or constructs to deal with foreign objects. As a simple example,
foreign_array[index] should just work, and not require something like
Interop.read_array_element(foreign_array, index). As something more advanced we want all Ruby Array methods, such as
map to also be available on foreign arrays.
In this talk we explore how to integrate foreign objects fully into the GraalVM Ruby implementation, TruffleRuby. This means we want foreign objects to behave exactly the same as Ruby objects, to have the same methods, to be given a Ruby class, to use the Ruby class hierarchy, etc. By giving them a Ruby class, we are able to define methods for foreign objects as regular Ruby methods, in Ruby code. Foreign objects can also be extended with new methods by the user, just like it is possible to add methods to any Ruby class at runtime. We hope this deep integration makes it easier to use the polyglot nature of GraalVM, and we hope the design in TruffleRuby inspires other Truffle languages to adopt a similar approach.
Tue 7 JunDisplayed time zone: Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna change
11:00 - 12:30
|Efficient Object Graph Recording with Truffle for Live Data-Structure Programming|
Shusuke Takahashi Tokyo Institute of Technology, Yusuke Izawa Tokyo Institute of Technology, Hidehiko Masuhara Tokyo Institute of Technology, Youyou Cong Tokyo Institute of TechnologyMedia Attached
|Designing an intuitive language-agnostic integration of foreign objects in Ruby|
Benoit Daloze Oracle LabsPre-print Media Attached
|Embedding Truffle Languages|
Kevin Menard ShopifyMedia Attached