(*
** Course: Concepts of Programming Languages (BU CAS CS 320)
** Semester: Summer I, 2009
** Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu)
*)

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

staload _(*anonymous*) = "libc/SATS/stdio.sats"
staload _(*anonymous*) = "libc/SATS/string.sats"
staload _(*anonymous*) = "libc/SATS/strings.sats"

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

staload _(*anonymous*) = "prelude/DATS/list.dats"
staload _(*anonymous*) = "prelude/DATS/list0.dats"
staload _(*anonymous*) = "prelude/DATS/list_vt.dats"

staload _(*anonymous*) = "prelude/DATS/array.dats"
staload _(*anonymous*) = "prelude/DATS/reference.dats"

staload _(*anonymous*) = "prelude/DATS/lazy.dats"

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

exception Domain of ()
exception StreamSubscript of () 

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

extern
fun string_implode (cs: list0 char): string = "atspre_string_implode"
extern
fun string_explode (str: string): list0 char = "atspre_string_explode"

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

extern
fun feof (fp: FILEref): int = "mac#atslib_feof"

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

extern
fun string_contains (s: string, c: char): bool = "mac#atspre_string_contains"

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

extern
fun strcmp (x1: string, x2: string):<> int = "mac#atslib_strcmp"

extern
fun strncmp (x1: string, x2: string, n: size_t):<> int = "mac#atslib_strncmp"

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

extern
fun strcasecmp (x1: string, x2: string): int = "mac#atslib_strcasecmp"

extern
fun strncasecmp (x1: string, x2: string, n: size_t): int = "mac#atslib_strncasecmp"

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

extern
fun randint (n: int): int

(*

local

staload RAND = "libc/SATS/random.sats"

in // in of [local]

implement randint (n) = let
  val n = int1_of_int n in
  if n > 0 then $RAND.randint (n) else $raise Domain ()
end // end of [randint]

end // end of [local]

*)

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

%{^

#ifndef ISNAN
#define ISNAN
#ifndef isnan
extern int isnan (double x) ;
#endif // end of [isnan]
#endif // end of [ISNAN]

%} // end of [%{^]

extern fun isnan (x: double): int = "mac#isnan" // declared in [math.h]?

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

(* end of [BUCASCS320.hats] *)