This package contains some common functions for creating/freeing and manipulating arrayptr-values.
stadef arrayptr = arrayptr_vt0ype_addr_int_vtype
vtypedef arrayptr (a:vt0p, n:int) = [l:addr] arrayptr(a, l, n)
overload arrayptr with arrayptr_make_arrpsz
absvtype
arrayptr_vt0ype_addr_int_vtype
(a:vt0ype+, l: addr, n: int) = ptr(l)
stadef arrayptrout = arrayptrout_vt0ype_addr_int_vtype
absvtype
arrayptrout_vt0ype_addr_int_vtype
(a:t@ype, l: addr, n: int) = ptr(l)
castfn
arrayptr_encode :
{a:vt0p}{l:addr}{n:int}
(array_v(INV(a), l, n), mfree_gc_v(l) | ptr(l)) -<0> arrayptr(a, l, n)
castfn
arrayptr2ptr
{a:vt0p}
{l:addr}{n:int}
(A: !arrayptr(INV(a), l, n)):<> ptr(l)
castfn
arrayptrout2ptr
{a:t0p}{l:addr}{n:int}
(A: !arrayptrout(INV(a), l, n)):<> ptr(l)
praxi arrayptr_takeout {a:vt0p}{l:addr}{n:int} ( A: !arrayptr(INV(a), l, n) >> arrayptrout(a?, l, n) ) : array_v(a, l, n) // end of [arrayptr_takeout]
praxi arrayptr_addback {a:vt0p}{l:addr}{n:int} ( pf: array_v(INV(a), l, n) | A: !arrayptrout(a?, l, n) >> arrayptr(a, l, n) ) : void // end of [arrayptr_addback]
fun{
a:t0p
} arrayptr_make_elt
{n:int} (asz: size_t(n), x: a):<!wrt> arrayptr(a, n)
fun{}
arrayptr_make_intrange
{l,r:int | l <= r}
(l: int l, r: int r):<!wrt> arrayptr(intBtw(l, r), r-l)
fun
arrayptr_make_arrpsz
{a:vt0p}{n:int}
(psz: arrpsz(INV(a), n)):<> arrayptr(a, n) = "mac#%"
implement main () = 0 where { val out = stdout_ref val A = (arrayptr)$arrpsz{int} (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) val () = fprint_arrayptr_sep<int> (out, A, g1int2uint(10), ", ") val () = arrayptr_free (A) val () = fprint_newline (out) } // end of [main]
fun
{a:t0p}
arrayptr_make_list{n:int}
(asz: int n, xs: list(INV(a), n)):<!wrt> arrayptr(a, n)
fun
{a:t0p}
arrayptr_make_rlist{n:int}
(asz: int n, xs: list(INV(a), n)):<!wrt> arrayptr(a, n)
fun{a:t0p}
arrayptr_make_subarray
{n:int}{st,ln:int | st+ln <= n}
(A: RD(arrayref(a, n)), size_t(st), size_t(ln)): arrayptr(a, ln)
fun
{a:vt0p}
arrayptr_make_list_vt{n:int}
(asz: int n, xs: list_vt (INV(a), n)):<!wrt> arrayptr(a, n)
fun
{a:vt0p}
arrayptr_make_uninitized
{n:int} (asz: size_t(n)):<!wrt> arrayptr(a?, n)
fun {a:vt0p} arrayptr_imake_list{n:int} ( A: !arrayptr(INV(a), n) >> arrayptr(a?!, n), n: size_t(n) ) : list_vt (a, n) // end of [arrayptr_imake_list]
fun
arrayptr_free
{a:t0p}{l:addr}{n:int}
(A: arrayptr(INV(a), l, n)):<!wrt> void = "mac#%"
overload arrayptr_get_at with arrayptr_get_at_gint
overload arrayptr_get_at with arrayptr_get_at_guint
fun{
a:t0p}{tk:tk
} arrayptr_get_at_gint
{n:int}{i:nat | i < n}
(A: !arrayptr(INV(a), n), i: g1int (tk, i)):<> (a)
fun{
a:t0p}{tk:tk
} arrayptr_get_at_guint
{n:int}{i:nat | i < n}
(A: !arrayptr(INV(a), n), i: g1uint (tk, i)):<> (a)
overload arrayptr_set_at with arrayptr_set_at_gint of 0
overload arrayptr_set_at with arrayptr_set_at_guint of 0
fun{
a:t0p}{tk:tk
} arrayptr_set_at_gint
{n:int}{i:nat | i < n}
(A: !arrayptr(INV(a), n), i: g1int (tk, i), x: a):<!wrt> void
fun{
a:t0p}{tk:tk
} arrayptr_set_at_guint
{n:int}{i:nat | i < n}
(A: !arrayptr(INV(a), n), i: g1uint (tk, i), x: a):<!wrt> void
overload arrayptr_exch_at with arrayptr_exch_at_gint of 0
overload arrayptr_exch_at with arrayptr_exch_at_guint of 0
fun{
a:vt0p}{tk:tk
} arrayptr_exch_at_gint
{n:int}{i:nat | i < n}
(A: !arrayptr(INV(a), n), i: g1int (tk, i), x: &a >> _):<!wrt> void
fun{
a:vt0p}{tk:tk
} arrayptr_exch_at_guint
{n:int}{i:nat | i < n}
(A: !arrayptr(INV(a), n), i: g1uint (tk, i), x: &a >> _):<!wrt> void
fun{a:vt0p} fprint_arrayptr {l:addr}{n:int} ( out: FILEref, A: !arrayptr(INV(a), l, n), n: size_t(n) ) : void // end of [fprint_arrayptr]
fun{a:vt0p} fprint_arrayptr_sep {l:addr}{n:int} ( out: FILEref , A: !arrayptr(INV(a), l, n), n: size_t(n), sep: NSH(string) ) : void // end of [fprint_arrayptr_sep]
fun{ a:vt0p } arrayptr_foreach{n:int} ( A: !arrayptr(INV(a), n), asz: size_t(n) ) : sizeLte(n) // end of [arrayptr_foreach]
fun{ a:vt0p}{env:vt0p } arrayptr_foreach_env{n:int} ( A: !arrayptr(INV(a), n), asz: size_t(n), env: &(env) >> _ ) : sizeLte(n) // end of [arrayptr_foreach_env]
implement main () = let // val N = 10 val asz = g1int2uint (N) val A = arrayptr_make_intrange (0, N) // typedef a = int typedef tenv = int var ans: tenv = 0 implement array_foreach$fwork<a><tenv> (x, env) = env := env + x val _(*ignored*) = arrayptr_foreach_env<a><tenv> (A, asz, ans) // val () = arrayptr_free (A) // val () = assertloc (ans = N*(N-1)/2) // in 0(*normal*) end // end of [main]
fun
{a:vt0p}
arrayptr_foreach_funenv
{v:view}
{vt:vtype}
{n:int}
{fe:eff}
(
pfv: !v
| A: !arrayptr(INV(a), n)
, asz: size_t(n)
, fop: (!v | &a, !vt) -<fun,fe> void
, env: !vt
) :<fe> void
fun {a:vt0p} arrayptr_foreach_fun {n:int}{fe:eff} ( A: !arrayptr(INV(a), n), asz: size_t(n), fwork: (&a) -<fun,fe> void ) :<fe> void // end of [arrayptr_foreach_fun]
fun{ a:vt0p } arrayptr_rforeach{n:int} ( A: !arrayptr(INV(a), n), asz: size_t(n) ) : sizeLte(n) // end of [arrayptr_rforeach]
fun{ a:vt0p}{env:vt0p } arrayptr_rforeach_env{n:int} ( A: !arrayptr(INV(a), n), asz: size_t(n), env: &(env) >> _ ) : sizeLte(n) // end of [arrayptr_rforeach_env]
fun{a:vt0p} arrayptr_initize {l:addr}{n:int} ( A: !arrayptr(a?, l, n) >> arrayptr(a, l, n), asz: size_t(n) ) : void // end of [arrayptr_initize]
fun{a:vt0p} arrayptr_uninitize {l:addr}{n:int} ( A: !arrayptr(INV(a), l, n) >> arrayptr(a?, l, n), asz: size_t(n) ) : void // end of [arrayptr_uninitize]
fun{a:vt0p}
arrayptr_freelin
{l:addr}{n:int}
(A: arrayptr(INV(a), l, n), asz: size_t(n)): void
fun{a:vt0p}
arrayptr_tabulate
{n:int} (asz: size_t(n)): arrayptr(a, n)
overload [] with arrayptr_get_at_gint of 0
overload [] with arrayptr_set_at_gint of 0
overload [] with arrayptr_get_at_guint of 0
overload [] with arrayptr_set_at_guint of 0
overload ptrcast with arrayptr2ptr
overload ptrcast with arrayptrout2ptr
overload free with arrayptr_free
overload fprint with fprint_arrayptr
overload fprint with fprint_arrayptr_sep
This page is created with ATS by Hongwei Xi and also maintained by Hongwei Xi. |