2016-09-26 64 views
3

我试图使用funset_avltree库,但编译器生成无效的C代码。我正在使用ATS/Postiats 0.2.10版。如何使用funset_avltree库?

我的代码是相当简单:

(* ast.sats *) 
staload "libats/SATS/funset_avltree.sats" 

datatype ast = 
    | ast_var of string 

fun free_vars (ast : ast) :<> set string 
(* ast.dats *) 
#include "share/atspre_staload.hats" 
staload "./ast.sats" 
staload "libats/SATS/funset_avltree.sats" 
dynload "libats/DATS/funset_avltree.dats" 

implement free_vars (ast : ast) : set string = 
    case+ ast of 
    | ast_var name => funset_sing name 

编译器的输出,但是,相当混乱:

 
ast_dats.c:359:51: warning: implicit declaration of function 'S2EVar' is invalid 
     in C99 [-Wimplicit-function-declaration] 
ATSINSmove(tmpret0, PMVtmpltcstmat[0](funset_sing<S2EVar(4713)>)(tmp1)) ; 
               ^

ast_dats.c:359:39: error: use of undeclared identifier 'funset_sing' 
ATSINSmove(tmpret0, PMVtmpltcstmat[0](funset_sing<S2EVar(4713)>)(tmp1)) ; 
            ^

ast_dats.c:359:64: error: expected expression 
ATSINSmove(tmpret0, PMVtmpltcstmat[0](funset_sing<S2EVar(4713)>)(tmp1)) ; 
                  ^

我得到类似的错误与funsetfunset_listord。我必须错过一些微不足道的东西。我是否需要包含某些内容或将某个标记传递给编译器?

回答

3

的根本原因是您没有静态加载库提供的AVL树模板。

在错误消息中,PMVtmpltcstmat通常表示模板有问题。程序员通常会忘记包含模板,或者忘记提供模板变量。你是第一个案子。

请加入这一行,

staload _ = "libats/DATS/funset_avltree.dats" 

静态加载模板,并将其提供给编译器。在这里看到一个工作示例,https://glot.io/snippets/eiu6f3dd2r


此外,当你有一个需要评估“全球”值需要dynload。在你的情况下,你不需要dynload avl树库。另外,在你自己的文件ast.dats中,没有这样的全局值。你可以定义

#define ATS_DYNLOADFLAG 0 

告诉编译器不要为ast.dats产生动态加载代码。

+0

嗨,谢谢。我不知道你必须使用模板定义来调整dat文件。在“ATS编程简介”一书中我找不到这个。 – rightfold

+0

不客气。模板系统是相当新的。我认为作者还在完成相关章节。 –

+1

@rightfold,我访问了你的网站。您保存有关ATS的文档真的很棒。我只想提请你注意http://discourse.ats-lang.org/c/documentation是官方的,并且计划包括越来越多的用户提供的文档。你的贡献非常受欢迎。谢谢。 –