This file is indexed.

/usr/lib/ats-anairiats-0.2.11/prelude/DATS/matrix0.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
(***********************************************************************)
(*                                                                     *)
(*                         Applied Type System                         *)
(*                                                                     *)
(*                              Hongwei Xi                             *)
(*                                                                     *)
(***********************************************************************)

(*
** ATS - Unleashing the Potential of Types!
** Copyright (C) 2002-2009 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) *)

(* ****** ****** *)
//
// matrix0 implementation
//
(* ****** ****** *)

#define ATS_DYNLOADFLAG 0 // loaded by [ats_main_prelude]

(* ****** ****** *)

staload "prelude/SATS/matrix0.sats"
staload _(*anonymous*) = "prelude/DATS/reference.dats"

(* ****** ****** *)

#define i2sz size1_of_int1

(* ****** ****** *)

assume matrix0_viewt0ype_type
  (a:viewt@ype) = ref [l:addr] [m,n:nat] [mn:int] (
  MUL (m, n, mn), free_gc_v (a?, mn, l), @[a][mn] @ l | ptr l, size_t m, size_t n
) // end of [matrix0_viewt0ype_type]

(* ****** ****** *)

implement
matrix0_make_arrpsz
  {a} {m,n} (m, n, psz) = let
  prval pfmul = mul_istot {m,n} ()
  prval () = mul_elim (pfmul)
in
  ref @(pfmul, psz.0, psz.1 | psz.2, m, n)
end // end of [matrix0_make_arrpsz]

implement
matrix0_make_arrpsz__main
  {a} {m,n} {mn} (pfmul | m, n, psz) = let
in
  ref @(pfmul, psz.0, psz.1 | psz.2, m, n)
end (* end of [matrix0_make_arrpsz] *)

(* ****** ****** *)

implement{a}
matrix0_make_elt (row, col, x0) = let
  val [m:int] row = size1_of_size (row)
  val [n:int] col = size1_of_size (col)
  val [mn:int] (pfmul | asz) = mul2_size1_size1 (row, col)
  prval () = mul_nat_nat_nat (pfmul)
  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
  matrix0_make_arrpsz__main {a} (pfmul | row, col, @(pf_gc, pf_arr | p_arr, asz))
end // end of [matrix0_make_elt]

(* ****** ****** *)

implement matrix0_row (M) = let
  val (vbox pf | p) = ref_get_view_ptr (M) in p->4
end // end of [matrix0_row]

implement matrix0_col (M) = let
  val (vbox pf | p) = ref_get_view_ptr (M) in p->5
end // end of [matrix0_col]

(* ****** ****** *)

// this one is proven in [matrix.dats]
extern prfun lemma_for_matrix_subscripting
  {m,n:nat} {i:nat | i < m} {mn,p:int}
  (pf1: MUL (m, n, mn), pf2: MUL (i, n, p)): [p+n <= mn] void
// end of [lemma_for_matrix_subscripting]  

implement{a}
matrix0_get_elt_at (M, i, j) = let
  val (vbox pf | p) = ref_get_view_ptr (M)
  val i = size1_of_size i
  val j = size1_of_size j
  val p_data = p->3; val row = p->4 and col = p->5
in
  if i < row then (
    if j < col then let
      prval pf_data = p->2
      val (pfmul | icol) = mul2_size1_size1 (i, col)
      prval () = lemma_for_matrix_subscripting (p->0, pfmul)
      prval () = mul_nat_nat_nat (pfmul) 
      val x = p_data->[icol + j]
      prval () = p->2 := pf_data
    in
      x // return value
    end else // out-of-col
      $raise MatrixSubscriptException ()
    // end of [if]
  ) else (
    $raise MatrixSubscriptException () // out-of-row
  ) // end of [if]
end (* end of [matrix0_get_elt_at] *)

implement{a}
matrix0_set_elt_at (M, i, j, x) = let
  val (vbox pf | p) = ref_get_view_ptr (M)
  val i = size1_of_size i
  val j = size1_of_size j
  val p_data = p->3; val row = p->4 and col = p->5
in
  if i < row then (
    if j < col then let
      prval pf_data = p->2
      val (pfmul | icol) = mul2_size1_size1 (i, col)
      prval () = lemma_for_matrix_subscripting (p->0, pfmul)
      prval () = mul_nat_nat_nat (pfmul) 
      val () = p_data->[icol + j] := x
      prval () = p->2 := pf_data
    in
      // nothing
    end else // out-of-col
      $raise MatrixSubscriptException ()
    // end of [if]
  ) else (
    $raise MatrixSubscriptException () // out-of-row
  ) // end of [if]
end (* end of [matrix0_set_elt_at] *)

(* ****** ****** *)

implement{a}
matrix0_get_elt_at__intsz (A, i, j) = let
  val i = int1_of_int i and j = int1_of_int j in
  if i >= 0 then (
    if j >= 0 then (
      matrix0_get_elt_at<a> (A, i2sz i, i2sz j)
    ) else (
      $raise MatrixSubscriptException ()
    ) // end of [if]
  ) else (
    $raise MatrixSubscriptException () // out-of-row
  ) // end of [if]
end (* end of [matrix0_get_elt_at__intsz] *)

implement{a}
matrix0_set_elt_at__intsz (A, i, j, x) = let
  val i = int1_of_int i and j = int1_of_int j in
  if i >= 0 then (
    if j >= 0 then (
      matrix0_set_elt_at<a> (A, i2sz i, i2sz j, x)
    ) else (
      $raise MatrixSubscriptException ()
    ) // end of [if]
  ) else (
    $raise MatrixSubscriptException () // out-of-row
  ) // end of [if]
end (* end of [matrix0_set_elt_at__intsz] *)

(* ****** ****** *)

implement{a}
matrix0_foreach (M, f) = let
  fun loop {k:nat} {l:addr} .<k>. (
      pf: !array_v (a, k, l)
    | p: ptr l, k: size_t k, f: (&a) -<cloref> void
    ) :<> void =
    if k > 0 then let
      prval (pf1, pf2) = array_v_uncons {a} (pf)
      val () = f (!p)
      val () = loop (pf2 | p+sizeof<a>, k-1, f)
    in
      pf := array_v_cons {a} (pf1, pf2)
    end // end of [if]
  // end of [loop]
  val (vbox pf | p) = ref_get_view_ptr (M)
  val m = p->4 and n = p->5
  val (pf_mn | mn) = mul2_size1_size1 (m, n)
  prval () = mul_nat_nat_nat (pf_mn)
  prval () = mul_isfun (pf_mn, p->0)
in
  loop (p->2 | p->3, mn, f)
end // end of [matrix0_foreach]

(* ****** ****** *)

implement{a}
matrix0_iforeach (M, f) = let
  fun loop {k:nat} {l:addr} .<k>. (
      pf: !array_v (a, k, l)
    | p: ptr l, k: size_t k
    , i: size_t, n: size_t, j: size_t
    , f: (size_t, size_t, &a) -<cloref> void
    ) :<> void =
    if k > 0 then let
      prval (pf1, pf2) = array_v_uncons {a} (pf)
      val () = f (i, j, !p)
      val j1 = j+1
      val () = (if j1 < n
        then loop (pf2 | p+sizeof<a>, k-1, i, n, j1, f)
        else loop (pf2 | p+sizeof<a>, k-1, i+1, n, 0, f)
      ) : void
    in
      pf := array_v_cons {a} (pf1, pf2)
    end // end of [if]
  // end of [loop]
  val (vbox pf | p) = ref_get_view_ptr (M)
  val m = p->4 and n = p->5
  val (pf_mn | mn) = mul2_size1_size1 (m, n)
  prval () = mul_nat_nat_nat (pf_mn)
  prval () = mul_isfun (pf_mn, p->0)
in
  loop (p->2 | p->3, mn, 0, n, 0, f)
end // end of [matrix0_iforeach]

(* ****** ****** *)

implement{a}
matrix0_tabulate (row, col, f) = let
  val [m:int] m = size1_of_size row
  val [n:int] n = size1_of_size col
  val [mn:int] (pf_mn | mn) = mul2_size1_size1 (m, n)
  prval () = mul_nat_nat_nat (pf_mn)
  val (pf_gc, pf_arr | p_arr) = array_ptr_alloc_tsz {a} (mn, sizeof<a>)
  fun loop {k:nat} {l:addr} .<k>. (
      pf: !array_v (a?, k, l) >> array_v (a, k, l)
    | p: ptr l, k: size_t k
    , i: size_t, n: size_t n, j: size_t, f: (size_t, size_t) -<cloref> a
    ) :<> void =
    if k > 0 then let
      prval (pf1, pf2) = array_v_uncons {a?} (pf)
      val () = !p := f (i, j)
      val j1 = j+1
    in
      if j1 < n then let
        val () = loop (pf2 | p+sizeof<a>, k-1, i, n, j1, f)
      in
        pf := array_v_cons {a} (pf1, pf2)
      end else let
        val () = loop (pf2 | p+sizeof<a>, k-1, i+1, n, 0, f)
      in
        pf := array_v_cons {a} (pf1, pf2)
      end // end of [if]
    end else let
      prval () = array_v_unnil {a?} (pf)
    in
      pf := array_v_nil {a} ()
    end // end of [if]
  // end of [loop]
  val () = loop (pf_arr | p_arr, mn, 0, n, 0, f)
in
  matrix0_make_arrpsz__main {a} (pf_mn | m, n, @(pf_gc, pf_arr | p_arr, mn))
end // end of [array0_tabulate]

(* ****** ****** *)

// [matrix0.sats] is already loaded by a call to [pervasive_load]
staload _(*anonymous*) = "prelude/SATS/matrix0.sats" // this forces that the static
// loading function for [matrix0.sats] is to be called at run-time
// this is really needed only if some datatypes are declared in [matrix0.sats]

(* ****** ****** *)

(* end of [matrix0.dats] *)