I am trying to implement the Truffle Framework into an existing language (INI) and I managed to run the language with basic features and Truffle. However, when I try to add @Specialization
annotations to my methods, the compiler crashes and outputs this message :
src/main/java/ini/eval/function/PrintFunction.java:[17,17] Not enough child node declarations found. Please annotate the node class with addtional @NodeChild annotations or remove all execute methods that do not provide all evaluated values. The following execute methods do not provide all evaluated values for the expected signature size 1: [executeGeneric(VirtualFrame), executeNumber(VirtualFrame), executeBoolean(VirtualFrame), executeChar(VirtualFrame), executeString(VirtualFrame)]
However, when I remove the @Specialization
annotation, it works fine
This is the only class where I've put specialization yet :
@NodeInfo(shortName = "print")
@GenerateNodeFactory()
public abstract class PrintFunction extends BuiltInExecutable {
public PrintFunction(IniParser parser, String name, String[] parameterNames) {
super();
}
private static final PrintStream out = System.out;
@Specialization
public Number print(Number value) {
doPrint(value);
return value;
}
@TruffleBoundary
private static void doPrint(Number value) {
out.print(value);
}
... More specializations for other types (boolean, and String)
@Specialization
public Object print(Object value) {
doPrint(value);
return value;
}
@TruffleBoundary
private static void doPrint(Object value) {
out.print(value);
}
}
The superclass of all nodes (AstElement) has the methods executeGeneric(VirtaulFrame) and executeNumber, executeBoolean, executeChar and executeString. So the class PrintFunction also has these methods
So, what do you think is really causing the error message, or at least, what does it mean ?
I am taking inspiration from the Mumbler Language and SimpleLanguage both implemented with Truffle.
An answer I got from a great person on the Graal Slack
The value
needs to come from somewhere. And Truffle expects you to have a form of expression as a subnode to your print function. The standard way is to add something like @NodeChild(value = "receiver", type = ExpressionNode.class)
to the class definition
Stefan Marr il y a 10 minutes
if the value
is not supposed to come from a subnode, i.e., child node, you can instead define an abstract execute(Object value)
method, which the DLS will implement for you using the specializations