首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么在添加@Specialization注解时Truffle DSL会出错?

为什么在添加@Specialization注解时Truffle DSL会出错?
EN

Stack Overflow用户
提问于 2020-05-27 16:42:43
回答 1查看 34关注 0票数 0

我正在尝试将Truffle框架实现到一种现有的语言(INI)中,并且我设法运行具有基本功能和Truffle的语言。但是,当我尝试向我的方法添加@Specialization注释时,编译器崩溃并输出以下消息:

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)]

但是,当我删除@Specialization注释时,它工作得很好

这是我唯一将特殊化放在其中的类:

代码语言:javascript
运行
复制
@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);
    }
}

所有节点的超类(AstElement)具有方法executeGeneric(VirtaulFrame)和executeNumber、executeBoolean、executeChar和executeString。所以类PrintFunction也有这些方法

那么,您认为是什么真正导致了错误消息,或者至少是什么意思?

我从Mumbler语言和SimpleLanguage中获得了灵感,这两种语言都是用Truffle实现的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-27 17:10:46

我在Graal Slack上从一个很棒的人那里得到的答案

value需要来自某个地方。而Truffle希望您拥有一种表达式形式,作为print函数的子节点。标准方法是向类定义Stefan Marr il y a 10分钟添加类似@NodeChild(value = "receiver", type = ExpressionNode.class)的内容如果value不是来自子节点,那么您可以定义一个抽象的execute(Object value)方法,DLS将使用专门化为您实现该方法。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62038918

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档