/usr/lib/ats2-postiats-0.2.6/libats/DATS/linmap_list.dats is in ats2-lang 0.2.6-2.
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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | (***********************************************************************)
(* *)
(* Applied Type System *)
(* *)
(***********************************************************************)
(*
** ATS/Postiats - Unleashing the Potential of Types!
** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc.
** All rights reserved
**
** ATS is free software; you can redistribute it and/or modify it under
** the terms of the GNU GENERAL PUBLIC LICENSE (GPL) as published by the
** Free Software Foundation; either version 3, 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 *)
(* Authoremail: hwxi AT cs DOT bu DOT edu *)
(* Start time: December, 2012 *)
(* ****** ****** *)
#define ATS_PACKNAME "ATSLIB.libats.linmap_list"
#define ATS_DYNLOADFLAG 0 // no need for dynloading at run-time
(* ****** ****** *)
staload
UN = "prelude/SATS/unsafe.sats"
(* ****** ****** *)
staload "libats/SATS/linmap_list.sats"
(* ****** ****** *)
#include "./SHARE/linmap.hats" // code reuse
#include "./SHARE/linmap_node.hats" // code reuse
(* ****** ****** *)
stadef
mytkind = $extkind"atslib_linmap_list"
(* ****** ****** *)
assume
map_vtype (k:t0p, i:vt0p) = List0_vt @(k, i)
(* ****** ****** *)
implement{}
linmap_nil () = list_vt_nil ()
implement{}
linmap_make_nil () = list_vt_nil ()
(* ****** ****** *)
implement{}
linmap_is_nil
(map) = ans where {
val ans = (
case+ map of list_vt_nil _ => true | list_vt_cons _ => false
) : bool // end of [val]
} // end of [linmap_is_nil]
implement{}
linmap_isnot_nil
(map) = ans where {
val ans = (
case+ map of list_vt_nil _ => false | list_vt_cons _ => true
) : bool // end of [val]
} // end of [linmap_isnot_nil]
(* ****** ****** *)
implement
{key,itm}
linmap_size (map) = g1int2uint (list_vt_length (map))
(* ****** ****** *)
implement
{key,itm}
linmap_free (map) = list_vt_free<(key,itm)> (map)
implement
{key,itm}
linmap_freelin (map) = let
//
vtypedef ki = @(key, itm)
fun aux (kxs: List_vt(ki)): void =
(
case+ kxs of
| @list_vt_cons
(kx, kxs1) => let
val kxs1 = kxs1
val () = linmap_freelin$clear<itm> (kx.1)
val () = free@{ki}{0}(kxs)
in
aux (kxs1)
end // end of [list_vt_cons]
| ~list_vt_nil ((*void*)) => ()
)
//
in
$effmask_all (aux (map))
end // end of [linmap_freelin]
(* ****** ****** *)
implement
{key,itm}
linmap_insert
(map, k0, x0, res) = let
//
val nx0 =
mynode_make_keyitm<key,itm> (k0, x0)
//
val nx1 =
linmap_insert_ngc<key,itm> (map, nx0)
//
val p1 = mynode2ptr (nx1)
//
in
//
if p1 > 0 then let
val () =
res := mynode_getfree_itm (nx1)
prval () = opt_some{itm}(res)
in
true
end else let
prval () = mynode_free_null (nx1)
prval () = opt_none{itm}(res)
in
false
end (* end of [if] *)
//
end // end of [linmap_insert]
(* ****** ****** *)
implement
{key,itm}
linmap_insert_any
(map, k0, x0) = let
//
vtypedef ki = @(key, itm)
val () = map := list_vt_cons{ki}( @(k0, x0), map )
//
in
// nothing
end // end of [linmap_insert_any]
(* ****** ****** *)
implement
{key,itm}{env}
linmap_foreach_env
(map, env) = let
//
vtypedef ki = @(key, itm)
//
implement{ki}{env}
list_vt_foreach$cont (kx, env) = true
implement
list_vt_foreach$fwork<ki><env>
(kx, env) = linmap_foreach$fwork<key,itm><env> (kx.0, kx.1, env)
//
in
list_vt_foreach_env<ki><env> (map, env)
end // end of [linmap_foreach_env]
(* ****** ****** *)
//
// HX: [map] is just a list
//
implement
{key,itm}
linmap_listize (map) = map
implement
{key,itm}{ki2}
linmap_flistize (map) = let
//
vtypedef ki = @(key, itm)
implement
list_vt_mapfree$fopr<ki><ki2>
(kx) = linmap_flistize$fopr<key,itm><ki2> (kx.0, kx.1)
//
in
list_vt_mapfree<ki><ki2> (map)
end // end of [linmap_flistize]
(* ****** ****** *)
implement
{key,itm}
linmap_listize1 (map) = list_vt_copy<(key,itm)> (map)
(* ****** ****** *)
//
// HX: functions for processing mynodes
//
(* ****** ****** *)
implement{
} mynode_null
{key,itm} () = let
//
vtypedef
mynode = mynode(key,itm,null)
//
in
$UN.castvwtp0{mynode}(the_null_ptr)
end // end of [mynode_null]
(* ****** ****** *)
implement
{key,itm}
mynode_make_keyitm
(k, x) = let
//
vtypedef ki = @(key, itm)
val nx = list_vt_cons{ki}{0}( @(k, x), _ )
//
in
$UN.castvwtp0{mynode1(key,itm)}(nx)
end // end of [mynode_make_keyitm]
(* ****** ****** *)
implement
{key,itm}
mynode_get_key
(nx) = k where {
//
vtypedef ki = @(key, itm)
//
val nx2 = $UN.castvwtp1{List1_vt(ki)}(nx)
//
val+@list_vt_cons (kx, _) = nx2
//
val k = kx.0
//
prval () = fold@ (nx2)
prval () = __assert (nx2) where {
extern praxi __assert : List1_vt(ki) -<prf> void
} // end of [where] // end of [prval]
//
} // end of [mynode_get_key]
implement
{key,itm}
mynode_getref_itm
(nx) = p_x where {
//
vtypedef ki = @(key, itm)
//
val nx2 = $UN.castvwtp1{List1_vt(ki)}(nx)
//
val+@list_vt_cons (kx, _) = nx2
//
val p_x = addr@ (kx.1)
val p_x = $UN.cast{cPtr1(itm)}(p_x)
//
prval () = fold@ (nx2)
prval () = __assert (nx2) where {
extern praxi __assert : List1_vt(ki) -<prf> void
} // end of [where] // end of [prval]
//
} // end of [mynode_getref_itm]
(* ****** ****** *)
implement
{key,itm}
mynode_free_keyitm
(nx, k0, x0) = () where {
//
vtypedef ki = @(key, itm)
//
val nx = $UN.castvwtp0{List1_vt(ki)}(nx)
//
val+~list_vt_cons (kx, nx2) = nx
val () = k0 := kx.0 and () = x0 := kx.1
prval () = __assert (nx2) where {
extern praxi __assert : List0_vt(ki) -<prf> void
} // end of [where] // end of [prval]
//
} // end of [mynode_free_keyitm]
(* ****** ****** *)
implement
{key,itm}
mynode_getfree_itm
(nx) = kx.1 where {
//
vtypedef ki = @(key, itm)
//
val nx = $UN.castvwtp0{List1_vt(ki)}(nx)
//
val+~list_vt_cons (kx, nx2) = nx
//
prval ((*void*)) = $UN.cast2void (nx2)
//
} // end of [mynode_getfree_itm]
(* ****** ****** *)
implement
{key,itm}
linmap_search_ngc
(map, k0) = let
//
vtypedef ki = @(key, itm)
//
fun loop
{n:nat} .<n>. (
kxs: !list_vt (ki, n), k0: key
) :<> Ptr0 = let
in
//
case+ kxs of
| @list_vt_cons
(kx, kxs1) => let
val iseq = equal_key_key<key> (kx.0, k0)
in
if iseq then let
prval () = fold@ (kxs)
in
$UN.castvwtp1{Ptr1} (kxs)
end else let
val res = loop (kxs1, k0)
prval () = fold@ (kxs) in res
end // end of [if]
end // end of [list_vt_cons]
| @list_vt_nil () => let
prval () = fold@ (kxs) in the_null_ptr
end // end of [list_vt_cons]
//
end // end of [loop]
//
in
loop (map, k0) // HX: Ptr1
end // end of [linmap_search_ngc]
(* ****** ****** *)
implement
{key,itm}
linmap_insert_ngc
(map, nx0) = let
//
val k0 = mynode_get_key (nx0)
val nx1 =
linmap_takeout_ngc<key,itm> (map, k0)
val () =
linmap_insert_any_ngc<key,itm> (map, nx0)
//
in
nx1
end // end of [linmap_insert_ngc]
(* ****** ****** *)
implement
{key,itm}
linmap_insert_any_ngc
(map, nx0) = let
//
vtypedef ki = @(key, itm)
//
val nx0 = $UN.castvwtp0{List1_vt(ki)}(nx0)
//
val+@list_vt_cons (_, kxs) = nx0
prval () = __assert (kxs) where {
extern praxi __assert : List0_vt(ki) -<prf> void
} // end of [where] // end of [prval]
//
in
kxs := map; fold@ (nx0); map := nx0
end // end of [linmap_insert_any_ngc]
(* ****** ****** *)
implement
{key,itm}
linmap_takeout_ngc
(map, k0) = let
//
vtypedef ki = @(key, itm)
vtypedef mynode0 = mynode0 (key, itm)
vtypedef mynode1 = mynode1 (key, itm)
//
fun loop (
kxs: &List0_vt (ki) >> _, k0: key
) : mynode0 = let
//
vtypedef kis = List0_vt (ki)
//
in
//
case+ kxs of
| @list_vt_cons
(kx, kxs1) => let
val iseq =
equal_key_key<key> (kx.0, k0)
// end of [val]
in
if iseq then let
val p1 = $UN.castvwtp1{ptr}(kxs1)
prval () = fold@ (kxs)
val res = $UN.castvwtp0{mynode1}(kxs)
val () = kxs := $UN.castvwtp0{kis}(p1)
in
res
end else let
val res = loop (kxs1, k0)
prval () = fold@ (kxs) in res
end // end of [if]
end // end of [list_vt_cons]
| @list_vt_nil () => let
prval () = fold@ (kxs) in mynode_null ()
end // end of [list_vt_cons]
//
end // end of [loop]
//
in
loop (map, k0) // HX: mynode0
end // end of [linmap_takeout_ngc]
(* ****** ****** *)
(* end of [linmap_list.dats] *)
|