Use java.util.List in type system

Christian Humer christian.humer at gmail.com
Tue Apr 7 18:09:22 UTC 2015


Hi,

I have to admit, that support for generics in the DSL is a bit rough. So you should rather avoid using them for now (I've put proper support for generics higher on my TODO list). 

I would not recommend you to use List as a type, but rather define your own list interface that is more to the point. I would also not recommend you to use ArrayList or other existing list implementations because they are not written for Truffle partial evaluation and may produce way to much code (or even worse, contain recursions). Please note that Truffle partial evaluation inlines everything until it sees a @TruffleBoundary or a virtual call. 

You can get some inspiration on the array implementation of JRuby:
https://github.com/jruby/jruby/blob/master/truffle/src/main/java/org/jruby/truffle/runtime/core/RubyArray.java

For your first implementation I'd suggest that you start with a simple representation that uses an object array as store. In a next step you can explore using primitive array representations to avoid boxing.

Hope this helps.


- Christian Humer
On 07.04.2015 19:49:25, Renze Torensma <renzetorensma at gmail.com> wrote:
Hi,

I want to implement a List datatype, but since SimpleLanguage doesn’t implement that I am a bit puzzled about how I should do it.
I tried adding List.class to my type system (without the because that results in an error) and creating specializations like

@Specialization
public List add(List left, List right)

This all compiles well, but the generated code in the src_gen folder generates an error:

The method add(long, long) in the type AdditionNode is not applicable for the arguments (List, List)

The add(long, long) is the first specialization of this node, my type system begins with long and List is the last type so far.
I’m not sure it is possible to use generic classes in the type system, and if I use a concrete class like ArrayList instead of the List interface it results in the same error so List being an interface and not a class isn’t the problem I think.

So how should I implement a list type? Am I on the right track or should I try a different approach?

Renze


More information about the graal-dev mailing list