Truffle DSL with Array of Primitive Types

Cristian Esquivias cristian.esquivias at gmail.com
Sat Dec 6 22:46:46 UTC 2014


I'm writing a simple lisp language to try out Truffle, but I'm running into
problems implementing a plus function that takes a variable number of
arguments. I figured the Truffle DSL can do the node rewriting for me and
all I needed was to request an array of longs. Something like:

@NodeChild(value = "arguments", type = Node.class)
public abstract AddNode extends Node {
    @Specialization
    protected long add(long[] arguments) {
         long sum = 0;
         for (long arg : arguments) {
             sum += arg;
         }
         return sum;
    }
}

I'm not worrying about overflows right now.

And Truffle would create an AddNodeFactory that will map Node#executeLong
over all the arguments then call my add method, but I get a compilation
error: "Method signature (long[]) does not match to the expected
signature." It looks like an array isn't allowed.

What's the preferred way of implementing (builtin) functions that take a
variable number of arguments? The only thing I can think of right now is to
do my own tree rewriting and write a custom node that does the mapping
across the arguments myself.

Thanks,
Cristian


More information about the graal-dev mailing list