Any idea why this code (given below) seg faults when run from console .
#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 :addr} {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
make_nil_list {a:t@ype+} () : (sl_v (a,0,null) | ptr null) =
(slseg_v_nil () | $UN.cast{ptr null}(0))
fun
node_alloc{a:t@ype+}{m:addr} () :
[l:agz] ((a, ptr m)? @ l, mfree_gc_v (l) | ptr (l))
= ptr_alloc<(a,ptr m)> ()
//extern
fun
print_lst {a:t@ype} {n:nat} {l:addr} ..
(pf : !sl_v (a,n,l) | p : ptr l, printfn : a - void) : void =
if ptr1_is_null§ then let
prval slseg_v_nil () = pf
val () = println!(“done”) in pf := slseg_v_nil () end
else let
prval slseg_v_cons (pat , plst) = pf
val x = !p.0
val () = printfn (x)
val nxt_ptr = !p.1
val ()= println!(ptr1_is_null (nxt_ptr))
val () = println!("ok ")
val () = print_lst (plst | nxt_ptr, printfn)
in pf := slseg_v_cons (pat , plst) end
//extern
prfun
at2lst{a:t@ype} {n:nat} {l:agz} {m:addr} .<>.
(pat : (a,ptr m) @ l, plst : sl_v(a,n,m) ) : sl_v(a,n+1,l) =
slseg_v_cons(pat , plst)
val (pf_null_lst | null_p) = make_nil_list{int}()
val () = print_lst{int}{…}{…} (pf_null_lst | null_p , lam (x) => ())
val [l:addr] (pat,pfree | p) = node_alloc{int}()
val () = !p.1 := null_p
val () = !p.0 := 1908
prval pf_lst = at2lst{int}{…}{…}{…} (pat , pf_null_lst)
val () = print_lst{int}{…}{…} (pf_lst | p , lam (x) => () )
implement main0 () = {
(* val () = print(“hello\n”) )
( val () = println!(“whatever”) )
( val x = 123 )
( val () = println!(“hello “,x,” hah”) )
( val () = print_val (100) *)
val () = println!()
}