hello,
I struggling with making a dataviewtype that may contain a set of himself.
I started with a simple static datatype :
staload _(anonymous)=“prelude/DATS/array.dats”
datatype toto =
Titi of (string)
| {n: nat} Totos of (array(toto, n), size_t n)
extern fun make_totos(t1: toto, t2: toto, t3: toto): array(toto, 3)
extern fun print_toto(t: toto): void
extern fun test_toto(): void
implement make_totos(t1, t2, t3) = array_make_view_ptr(pf|p) where {
val (_, pf|p, sz) = $arrsz {toto}(t1, t2, t3)
}
implement print_toto(t) = case+ t of
| Titi (s) => printf("-> %s\n", @(s))
| Totos (ar, sz) => array_foreach_fun(ar, f, sz) where {
fun f .<>. (t: &toto): void = $effmask_all(print_toto t)
}
implement test_toto() = let
val totos = Totos(make_totos(Titi(“hello”), Titi(“world”), Titi("!")), 3)
in
print_toto totos
end
implement main(argc, argv) = test_toto()
I am unable to translate into a dataviewtype.
My incomplete attempt :
staload _(anonymous)=“prelude/DATS/array.dats”
dataviewtype toto_vt =
Titi_vt of (string)
| {n: nat}{l: addr} Totos_vt of (free_gc_v (toto_vt, n, l), array_v (
toto_vt, n, l) | ptr l, size_t n)
extern fun make_totos_vt(t1: toto_vt, t2: toto_vt, t3: toto_vt): [n: nat] [l
: addr] (free_gc_v (toto_vt, n, l), array_v (toto_vt, n, l) | ptr l)
extern fun print_toto_vt(t: toto_vt): void
extern fun test_toto_vt(): void
implement make_totos_vt(t1, t2, t3) = let
val (pf2gc, pf | p) = array_ptr_alloc<toto_vt>(3)
… // <- assign values to array here ?
in
(pf2gc, pf| p)
end
implement print_toto_vt(t) = case+ t of
| ~Titi_vt (s) => printf("-> %s\n", @(s))
| ~Totos_vt (pf2gc, pf| p, sz_t) => …// loop on array here and release
memory of array here
implement test_toto_vt() = let
val (pf2gc, pf | p) = make_totos_vt(Titi_vt(“hello”), Titi_vt(“world”),
Titi_vt("!"))
val totos = Totos_vt(pf2gc, pf| p, 3)
in
print_toto_vt totos
end
implement main(argc, argv) = test_toto_vt()
My problem is that most of array_v examples are dealing with static type
and not viewtypes.
For example to initialize array, the array_ptr_set_elt_at function deals
with values based on t@ype.
Any advices ?
thanks a lot
cyrille