代码之家  ›  专栏  ›  技术社区  ›  user1804599

如何使用funset_avltree库?

  •  5
  • user1804599  · 技术社区  · 8 年前

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

    我的代码相当简单:

    (* 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)) ;
                                                                   ^
    

    我也有类似的错误 funset funset_listord .我一定错过了一些小事。我需要包含一些内容还是向编译器传递一些标志?

    2 回复  |  直到 8 年前
        1
  •  3
  •   Steinway Wu    8 年前

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

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

    请添加此行,

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

    静态加载模板,并使它们对编译器可用。这里有一个工作示例, https://glot.io/snippets/eiu6f3dd2r


    此外 dynload 当您具有需要评估的“全局”值时,需要使用。在您的情况下,您不需要 动态负载 avl树库。此外,在您自己的文件中 ast.dats ,没有这样的全球价值。您可以定义

    #define ATS_DYNLOADFLAG 0
    

    告诉编译器不要为生成动态加载代码 ast.dats公司 .