/usr/lib/ats-anairiats-0.2.11/prelude/DATS/array0.dats is in ats-lang-anairiats 0.2.11-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | (***********************************************************************)
(* *)
(* Applied Type System *)
(* *)
(* Hongwei Xi *)
(* *)
(***********************************************************************)
(*
** ATS - Unleashing the Potential of Types!
** Copyright (C) 2002-2008 Hongwei Xi, Boston University
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by the
** Free Software Foundation; either version 2.1, or (at your option) any
** later version.
**
** ATS is distributed in the hope that it will be useful, but WITHOUT ANY
** WARRANTY; without even the implied warranty of MERCHANTABILITY or
** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
** for more details.
**
** You should have received a copy of the GNU General Public License
** along with ATS; see the file COPYING. If not, please write to the
** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
** 02110-1301, USA.
*)
(* ****** ****** *)
(* author: Hongwei Xi (hwxi AT cs DOT bu DOT edu) *)
(* ****** ****** *)
#define ATS_DYNLOADFLAG 0 // loaded by [ats_main_prelude]
(* ****** ****** *)
#define i2sz size1_of_int1
(* ****** ****** *)
//
// HX: array0 implementation
//
(* ****** ****** *)
staload "prelude/SATS/array0.sats"
staload _(*anonymous*) = "prelude/DATS/reference.dats"
(* ****** ****** *)
assume
array0_viewt0ype_type (a:viewt@ype) = ref (Arrpsz (a))
(* ****** ****** *)
(*
//
// HX-2011-01-12:
// it is a casting function now!
//
implement array0_get_arrszref (A) = A
*)
implement array0_make_arrpsz (psz) = ref_make_elt (psz)
(* ****** ****** *)
implement{a}
array0_make_elt (asz, x0) = let
val [n:int] asz = size1_of_size asz
val tsz = sizeof<a>
val (pf_gc, pf_arr | p_arr) = array_ptr_alloc_tsz {a} (asz, tsz)
var ini: a = x0
val () = array_ptr_initialize_elt_tsz {a} (!p_arr, asz, ini, tsz)
in
array0_make_arrpsz {a} {n} @(pf_gc, pf_arr | p_arr, asz)
end // end of [array0_make_elt]
(* ****** ****** *)
implement{a}
array0_make_lst (xs) = let
val [n:int] xs = list_of_list0 (xs)
val n = list_length (xs)
val asz = size1_of_int1 (n)
val (pf_gc, pf_arr | p_arr) = array_ptr_alloc_tsz {a} (asz, sizeof<a>)
val () = array_ptr_initialize_lst<a> (!p_arr, xs)
in
array0_make_arrpsz {a} {n} @(pf_gc, pf_arr | p_arr, asz)
end // end of [array_make_lst]
(* ****** ****** *)
implement
array0_size (A) = let
val (vbox pf_arrpsz | p_psz) = ref_get_view_ptr (A)
in
p_psz->3
end // end of [array0_size]
(* ****** ****** *)
implement{a}
array0_get_elt_at (A, i) = let
val (
vbox pf_psz | p_psz
) = ref_get_view_ptr (A)
val i = size1_of_size i
val p_data = p_psz->2; val asz = p_psz->3
in
if i < asz then let
prval pf_data = p_psz->1
val x = p_data->[i]
prval () = p_psz->1 := pf_data
in
x // return value
end else begin
$raise ArraySubscriptException()
end // end of [if]
end (* end of [array0_get_elt_at] *)
implement{a}
array0_get_elt_at__intsz (A, i) = let
val i = int1_of_int i
in
if i >= 0 then begin
array0_get_elt_at<a> (A, i2sz i)
end else begin
$raise ArraySubscriptException()
end // end of [if]
end (* end of [array0_get_elt_at__intsz] *)
(* ****** ****** *)
implement{a}
array0_set_elt_at (A, i, x) = let
val (vbox pf_psz | p_psz) = ref_get_view_ptr (A)
val i = size1_of_size i
val p_data = p_psz->2; val asz = p_psz->3
in
if i < asz then let
prval pf_data = p_psz->1
val () = p_data->[i] := x
prval () = p_psz->1 := pf_data
in
() // return no value
end else begin
$raise ArraySubscriptException()
end // end of [if]
end (* end of [array0_set_elt_at] *)
implement{a}
array0_set_elt_at__intsz (A, i, x) = let
val i = int1_of_int i
in
if i >= 0 then begin
array0_set_elt_at<a> (A, i2sz i, x)
end else begin
$raise ArraySubscriptException()
end // end of [if]
end (* end of [array0_set_elt_at__intsz] *)
(* ****** ****** *)
implement{a}
array0_exch
(A, i, j) = let
//
val (
vbox pf_psz | p_psz
) = ref_get_view_ptr (A)
val i = size1_of_size (i)
val j = size1_of_size (j)
val p_data = p_psz->2; val asz = p_psz->3
//
in
//
if i < asz then let
in
//
if j < asz then let
prval pf_data = p_psz->1
val () = array_ptr_exch<a> (!p_data, i, j)
prval () = p_psz->1 := pf_data
in
// nothing
end else (
$raise ArraySubscriptException()
) // end of [if]
//
end else (
$raise ArraySubscriptException()
) // end of [if]
//
end // end of [array0_exch]
implement{a}
array0_exch__intsz
(A, i, j) = let
val i = int1_of_int (i)
val j = int1_of_int (j)
in
//
if i >= 0 then let
in
//
if j >= 0 then (
array0_exch<a> (A, (i2sz)i, (i2sz)j)
) else
$raise ArraySubscriptException()
//
end else (
$raise ArraySubscriptException()
) // end of [if]
//
end (* end of [array0_exch__intsz] *)
(* ****** ****** *)
implement{a}
array0_foreach
(A, f) = let
fun loop {n:nat} {l:addr} .<n>. (
pf: !array_v (a, n, l)
| p: ptr l, n: size_t n, f: (&a) -<cloref> void
) :<> void = let
in
//
if n > 0 then let
prval (
pf1, pf2
) = array_v_uncons {a} (pf)
val () = f (!p)
val () = loop (pf2 | p+sizeof<a>, n-1, f)
in
pf := array_v_cons {a} (pf1, pf2)
end // end of [if]
//
end // end of [loop]
//
val (
vbox pf_psz | p_psz
) = ref_get_view_ptr (A)
//
in
loop (p_psz->1 | p_psz->2, p_psz->3, f)
end // end of [array0_foreach]
implement{a}
array0_iforeach
(A, f) = let
//
val (
vbox pf_psz | p_psz
) = ref_get_view_ptr (A)
stavar n0: int
val n0: size_t n0 = p_psz->3
fun loop
{n,i:nat | n0==n+i} {l:addr} .<n>. (
pf: !array_v (a, n, l)
| p: ptr l, n: size_t n, i: size_t i, f: (size_t, &a) -<cloref> void
) :<> void = let
in
//
if n > 0 then let
prval (
pf1, pf2
) = array_v_uncons {a} (pf)
val () = f (i, !p)
val () = loop {n-1,i+1} (pf2 | p+sizeof<a>, n-1, i+1, f)
prval () = pf := array_v_cons {a} (pf1, pf2)
//
in
// nothing
end // end of [if]
//
end // end of [loop]
//
in
loop (p_psz->1 | p_psz->2, n0, 0, f)
end // end of [array0_iforeach]
(* ****** ****** *)
implement{a}
array0_tabulate
(asz, f) = let
//
val [n0:int] asz = size1_of_size asz
val (
pf_gc, pf_arr | p_arr
) = array_ptr_alloc_tsz {a} (asz, sizeof<a>)
//
fun loop
{n,i:nat | n0 == n+i} {l:addr} .<n>. (
pf: !array_v (a?, n, l) >> array_v (a, n, l)
| p: ptr l, n: size_t n, i: size_t i, f: size_t -<cloref> a
) :<> void = let
in
//
if n > 0 then let
prval (pf1, pf2) = array_v_uncons {a?} (pf)
val () = !p := f (i)
val () = loop (pf2 | p+sizeof<a>, n-1, i+1, f)
prval () = pf := array_v_cons {a} (pf1, pf2)
in
// nothing
end else let
prval () = array_v_unnil {a?} (pf)
prval () = pf := array_v_nil {a} ()
in
// nothing
end // end of [if]
//
end // end of [loop]
//
val () = loop (pf_arr | p_arr, asz, 0, f)
//
in
array0_make_arrpsz {a}{n0} @(pf_gc, pf_arr | p_arr, asz)
end // end of [array0_tabulate]
(* ****** ****** *)
(* end of [array0.dats] *)
|