Question about the new polyglot API and its `Value` class

Jaroslav Tulach jaroslav.tulach at oracle.com
Mon Jan 15 09:53:12 UTC 2018


Hello Peter,
thanks for your interest in Truffle polyglot programming.

On sobota 13. ledna 2018 13:30:35 CET Peter Niederwieser wrote:
> > There are certain aspects in some of our languages that cannot be
> > represented with core JDK classes. This is where the Value API comes in.
> I totally see the usefulness of the `Value` abstraction. My only gripe is
> that there is no way to do without it for language-specific use cases.

While `Value` abstraction may be useful in certain situations, there is a lot 
of use-cases already supported by Truffle/Java polyglot API that can do without 
it. The goal of my design in 2015 and 2016 was to allow POJO interfaces to 
smoothly interact with Truffle languages. As far as I can tell my ideas are 
still supported and could be exactly what you are looking for.

Me and Michael had written a tutorial that shows the capabilities:
http://www.graalvm.org/truffle/javadoc/com/oracle/truffle/tutorial/embedding/
package-summary.html
please take a look at section like "Access a JavaScript class", "Access a 
JavaScript Array", "Access a JavaScript JSON structure", etc.

All these ideas are used in graal-js-archetype, see 
https://github.com/graalvm/graal-js-archetype#readme for explanation and 
instructiosn how to get started. The archetype performs all the JavaScript/
Ruby/R/Java interop and it does it all without the `Value` class. Give it a 
try to get better understanding of the existing POJO-based interop 
possibilities.

I believe these two examples show you can do without the `Value` class[1]. 
Give it a try. If you have some questions about graal-js-archetype or the 
tutorial, let me know. I'll be glad to reveal the proper way to POJO-like 
Truffle interop.
-jt

[1] In fact the `Value` approach stays in the way as it (in contrary to 
original `PolyglotEngine.Value` class) doesn't offer `T as(Class<T>)` 
conversion function. However (as the graal-js-archetype shows) this limitation 
can be overcome. Good luck.



More information about the graal-dev mailing list