Hi,
I am unable to compile following code in ATS/Postiats version 0.0.4 :
E#include “share/atspre_define.hats”
#include "share/atspre_staload.hats"
staload
UN = “prelude/SATS/unsafe.sats”
dataview slseg_v (a:t@ype, int(len) , addr(beg) , addr(end)) =
| {l:addr} slseg_v_nil(a,0,l,l) of ()
| {n:nat} {l_fst : agz} {l_nxt,l_end : addr}
slseg_v_cons (a,n+1,l_fst,l_end) of
( (a,ptr l_nxt) @ l_fst , slseg_v(a , n , l_nxt , l_end))
viewdef sl_v
(a:t@ype+ , n:int, l:addr) = slseg_v(a,n,l,null)
fun{a:t@ype}
make_nil_list () : (sl_v (a,0,null) | ptr null) =
(slseg_v_nil () | $UN.cast{ptr null}(0))
fun{a:t@ype}
con_alloc ()
: [l:agz][k:addr] ((a,ptr k) @ l , mfree_gc_v (l) | ptr l) = let
val [l:addr] (pf , pfgc | p) = malloc_gc(sizeof<{k:addr} (a,ptr k)>)
prval pf = __assert(pf) where {
extern praxi __assert {k:addr}
(pf : b0ytes (sizeof (@(a,ptr k)) ) @ l ) : (a,ptr k) @ l
}
in
(pf,pfgc | p)
end
fun{a:t@ype}
cons {n:nat}{l:addr} (pf: sl_v(a,n,l) | lstp : ptr l , x:a)
//: [ll:agz] ((a , ptr l) @ ll , sl_v(a,n+1,ll) | ptr ll) = let
: [ll:agz] (sl_v(a,n+1,ll) | ptr ll) = let
val (pfn ,_ | pn) = con_alloc ()
val () = ptr_set (pfn | pn , (x,lstp))
prval npf = slseg_v_cons (pfn , pf)
in
(npf | pn)
end
val (pf | lst_p) = make_nil_list ()
(* compiles succesfully , if I comment the line below *)
val (pf | lst_p) = cons (pf | lst_p , 100) //???
implement main0 () = ()
nter code here…
Problem seem to be in this “val (pf | lst_p) = cons (pf | lst_p , 100)
” part of the code
Thanks