首页 > 解决方案 > PMVtmpltcstmat,atstype_undefined 未声明

问题描述

在以下代码中:

#include "share/atspre_staload.hats"

extern castfn usize_of_int(num: int): size_t
extern castfn usize_of_int_n{n:int}(num: int(n)): size_t(n)

overload _usize with usize_of_int
overload _usize1 with usize_of_int_n

postfix _usize
postfix _usize1

dataview array_view(a:viewt@ype+, addr, int) =
    | {l:addr} array_nil(a, l, 0)
    | {l:addr}{n:nat} array_cons(a, l, n + 1) of (a@l, array_view(a, l + sizeof(a), n))

datavtype Vec(a:viewt@ype+, n:int) =
    {c:nat} Vector of (size_t(c), [l:addr] (array_view(a, l, c) | ptr l), size_t(n))

extern fun calloc {a:t@ype}{n:nat} (num: size_t(n), tsz: size_t(sizeof(a))) : [l:addr] (array_view(a, l, n) | ptr l) = "ext#"
extern fun {a:t@ype} free {l:addr}(a@l | ptr l): void = "ext#"

extern prfun {a:t@ype} consume{n:nat}{l:addr}(array_view(a, l, n)): void

fun {a:t@ype} allocate_array {n:nat}(num: size_t(n)): [l:addr] (array_view(a, l, n) | ptr l) =
    calloc{a}(num, sizeof<a>)

fun {a:t@ype} free_array{l:addr}{n:int | n > 0}(array_view: array_view(a, l, n) | ptr: ptr l): void =
    let prval array_cons(element_proof, _) = array_view
    in
        free(element_proof | ptr)
    end

fun {a:t@ype} new_vector(): Vec(a, 0) =
    let val capacity = 10_usize1
        val (array_view | elements) = allocate_array<a>(capacity)
    in
       Vector(capacity, (array_view | elements), 0_usize1)
    end

fun {a:t@ype} vector_free(vec: [n:int] Vec(a, n)): void =
    let val+ ~Vector(capacity, (array_view | elements), _) = vec
    in
        if capacity > (0_usize1) then
            free_array(array_view | elements)
        else
            consume(array_view)
    end

overload .free with vector_free

implement main0() = {
    val vector = new_vector<int>()
    val () = vector.free()
}

我从 gcc 收到很多错误:

In file included from build/release/src/main_dats.o.c:15:
build/release/src/main_dats.o.c: Dans la fonction « vector_free_3__3__1 »:
build/release/src/main_dats.o.c:795:29: error: « PMVtmpltcstmat » non déclaré (première utilisation dans cette fonction)
 ATSINSmove_void(tmpret4__1, PMVtmpltcstmat[0](consume<S2EVar(5259)>)()) ;
                             ^~~~~~~~~~~~~~
/usr/lib/ats2-postiats-0.3.11/ccomp/runtime/pats_ccomp_instrset.h:284:39: note: dans la définition de la macro « ATSINSmove_void »
 #define ATSINSmove_void(tmp, command) command
                                       ^~~~~~~
build/release/src/main_dats.o.c:795:29: note: chaque identificateur non déclaré est rapporté une seule fois pour chaque fonction dans laquelle il apparaît
 ATSINSmove_void(tmpret4__1, PMVtmpltcstmat[0](consume<S2EVar(5259)>)()) ;
                             ^~~~~~~~~~~~~~
/usr/lib/ats2-postiats-0.3.11/ccomp/runtime/pats_ccomp_instrset.h:284:39: note: dans la définition de la macro « ATSINSmove_void »
 #define ATSINSmove_void(tmp, command) command
                                       ^~~~~~~
build/release/src/main_dats.o.c:795:47: error: « consume » non déclaré (première utilisation dans cette fonction)
 ATSINSmove_void(tmpret4__1, PMVtmpltcstmat[0](consume<S2EVar(5259)>)()) ;
                                               ^~~~~~~
/usr/lib/ats2-postiats-0.3.11/ccomp/runtime/pats_ccomp_instrset.h:284:39: note: dans la définition de la macro « ATSINSmove_void »
 #define ATSINSmove_void(tmp, command) command
                                       ^~~~~~~
build/release/src/main_dats.o.c:795:55: warning: déclaration implicite de la fonction « S2EVar » [-Wimplicit-function-declaration]
 ATSINSmove_void(tmpret4__1, PMVtmpltcstmat[0](consume<S2EVar(5259)>)()) ;
                                                       ^~~~~~
/usr/lib/ats2-postiats-0.3.11/ccomp/runtime/pats_ccomp_instrset.h:284:39: note: dans la définition de la macro « ATSINSmove_void »
 #define ATSINSmove_void(tmp, command) command
                                       ^~~~~~~
build/release/src/main_dats.o.c:795:68: error: expected expression before « ) » token
 ATSINSmove_void(tmpret4__1, PMVtmpltcstmat[0](consume<S2EVar(5259)>)()) ;
                                                                    ^
/usr/lib/ats2-postiats-0.3.11/ccomp/runtime/pats_ccomp_instrset.h:284:39: note: dans la définition de la macro « ATSINSmove_void »
 #define ATSINSmove_void(tmp, command) command
                                       ^~~~~~~
build/release/src/main_dats.o.c: Dans la fonction « free_array_1__1__1 »:
build/release/src/main_dats.o.c:832:29: error: « PMVtmpltcstmat » non déclaré (première utilisation dans cette fonction)
 ATSINSmove_void(tmpret1__1, PMVtmpltcstmat[0](free<S2EVar(5259)>)(arg0)) ;
                             ^~~~~~~~~~~~~~
/usr/lib/ats2-postiats-0.3.11/ccomp/runtime/pats_ccomp_instrset.h:284:39: note: dans la définition de la macro « ATSINSmove_void »
 #define ATSINSmove_void(tmp, command) command
                                       ^~~~~~~
build/release/src/main_dats.o.c:832:51: warning: comparaison entre un pointeur et un entier
 ATSINSmove_void(tmpret1__1, PMVtmpltcstmat[0](free<S2EVar(5259)>)(arg0)) ;
                                                   ^
/usr/lib/ats2-postiats-0.3.11/ccomp/runtime/pats_ccomp_instrset.h:284:39: note: dans la définition de la macro « ATSINSmove_void »
 #define ATSINSmove_void(tmp, command) command
                                       ^~~~~~~
build/release/src/main_dats.o.c:832:65: error: expected expression before « ) » token
 ATSINSmove_void(tmpret1__1, PMVtmpltcstmat[0](free<S2EVar(5259)>)(arg0)) ;
                                                                 ^
/usr/lib/ats2-postiats-0.3.11/ccomp/runtime/pats_ccomp_instrset.h:284:39: note: dans la définition de la macro « ATSINSmove_void »
 #define ATSINSmove_void(tmp, command) command
                                       ^~~~~~~

我不确定出了什么问题,那么我该如何解决这些错误?

此外,注释代码也不能编译,所以我也想要这个解决方案。

标签: ats

解决方案


'calloc' 应该是一个多态函数(而不是函数模板):

extern
fun
calloc
{a:t@ype}{n:nat}
(
num: size_t(n), tsz: size_t(sizeof(a))
) : [l:addr] (array_view(a, l, n) | ptr l) = "ext#"

此外,“Vec”应定义为“datavtype”。请参阅以下应该有帮助的示例:

http://ats-lang.sourceforge.net/EXAMPLE/EFFECTIVATS/queue-sllist2/main.html


推荐阅读