Updating: working more on ATS-extsolve-z3

(*
** ATS-extsolve:
** For solving ATS-constraints
** with external SMT-solvers
*)

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

(*
** Author: Hongwei Xi
** Authoremail: gmhwxiATgmailDOTcom
*)

(* ****** ****** *)
//
#define ATS_PACKNAME "PATSOLVE_CNSTRNT"
//
(* ****** ****** *)
//
abst0ype
stamp_t0ype = int
//
typedef stamp = stamp_t0ype
//
(* ****** ****** *)
//
fun print_stamp: stamp -> void
and prerr_stamp: stamp -> void
fun fprint_stamp: fprint_type(stamp)
//
overload print with print_stamp
overload prerr with prerr_stamp
overload fprint with fprint_stamp
//
(* ****** ****** *)

fun stamp_make(int): stamp

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

fun stamp_get_int(stamp): int

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

fun hash_stamp(stamp):<> ulint

(* ****** ****** *)
//
fun
eq_stamp_stamp : (stamp, stamp) -<fun0> bool
fun
neq_stamp_stamp : (stamp, stamp) -<fun0> bool
fun
compare_stamp_stamp : (stamp, stamp) -<fun0> int
//
overload = with eq_stamp_stamp
overload != with neq_stamp_stamp
overload compare with compare_stamp_stamp
//
(* ****** ****** *)
//
fun the_stamp_getinc(): stamp
//
fun the_stamp_update(n: stamp): void
//
(* ****** ****** *)

abstype symbol_type = ptr
typedef symbol = symbol_type

(* ****** ****** *)
//
fun print_symbol: symbol -> void
and prerr_symbol: symbol -> void
fun fprint_symbol: fprint_type(symbol)
//
overload print with print_symbol
overload prerr with prerr_symbol
overload fprint with fprint_symbol
//
(* ****** ****** *)

fun
symbol_make_name (string): symbol

(* ****** ****** *)
//
fun
symbol_get_name (symbol): string
//
overload .name with symbol_get_name
//
(* ****** ****** *)
//
fun
eq_symbol_symbol : (symbol, symbol) -<fun0> bool
fun
neq_symbol_symbol : (symbol, symbol) -<fun0> bool
fun
compare_symbol_symbol : (symbol, symbol) -<fun0> int
//
overload = with eq_symbol_symbol
overload != with neq_symbol_symbol
overload compare with compare_symbol_symbol
//
(* ****** ****** *)
//
abstype
location_type = ptr
//
typedef loc_t = location_type
//
(* ****** ****** *)
//
fun
fprint_location: fprint_type(loc_t)
//
overload fprint with fprint_location
//
(* ****** ****** *)
//
fun location_make (rep: string): loc_t
//
(* ****** ****** *)

datatype s2rt =
//
  | S2RTint of ()
  | S2RTaddr of ()
  | S2RTbool of ()
//
  | S2RTreal of ()
  | S2RTstring of ()
//
  | S2RTcls of ()
//
  | S2RTtup of ((*void*))
//
  | S2RTtype of ((*void*))
  | S2RTvtype of ((*void*))
//
  | S2RTt0ype of ((*void*))
  | S2RTvt0ype of ((*void*))
//
  | S2RTfun of (s2rtlst(*args*), s2rt (*res*))
//
  | S2RTnamed of (symbol)
//
  | S2RTignored of ((*void*))
//
// end of [datatype]

where s2rtlst = List0(s2rt)

(* ****** ****** *)
//
fun s2rt_int((*void*)): s2rt
fun s2rt_addr((*void*)): s2rt
fun s2rt_bool((*void*)): s2rt
//
fun s2rt_real((*void*)): s2rt
fun s2rt_string((*void*)): s2rt
//
(* ****** ****** *)
//
fun print_s2rt : s2rt -> void
and prerr_s2rt : s2rt -> void
fun fprint_s2rt: fprint_type(s2rt)
//
overload print with print_s2rt
overload prerr with prerr_s2rt
overload fprint with fprint_s2rt
//
(* ****** ****** *)
//
abstype
s2cst_type = ptr
//
typedef s2cst = s2cst_type
//
typedef s2cstlst = List0(s2cst)
vtypedef s2cstlst_vt = List0_vt(s2cst)
//
typedef s2cstopt = Option(s2cst)
vtypedef s2cstopt_vt = Option_vt(s2cst)
//
(* ****** ****** *)
//
fun
s2cst_make
  (symbol, s2rt, stamp): s2cst
//
(* ****** ****** *)
//
fun print_s2cst: s2cst -> void
and prerr_s2cst: s2cst -> void
fun fprint_s2cst: fprint_type(s2cst)
//
overload print with print_s2cst
overload prerr with prerr_s2cst
overload fprint with fprint_s2cst
//
(* ****** ****** *)
//
fun s2cst_get_srt (s2cst): s2rt
fun s2cst_get_name (s2cst): symbol
fun s2cst_get_stamp (s2cst): stamp
//
overload .srt with s2cst_get_srt
overload .name with s2cst_get_name
overload .stamp with s2cst_get_stamp
//
(* ****** ****** *)

fun s2cst_get_payload(s2cst): ptr
fun s2cst_set_payload(s2cst, payload: ptr): void

(* ****** ****** *)
//
abstype
s2var_type = ptr
//
typedef s2var = s2var_type
//
typedef s2varlst = List0(s2var)
vtypedef s2varlst_vt = List0_vt(s2var)
//
typedef s2varopt = Option(s2var)
vtypedef s2varopt_vt = Option_vt(s2var)
//
(* ****** ****** *)
//
fun
s2var_make
  (symbol, s2rt, stamp): s2var
//
(* ****** ****** *)
//
fun
print_s2var: s2var -> void
fun
fprint_s2var: fprint_type(s2var)
//
overload print with print_s2var
overload fprint with fprint_s2var
//
(* ****** ****** *)
//
fun
s2var_get_srt (s2var): s2rt
fun
s2var_get_name (s2var): symbol
fun
s2var_get_stamp (s2var): stamp
//
overload .srt with s2var_get_srt
overload .name with s2var_get_name
overload .stamp with s2var_get_stamp
//
(* ****** ****** *)
//
fun s2var_get_payload(s2var): ptr
fun s2var_set_payload(s2var, payload: ptr): void
//
(* ****** ****** *)
//
abstype
s2Var_type = ptr
//
typedef s2Var = s2Var_type
//
typedef s2Varlst = List0(s2Var)
vtypedef s2Varlst_vt = List0_vt(s2Var)
//
typedef s2Varopt = Option(s2Var)
vtypedef s2Varopt_vt = Option_vt(s2Var)
//
(* ****** ****** *)
//
fun s2Var_make(stamp): s2Var
//
(* ****** ****** *)
//
fun
print_s2Var: s2Var -> void
fun
fprint_s2Var: fprint_type(s2Var)
//
overload print with print_s2Var
overload fprint with fprint_s2Var
//
(* ****** ****** *)
//
fun
s2Var_get_stamp (s2Var): stamp
//
overload .stamp with s2Var_get_stamp
//
(* ****** ****** *)

datatype
tyreckind =
  | TYRECKINDbox (* boxed *)
  | TYRECKINDbox_lin (* boxed *)
  | TYRECKINDflt0 (* flat *)
  | TYRECKINDflt1 of stamp (* flat *)
  | TYRECKINDflt_ext of string  (* flat *)
// end of [tyreckind]

(* ****** ****** *)
//
fun tyreckind_is_box (knd: tyreckind): bool
fun tyreckind_is_box_lin (knd: tyreckind): bool
//
fun tyreckind_is_flt0 (knd: tyreckind): bool
fun tyreckind_is_flt1 (knd: tyreckind): bool
fun tyreckind_is_flt_ext (knd: tyreckind): bool
//
(* ****** ****** *)

datatype
s2exp_node =
//
| S2Eint of (int)
| S2Eintinf of (string)
//
| S2Ecst of (s2cst)
| S2Evar of (s2var)
| S2EVar of (s2Var)
//
| S2Eeqeq of (s2exp, s2exp)
//
| S2Eapp of (s2exp, s2explst)
| S2Emetdec of
    (s2explst(*met*), s2explst(*bound*)) // strictly decreasing
  // end of [S2Emetdec]
//
| S2Einvar of (s2exp)
//
| S2Eignored of ((*void*))
// end of [s2exp_node]

where
s2exp = $rec{
  s2exp_srt= s2rt, s2exp_node= s2exp_node
} (* end of [s2exp] *)

and s2explst = List0 (s2exp)

(* ****** ****** *)
//
fun
s2exp_make_node (s2rt, s2exp_node): s2exp
//
fun s2exp_var (s2v: s2var): s2exp
fun s2exp_eqeq (s2e1: s2exp, s2e2: s2exp): s2exp
//
(* ****** ****** *)
//
fun print_s2exp(s2exp): void
and prerr_s2exp(s2exp): void
//
overload print with print_s2exp
overload prerr with prerr_s2exp
//
fun print_s2explst(s2explst): void
and prerr_s2explst(s2explst): void
//
overload print with print_s2explst
overload prerr with prerr_s2explst
//
fun fprint_s2exp : fprint_type(s2exp)
fun fprint_s2explst : fprint_type(s2explst)
//
overload fprint with fprint_s2exp
overload fprint with fprint_s2explst of 10
//
(* ****** ****** *)

abstype d2var_type = ptr
typedef d2var = d2var_type

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

datatype
caskind =
  | CK_case // case
  | CK_case_pos // case+
  | CK_case_neg // case-
// end of [caskind]

datatype
c3nstrkind =
//
  | C3TKmain of () // generic
//
  | C3TKcase_exhaustiveness of (caskind)
//
  | C3TKtermet_isnat of () // term. metric welfounded
  | C3TKtermet_isdec of () // term. metric decreasing
//
  | C3TKsome_fin of (d2var, s2exp(*fin*), s2exp)
  | C3TKsome_lvar of (d2var, s2exp(*lvar*), s2exp)
  | C3TKsome_vbox of (d2var, s2exp(*vbox*), s2exp)
//
  | C3TKlstate of () // lstate merge
  | C3TKlstate_var of (d2var) // lstate merge for d2var
//
  | C3TKloop of (int) // HX: ~1/0/1: enter/break/continue
//
  | C3TKignored of () // HX-2015-06-06: ignored c3nstrkind
// end of [c3nstrkind]

datatype s3itm =
  | S3ITMsvar of s2var
  | S3ITMsVar of s2Var
  | S3ITMhypo of h3ypo
  | S3ITMcnstr of c3nstr
  | S3ITMcnstr_ref of (loc_t, c3nstropt)
  | S3ITMdisj of s3itmlstlst
// end of [s3item]

and h3ypo_node =
  | H3YPOprop of s2exp
  | H3YPObind of (s2var, s2exp)
  | H3YPOeqeq of (s2exp, s2exp)
// end of [h3ypo_node]

and c3nstr_node =
  | C3NSTRprop of s2exp
  | C3NSTRitmlst of s3itmlst
// end of [c3nstr_node]

where
//
s3itmlst = List0(s3itm)
//
and
s3itmlstlst = List0(s3itmlst)
//
and
h3ypo = $rec{
  h3ypo_loc= loc_t
, h3ypo_node= h3ypo_node
} (* end of [h3ypo] *)
//
and
c3nstr = $rec{
  c3nstr_loc= loc_t
, c3nstr_kind= c3nstrkind
, c3nstr_node= c3nstr_node
} (* end of [c3nstr] *)
//
and c3nstropt = Option(c3nstr)

(* ****** ****** *)
//
fun
h3ypo_make_node (loc_t, h3ypo_node): h3ypo
//
(* ****** ****** *)
//
fun
c3nstr_make_node
  (loc: loc_t, knd: c3nstrkind, c3nstr_node): c3nstr
//
(* ****** ****** *)
//
fun
fprint_s3itm: fprint_type(s3itm)
fun
fprint_s3itmlst: fprint_type(s3itmlst)
fun
fprint_s3itmlstlst: fprint_type(s3itmlstlst)
//
overload fprint with fprint_s3itm
overload fprint with fprint_s3itmlst of 10
overload fprint with fprint_s3itmlstlst of 20
//
(* ****** ****** *)
//
fun
fprint_h3ypo: fprint_type(h3ypo)
//
overload fprint with fprint_h3ypo
//
(* ****** ****** *)
//
fun
fprint_c3nstr: fprint_type(c3nstr)
fun
fprint_c3nstropt: fprint_type(c3nstropt)
//
overload fprint with fprint_c3nstr
overload fprint with fprint_c3nstropt of 10
//
(* ****** ****** *)
//
// HX-2015-05-25:
// pretty-printing
//
fun fpprint_c3nstr: fprint_type(c3nstr)
//
(* ****** ****** *)

fun s2exp_make_h3ypo(h3p: h3ypo): s2exp

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

(* end of [patsolve_cnstrnt.sats] *)

(*
** ATS-extsolve:
** For solving ATS-constraints
** with external SMT-solvers
*)

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

(*
** Author: Hongwei Xi
** Authoremail: gmhwxiATgmailDOTcom
*)

(* ****** ****** *)
//
#define ATS_PACKNAME "PATSOLVE_CNSTRNT"
//
(* ****** ****** *)
//
abst0ype
stamp_t0ype = int
//
typedef stamp = stamp_t0ype
//
(* ****** ****** *)
//
fun print_stamp: stamp -> void
and prerr_stamp: stamp -> void
fun fprint_stamp: fprint_type(stamp)
//
overload print with print_stamp
overload prerr with prerr_stamp
overload fprint with fprint_stamp
//
(* ****** ****** *)

fun stamp_make(int): stamp

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

fun stamp_get_int(stamp): int

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

fun hash_stamp(stamp):<> ulint

(* ****** ****** *)
//
fun
eq_stamp_stamp : (stamp, stamp) -<fun0> bool
fun
neq_stamp_stamp : (stamp, stamp) -<fun0> bool
fun
compare_stamp_stamp : (stamp, stamp) -<fun0> int
//
overload = with eq_stamp_stamp
overload != with neq_stamp_stamp
overload compare with compare_stamp_stamp
//
(* ****** ****** *)
//
fun the_stamp_getinc(): stamp
//
fun the_stamp_update(n: stamp): void
//
(* ****** ****** *)

abstype symbol_type = ptr
typedef symbol = symbol_type

(* ****** ****** *)
//
fun print_symbol: symbol -> void
and prerr_symbol: symbol -> void
fun fprint_symbol: fprint_type(symbol)
//
overload print with print_symbol
overload prerr with prerr_symbol
overload fprint with fprint_symbol
//
(* ****** ****** *)

fun
symbol_make_name (string): symbol

(* ****** ****** *)
//
fun
symbol_get_name (symbol): string
//
overload .name with symbol_get_name
//
(* ****** ****** *)
//
fun
eq_symbol_symbol : (symbol, symbol) -<fun0> bool
fun
neq_symbol_symbol : (symbol, symbol) -<fun0> bool
fun
compare_symbol_symbol : (symbol, symbol) -<fun0> int
//
overload = with eq_symbol_symbol
overload != with neq_symbol_symbol
overload compare with compare_symbol_symbol
//
(* ****** ****** *)
//
abstype
location_type = ptr
//
typedef loc_t = location_type
//
(* ****** ****** *)
//
fun
fprint_location: fprint_type(loc_t)
//
overload fprint with fprint_location
//
(* ****** ****** *)
//
fun location_make (rep: string): loc_t
//
(* ****** ****** *)

datatype s2rt =
//
  | S2RTint of ()
  | S2RTaddr of ()
  | S2RTbool of ()
//
  | S2RTreal of ()
  | S2RTstring of ()
//
  | S2RTcls of ()
//
  | S2RTtup of ((*void*))
//
  | S2RTtype of ((*void*))
  | S2RTvtype of ((*void*))
//
  | S2RTt0ype of ((*void*))
  | S2RTvt0ype of ((*void*))
//
  | S2RTfun of (s2rtlst(*args*), s2rt (*res*))
//
  | S2RTnamed of (symbol)
//
  | S2RTignored of ((*void*))
//
// end of [datatype]

where s2rtlst = List0(s2rt)

(* ****** ****** *)
//
fun s2rt_int((*void*)): s2rt
fun s2rt_addr((*void*)): s2rt
fun s2rt_bool((*void*)): s2rt
//
fun s2rt_real((*void*)): s2rt
fun s2rt_string((*void*)): s2rt
//
(* ****** ****** *)
//
fun print_s2rt : s2rt -> void
and prerr_s2rt : s2rt -> void
fun fprint_s2rt: fprint_type(s2rt)
//
overload print with print_s2rt
overload prerr with print_s2rt
overload fprint with fprint_s2rt
//
(* ****** ****** *)
//
abstype
s2cst_type = ptr
//
typedef s2cst = s2cst_type
//
typedef s2cstlst = List0(s2cst)
vtypedef s2cstlst_vt = List0_vt(s2cst)
//
typedef s2cstopt = Option(s2cst)
vtypedef s2cstopt_vt = Option_vt(s2cst)
//
(* ****** ****** *)
//
fun
s2cst_make
  (symbol, s2rt, stamp): s2cst
//
(* ****** ****** *)
//
fun print_s2cst: s2cst -> void
and prerr_s2cst: s2cst -> void
fun fprint_s2cst: fprint_type(s2cst)
//
overload print with print_s2cst
overload prerr with prerr_s2cst
overload fprint with fprint_s2cst
//
(* ****** ****** *)
//
fun s2cst_get_srt (s2cst): s2rt
fun s2cst_get_name (s2cst): symbol
fun s2cst_get_stamp (s2cst): stamp
//
overload .srt with s2cst_get_srt
overload .name with s2cst_get_name
overload .stamp with s2cst_get_stamp
//
(* ****** ****** *)

fun s2cst_get_payload(s2cst): ptr
fun s2cst_set_payload(s2cst, payload: ptr): void

(* ****** ****** *)
//
abstype
s2var_type = ptr
//
typedef s2var = s2var_type
//
typedef s2varlst = List0(s2var)
vtypedef s2varlst_vt = List0_vt(s2var)
//
typedef s2varopt = Option(s2var)
vtypedef s2varopt_vt = Option_vt(s2var)
//
(* ****** ****** *)
//
fun
s2var_make
  (symbol, s2rt, stamp): s2var
//
(* ****** ****** *)
//
fun
print_s2var: s2var -> void
fun
fprint_s2var: fprint_type(s2var)
//
overload print with print_s2var
overload fprint with fprint_s2var
//
(* ****** ****** *)
//
fun
s2var_get_srt (s2var): s2rt
fun
s2var_get_name (s2var): symbol
fun
s2var_get_stamp (s2var): stamp
//
overload .srt with s2var_get_srt
overload .name with s2var_get_name
overload .stamp with s2var_get_stamp
//
(* ****** ****** *)
//
fun s2var_get_payload(s2var): ptr
fun s2var_set_payload(s2var, payload: ptr): void
//
(* ****** ****** *)
//
abstype
s2Var_type = ptr
//
typedef s2Var = s2Var_type
//
typedef s2Varlst = List0(s2Var)
vtypedef s2Varlst_vt = List0_vt(s2Var)
//
typedef s2Varopt = Option(s2Var)
vtypedef s2Varopt_vt = Option_vt(s2Var)
//
(* ****** ****** *)
//
fun s2Var_make(stamp): s2Var
//
(* ****** ****** *)
//
fun
print_s2Var: s2Var -> void
fun
fprint_s2Var: fprint_type(s2Var)
//
overload print with print_s2Var
overload fprint with fprint_s2Var
//
(* ****** ****** *)
//
fun
s2Var_get_stamp (s2Var): stamp
//
overload .stamp with s2Var_get_stamp
//
(* ****** ****** *)

datatype
tyreckind =
  | TYRECKINDbox (* boxed *)
  | TYRECKINDbox_lin (* boxed *)
  | TYRECKINDflt0 (* flat *)
  | TYRECKINDflt1 of stamp (* flat *)
  | TYRECKINDflt_ext of string  (* flat *)
// end of [tyreckind]

(* ****** ****** *)
//
fun tyreckind_is_box (knd: tyreckind): bool
fun tyreckind_is_box_lin (knd: tyreckind): bool
//
fun tyreckind_is_flt0 (knd: tyreckind): bool
fun tyreckind_is_flt1 (knd: tyreckind): bool
fun tyreckind_is_flt_ext (knd: tyreckind): bool
//
(* ****** ****** *)

datatype
s2exp_node =
//
| S2Eint of (int)
| S2Eintinf of (string)
//
| S2Ecst of (s2cst)
| S2Evar of (s2var)
| S2EVar of (s2Var)
//
| S2Eeqeq of (s2exp, s2exp)
//
| S2Eapp of (s2exp, s2explst)
| S2Emetdec of
    (s2explst(*met*), s2explst(*bound*)) // strictly decreasing
  // end of [S2Emetdec]
//
| S2Einvar of (s2exp)
//
| S2Eignored of ((*void*))
// end of [s2exp_node]

where
s2exp = $rec{
  s2exp_srt= s2rt, s2exp_node= s2exp_node
} (* end of [s2exp] *)

and s2explst = List0 (s2exp)

(* ****** ****** *)
//
fun
s2exp_make_node (s2rt, s2exp_node): s2exp
//
fun s2exp_var (s2v: s2var): s2exp
fun s2exp_eqeq (s2e1: s2exp, s2e2: s2exp): s2exp
//
(* ****** ****** *)
//
fun print_s2exp(s2exp): void
and prerr_s2exp(s2exp): void
//
overload print with print_s2exp
overload prerr with prerr_s2exp
//
fun print_s2explst(s2explst): void
and prerr_s2explst(s2explst): void
//
overload print with print_s2explst
overload prerr with prerr_s2explst
//
fun fprint_s2exp : fprint_type(s2exp)
fun fprint_s2explst : fprint_type(s2explst)
//
overload fprint with fprint_s2exp
overload fprint with fprint_s2explst of 10
//
(* ****** ****** *)

abstype d2var_type = ptr
typedef d2var = d2var_type

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

datatype
caskind =
  | CK_case // case
  | CK_case_pos // case+
  | CK_case_neg // case-
// end of [caskind]

datatype
c3nstrkind =
//
  | C3TKmain of () // generic
//
  | C3TKcase_exhaustiveness of (caskind)
//
  | C3TKtermet_isnat of () // term. metric welfounded
  | C3TKtermet_isdec of () // term. metric decreasing
//
  | C3TKsome_fin of (d2var, s2exp(*fin*), s2exp)
  | C3TKsome_lvar of (d2var, s2exp(*lvar*), s2exp)
  | C3TKsome_vbox of (d2var, s2exp(*vbox*), s2exp)
//
  | C3TKlstate of () // lstate merge
  | C3TKlstate_var of (d2var) // lstate merge for d2var
//
  | C3TKloop of (int) // HX: ~1/0/1: enter/break/continue
//
  | C3TKignored of () // HX-2015-06-06: ignored c3nstrkind
// end of [c3nstrkind]

datatype s3itm =
  | S3ITMsvar of s2var
  | S3ITMsVar of s2Var
  | S3ITMhypo of h3ypo
  | S3ITMcnstr of c3nstr
  | S3ITMcnstr_ref of (loc_t, c3nstropt)
  | S3ITMdisj of s3itmlstlst
// end of [s3item]

and h3ypo_node =
  | H3YPOprop of s2exp
  | H3YPObind of (s2var, s2exp)
  | H3YPOeqeq of (s2exp, s2exp)
// end of [h3ypo_node]

and c3nstr_node =
  | C3NSTRprop of s2exp
  | C3NSTRitmlst of s3itmlst
// end of [c3nstr_node]

where
//
s3itmlst = List0(s3itm)
//
and
s3itmlstlst = List0(s3itmlst)
//
and
h3ypo = $rec{
  h3ypo_loc= loc_t
, h3ypo_node= h3ypo_node
} (* end of [h3ypo] *)
//
and
c3nstr = $rec{
  c3nstr_loc= loc_t
, c3nstr_kind= c3nstrkind
, c3nstr_node= c3nstr_node
} (* end of [c3nstr] *)
//
and c3nstropt = Option(c3nstr)

(* ****** ****** *)
//
fun
h3ypo_make_node (loc_t, h3ypo_node): h3ypo
//
(* ****** ****** *)
//
fun
c3nstr_make_node
  (loc: loc_t, knd: c3nstrkind, c3nstr_node): c3nstr
//
(* ****** ****** *)
//
fun
fprint_s3itm: fprint_type(s3itm)
fun
fprint_s3itmlst: fprint_type(s3itmlst)
fun
fprint_s3itmlstlst: fprint_type(s3itmlstlst)
//
overload fprint with fprint_s3itm
overload fprint with fprint_s3itmlst of 10
overload fprint with fprint_s3itmlstlst of 20
//
(* ****** ****** *)
//
fun
fprint_h3ypo: fprint_type(h3ypo)
//
overload fprint with fprint_h3ypo
//
(* ****** ****** *)
//
fun
fprint_c3nstr: fprint_type(c3nstr)
fun
fprint_c3nstropt: fprint_type(c3nstropt)
//
overload fprint with fprint_c3nstr
overload fprint with fprint_c3nstropt of 10
//
(* ****** ****** *)
//
// HX-2015-05-25:
// pretty-printing
//
fun fpprint_c3nstr: fprint_type(c3nstr)
//
(* ****** ****** *)

fun s2exp_make_h3ypo(h3p: h3ypo): s2exp

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

(* end of [patsolve_cnstrnt.sats] *)


Updating: very minorly improving

Updating: very minorly improving

(* ****** ****** *)
//
// HX-2015-07:
// A running example
// from ATS2 to Erlang
//
(* ****** ****** *)
//
#define ATS_DYNLOADFLAG 0
//
(* ****** ****** *)

%{^
%%
-module(listlen_dats).
%%
-export([listlen/1]).
%%
-export( [mytest/0] ).
%%
-compile(nowarn_unused_function).
%%
-include("./libatscc2erl/libatscc2erl_all.hrl").
%%
%} // end of [%{]

(* ****** ****** *)
//
#include
"share/atspre_define.hats"
//
(* ****** ****** *)
//
#include
"{$LIBATSCC2ERL}/staloadall.hats"
//
(* ****** ****** *)
//
extern
fun
listlen{a:t0p}
  : List0 (a) -> int = "mac#listlen"
//
implement
listlen{a}
  (xs) = let
//
prval () = lemma_list_param (xs)
//
fun
loop{i,j:nat} .<i>.
(
  xs: list (a, i), res: int(j)
) : int(i+j) = let
in
//
case+ xs of
| list_nil () => res
| list_cons (_, xs) => loop (xs, res+1)
//
end // end of [loop]
//
in
  loop (xs, 0)
end // end of [listlen]

(* ****** ****** *)
//
extern
fun
fromto
  : (int, int) -> List0 (int) = "mac#fromto"
//
implement
fromto (m, n) =
if m < n
  then list_cons (m, fromto (m+1, n)) else list_nil ()
// end of [if]
//
(* ****** ****** *)

%{$
mytest() ->
  N = 10
, io:format("listlen(fromto(0, ~p)) = ~p~n", [N, listlen(fromto(0, N))])
. %% mytest()
%} // end of [%{$]

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

(* end of [listlen.dats] *)

(* ****** ****** *)
//
// HX-2015-07:
// A running example
// from ATS2 to Erlang
//
(* ****** ****** *)
//
#define ATS_DYNLOADFLAG 0
//
(* ****** ****** *)

%{^
%%
-module(listlen_dats).
%%
-export([listlen/1,fromto/2]).
%%
-compile(nowarn_unused_function).
%%
-include("./libatscc2erl/libatscc2erl_all.hrl").
%%
%} // end of [%{]

(* ****** ****** *)
//
#include
"share/atspre_define.hats"
//
(* ****** ****** *)
//
#include
"{$LIBATSCC2ERL}/staloadall.hats"
//
(* ****** ****** *)
//
extern
fun
listlen{a:t0p}
  : List0 (a) -> int = "mac#listlen"
//
implement
listlen{a}
  (xs) = let
//
prval () = lemma_list_param (xs)
//
fun
loop{i,j:nat} .<i>.
(
  xs: list (a, i), res: int(j)
) : int(i+j) = let
in
//
case+ xs of
| list_nil () => res
| list_cons (_, xs) => loop (xs, res+1)
//
end // end of [loop]
//
in
  loop (xs, 0)
end // end of [listlen]

(* ****** ****** *)
//
extern
fun
fromto
  : (int, int) -> List0 (int) = "mac#fromto"
//
implement
fromto (m, n) =
if m < n
  then list_cons (m, fromto (m+1, n)) else list_nil ()
// end of [if]
//
(* ****** ****** *)

(* end of [listlen.dats] *)


updating jsmn to be more portable

updating jsmn to be more portable

staload UN = "prelude/SATS/unsafe.sats"

staload "./../SATS/jsmn.sats"

implement
jsmntokptr_numtokens (jsv) =
    if jsv.type() = JSMN_PRIMITIVE then let
    in
        1
    end
    else if jsv.type() = JSMN_STRING then let
    in
        1
    end
    else if jsv.type() = JSMN_ARRAY orelse
               jsv.type() = JSMN_OBJECT then let
        val stop = jsv.ending()

        fun loop (jsv: jsmntokptr, n:int): int = let
            val p = $UN.cast{ptr} (jsv)
            val p = add_ptr_bsz (p, sizeof<jsmntok_t>)
            val next = $UN.cast{jsmntokptr}(p)
            val ending = next.ending()
        in
            if ending > stop orelse ending = 0 then
                n
            else
                loop (next, succ(n))
        end

     in
          loop (jsv, 1)
     end

     else let
         val () = prerrln! ("Invalid json value.")
         val () = prerrln! ("Has type: ", jsv.type())
         val () = println! ("Invalid json value starts @ ", jsv.start())
     in
         ~1
     end

staload UN = "prelude/SATS/unsafe.sats"

staload "contrib/libats-/wdblair/jsmn/SATS/jsmn.sats"

implement
jsmntokptr_numtokens (jsv) =
    if jsv.type() = JSMN_PRIMITIVE then let
    in
        1
    end
    else if jsv.type() = JSMN_STRING then let
    in
        1
    end
    else if jsv.type() = JSMN_ARRAY orelse
               jsv.type() = JSMN_OBJECT then let
        val stop = jsv.ending()

        fun loop (jsv: jsmntokptr, n:int): int = let
            val p = $UN.cast{ptr} (jsv)
            val p = add_ptr_bsz (p, sizeof<jsmntok_t>)
            val next = $UN.cast{jsmntokptr}(p)
            val ending = next.ending()
        in
            if ending > stop orelse ending = 0 then
                n
            else
                loop (next, succ(n))
        end

     in
          loop (jsv, 1)
     end

     else let
         val () = prerrln! ("Invalid json value.")
         val () = prerrln! ("Has type: ", jsv.type())
         val () = println! ("Invalid json value starts @ ", jsv.start())
     in
         ~1
     end


Updating: adding a missing test

Updating: adding a missing test

(* ****** ****** *)
//
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)
//
staload
"./../prelude/SATS/integer.sats"
//
(* ****** ****** *)
//
extern
fun
listlen
  : {a:t@ype} List0 (a) -> int = "mac#listlen"
//
implement
listlen{a}
  (xs) = let
//
prval () = lemma_list_param (xs)
//
fun
loop{i,j:nat} .<i>.
(
  xs: list (a, i), res: int(j)
) : int(i+j) = let
in
//
case+ xs of
| list_nil () => res | list_cons (_, xs) => loop (xs, res+1)
//
end // end of [loop]
//
in
  loop (xs, 0)
end // end of [intlistlen]

(* ****** ****** *)
//
extern
fun
fromto
  : (int, int) -> List0 (int) = "mac#fromto"
//
implement
fromto (m, n) =
if m < n
  then list_cons (m, fromto (m+1, n)) else list_nil ()
// end of [if]
//
(* ****** ****** *)

%{^
//
// file is included here:
//
var fs = require('fs');
eval(fs.readFileSync('./../prelude/CATS/basics_cats.js').toString());
eval(fs.readFileSync('./../prelude/CATS/integer_cats.js').toString());
%} // end of [%{^]

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

%{$
var xs = fromto(0, 10)
console.log("listlen(", xs, ") =", listlen(xs))
%} // end of [%{$]

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

(* end of [listlen.dats] *)

error: pathspec 'projects/MEDIUM/ATS-parse-emit/JavaScript/TEST/listlen.dats' did not match any file(s) known to git


Updating: very minorly improving

Updating: very minorly improving

(*
##
## ATS-extsolve-smt2:
## Outputing ATS-constraints
## in the format of smt-lib2
##
*)

(* ****** ****** *)
//
#define
PATSOLVE_targetloc "./../.ATS-extsolve"
//
(* ****** ****** *)
//
staload
"{$PATSOLVE}/patsolve_cnstrnt.sats"
//
(* ****** ****** *)
//
staload "./../patsolve_smt2_solving.sats"
//
(* ****** ****** *)

(* end of [myheader.hats] *)

error: pathspec 'projects/MEDIUM/ATS-extsolve-smt2/SOLVING/myheader.hats' did not match any file(s) known to git


Updating: scratching a bit

Updating: scratching a bit

(* ****** ****** *)
//
// HX-2014-12-25:
// For the purpose of
// studying session types
//
(* ****** ****** *)
//
abstype send (a:vt@ype)
abstype recv (a:vt@ype)
//
(* ****** ****** *)

abstype
chseq (a:type, b:type)

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

stadef nil = unit
stadef :: (a:type, b:type) = chseq (a, b)

(* ****** ****** *)
//
absvtype chpos(type)
absvtype chneg(type)
//
(* ****** ****** *)
//
extern
fun{a:vt0p}
chpos_send{ss:type}
  (ch: !chpos(send(a) :: ss) >> chpos(ss), x: a): void
extern
fun{a:vt0p}
chpos_recv{ss:type}
  (ch: !chpos(recv(a) :: ss) >> chpos(ss), x: &a? >> _): void
extern
fun{a:vt0p}
chpos_recv_val{ss:type}(ch: !chpos(recv(a) :: ss) >> chpos(ss)): a
//
(* ****** ****** *)
//
extern
fun{a:vt0p}
chneg_recv{ss:type}
  (ch: !chneg(recv(a) :: ss) >> chneg(ss), x: a): void
extern
fun{a:vt0p}
chneg_send{ss:type}
  (ch: !chneg(send(a) :: ss) >> chneg(ss), x: &a? >> _): void
extern
fun{a:vt0p}
chneg_send_val{ss:type}(ch: !chneg(send(a) :: ss) >> chneg(ss)): a
//
(* ****** ****** *)

extern
fun chpos_recv_close (ch: chpos(nil)): void
extern
fun chneg_send_close (ch: chneg(nil)): void

(* ****** ****** *)
//
extern
fun
chpos_chneg_connect{ss:type} (ch1: chpos(ss), ch2: chneg(ss)): void
//
(* ****** ****** *)
//
datatype
sslist (a:t@ype) =
| sslist_nil of (nil)
| sslist_cons of (send(a) :: sslist(a))
//
(*
datavtype
chpos_sslist (a:t@ype) =
| chpos_sslist_nil of ()
| chpos_sslist_cons of (chpos(send(a) :: sslist(a)))
*)
//
datavtype
chneg_sslist (a:t@ype) =
| chneg_sslist_nil of ()
| chneg_sslist_cons of (chneg(send(a) :: sslist(a)))
//
(* ****** ****** *)
//
(*
extern
fun
chpos_sslist
  {a:t0p}(chpos(sslist(a))): chpos_sslist(a)
extern
fun
chneg_sslist_nil{a:t0p}(chneg(sslist(a))): void
and
chneg_sslist_cons
  {a:t0p}(chneg(sslist(a))): chneg(send(a) :: sslist(a))
*)
//
(* ****** ****** *)
//
extern
fun
chneg_sslist
  {a:t0p}(chneg(sslist(a))): chneg_sslist(a)
extern
fun
chpos_sslist_nil{a:t0p}(chpos(sslist(a))): void
and
chpos_sslist_cons
  {a:t0p}(chpos(sslist(a))): chpos(send(a) :: sslist(a))
//
(* ****** ****** *)

staload
UN = "prelude/SATS/unsafe.sats"

(* ****** ****** *)
//
abst@ype bit = natLt(2)
//
macdef B0 = $UN.cast{bit}(0)
macdef B1 = $UN.cast{bit}(1)
//
(* ****** ****** *)
//
extern
fun
chneg_create{ss:type}
  (f: chpos(ss) -<lincloptr1> void): chneg(ss)
//
(* ****** ****** *)

extern
fun int2bits{n:nat} (int(n)): chneg(sslist(bit))

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

implement
int2bits (n) = let
//
fun
fserv{n:nat}
(
  n: int(n), ch: chpos(sslist(bit))
) : void = (
//
if
n > 0
then let
  val n2 = half(n)
  val bit = (if n = 2*n2 then 0 else 1): natLt(2)
  val bit = $UN.cast{bit}(bit)
  val ch = chpos_sslist_cons (ch)
  val ((*void*)) = chpos_send (ch, bit)
in
  fserv (n2, ch)
end // end of [then]
else chpos_sslist_nil (ch)
//
) (* end of [fserv] *)
//
in
  chneg_create{sslist(bit)}(llam (ch) => fserv (n, ch))
end // end of [int2bits]

(* ****** ****** *)
//
extern
fun succ_bits (chneg(sslist(bit))): chneg(sslist(bit))
extern
fun add_bits_bits (chneg(sslist(bit)), chneg(sslist(bit))): chneg(sslist(bit))
//
(* ****** ****** *)

implement
succ_bits (ch1) = let
//
fun
fserv
(
  ch: chpos(sslist(bit))
, ch1: chneg(sslist(bit))
) : void = let
//
val opt = chneg_sslist (ch1)
//
in
//
case+ opt of
| ~chneg_sslist_nil () => let
    val ch = chpos_sslist_cons (ch)
    val ((*void*)) = chpos_send (ch, B1)
    val ((*void*)) = chpos_sslist_nil (ch)
  in
    // nothing
  end // end of [chneg_sslist_nil]
| ~chneg_sslist_cons (ch1) => let
    val ch = chpos_sslist_cons (ch)
    val bit = chneg_send_val (ch1)
    val bit = $UN.cast{natLt(0)}(bit)
  in
    if bit = 0
      then let
        val ((*void*)) = chpos_send (ch, B1)
      in
        chpos_chneg_connect (ch, ch1)
      end // end of [then]
      else let
        val ((*void*)) = chpos_send (ch, B0)
      in
        fserv (ch, ch1)
      end // end of [else]
  end // end of [chneg_sslist_cons]
//
end // end of [fserv]
//
in
  chneg_create{sslist(bit)}(llam (ch) => fserv (ch, ch1))
end // end of [succ_bits]

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

implement
add_bits_bits
  (ch1, ch2) = let
//
fun
fserv
(
  ch: chpos(sslist(bit))
, ch1: chneg(sslist(bit))
, ch2: chneg(sslist(bit))
) : void = let
//
val opt1 = chneg_sslist (ch1)
//
in
//
case+ opt1 of
| ~chneg_sslist_nil () =>
    chpos_chneg_connect (ch, ch2)
| ~chneg_sslist_cons (ch1) => let
    val opt2 = chneg_sslist (ch2)
  in
    case+ opt2 of
    | ~chneg_sslist_nil () => let
        val ch = chpos_sslist_cons (ch)
      in
        chpos_chneg_connect (ch, ch1)
      end // end of [chneg_sslist_nil]
    | ~chneg_sslist_cons (ch2) => let
        val b1 = chneg_send_val (ch1)
        and b2 = chneg_send_val (ch2)
        val b1_ = $UN.cast{natLt(2)}(b1)
        and b2_ = $UN.cast{natLt(2)}(b2)
        val ch = chpos_sslist_cons (ch)
      in
        case+ b1_ of
        | 0 => (chpos_send (ch, b2); fserv (ch, ch1, ch2))
        | 1 => (
          case+ b2_ of
          | 0 => (chpos_send (ch, B1); fserv (ch, ch1, ch2))
          | 1 => (chpos_send (ch, B0); fserv (ch, ch1, succ_bits(ch2)))
          ) (* end of [1] *)
      end // end of [chneg_sslist_cons]
  end // end of [chneg_sslist_cons]
//
end // end of [fserv]
//
in
  chneg_create{sslist(bit)}(llam (ch) => fserv (ch, ch1, ch2))
end // end of [add_bits_bits]

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

(* end of [scratch08.dats] *)

error: pathspec 'projects/MEDIUM/ATS-parse-emit/Erlang/SCRATCH/scratch08.dats' did not match any file(s) known to git


Merging

Merging

(*
** libatscc-common
*)

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

(*
staload "./../basics.sats"
*)

(* ****** ****** *)
//
abstype
funset_t0ype_type(a:t@ype+)
//
typedef
funset(a:t0p) = funset_t0ype_type(a)
//
(* ****** ****** *)
//
fun
funset_make_nil
  {a:t0p}((*void*)): funset(a) = "mac#%"
//
(* ****** ****** *)
//
fun
funset_is_nil
  {a:t0p}(A: funset(INV(a))): bool = "mac#%"
fun
funset_is_cons
  {a:t0p}(A: funset(INV(a))): bool = "mac#%"
//
(* ****** ****** *)
//
fun
funset_size
  {a:t0p}(A: funset(INV(a))): intGte(0) = "mac#%"
//
(* ****** ****** *)
//
fun{a:t0p}
funset_insert
  (A: funset(INV(a)), x0: a): bool = "mac#%"
fun{a:t0p}
funset_remove
  (A: funset(INV(a)), x0: a): bool = "mac#%"
//
(* ****** ****** *)

fun{a:t0p}
funset_listize
  {a:t0p}(xs: funset(INV(a))):<!wrt> List0 (a)

(* ****** ****** *)
//
fun
funset_fold
  {a:t0p}{res:vt0p}
(
  xs: funset(INV(a))
, fopr: (a, res) -<cloref1> res, sink: res
) : res // end of [funset_fold]
//
(* ****** ****** *)
//
fun
funset_foreach
  {a:t0p}
(
  xs: funset(INV(a)), fwork: (a) -<cloref1> void
) : void // end of [funset_foreach]
//
(* ****** ****** *)

(* end of [funset_avl.sats] *)

error: pathspec 'contrib/libatscc/SATS/funset_avl.sats' did not match any file(s) known to git


Updating: very minorly ...

Updating: very minorly ...

(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: gmhwxiATgmailDOTcom
// Start time: February, 2016
//
(* ****** ****** *)
//
// Following a Promela-example in
// (Spin Model Checker Primer Reference)
//
(* ****** ****** *)

(*
proctype
Agent(chan listen; chan talk)
{
    do
    :: talk!hold(listen)
    :: talk!deny(listen) -> break
    :: talk!grant(listen) ->
        wait:
        listen?return0; break
    od;
    server!return0(listen)
}
*)

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

abstype ssnil()
abstype sscons(x:vt@ype, xs:type)

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

stadef :: = sscons

(* ****** ****** *)
//
absvtype channel()
//
absvtype chanpos(ss:type)
absvtype channeg(ss:type)
//
(* ****** ****** *)

extern
fun
chanpos_recv
{x:vt@ype}{xs:type}
(
  chan: !chanpos(x::xs) >> channeg(xs)
) : x // end of [channel_recv]

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

extern
fun
channel_send
{x:vt@ype}{xs:type}
(
  chan: !chanpos(x::xs) >> chanpos(xs), x: (x)
) : void // end of [channel_send]

(* ****** ****** *)
////
datatype
ClientOpt =
  | DENY of ()
  | DENY of (chanpos(ssnil))
  | HOLD of (chanpos(ss_hold))
  | GRANT of (chanpos(ss_grand))
//
datatype
ClientReply = RETURN0 of ()
//
datatype
ServerOpt =
  | RETURN0 of (channel)
  | REQUEST0 of (channel)
//
(* ****** ****** *)

(* end of [ClientServer-2.dats] *)

error: pathspec 'projects/MEDIUM/M-Check/SCRATCH/ClientServer-2.dats' did not match any file(s) known to git


Updating: very very minorly

Updating: very very minorly

(*
For testing GraphSearh_bfs
*)

(* ****** ****** *)
//
#define
ATS_STATIC_PREFIX "_QueenPuzzle_bfs_"
//
(* ****** ****** *)
//
#include "./../../../staloadall.hats"
//
#staload "./../../../SATS/print.sats"
#staload _ = "./../../../DATS/print.dats"
//
(* ****** ****** *)
//
#staload
"./../../../DATS/BUCS320/GraphSearch/GraphSearch_bfs.dats"
//
(* ****** ****** *)

#staload
UN = "prelude/SATS/unsafe.sats"

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

implement node_mark<>(nx) = ()
implement node_unmark<>(nx) = ()
implement node_is_marked<>(nx) = false

(* ****** ****** *)
//
datatype expr =
 | EXPRval of double
 | EXPRadd of (expr, expr)
 | EXPRsub of (expr, expr)
 | EXPRmul of (expr, expr)
 | EXPRdiv of (expr, expr)
//
typedef exprlst = list0(expr)
//
(* ****** ****** *)
//
extern
fun
print_expr : expr -> void
and
print_expr : print_type(expr)
//
overload print with print_expr
//
implement
print_expr(x0) =
(
case+ x0 of
  | EXPRval(v) => print(double2int(v))
  | EXPRadd(e1, e2) => print!("(", e1, "+", e2, ")")
  | EXPRsub(e1, e2) => print!("(", e1, "-", e2, ")")
  | EXPRmul(e1, e2) => print!("(", e1, "*", e2, ")")
  | EXPRdiv(e1, e2) => print!("(", e1, "/", e2, ")")
)
//
(* ****** ****** *)

implement print_val<expr> = print_expr

(* ****** ****** *)
//
#define EPSILON 1E-6
//
extern
fun
eval_expr(expr): double
overload ! with eval_expr
//
implement
eval_expr(e0) =
(
case+ e0 of
| EXPRval(v) => v
| EXPRadd(e1, e2) => !e1 + !e2
| EXPRsub(e1, e2) => !e1 - !e2
| EXPRmul(e1, e2) => !e1 * !e2
| EXPRdiv(e1, e2) => !e1 / !e2
) (* end of [eval_expr] *)
//
(* ****** ****** *)
//
extern
fun
expr_is_0 : expr -> bool
extern
fun
expr_is_24 : expr -> bool
//
overload iseqz with expr_is_0
//
(* ****** ****** *)
//
implement
expr_is_0(e) =
abs_double(!e - 0) < EPSILON
implement
expr_is_24(e) =
abs_double(!e - 24) < EPSILON
//
(* ****** ****** *)
//
#define
list0_sing(x)
list0_cons(x, list0_nil())
//
extern
fun
arithops(x: expr, y: expr): exprlst
//
implement
arithops(x, y) =
list0_reverse(res) where
{
  val res = nil0()
  val res = cons0(EXPRadd(x, y), res)
  val res = cons0(EXPRsub(x, y), res)
  val res = cons0(EXPRsub(y, x), res)
  val res = cons0(EXPRmul(x, y), res)
  val res = (if iseqz(y) then res else cons0(EXPRdiv(x, y), res)): exprlst
  val res = (if iseqz(x) then res else cons0(EXPRdiv(y, x), res)): exprlst
}

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

assume node = exprlst
assume nodelst = list0(exprlst)

(* ****** ****** *)
//
implement
{}(*tmp*)
theSearchStore_insert_lst(nxs) =
(
nxs
).rforeach()(lam nx => theSearchStore_insert(nx))
//
(* ****** ****** *)

implement
node_get_neighbors<>
  (nx) = aux1(nx, nil0()) where
{
//
fun
aux1
(
xs: exprlst
,
ys: exprlst
) : list0(exprlst) =
(
case+ xs of
| nil0() =>
  list0_nil()
| cons0(x, xs) =>
  aux2(x, xs, ys) + aux1(xs, cons0(x, ys))
)
//
and
aux2
(
x0: expr
,
xs: exprlst
,
ys: exprlst
) : list0(exprlst) =
(
case+ xs of
| nil0() =>
  list0_nil()
| cons0(x, xs) =>
  (arithops(x0, x)).map(TYPE{exprlst})
    (lam x1 => cons0(x1, list0_reverse_append(ys, xs))) + aux2(x0, xs, cons0(x, ys))
) (* end of [aux2] *)
//
} (* end of [node_get_neighbors] *)

(* ****** ****** *)
//
extern
fun
GameOf24Play
(
n1: int, n2: int, n3: int, n4: int
) : void = "mac#" // end-of-function
//
implement
GameOf24Play
(
  n1, n2, n3, n4
) = let
//
#define :: cons0
//
val nx =
(
n1::n2::n3::n4::nil0()
).map(TYPE{expr})(lam x => EXPRval(int2double(x)))
//
val
nsol = ref{int}(0)
//
implement
process_node<>
  (nx) = true where
{
//
(*
val () =
println!("process_node: nx = ", nx)
*)
//
val () =
case+ nx of
| list0_sing(x) =>
  if expr_is_24(x)
    then (nsol[] := nsol[]+1; println!(x))
  // end of [if]
| _(*non-sing*) => ()
}
//
val
store =
qlistref_make_nil{node}()
val () =
qlistref_insert(store, nx)
//
in
//
GraphSearch_bfs(store);
if nsol[] = 0
  then println! ("There is no solution found!")
// end of [if]
//
end (* end of [GameOf24Play] *)
//
(* ****** ****** *)

%{^
//
// file inclusion
//
var fs = require('fs');
eval(fs.readFileSync('./../../../libatscc2js_all.js').toString());
eval(fs.readFileSync('./../../../CATS/PRINT/print_store_cats.js').toString());
//
%} // end of [%{^]

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

%{$
//
GameOf24Play(3, 3, 8, 8);
GameOf24Play(3, 5, 7, 13);
GameOf24Play(4, 4, 10, 10);
GameOf24Play(5, 5, 7, 11);
GameOf24Play(5, 7, 7, 11);
process.stdout.write(ats2jspre_the_print_store_join());
//
%} // end of [%{$]

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

(* end of [GameOf24Play_bfs.dats] *)

error: pathspec 'contrib/libatscc/libatscc2js/TEST/BUCS320/GraphSearch/GameOf24Play_bfs.dats' did not match any file(s) known to git


super basic ATS exercise

super basic ATS exercise

// patscc -o s scratch.dats && ./s

#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"

fun test_in_operator (dataset: (int, int, int), i: int): (int, int, int) = let
  val (x0, x1, x2) = dataset
in
  let val x0 = i in (x0, x1, x2) end
end

implement main0 () = let
  val v = (1, 2, 3)
in
  print(v)
end

error: pathspec 'ats/introduction_to_programming_in_ats/scratch.dats' did not match any file(s) known to git


Updating: very minorly

Updating: very minorly

(* ****** ****** *)
//
// HX-2016-05
// A running example
// from ATS2 to Scheme
//
(* ****** ****** *)
//
#define ATS_DYNLOADFLAG 0
//
(* ****** ****** *)
//
#include
"share/atspre_define.hats"
//
(* ****** ****** *)
//
staload
"{$LIBATSCC2SCM}/basics_scm.sats"
staload
"{$LIBATSCC2SCM}/SATS/integer.sats"
//
(* ****** ****** *)
//
extern
fun acker
  : (int, int) -> int = "mac#acker"
//
implement
acker (m, n) =
(
case+
  (m, n) of
| (0, _) => n + 1
| (_, 0) => acker(m-1, 1)
| (_, _) => acker(m-1, acker(m, n-1))
)
//
(* ****** ****** *)

(* end of [acker.dats] *)

error: pathspec 'projects/MEDIUM/CATS-atsccomp/CATS-atscc2scm/TEST/acker.dats' did not match any file(s) known to git


Updating: reorganizing atscc2py

Updating: reorganizing atscc2py

//
(*
** For writing ATS code that translates into Python
*)
//
(* ****** ****** *)
//
(*
The MIT License (MIT)

Copyright (c) 2014 Hongwei Xi

Permission is hereby granted,  free of charge,  to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use,  copy,  modify, merge, publish, distribute, sublicense,
and/or  sell  copies  of  the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*)
(* ****** ****** *)
//
// HX-2014-08:
// prefix for external names
//
#define
ATS_EXTERN_PREFIX "ats2pypre_"
//
(* ****** ****** *)
//
typedef
cfun1 (a:t0p, b:t0p) = (a) -<cloref1> b
typedef
cfun2 (a1:t0p, a2:t0p, b:t0p) = (a1, a2) -<cloref1> b
//
stadef cfun = cfun1
stadef cfun = cfun2
//
(* ****** ****** *)

abstype PYfile

(* ****** ****** *)
//
// HX-2014-08:
// invariant constructors!
//
abstype PYlist (a:t@ype)
abstype PYset  (a:t@ype)
abstype PYdict (a:t@ype)
//
(* ****** ****** *)
//
fun
print_obj{a:t@ype}(obj: a): void = "mac#%"
fun
println_obj{a:t@ype}(obj: a): void = "mac#%"
//
(* ****** ****** *)

fun print_newline ((*void*)): void = "mac#%"

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

(* end of [basics_py.sats] *)

error: pathspec 'contrib/libatscc2py/basics_py.sats' did not match any file(s) known to git


Updating: initiating libatscc2clj

Updating: initiating libatscc2clj

(*
** For writing ATS code
** that translates into Clojure
*)

(* ****** ****** *)
//
// HX: prefix for external names
//
#define ATS_EXTERN_PREFIX "ats2cljpre_"
//
(* ****** ****** *)
//
// HX: for signed integers
//
(* ****** ****** *)
//
fun
abs_int0 : int -> int = "mac#%"
//
fun
abs_int1 :
  {i:int} (int(i)) -> int(abs(i)) = "mac#%"
//
overload abs with abs_int0 of 100
overload abs with abs_int1 of 100
//
(* ****** ****** *)
//
fun
neg_int0 : int -> int = "mac#%"
//
fun neg_int1
  : {i:int} int(i) -> int(~i) = "mac#%"
//
overload ~ with neg_int0 of 100
overload ~ with neg_int1 of 110
overload neg with neg_int0 of 100
overload neg with neg_int1 of 110
//
(* ****** ****** *)
//
fun succ_int0 : int -> int = "mac#%"
fun pred_int0 : int -> int = "mac#%"
//
fun succ_int1
  : {i:int} int(i) -> int(i+1) = "mac#%"
fun pred_int1
  : {i:int} int(i) -> int(i-1) = "mac#%"
//
overload succ with succ_int0 of 100
overload pred with pred_int0 of 100
//
overload succ with succ_int1 of 110
overload pred with pred_int1 of 110
//
(* ****** ****** *)
//
fun half_int0 : int -> int = "mac#%"
fun half_int1 : {i:int} int(i) -> int(i/2) = "mac#%"
//
overload half with half_int0 of 100
overload half with half_int1 of 110
//
(* ****** ****** *)
//
fun add_int0_int0: (int, int) -> int = "mac#%"
fun sub_int0_int0 : (int, int) -> int = "mac#%"
fun mul_int0_int0 : (int, int) -> int = "mac#%"
fun div_int0_int0 : (int, int) -> int = "mac#%"
fun mod_int0_int0 : (int, int) -> int = "mac#%"
//
fun add_int1_int1
  : {i,j:int} (int(i), int(j)) -> int(i+j) = "mac#%"
fun sub_int1_int1
  : {i,j:int} (int(i), int(j)) -> int(i-j) = "mac#%"
fun mul_int1_int1
  : {i,j:int} (int(i), int(j)) -> int(i*j) = "mac#%"
fun div_int1_int1
  : {i,j:int} (int(i), int(j)) -> int(i/j) = "mac#%"
//
(* ****** ****** *)
//
overload + with add_int0_int0 of 100
overload - with sub_int0_int0 of 100
overload * with mul_int0_int0 of 100
overload / with div_int0_int0 of 100
overload % with mod_int0_int0 of 100
overload mod with mod_int0_int0 of 100
//
overload + with add_int1_int1 of 120
overload - with sub_int1_int1 of 120
overload * with mul_int1_int1 of 120
overload / with div_int1_int1 of 120
//
(* ****** ****** *)
//
fun
asl_int0_int1
  : (int, intGte(0)) -> int = "mac#%"
fun
asr_int0_int1
  : (int, intGte(0)) -> int = "mac#%"
//
(* ****** ****** *)
//
overload << with asl_int0_int1 of 110
overload >> with asr_int0_int1 of 110
//
(* ****** ****** *)
//
fun lt_int0_int0: (int, int) -> bool = "mac#%"
fun lte_int0_int0: (int, int) -> bool = "mac#%"
fun gt_int0_int0: (int, int) -> bool = "mac#%"
fun gte_int0_int0: (int, int) -> bool = "mac#%"
//
fun eq_int0_int0: (int, int) -> bool = "mac#%"
fun neq_int0_int0: (int, int) -> bool = "mac#%"
//
fun compare_int0_int0: (int, int) -> int = "mac#%"
//
fun lt_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i < j) = "mac#%"
fun lte_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i <= j) = "mac#%"
fun gt_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i > j) = "mac#%"
fun gte_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i >= j) = "mac#%"
//
fun eq_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i == j) = "mac#%"
fun neq_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i != j) = "mac#%"
//
(* ****** ****** *)
//
overload < with lt_int0_int0 of 100
overload <= with lte_int0_int0 of 100
overload > with gt_int0_int0 of 100
overload >= with gte_int0_int0 of 100
overload = with eq_int0_int0 of 100
overload != with neq_int0_int0 of 100
overload <> with neq_int0_int0 of 100
//
overload compare with compare_int0_int0 of 100
//
(* ****** ****** *)
//
overload < with lt_int1_int1 of 120
overload <= with lte_int1_int1 of 120
overload > with gt_int1_int1 of 120
overload >= with gte_int1_int1 of 120
overload = with eq_int1_int1 of 120
overload != with neq_int1_int1 of 120
overload <> with neq_int1_int1 of 120
//
(* ****** ****** *)
//
// HX: for unsigned integers
//
(* ****** ****** *)
//
fun add_uint0_uint0: (uint, uint) -> uint = "mac#%"
fun sub_uint0_uint0 : (uint, uint) -> uint = "mac#%"
fun mul_uint0_uint0 : (uint, uint) -> uint = "mac#%"
fun div_uint0_uint0 : (uint, uint) -> uint = "mac#%"
fun mod_uint0_uint0 : (uint, uint) -> uint = "mac#%"
//
(* ****** ****** *)
//
overload + with add_uint0_uint0 of 100
overload - with sub_uint0_uint0 of 100
overload * with mul_uint0_uint0 of 100
overload / with div_uint0_uint0 of 100
overload % with mod_uint0_uint0 of 100
overload mod with mod_uint0_uint0 of 100
//
(* ****** ****** *)
//
fun lt_uint0_uint0: (uint, uint) -> bool = "mac#%"
fun lte_uint0_uint0: (uint, uint) -> bool = "mac#%"
fun gt_uint0_uint0: (uint, uint) -> bool = "mac#%"
fun gte_uint0_uint0: (uint, uint) -> bool = "mac#%"
//
fun eq_uint0_uint0: (uint, uint) -> bool = "mac#%"
fun neq_uint0_uint0: (uint, uint) -> bool = "mac#%"
//
fun compare_uint0_uint0: (uint, uint) -> int = "mac#%"
//
(* ****** ****** *)
//
overload < with lt_uint0_uint0 of 100
overload <= with lte_uint0_uint0 of 100
overload > with gt_uint0_uint0 of 100
overload >= with gte_uint0_uint0 of 100
overload = with eq_uint0_uint0 of 100
overload != with neq_uint0_uint0 of 100
overload <> with neq_uint0_uint0 of 100
//
overload compare with compare_uint0_uint0 of 100
//
(* ****** ****** *)

(* end of [integer.sats] *)

error: pathspec 'contrib/libatscc/libatscc2clj/SATS/integer.sats' did not match any file(s) known to git


Updating: very minorly improving

Updating: very minorly improving

(*
** For writing ATS code
** that translates into JavaScript
*)

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

(*
** Permission to use, copy, modify, and distribute this software for any
** purpose with or without fee is hereby granted, provided that the above
** copyright notice and this permission notice appear in all copies.
**
** THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
** WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
** ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

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

(*
** Author: Hongwei Xi
** Authoremail: gmhwxi AT gmail DOT com
** Start Time: October, 2015
*)

(* ****** ****** *)
//
#define
ATS_DYNLOADFLAG 0 // no staloading at run-time
//
#define
ATS_EXTERN_PREFIX "ats2js_bacon_ext_" // prefix for extern names
#define
ATS_STATIC_PREFIX "_ats2js_bacon_ext_" // prefix for static names
//
(* ****** ****** *)
//
staload
UN = "prelude/SATS/unsafe.sats"
//
(* ****** ****** *)
//
#include "./../../staloadall.hats"
//
(* ****** ****** *)
//
staload "./../../SATS/Bacon.js/baconjs.sats"
staload "./../../SATS/Bacon.js/baconjs_ext.sats"
//
(* ****** ****** *)
//
(*
fun
EStream_zip_stream_cfun
  {a,b:t0p}{c:t0p}
(
  xs: EStream(a)
, ys: stream(b), y0: b, fopr: cfun(a, b, c)
) : EStream(c) = "mac#%" // end-of-function
*)
//
implement
EStream_zip_stream_cfun
  {a,b}{c}
  (xs, ys, y0, fopr) = let
//
val fys =
  stream2cloref_last(ys, y0)
//
in
  EStream_map(xs, lam(x) =<cloref1> fopr(x, fys()))
end // end of [EStream_zip_stream_cfun]
//
(* ****** ****** *)

(* end of [baconjs_ext.dats] *)

error: pathspec 'contrib/libatscc/libatscc2js/DATS/Bacon.js/baconjs_ext.dats' did not match any file(s) known to git


Updating: atsccomp: supporting stream_vt

(*
// Linear Lazy-evaluation:
// Erathosthene's sieve for primes
*)
(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: hwxiATcsDOTbuDOTedu)
// Start Time: February, 2008
//
(* ****** ****** *)

(*
** Ported to ATS2 by HX-2013-09
*)

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

#define
ATS_MAINATSFLAG 1
#define
ATS_DYNLOADNAME "sieve_llazy_main"

(* ****** ****** *)
//
#include
"share/atspre_define.hats"
//
(* ****** ****** *)
//
#include
"{$LIBATSCC2JS}/staloadall.hats"
//
(* ****** ****** *)
//
staload
"{$LIBATSCC2JS}/SATS/print.sats"
//
(* ****** ****** *)

#define nil stream_vt_nil
#define cons stream_vt_cons

(* ****** ****** *)
//
fun
stream_vt_nth
  {a:t0p}
(
  xs0: stream_vt a, i: intGte(0)
) : a = let
//
val-~cons(x, xs) = !xs0
//
in
  if i = 0
    then (~xs; x) else stream_vt_nth(xs, i-1)
  // end of [if]
end // end of [stream_vt_nth]
//
(* ****** ****** *)

fun
from_con{n:int} (n: int n)
  :<!laz> stream_vt_con (intGte n) =
  stream_vt_cons{intGte(n)}(n, from (n+1))
and from{n:int} (n: int n)
  :<!laz> stream_vt (intGte n) = $ldelay (from_con n)

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

typedef N2 = intGte(2)

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

fun
sieve_con
  (ns: stream_vt N2)
  : stream_vt_con (N2) = let
  val-
  ~cons(n, ns2) = !ns; val p = n
  val ps = sieve
  (
    stream_vt_filter_cloref
      (ns2, lam x => nmod_int1_int1(x, p) > 0)
    // stream_vt_filter_cloref
  ) (* end of [val] *)
in
  cons(p, ps)
end // end of [sieve_con]

and
sieve
(
  ns: stream_vt N2
) : stream_vt (N2) = $ldelay (sieve_con ns, ~ns)
// end of [sieve]

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

fn primes (): stream_vt N2 = sieve (from 2)
fn prime_get (n: Nat): Nat = stream_vt_nth{N2}(primes(), n)

(* ****** ****** *)
//
val () =
{
//
val () =
println! ("prime(1000) = ", prime_get (1000)) ; // = 7927
//
} (* end of [val] *)

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

%{^
//
// file inclusion
//
var fs = require('fs');
//
eval(fs.readFileSync('./libatscc2js/CATS/basics_cats.js').toString());
eval(fs.readFileSync('./libatscc2js/CATS/integer_cats.js').toString());
eval(fs.readFileSync('./libatscc2js/CATS/string_cats.js').toString());
//
eval(fs.readFileSync('./libatscc2js/CATS/Node.js/basics_cats.js').toString());
eval(fs.readFileSync('./libatscc2js/CATS/Node.js/fprint_cats.js').toString());
//
eval(fs.readFileSync('./libatscc2js/DATS/stream_vt_dats.js').toString());
//
%} // end of [%{^]

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

%{$
//
sieve_llazy_main(/*void*/);
//
%} // end of [%{$]

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

(* end of [sieve_llazy.dats] *)

error: pathspec 'projects/MEDIUM/CATS-atsccomp/CATS-atscc2js/TEST/sieve_llazy.dats' did not match any file(s) known to git


Updating: very very minorly

Updating: very very minorly

(*
** For writing ATS code
** that translates into Javascript
*)

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

#define ATS_DYNLOADFLAG 0

(* ****** ****** *)
//
// HX-2014-08:
// prefix for external names
//
#define
ATS_EXTERN_PREFIX "ats2pypre_"
#define
ATS_STATIC_PREFIX "_ats2pypre_basics_"
//
(* ****** ****** *)
//
#include
"share/atspre_define.hats"
//
(* ****** ****** *)
//
staload "./../basics_py.sats"
//
(* ****** ****** *)
//
staload "./../SATS/integer.sats"
//
staload "./../SATS/bool.sats"
staload "./../SATS/float.sats"
staload "./../SATS/string.sats"
//
(* ****** ****** *)
//
#include "{$LIBATSCC}/DATS/basics.dats"
//
(* ****** ****** *)
//
implement
gcompare_val_val<int>
  (x, y) =
  $effmask_all(compare_int0_int0(x, y))
//
(* ****** ****** *)
//
implement
gcompare_val_val<bool>
  (x, y) =
(
//
if (x)
  then (if y then 0(*t/t*) else 1(*t/f*))
  else (if y then ~1(*f/t*) else 0(*f/f*))
//
) (* gcompare_val_val<bool> *)
//
(* ****** ****** *)
//
implement
gcompare_val_val<double>
  (x, y) =
  $effmask_all(compare_double_double(x, y))
//
implement
gcompare_val_val<string>
  (x, y) =
  $effmask_all(compare_string_string(x, y))
//
(* ****** ****** *)

(* end of [basics.dats] *)

error: pathspec 'contrib/libatscc/libatscc2py3/DATS/basics.dats' did not match any file(s) known to git


Updating: very minorly improving

Updating: very minorly improving

(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: gmhwxiATgmailDOTcom
// Start time: December, 2015
//
(* ****** ****** *)

(*
//
// the shared variables, booleans
bool turn, flag[2];
byte ncrit; // number of procs in critical section
//
*)

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

(*
//
// two processes
//
active[2]
proctype user()
{
  assert(_pid == 0 || _pid == 1);
  again:
  flag[_pid] = 1; turn = _pid;
  (flag[1 - _pid] == 0 || turn == 1 - _pid);
//
  ncrit++;
  assert(ncrit == 1); // critical section
  ncrit--;
//
  flag[_pid] = 0; goto again
}
*)

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

staload "./Promela.sats"

(* ****** ****** *)
//
sortdef two = {a:nat | a < 2}
//
extern
fun
proctype$user{i:nat}(pid(i)): void
//
extern
fun
flag_get{i:two}(pid(i), int(1-i)): bool
and
flag_set{i:two}(pid(i), int( i ), bool): void
//
(* ****** ****** *)
//
extern
fun
turn_get{i:two}(pid(i)): [j:two] int(j)
//
extern
fun turn_set{i,j:two}(pid(i), int(j)): void
//
(* ****** ****** *)

implement
proctype$user(pid) = let
//
val i = pid2int(pid)
//
val ((*void*)) =
  Promela$assert((i=0)+(i=1))
//
fun
loop
(
// argless
) : void = loop() where
{
  val i0 = i
  val i1 = 1 - i
  val () = turn_set(pid, i1)
  val () = flag_set(pid, i0, true)
  val () = if ~flag_get(pid, i1) then turn_set(pid, i0)
  val () = Promela$wait_until(lam() => (turn_get(pid)=i0))
//
// This is a critial section
//
  val () = turn_set(pid, i1)
  val () = flag_set(pid, i0, false)
}
//
in
  loop()
end // end of [proctype$user]

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

(* end of [Peterson-2.dats] *)

error: pathspec 'projects/MEDIUM/M-Check/SCRATCH/Peterson-2.dats' did not match any file(s) known to git


Updating: getting JSmydraw/DiningPhil to work

(* ****** ****** *)
//
// HX-2015-03-20:
//
// Animating a variant of
// the Dining Philosophers problem
//
(* ****** ****** *)
//
#include
"share/atspre_define.hats"
//
(* ****** ****** *)

#define ATS_MAINATSFLAG 1
#define ATS_DYNLOADNAME "my_dynload"

(* ****** ****** *)
//
staload
UN = "prelude/SATS/unsafe.sats"
//
(* ****** ****** *)
//
#include
"{$LIBATSCC2JS}/staloadall.hats"
//
staload
"{$LIBATSCC2JS}/SATS/HTML/canvas-2d/canvas2d.sats"
//
(* ****** ****** *)
//
#define NPHIL 5
typedef nphil = natLt(NPHIL)
//
(* ****** ****** *)
//
extern
fun theCtx2d_get(): canvas2d = "mac#"
//
(* ****** ****** *)
//
extern
fun
cloref_app
(
  fwork: () -<cloref1> void
) : void = "mac#" // endfun
//
implement cloref_app(fwork) = fwork()
//
extern
fun
setTimeout_cloref
(
  fwork: () -<cloref1> void, ntime: double
) : void = "mac#" // end-of-function
//
(* ****** ****** *)
//
fun
rand_int2
(
  x0: int, len: intGte(0)
) : double =
(
  x0 + len * JSmath_random()
)
//
(* ****** ****** *)

extern
fun
phil_draw(id: nphil): void = "mac#"

(* ****** ****** *)
//
extern
fun
phil_pick_lfork(id: nphil): int = "mac#"
and
phil_pick_rfork(id: nphil): int = "mac#"
//
extern
fun
phil_return_lfork(id: nphil): void = "mac#"
and
phil_return_rfork(id: nphil): void = "mac#"
//
(* ****** ****** *)
//
extern
fun
phil_loop (id: nphil): void = "mac#"
//
extern
fun phil_think_beg (id: nphil): void
and phil_think_end (id: nphil): void
//
extern
fun phil_dine_start (id: nphil): void
and phil_dine_lfork (id: nphil): void
and phil_dine_rfork (id: nphil): void
and phil_dine_finish (id: nphil): void
//
(* ****** ****** *)
//
implement
phil_loop(id) =
  (phil_draw(id); phil_think_beg (id))
//
(* ****** ****** *)
//
implement
phil_think_beg
  (id) = let
//
val ntime = rand_int2(500, 2500)
//
in
//
setTimeout_cloref(lam() => phil_think_end(id), ntime)
//
end // end of [phil_think_beg]
//
implement phil_think_end(id) = phil_dine_start(id)
//
(* ****** ****** *)
//
implement
phil_dine_start
  (id) = phil_dine_lfork(id)
//
implement
phil_dine_lfork
  (id) = let
//
val ntime =
  rand_int2(250, 1000)
//
val lfork = phil_pick_lfork(id)
val ((*void*)) = if lfork > 0 then phil_draw(id)
//
in
//
if
lfork = 0
then setTimeout_cloref(lam() => phil_dine_lfork(id), ntime)
else setTimeout_cloref(lam() => phil_dine_rfork(id), ntime)
//
end // end of [phil_dine_lfork]
//
implement
phil_dine_rfork(id) = let
//
val ntime =
  rand_int2(250, 1000)
//
val rfork = phil_pick_rfork(id)
val ((*void*)) = if rfork > 0 then phil_draw(id)
//
in
//
if
rfork = 0
then setTimeout_cloref(lam() => phil_dine_rfork(id), ntime)
else setTimeout_cloref(lam() => phil_dine_finish(id), ntime)
//
end // end of [phil_dine_rfork]

implement
phil_dine_finish(id) =
(
  phil_return_lfork(id); phil_return_rfork(id); phil_loop(id)
)
//
(* ****** ****** *)

%{$
//
var
mycanvas =
document.getElementById
  ("Patsoptaas-Evaluate-canvas");
//
var
myctx2d0 = mycanvas.getContext( '2d' );
//
var theFks = [1, 1, 1, 1, 1]
//
var Ph0 = { lfork: 0, rfork: 0 }
var Ph1 = { lfork: 0, rfork: 0 }
var Ph2 = { lfork: 0, rfork: 0 }
var Ph3 = { lfork: 0, rfork: 0 }
var Ph4 = { lfork: 0, rfork: 0 }
var thePhs = [Ph0, Ph1, Ph2, Ph3, Ph4]
//
function
phil_pick_lfork
  (id0)
{
//
var
lf0 =
theFks[id0];
if(lf0 > 0)
{
  theFks[id0] = 0;
  thePhs[id0].lfork = 1;
}
return (lf0);
//
} // phil_pick_lfork
//
function
phil_pick_rfork
  (id0)
{
//
var id1 = (id0+1)%5;
var rf1 = theFks[id1];
if(rf1 > 0)
{
  theFks[id1] = 0;
  thePhs[id0].rfork = 1;
}
return (rf1);
//
} // phil_pick_rfork
//
function
phil_return_lfork
  (id0)
{
  var ph = thePhs[id0];
  ph.lfork = 0; theFks[id0] = 1; return;
}
function
phil_return_rfork
  (id0)
{
  var ph = thePhs[id0];
  var id1 = (id0+1)%5
  ph.rfork = 0; theFks[id1] = 1; return;
}
//
function
theCx_get() { return mycanvas.width/2; }
function
theCy_get() { return mycanvas.height/2; }
function
theRadius1_get() { return Math.min(mycanvas.width, mycanvas.height)/2; }
function
theRadius2_get() { return theRadius1_get() / 5; }
//
function
phil_Cx(id)
{
  var r1 = theRadius1_get();
  var r2 = theRadius2_get();
  var theta = Math.PI/2 - id*(2*Math.PI/5);
  return theCx_get() + (r1-r2) * Math.cos(theta);
}
function
phil_Cy(id)
{
  var r1 = theRadius1_get();
  var r2 = theRadius2_get();
  var theta = Math.PI/2 - id*(2*Math.PI/5);
  return theCy_get() - (r1-r2) * Math.sin(theta);
}
//
function
phil_draw(id)
{
  var ph = thePhs[id];
  var Cx = phil_Cx(id);
  var r2 = theRadius2_get();
  var Cy = phil_Cy(id) + 2*r2/5;
  var fg_color = "#000000"; // black
  var bg_color = "#ffffff"; // white
//
  var PI = Math.PI
//
  myctx2d0.beginPath();
  myctx2d0.arc(Cx, Cy, r2, 0, 2*PI, true);
  myctx2d0.closePath();
  myctx2d0.fillStyle = bg_color; myctx2d0.fill();
//
  if (ph.lfork > 0)
  {
    myctx2d0.beginPath();
    myctx2d0.arc(Cx, Cy, r2, 1*PI/2, 3*PI/2, true);
    myctx2d0.closePath();
    myctx2d0.fillStyle = fg_color; myctx2d0.fill();
  }
  if (ph.rfork > 0)
  {
    myctx2d0.beginPath();
    myctx2d0.arc(Cx, Cy, r2, 3*PI/2, 1*PI/2, true);
    myctx2d0.closePath();
    myctx2d0.fillStyle = fg_color; myctx2d0.fill();
  }
//
  return;
}
//
function
DininingPhil_initize()
{
  phil_loop(0);
  phil_loop(1);
  phil_loop(2);
  phil_loop(3);
  phil_loop(4); return;
}
/*
function
DininingPhil_initize() { alert("DininingPhil_initize"); }
*/
//
function
setTimeout_cloref(fwork, ntime)
{
  setTimeout(function(){cloref_app(fwork);return;}, ntime); return;
}
//
jQuery(document).ready(function(){DininingPhil_initize();});
//
%} // end of [%{$]

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

(* end of [DiningPhil.php] *)

error: pathspec 'projects/SMALL/JSmydraw/DiningPhil/DiningPhil.dats' did not match any file(s) known to git


Updating: adding queueref_list2

Updating: adding queueref_list2

(* ****** ****** *)
(*
//
// for teaching purpose
//
*)
(* ****** ****** *)
//
staload
"./../../basics.sats"
//
staload "./../ML/list0.sats"
//
(* ****** ****** *)
//
datatype
queueref(a:t@ype) =
QUEUEREF of
  (ref(list0(a)), ref(list0(a)))
//
(* ****** ****** *)

extern
fun
{a:t@ype}
queueref_make_nil(): queueref(a)

(* ****** ****** *)
//
extern
fun
{a:t@ype}
queueref_enqueue
  (que: queueref(a), x0: a): void
//
extern
fun
{a:t@ype}
queueref_enqueue_list
  (que: queueref(a), xs: list0(a)): void
//
(* ****** ****** *)

extern
fun
{a:t@ype}
queueref_dequeue_opt(que: queueref(a)): Option(a)

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

implement
{a}
queueref_make_nil
  () = let
//
val left = ref<list0(a)>(list0_nil)
val right = ref<list0(a)>(list0_nil)
//
in
  QUEUEREF(left, right)
end // end of [queueref_make_nil]

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

implement
{a}(*tmp*)
queueref_enqueue
  (que, x0) = let
//
val QUEUEREF(left, right) = que
//
in
  !left := list0_cons(x0, !left)
end // end of [queueref_enqueue]

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

implement
{a}(*tmp*)
queueref_enqueue_list
  (que, xs) = let
//
val QUEUEREF(left, right) = que
//
in
  !left := list0_reverse_append(xs, !left)
end // end of [queueref_enqueue_list]

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

implement
{a}(*tmp*)
queueref_dequeue_opt
  (que) = let
//
val QUEUEREF(left, right) = que
//
in
//
case+ !right of
| list0_nil() => let
    val ys = !left
    val () = !left := list0_nil()
    val ys = list0_reverse(ys)
  in
    case+ ys of
    | list0_nil() => None()
    | list0_cons
        (y, ys) => (!right := ys; Some(y))
      // list0_cons
  end // end of [list0_nil]
| list0_cons(y, ys) => (!right := ys; Some(y))
//
end // end of [queueref_dequeue_opt]

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

(* end of [queueref.dats] *)

error: pathspec 'contrib/libatscc/DATS/TEACHING/queueref_list2.dats' did not match any file(s) known to git


Updating: experimenting with multi-party sessions

(* ****** ****** *)
//
// HX-2015-07-11:
// let the multi-party start!
//
(* ****** ****** *)

(*
Bob -> Alice: <String> ::
Bob -> Alice: {
  Time: Alice -> Bob: <Time> :: end
  Greet: Alice -> Bob: <String> :: end
}
*)

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

datasort party = // abstract

(* ****** ****** *)
//
abstype
trans(party, party, a:vt@ype) // p1->p2
//
abstype
trans_end(p1: party, p2: party) // p1->p2
//
(* ****** ****** *)

abstype Time

(* ****** ****** *)
//
datatype
HelloWorld
(Bob:party, Alice:party) =
| HelloWorld(Bob, Alice) of
    (trans(Bob, Alice, String), HelloWorld2(Bob, Alice))
//
and
HelloWorld2
(Bob:party, Alice:party) =
  | HelloWorld2_Time of (trans(Alice, Bob, Time), trans_end(Alice, Bob))
  | HelloWorld2_Greet of (trans(Alice, Bob, String), trans_end(Alice, Bob))
//
(* ****** ****** *)

(* end of [multi-party.dats] *)

error: pathspec 'projects/MEDIUM/CATS-atsccomp/CATS-atscc2erl/TEST/Sessiontype/TEST/multi-party.dats' did not match any file(s) known to git


Updating initiating funset_avl

Updating initiating funset_avl


Updating: very minorly improving

Updating: very minorly improving

fatal: unable to access 'https://github.com/bbarker/ATS-Postiats-contrib.git/': The requested URL returned error: 403


Updating: adding bouncing-ball2

Updating: adding bouncing-ball2

(*
** Bouncing ball: attemp 2
*)

(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: gmhwxiATgmailDOTedu
//
(* ****** ****** *)
//
#define
ATS_STATIC_PREFIX "bouncing_ball2_anim_"
//
(* ****** ****** *)

#define ATS_MAINATSFLAG 1
#define ATS_DYNLOADNAME "bouncing_ball2_anim_dynload"

(* ****** ****** *)
//
#include
"share/atspre_define.hats"
//
(* ****** ****** *)
//
staload
"libats/SATS/Number/real.sats"
//
(* ****** ****** *)
//
#include
"{$LIBATSCC2JS}/staloadall.hats"
//
staload
"{$LIBATSCC2JS}/DATS/Number/real_double.dats"
//
(* ****** ****** *)

sortdef mode = int
sortdef time = real

typedef mode(mode) = int(mode)

(* ****** ****** *)
//
absprop INF(t:time)
//
extern
praxi
lemma_inf_gte
  {t0,t1:time | t0 >= t1}(INF(t0), real(t1)): INF(t1)
//
(* ****** ****** *)

stacst g : real

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

#define m1 1; #define m2 2

(* ****** ****** *)
//
stacst x
  : (mode, time) -> real
stacst v
  : (mode, time) -> real
//
(* ****** ****** *)

stadef x1(t:time) = x(m1, t)
stadef x2(t:time) = x(m2, t)
stadef v1(t:time) = v(m1, t)
stadef v2(t:time) = v(m2, t)

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

(*
absvtype state(mode, time)
*)
//
datatype
state(m: mode, t:time) =
| STATE(m, t) of
    (mode(m), real(t), real(x(m,t)), real(v(m,t)))
  // end of [STATE]
//
vtypedef state1(t) = state(m1, t)
vtypedef state2(t) = state(m2, t)
//
(* ****** ****** *)
//
stacst
deriv :
(
  time -> real, time(*t*), time(*dt*)
) -> real
//
(* ****** ****** *)
//
extern
praxi
state1_eqn1
  {t,dt:time}
(
  INF(dt) | state1(t)
) : [deriv(x1,t,dt) == v1(t)] void
extern
praxi
state1_eqn2
  {t,dt:time}
  (INF(dt) | state1(t)): [deriv(v1,t,dt) == ~g] void
//
(* ****** ****** *)
//
extern
praxi
state2_eqn2
  {t,dt:time}
(
  INF(dt) | state(m2, t)
) : [deriv(x2,t,dt) == v2(t)] void
extern
praxi
state2_eqn2
  {t,dt:time}
  (INF(dt) | state(m2, t)): [deriv(v2,t,dt) == ~g] void
//
(* ****** ****** *)
//
extern
fun
state_get_t
  {m:mode}{t:time}
  (st: state(m, t)): real(t)
extern
fun
state_get_x
  {m:mode}{t:time}
  (st: state(m, t)): real(x(m, t))
extern
fun
state_get_v
  {m:mode}{t:time}
  (st: state(m, t)): real(v(m, t))
//
overload .t with state_get_t
overload .x with state_get_x
overload .v with state_get_v
//
(* ****** ****** *)
//
implement
state_get_t(STATE(m, t, x, v)) = t
implement
state_get_x(STATE(m, t, x, v)) = x
implement
state_get_v(STATE(m, t, x, v)) = v
//
(* ****** ****** *)
//
(*
extern
fun
jump_x1
{t:time|x1(t)==0}(state1(t)): [x2(t)==0] void
extern
fun
jump_v1
{t:time|x1(t)==0}(state1(t)): [v2(t)==(~v1(t))] void
*)
//
extern
fun
step_x1
  {t,dt:time}
(
  pf: INF(dt) | state1(t), dt: real(dt)
) : real(x1(t+dt))
extern
fun
step_v1
  {t,dt:time}
(
  pf: INF(dt) | state1(t), dt: real(dt)
) : real(v1(t+dt))
//
extern
fun
step_x2
  {t,dt:time}
(
  pf: INF(dt) | state2(t), dt: real(dt)
) : real(x2(t+dt))
extern
fun
step_v2
  {t,dt:time}
(
  pf: INF(dt) | state2(t), dt: real(dt)
) : real(v2(t+dt))
//
(* ****** ****** *)

extern
fun
state1_flow
{ t,dt:time
| x1(t+dt) >= 0
}
(INF(dt)|state1(t), real(dt)): state1(t+dt)
//
extern
fun
state1_jump
{t:time | x1(t) == 0} (state1(t)): state2(t)
//
(* ****** ****** *)
//
implement
state1_flow
  (pf | st, dt) = let
//
val t_dt = st.t() + dt
val x1_dt = step_x1(pf|st,dt)
val v1_dt = step_v1(pf|st,dt)
//
in
  STATE(m1, t_dt, x1_dt, v1_dt)
end // end of [state1_flow]
//
implement
state1_jump
  (st as STATE(m, t, x, v)) =
  STATE(m2, t, $UN.cast(x), $UN.cast(~v))
//
(* ****** ****** *)
//
extern
fun
state2_flow
{ t,dt:time
| v2(t+dt) >= 0
} (INF(dt) | state(m2, t), real(dt)): state(m2, t+dt)
//
extern
fun
state2_jump{t:time| v2(t) == 0}(state2(t)): state1(t)
//
(* ****** ****** *)
//
implement
state2_flow
  (pf | st, dt) = let
//
val t_dt = st.t() + dt
val x2_dt = step_x2(pf|st,dt)
val v2_dt = step_v2(pf|st,dt)
//
in
  STATE(m2, t_dt, x2_dt, v2_dt)
end // end of [state1_flow]
//
implement
state2_jump
  (st as STATE(m, t, x, v)) =
  STATE(m1, t, $UN.cast(x), $UN.cast( v ))
//
(* ****** ****** *)
//
extern
fun
x1_midval
{ r:real
; t,dt:time
| x1(t) >= r ; r >= x1(t+dt)
}
( INF(dt)
| state1(t)
, real(x1(t)), real(r), real(x1(t+dt))
) : [t1:time | t <= t1; t1 <= t+dt; x1(t1)==0] real(t1)
//
(* ****** ****** *)
//
implement
x1_midval
  (pf | st, x1_0, r, x1_1) = $UN.cast(st.t()-(x1_0/st.v()))
//
(* ****** ****** *)
//
extern
fun
v2_midval
{ r:real
; t,dt:time
| v2(t) >= r ; r >= v2(t+dt)
}
( INF(dt)
| state2(t)
, real(v2(t)), real(r), real(v2(t+dt))
) : [t1:time | t <= t1; t1 <= t+dt; v2(t1)==0] real(t)
//
(* ****** ****** *)
//
val g = $UN.cast{real(g)}(9.8)
//
implement
v2_midval
  (pf | st, v2_0, r, v2_1) = $UN.cast(st.t() + (v2_0 / (g)))
//
(* ****** ****** *)

extern
fun
state1_loop
{t,dt:time}
(
  pf: INF(dt) | st: state1(t), dt: real(dt)
) : void // end-of-function
extern
fun
state2_loop
{t,dt:time}
(
  pf: INF(dt) | st: state2(t), dt: real(dt)
) : void // end-of-function

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

val _0_ = int2real(0)

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

implement
state1_loop
  (pf | st, dt) = let
//
  val t_0 = state_get_t(st)
  val x1_0 = state_get_x(st)
  val x1_dx = step_x1(pf | st, dt)
//
in
//
  if x1_dx >= 0
    then let
      val st_1 =
      state1_flow(pf | st, dt)
    in
      state1_loop(pf | st_1, dt)
    end // end of [then]
    else let
        val t_1 =
          x1_midval(pf | st, x1_0, _0_, x1_dx)
        // end of [val]
        val dt_1 = t_1 - t_0
      prval pf_1 = lemma_inf_gte(pf, dt_1)
        val st_1 = state1_flow(pf_1 | st, dt_1)
    in
      state2_loop(pf | state1_jump(st_1), dt)
    end // end of [else]
//
end // end of [state1_loop]

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

implement
state2_loop
  (pf | st, dt) = let
//
  val t_0 = state_get_t(st)
  val v2_0 = state_get_v(st)
  val v2_dv = step_v2(pf | st, dt)
//
in
//
  if v2_dv >= 0
    then let
      val st_1 =
      state2_flow(pf | st, dt)
    in
      state2_loop(pf | st_1, dt)
    end // end of [then]
    else let
        val t_1 =
          v2_midval(pf | st, v2_0, _0_, v2_dv)
        // end of [val]
        val dt_1 = t_1 - t_0
      prval pf_1 = lemma_inf_gte(pf, dt_1)
        val st_1 = state2_flow(pf_1 | st, dt_1)
    in
      state1_loop(pf | state2_jump(st_1), dt)
    end // end of [else]
//
end // end of [state_loop2]

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

(* end of [bouncing_ball2_anim.dats] *)

error: pathspec 'projects/LARGE/DREACH/SCRATCH/bouncing_ball/bouncing_ball2_anim.dats' did not match any file(s) known to git


Wrap Semaphore with SATS

Wrap Semaphore with SATS

%{^
#include "cmsis_os.h"
%}

abst@ype osSemaphoreId = $extype"osSemaphoreId"

abst@ype osSemaphoreDef_t = $extype"osSemaphoreDef_t"
typedef osSemaphoreDef_t_p = cPtr0(osSemaphoreDef_t)

abst@ype osStatus             = $extype"osStatus"
macdef osOK                   = $extval(osStatus, "osOK")
macdef osEventSignal          = $extval(osStatus, "osEventSignal")
macdef osEventMessage         = $extval(osStatus, "osEventMessage")
macdef osEventMail            = $extval(osStatus, "osEventMail")
macdef osEventTimeout         = $extval(osStatus, "osEventTimeout")
macdef osErrorParameter       = $extval(osStatus, "osErrorParameter")
macdef osErrorResource        = $extval(osStatus, "osErrorResource")
macdef osErrorTimeoutResource = $extval(osStatus, "osErrorTimeoutResource")
macdef osErrorISR             = $extval(osStatus, "osErrorISR")
macdef osErrorISRRecursive    = $extval(osStatus, "osErrorISRRecursive")
macdef osErrorPriority        = $extval(osStatus, "osErrorPriority")
macdef osErrorNoMemory        = $extval(osStatus, "osErrorNoMemory")
macdef osErrorValue           = $extval(osStatus, "osErrorValue")
macdef osErrorOS              = $extval(osStatus, "osErrorOS")
macdef os_status_reserved     = $extval(osStatus, "os_status_reserved")

fun osSemaphoreCreate: (osSemaphoreDef_t_p, int32) -> osSemaphoreId = "mac#"
fun osSemaphoreWait: (osSemaphoreId, uint32) -> int32 = "mac#"
fun osSemaphoreRelease: (osSemaphoreId) -> osStatus = "mac#"
fun osSemaphoreDelete: (osSemaphoreId) -> osStatus = "mac#"

error: pathspec 'demos/halapi_ats/libmbedats/SATS/rtos_rtx_cmsis_os.sats' did not match any file(s) known to git


Updating: very minorly improving

Updating: very minorly improving

(*
** For writing ATS code
** that translates into Scheme
*)

(* ****** ****** *)
//
// HX-2014-07
//
(* ****** ****** *)
//
staload "./basics_scm.sats"
//
(* ****** ****** *)
//
staload "./SATS/integer.sats"
//
(* ****** ****** *)
//
staload "./SATS/bool.sats"
staload "./SATS/float.sats"
//
(* ****** ****** *)

(*
staload "./SATS/print.sats"
staload _ = "./DATS/print.dats"
*)

(* ****** ****** *)
//
(*
staload "./SATS/intrange.sats"
staload _ = "./DATS/intrange.dats"
*)
//
(* ****** ****** *)
//
(*
staload "./SATS/list.sats"
staload _ = "./DATS/list.dats"
*)
//
(* ****** ****** *)
//
(*
staload "./SATS/stream.sats"
staload _ = "./DATS/stream.dats"
*)
//
(* ****** ****** *)
//
staload "./SATS/reference.sats"
//
(* ****** ****** *)

(* end of [staloadall.hats] *)

error: pathspec 'contrib/libatscc/libatscc2scm/staloadall.hats' did not match any file(s) known to git


Updating: adding PEULER/P15

Updating: adding PEULER/P15

(*
** Project Euler: P15
** See https://projecteuler.net
*)
(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: gmhwxiATgmailDOTcom
// Start time: January 14, 2015
//
(* ****** ****** *)
//
#include "share/atspre_define.hats"
//
(* ****** ****** *)
//
staload
"{$LIBATSHWXI}/PEULER/SATS/peuler.sats"
//
(* ****** ****** *)
//
dataprop
NPATH (int, int, int) =
  | NPATH00 (0, 0, 1) of ()
  | {m:pos}{r:int}
    NPATHm0 (m, 0, r) of NPATH (m, 0, r)
  | {n:pos}{r:int}
    NPATH0n (0, n, r) of NPATH (0, n, r)
  | {m,n:pos}{r1,r2:int}
    NPATHmn (m, n, r1+r2) of (NPATH (m-1, n, r1), NPATH (m, n-1, r2))
//
(* ****** ****** *)
//
fun
npath{m,n:nat}
  (int(m), int(n)): [r:int] (NPATH(m, n, r) | int(r))
//
(* ****** ****** *)

(* end of [P15.sats] *)

error: pathspec 'projects/MEDIUM/PEULER/P15/P15.sats' did not match any file(s) known to git


Updating: adding M-Check/ClientServer-1

Updating: adding M-Check/ClientServer-1

(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: gmhwxiATgmailDOTcom
// Start time: February, 2016
//
(* ****** ****** *)

(*
proctype
Agent(chan listen; chan talk)
{
    do
    :: talk!hold(listen)
    :: talk!deny(listen) -> break
    :: talk!grant(listen) ->
        wait:
        listen?return0; break
    od;
    server!return0(listen)
}
*)

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

abstype channel

(* ****** ****** *)
//
extern
fun
channel_recv{a:type}(channel): a
extern
fun
channel_send{a:type}(channel, a): void
//
extern
fun
channel_create(cap: intGte(0)): channel
//
(* ****** ****** *)
//
datatype
AgentReply =
| DENY of (channel)
| HOLD of (channel)
| GRANT of (channel)
//
datatype ClientReply = RETURN0 of ()
datatype ClientRequest = REQUEST0 of (channel)
//
(* ****** ****** *)
//
val
theServer = channel_create(0)
//
(* ****** ****** *)
//
extern
fun
Agent
(
  agent: channel, client: channel
) : void // end of [Agent]
//
(* ****** ****** *)

extern val RAND: int

(* ****** ****** *)
//
implement
Agent(agent, client) = (
//
case RAND of
| 0 => let
    val () =
    channel_send(client, HOLD(agent))
  in
    Agent(agent, client)
  end // end of [_]
| 1 =>
    channel_send(client, DENY(agent))
| _ => let
    val () =
    channel_send(client, GRANT(agent))
    val-RETURN0() =
      channel_recv{ClientReply}(agent)
    // end of [val]
  in
    // break
  end // end of [_]
//
) (* end of [Agent] *)
//
(* ****** ****** *)

(*
#define M 2
active [M] proctype Client()
{
    chan me = [0] of { mtype, chan };
    chan agent;
end:
    do
    :: timeout ->
        server!request(me);
        do
        :: me?hold(agent)
        :: me?deny(agent) -> break
        :: me?grant(agent) -> agent!return0; break
        od
    od
}
*)

(* ****** ****** *)
//
extern
fun Client(): void
//
(* ****** ****** *)
//
implement
Client() = let
//
val
client = channel_create(0)
//
fun
loop
(
  client: channel
) : void =
(
//
case+ RAND of
| _ => let
    val () =
    channel_send(theServer, REQUEST0(client))
  in
    loop2(client)
  end // end of [loop]
//
) (* end of [loop] *)
//
and
loop2
(
  client: channel
) : void = let
  val opt = channel_recv{AgentReply}(client)
in
//
case+ opt of
| DENY(agent) => ()
| HOLD(agent) => loop2(client)
| GRANT(agent) => channel_send(agent, RETURN0())
//
end // end of [loop2]
//
in
end // end of [Client]

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

(* end of [ClientServer-1.dats] *)

error: pathspec 'projects/MEDIUM/M-Check/SCRATCH/ClientServer-1.dats' did not match any file(s) known to git


update experiments with tupled boxes

update experiments with tupled boxes

fatal: unable to access 'https://github.com/raventid/coursera_learning.git/': The requested URL returned error: 403


hello world in ATS2, finally here, show your appreciation

// Compile with `patscc -o hw hello.dats`
// Run with `./hw`
// To remove all ATS2 `tmp` files `rm -fv *_[sd]ats.[co]`

// If you forget:

// SPC-c-C and puts `patscc -o hw hello.dats && ./hw` to setup compilation
// SPC-c-r to recompile

//
val _ = print ("Hello, world!\n")
//
// You cannot use `_` variable in your code
// val _ = print (_)
//
implement main0 () = () // a dummy for [main]
//

error: pathspec 'ats/introduction_to_programming_in_ats/hello.dats' did not match any file(s) known to git


Updating: initiating atscc2scm

Updating: initiating atscc2scm

(*
** For writing ATS code
** that translates into Scheme
*)

(* ****** ****** *)
//
// HX: prefix for external names
//
#define ATS_EXTERN_PREFIX "ats2scmpre_"
//
(* ****** ****** *)
//
// HX: for signed integers
//
(* ****** ****** *)
//
fun
abs_int0 : int -> int = "mac#%"
//
fun
abs_int1 :
  {i:int} (int(i)) -> int(abs(i)) = "mac#%"
//
overload abs with abs_int0 of 100
overload abs with abs_int1 of 100
//
(* ****** ****** *)
//
fun
neg_int0 : int -> int = "mac#%"
//
fun neg_int1
  : {i:int} int(i) -> int(~i) = "mac#%"
//
overload ~ with neg_int0 of 100
overload ~ with neg_int1 of 110
overload neg with neg_int0 of 100
overload neg with neg_int1 of 110
//
(* ****** ****** *)
//
fun succ_int0 : int -> int = "mac#%"
fun pred_int0 : int -> int = "mac#%"
//
fun succ_int1
  : {i:int} int(i) -> int(i+1) = "mac#%"
fun pred_int1
  : {i:int} int(i) -> int(i-1) = "mac#%"
//
overload succ with succ_int0 of 100
overload pred with pred_int0 of 100
//
overload succ with succ_int1 of 110
overload pred with pred_int1 of 110
//
(* ****** ****** *)
//
fun half_int0 : int -> int = "mac#%"
fun half_int1 : {i:int} int(i) -> int(i/2) = "mac#%"
//
overload half with half_int0 of 100
overload half with half_int1 of 110
//
(* ****** ****** *)
//
fun add_int0_int0: (int, int) -> int = "mac#%"
fun sub_int0_int0 : (int, int) -> int = "mac#%"
fun mul_int0_int0 : (int, int) -> int = "mac#%"
fun div_int0_int0 : (int, int) -> int = "mac#%"
fun mod_int0_int0 : (int, int) -> int = "mac#%"
//
fun add_int1_int1
  : {i,j:int} (int(i), int(j)) -> int(i+j) = "mac#%"
fun sub_int1_int1
  : {i,j:int} (int(i), int(j)) -> int(i-j) = "mac#%"
fun mul_int1_int1
  : {i,j:int} (int(i), int(j)) -> int(i*j) = "mac#%"
fun div_int1_int1
  : {i,j:int} (int(i), int(j)) -> int(i/j) = "mac#%"
//
(* ****** ****** *)
//
overload + with add_int0_int0 of 100
overload - with sub_int0_int0 of 100
overload * with mul_int0_int0 of 100
overload / with div_int0_int0 of 100
overload % with mod_int0_int0 of 100
overload mod with mod_int0_int0 of 100
//
overload + with add_int1_int1 of 120
overload - with sub_int1_int1 of 120
overload * with mul_int1_int1 of 120
overload / with div_int1_int1 of 120
//
(* ****** ****** *)
//
fun
asl_int0_int1
  : (int, intGte(0)) -> int = "mac#%"
fun
asr_int0_int1
  : (int, intGte(0)) -> int = "mac#%"
//
(* ****** ****** *)
//
overload << with asl_int0_int1 of 110
overload >> with asr_int0_int1 of 110
//
(* ****** ****** *)
//
fun lt_int0_int0: (int, int) -> bool = "mac#%"
fun lte_int0_int0: (int, int) -> bool = "mac#%"
fun gt_int0_int0: (int, int) -> bool = "mac#%"
fun gte_int0_int0: (int, int) -> bool = "mac#%"
//
fun eq_int0_int0: (int, int) -> bool = "mac#%"
fun neq_int0_int0: (int, int) -> bool = "mac#%"
//
fun compare_int0_int0: (int, int) -> int = "mac#%"
//
fun lt_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i < j) = "mac#%"
fun lte_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i <= j) = "mac#%"
fun gt_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i > j) = "mac#%"
fun gte_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i >= j) = "mac#%"
//
fun eq_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i == j) = "mac#%"
fun neq_int1_int1
  : {i,j:int} (int(i), int(j)) -> bool(i != j) = "mac#%"
//
(* ****** ****** *)
//
overload < with lt_int0_int0 of 100
overload <= with lte_int0_int0 of 100
overload > with gt_int0_int0 of 100
overload >= with gte_int0_int0 of 100
overload = with eq_int0_int0 of 100
overload != with neq_int0_int0 of 100
overload <> with neq_int0_int0 of 100
//
overload compare with compare_int0_int0 of 100
//
(* ****** ****** *)
//
overload < with lt_int1_int1 of 120
overload <= with lte_int1_int1 of 120
overload > with gt_int1_int1 of 120
overload >= with gte_int1_int1 of 120
overload = with eq_int1_int1 of 120
overload != with neq_int1_int1 of 120
overload <> with neq_int1_int1 of 120
//
(* ****** ****** *)
//
// HX: for unsigned integers
//
(* ****** ****** *)
//
fun add_uint0_uint0: (uint, uint) -> uint = "mac#%"
fun sub_uint0_uint0 : (uint, uint) -> uint = "mac#%"
fun mul_uint0_uint0 : (uint, uint) -> uint = "mac#%"
fun div_uint0_uint0 : (uint, uint) -> uint = "mac#%"
fun mod_uint0_uint0 : (uint, uint) -> uint = "mac#%"
//
(* ****** ****** *)
//
overload + with add_uint0_uint0 of 100
overload - with sub_uint0_uint0 of 100
overload * with mul_uint0_uint0 of 100
overload / with div_uint0_uint0 of 100
overload % with mod_uint0_uint0 of 100
overload mod with mod_uint0_uint0 of 100
//
(* ****** ****** *)
//
fun lt_uint0_uint0: (uint, uint) -> bool = "mac#%"
fun lte_uint0_uint0: (uint, uint) -> bool = "mac#%"
fun gt_uint0_uint0: (uint, uint) -> bool = "mac#%"
fun gte_uint0_uint0: (uint, uint) -> bool = "mac#%"
//
fun eq_uint0_uint0: (uint, uint) -> bool = "mac#%"
fun neq_uint0_uint0: (uint, uint) -> bool = "mac#%"
//
fun compare_uint0_uint0: (uint, uint) -> int = "mac#%"
//
(* ****** ****** *)
//
overload < with lt_uint0_uint0 of 100
overload <= with lte_uint0_uint0 of 100
overload > with gt_uint0_uint0 of 100
overload >= with gte_uint0_uint0 of 100
overload = with eq_uint0_uint0 of 100
overload != with neq_uint0_uint0 of 100
overload <> with neq_uint0_uint0 of 100
//
overload compare with compare_uint0_uint0 of 100
//
(* ****** ****** *)

(* end of [integer.sats] *)

error: pathspec 'contrib/libatscc/libatscc2scm/SATS/integer.sats' did not match any file(s) known to git


Enable automatic identification of DATS version

fatal: unable to access 'https://github.com/jszroberto/cf-bosh-cli.git/': The requested URL returned error: 403


Updating: working on ATS-parse-emit-python

(*
** For writing ATS code
** that translates into Python
*)

(* ****** ****** *)
//
// HX: prefix for external names
//
#define ATS_EXTERN_PREFIX "atspre2py_"
//
(* ****** ****** *)

fun string_isalnum : string -> bool = "mac#%"
fun string_isalpha : string -> bool = "mac#%"
fun string_isdecimal : string -> bool = "mac#%"

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

fun string_lower (str: string): string = "mac#%"
fun string_upper (str: string): string = "mac#%"

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

(* end of [string.sats] *)

error: pathspec 'projects/MEDIUM/ATS-parse-emit/Python/prelude/SATS/string.sats' did not match any file(s) known to git


Final version

Final version

#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"

staload "SATS/arduino.sats"
staload "SATS/lcd.sats"
staload UN = "prelude/SATS/unsafe.sats"

#define MY_DELAY_MS 400.0
#define LCD_WIDTH 16

val g_string = "                 ATS is a statically typed programming language that unifies implementation with formal specification. It is equipped with a highly expressive type system rooted in the framework Applied Type System, which gives the language its name. In particular, both dependent types and linear types are available in ATS.                 "

implement main0 () = {
  fun loop {n:int}{i:nat | i < n}
           (lcd: !LCD, str: string (n), pos: size_t (i)): void = {
    val () = lcd_setCursor (lcd, $UN.cast 1, 0)
    val () = lcd_print (lcd, "<ATS running!>", i2sz 0, 14)
    val () = lcd_setCursor (lcd, $UN.cast 0, 1)
    val () = lcd_print (lcd, str, pos, LCD_WIDTH)
    val () = _delay_ms (MY_DELAY_MS)
    val () = if pos + LCD_WIDTH < length str then loop (lcd, str, pos + 1)
  }
  fun forever {n:int}{i:nat | i < n}
           (lcd: !LCD, str: string (n), pos: size_t (i)): void = {
    val () = loop (lcd, str, pos)
    val () = forever (lcd, str, pos)
  }
  val lcd = lcd_open ($UN.cast 8, $UN.cast 13, $UN.cast 9, $UN.cast 4, $UN.cast 5, $UN.cast 6, $UN.cast 7)
  val () = forever (lcd, g_string, i2sz 0)
  val () = lcd_close lcd
}

#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"

staload "SATS/arduino.sats"
staload "SATS/lcd.sats"
staload UN = "prelude/SATS/unsafe.sats"

//#define MY_DELAY_MS 400.0
#define MY_DELAY_MS 100.0
#define LCD_WIDTH 16

val g_string = "                 ATS is a statically typed programming language that unifies implementation with formal specification.                 "

implement main0 () = {
  fun loop {n:int}{i:nat | i < n}
           (lcd: !LCD, str: string (n), pos: size_t (i)): void = {
    val () = lcd_setCursor (lcd, $UN.cast 1, 0)
    val () = lcd_print (lcd, "<ATS running!>", i2sz 0, 14)
    val () = lcd_setCursor (lcd, $UN.cast 0, 1)
    val () = lcd_print (lcd, str, pos, LCD_WIDTH)
    val () = _delay_ms (MY_DELAY_MS)
    val () = if pos + LCD_WIDTH < length str then loop (lcd, str, pos + 1)
  }
  fun forever {n:int}{i:nat | i < n}
           (lcd: !LCD, str: string (n), pos: size_t (i)): void = {
    val () = loop (lcd, str, pos)
    val () = forever (lcd, str, pos)
  }
  val lcd = lcd_open ($UN.cast 8, $UN.cast 13, $UN.cast 9, $UN.cast 4, $UN.cast 5, $UN.cast 6, $UN.cast 7)
  val () = forever (lcd, g_string, i2sz 0)
  val () = lcd_close lcd
}


Updating: scratching a bit

Updating: scratching a bit

(* ****** ****** *)
//
// HX-2014-12-23:
// For the purpose of
// studying session types
//
(* ****** ****** *)
//
abstype send (a:vt@ype)
abstype recv (a:vt@ype)
//
(* ****** ****** *)

abstype
chseq (a:type, b:type)

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

stadef nil = unit
stadef :: (a:type, b:type) = chseq (a, b)

(* ****** ****** *)
//
absvtype chpos(type)
absvtype chneg(type)
//
(* ****** ****** *)
//
extern
fun{a:vt0p}
chpos_send{ss:type}
  (ch: !chpos(send(a) :: ss) >> chpos(ss), x: a): void
extern
fun{a:vt0p}
chpos_recv{ss:type}
  (ch: !chpos(recv(a) :: ss) >> chpos(ss), x: &a? >> _): void
//
(* ****** ****** *)
//
extern
fun{a:vt0p}
chneg_recv{ss:type}
  (ch: !chneg(recv(a) :: ss) >> chneg(ss), x: a): void
extern
fun{a:vt0p}
chneg_send{ss:type}
  (ch: !chneg(send(a) :: ss) >> chneg(ss), x: &a? >> _): void
//
(* ****** ****** *)

extern
fun chpos_recv_close (ch: chpos(nil)): void
extern
fun chneg_send_close (ch: chneg(nil)): void

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

abstype service(type)

(* ****** ****** *)
//
extern
fun
service_create
  {ss:type}(f: chpos(ss) -> void): service(ss)
//
extern
fun
service_request{ss:type}(service(ss)): chneg(ss)
//
(* ****** ****** *)

extern
val myservice1 : service (recv(int) :: send(int) :: nil)
extern
val myservice2 : service (recv(int) :: recv(int) :: send(int) :: nil)

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

extern fun myservice1_use (int): int
extern fun myservice2_use (int, int): int

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

implement
myservice1_use(x) = let
//
val ch =
  service_request (myservice1)
//
val () = chneg_recv (ch, x)
var res: int
val () = chneg_send (ch, res)
val () = chneg_send_close (ch)
//
in
  res
end // end of [myservice1_use]

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

implement
myservice2_use
  (x1, x2) = let
//
val ch =
  service_request (myservice2)
//
val () = chneg_recv (ch, x1)
val () = chneg_recv (ch, x2)
var res: int
val () = chneg_send (ch, res)
val () = chneg_send_close (ch)
//
in
  res
end // end of [myservice2_use]

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

(* end of [scratch05.dats] *)

error: pathspec 'projects/MEDIUM/ATS-parse-emit/Erlang/SCRATCH/scratch05.dats' did not match any file(s) known to git


Updating: adding a test for Z3

Updating: adding a test for Z3

(*
** Some basic tests for
** the API of Z3 Library in ATS
*)

(* ****** ****** *)
//
#include
"share/atspre_staload.hats"
//
(* ****** ****** *)

staload "./../SATS/z3.sats"

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

val () =
{
//
val cfg = Z3_mk_config ()
val ctx = Z3_mk_context_rc (cfg)
val ((*unref*)) = Z3_del_config (cfg)
val ((*unref*)) = Z3_del_context (ctx)
//
} (* end of [val] *)

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

implement main0 () = ()

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

(* end of [test00.dats] *)

error: pathspec 'contrib/SMT/Z3/TEST/test00.dats' did not match any file(s) known to git


Updating: very minorly improving

Updating: very minorly improving

(*
** For studying
** lambda-calculus
** cbv: call-by-value
*)

(* ****** ****** *)
//
staload
"libats/ML/SATS/basis.sats"
staload
"libats/ML/SATS/funset.sats"
//
(* ****** ****** *)

abstype tvar_type = ptr
typedef tvar = tvar_type

(* ****** ****** *)
//
val TVARSET: set_modtype(tvar)
//
(* ****** ****** *)
//
fun tvar_make_name : (string) -> tvar
fun tvar_make_index : (intGte(0)) -> tvar
//
(* ****** ****** *)
//
fun tvar_get_index : tvar -> intGte(~1)
//
fun tvar_shift_gte : (tvar, int) -> tvar
//
(* ****** ****** *)

abstype tcst_type = ptr
typedef tcst = tcst_type

(* ****** ****** *)
//
datatype term =
  | TMvar of tvar
  | TMcst of tcst
  | TMlam of (tvar, term)
  | TMapp of (term, term)
  | TMlet of (tvar, term, term)
  | TMfix of (tvar, tvar, term)
//
(* ****** ****** *)
//
datatype aterm =
  | ATMvar of tvar
  | ATMcst of tcst
  | ATMlam of (aterm)
  | ATMapp of (aterm, aterm)
  | ATMlet of (aterm, aterm)
  | ATMfix of (aterm)
  | ATMref of ref(aterm)
//
(* ****** ****** *)

(* end of [lamcal.sats] *)

error: pathspec 'projects/MEDIUM/LAMCAL/lambda-cbv/lamcal.sats' did not match any file(s) known to git


Add type to mbed interface

Add type to mbed interface

%{^
#include "mbed_interface.h"
%}

typedef char_p = cPtr0(char)

fun mbed_mac_address: (char_p) -> void = "mac#"

error: pathspec 'demos/halapi_ats/libmbedats/SATS/mbed_api_mbed_interface.sats' did not match any file(s) known to git


Updating: adding bouncing-ball2

Updating: adding bouncing-ball2

(*
** Bouncing ball
*)

(* ****** ****** *)
//
// Author: Hongwei Xi
// Authoremail: gmhwxiATgmailDOTedu
//
(* ****** ****** *)
//
staload
"libats/SATS/Number/real.sats"
staload
"libats/DATS/Number/real_double.dats"
//
(* ****** ****** *)
//
extern
fun{}
gte_real_int
  {x:real;i:int}
  (real(x), int(i)):<> bool(x >= i)
//
overload >= with gte_real_int of 10
//
(* ****** ****** *)

sortdef mode = int
sortdef time = real

(* ****** ****** *)
//
absprop INF(t:time)
//
extern
praxi
lemma_inf_gte
  {t0,t1:time | t0 >= t1}(INF(t0), real(t1)): INF(t1)
//
(* ****** ****** *)

stacst g : real

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

stadef m1 = 1 and m2 = 2

(* ****** ****** *)
//
stacst x
  : (mode, time) -> real
stacst v
  : (mode, time) -> real
//
(* ****** ****** *)

stadef x1(t:time) = x(m1, t)
stadef x2(t:time) = x(m2, t)
stadef v1(t:time) = v(m1, t)
stadef v2(t:time) = v(m2, t)

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

absvtype state(mode, time)

vtypedef state1(t) = state(m1, t)
vtypedef state2(t) = state(m2, t)

(* ****** ****** *)
//
stacst
deriv :
(
  time -> real, time(*t*), time(*dt*)
) -> real
//
(* ****** ****** *)
//
extern
praxi
state1_eqn1
  {t,dt:time}
(
  INF(dt) | !state1(t)
) : [deriv(x1,t,dt) == v1(t)] void
extern
praxi
state1_eqn2
  {t,dt:time}
  (INF(dt) | !state1(t)): [deriv(v1,t,dt) == ~g] void
//
(* ****** ****** *)
//
extern
praxi
state2_eqn2
  {t,dt:time}
(
  INF(dt) | !state(m2, t)
) : [deriv(x2,t,dt) == v2(t)] void
extern
praxi
state2_eqn2
  {t,dt:time}
  (INF(dt) | !state(m2, t)): [deriv(v2,t,dt) == ~g] void
//
(* ****** ****** *)
//
extern
fun
state_get_t
  {m:mode}{t:time}(!state(m, t)): real(t)
extern
fun
state_get_x
  {m:mode}{t:time}(!state(m, t)): real(x(m, t))
extern
fun
state_get_v
  {m:mode}{t:time}(!state(m, t)): real(v(m, t))
//
(* ****** ****** *)
//
extern
fun
state1_flow
{ t,dt:time
| x1(t+dt) >= 0
}
(INF(dt)|state1(t), real(dt)): state1(t+dt)
//
extern
fun
state1_jump
{
  t:time
| x1(t) == 0
} (state1(t))
: [x2(t) == 0; v2(t) == ~v1(t)] state(m2, t)
//
(* ****** ****** *)
//
extern
fun
state2_flow
{ t,dt:time
| v2(t+dt) >= 0
} (INF(dt) | state(m2, t), real(dt)): state(m2, t+dt)
//
extern
fun
state2_jump
{
  t:time
| v2(t) == 0
} (state2(t)): [x1(t) == x2(t); v1(t) == 0] state1(t)
//
(* ****** ****** *)

extern
fun
delta_x1
  {t,dt:time}
(
  pf: INF(dt) | !state1(t), dt: real(dt)
) : real(x1(t+dt))

extern
fun
delta_v2
  {t,dt:time}
(
  pf: INF(dt) | !state2(t), dt: real(dt)
) : real(v2(t+dt))

(* ****** ****** *)
//
extern
fun
x1_midval
{ r:real
; t0,t1:time
| x1(t0) >= r ; r >= x1(t1)
}
(
  real(x1(t0)), real(r), real(x1(t1))
) : [t:time | t0 >= t; t >= t1; x1(t)==0] real(t)
//
(* ****** ****** *)
//
extern
fun
v2_midval
{ r:real
; t0,t1:time
| v2(t0) >= r ; r >= v2(t1)
}
(
  real(v2(t0)), real(r), real(v2(t1))
) : [t:time | t0 >= t; t >= t1; v2(t)==0] real(t)
//
(* ****** ****** *)

extern
fun
state1_loop
{t,dt:time}
(
  pf: INF(dt) | st: state1(t), dt: real(dt)
) : void // end-of-function
extern
fun
state2_loop
{t,dt:time}
(
  pf: INF(dt) | st: state2(t), dt: real(dt)
) : void // end-of-function

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

val _0_ = int2real(0)

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

implement
state1_loop
  (pf | st, dt) = let
//
  val t_0 = state_get_t(st)
  val x1_0 = state_get_x(st)
  val x1_dx = delta_x1(pf | st, dt)
//
in
//
  if x1_dx >= 0
    then let
      val st_1 =
      state1_flow(pf | st, dt)
    in
      state1_loop(pf | st_1, dt)
    end // end of [then]
    else let
        val t_1 =
          x1_midval(x1_0, _0_, x1_dx)
        // end of [val]
        val dt_1 = t_1 - t_0
      prval pf_1 = lemma_inf_gte(pf, dt_1)
        val st_1 = state1_flow(pf_1 | st, dt_1)
    in
      state2_loop(pf | state1_jump(st_1), dt)
    end // end of [else]
//
end // end of [state1_loop]

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

implement
state2_loop
  (pf | st, dt) = let
//
  val t_0 = state_get_t(st)
  val v2_0 = state_get_v(st)
  val v2_dv = delta_v2(pf | st, dt)
//
in
//
  if v2_dv >= 0
    then let
      val st_1 =
      state2_flow(pf | st, dt)
    in
      state2_loop(pf | st_1, dt)
    end // end of [then]
    else let
        val t_1 =
          v2_midval(v2_0, _0_, v2_dv)
        // end of [val]
        val dt_1 = t_1 - t_0
      prval pf_1 = lemma_inf_gte(pf, dt_1)
        val st_1 = state2_flow(pf_1 | st, dt_1)
    in
      state1_loop(pf | state2_jump(st_1), dt)
    end // end of [else]
//
end // end of [state_loop2]

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

(* end of [bouncing_ball2.dats] *)

error: pathspec 'projects/LARGE/DREACH/SCRATCH/bouncing_ball/bouncing_ball2.dats' did not match any file(s) known to git


a couple of arithmetic things for ats

a couple of arithmetic things for ats

// This is a standard function-pack
// strongly recommend to include it everywhere
// to avoid very long-time debug sessions.

#include "share/atspre_staload.hats"

val _ = println! ("(1+2)/(3+4) = ", (1+2)/(3+4))

val _ = println! ("-1 = ", x) where {
    val x = ~1
}

implement main0 () = ()

error: pathspec 'ats/introduction_to_programming_in_ats/simple_arithmetic.dats' did not match any file(s) known to git


Added in the start of array insertion sort.

staload _ = "prelude/DATS/integer.dats"

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

staload "contrib/libats-/wdblair/prelude/SATS/list.sats"
staload "contrib/libats-/wdblair/patsolve/SATS/stampseq.sats"

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

error: pathspec 'contrib/libats-/wdblair/prelude/TEST/array_insort.dats' did not match any file(s) known to git


coin exchanging code

coin exchanging code

// Compile with `patscc -o ce coint_exchange.dats`
// Run with `./ce`
// To remove all ATS2 `tmp` files `rm -fv *_[sd]ats.[co]`

// If you forget:

// SPC-c-C and puts `patscc -o ce coint_exchange.dats && ./ce` to setup compilation
// SPC-c-r to recompile

#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"

//
typedef
int4 = (int, int, int, int)
//
val theCoins = (1, 5, 10, 25): int4
//
fun coin_get
  (n: int): int =
(
  if n = 0 then theCoins.0
  else if n = 1 then theCoins.1
  else if n = 2 then theCoins.2
  else if n = 3 then theCoins.3
  else ~1 (* erroneous value *)
) (* end of [coin_get] *)
//
fun coin_change
  (sum: int): int = let
  fun aux (sum: int, n: int): int =
    if sum > 0 then
     (if n >= 0 then aux (sum, n-1) + aux (sum-coin_get(n), n) else 0)
    else (if sum < 0 then 0 else 1)
  // end of [aux]
in
  aux (sum, 3)
end // end of [coin_change]
//

implement main0() = begin
  print(coin_change(5))
end

error: pathspec 'ats/introduction_to_programming_in_ats/coint_exchange.dats' did not match any file(s) known to git


Adding generic sats file

Adding generic sats file

(**
  Collect input from the user.
*)

datatype commarg =
  | JsonFile of (string)
  | Verbose of ()
  | ScriptDirectory of (string)
  | Script of (string)

typedef commarglst = List0 (commarg)

fun
parse_argv
  {n:int | n >= 1} (
  argc: int (n), argv: !argv (n)
): commarglst

error: pathspec 'projects/MEDIUM/patsolve/patsolve.sats' did not match any file(s) known to git