From 1c7f51653452133907b00ebf03150e1cd4f69099 Mon Sep 17 00:00:00 2001 From: Sahil Dua Date: Wed, 6 Jul 2016 01:14:05 +0530 Subject: [PATCH] Replace .hats GPL sample with MIT one --- samples/ATS/csv_parse.hats | 155 ++++++++++++++++++++++++++++++ samples/ATS/linset.hats | 187 ------------------------------------- 2 files changed, 155 insertions(+), 187 deletions(-) create mode 100644 samples/ATS/csv_parse.hats delete mode 100644 samples/ATS/linset.hats diff --git a/samples/ATS/csv_parse.hats b/samples/ATS/csv_parse.hats new file mode 100644 index 00000000..658723ca --- /dev/null +++ b/samples/ATS/csv_parse.hats @@ -0,0 +1,155 @@ +// Source: https://github.com/githwxi/ATS-Postiats-contrib/blob/0f26aa0df8542d2ae21df9be1e13208f66f571d6/contrib/libats-/hwxi/teaching/mygrading/HATS/csv_parse.hats + +(* ****** ****** *) +// +// Author: Hongwei Xi +// Authoremail: gmhwxiATgmailDOTcom +// Start time: the first of July, 2016 +// +(* ****** ****** *) +// +#ifdef +MYGRADING_HATS +#then +#else +// +extern +fun +csv_parse_line +( + line: string +) : List0_vt(Strptr1) +// +#endif // #ifdef +// +(* ****** ****** *) + +local +// +staload +UN = "prelude/SATS/unsafe.sats" +// +extern +fun{} +getpos(): int +// +extern +fun{} +is_end(): bool +// +extern +fun{} +char_at(): int +// +extern +fun{} +Strptr1_at(i0: int): Strptr1 +// +extern +fun{} +rmove(): void +extern +fun{} +rmove_while(test: char - bool): void +// +in (* in-of-local *) +// +implement +{}(*tmp*) +rmove_while + (test) = let +// +val c0 = char_at() +// +in +// +if c0 >= 0 then + if test(int2char0(c0)) then (rmove(); rmove_while(test)) else () +// end of [if] +// +end // end of [rmove_while] + +(* ****** ****** *) + +implement +csv_parse_line + (line) = let +// +val line = g1ofg0(line) +// +var i: int = 0 +val p_i = addr@i +// +val n0 = sz2i(length(line)) +// +macdef get_i() = $UN.ptr0_get(p_i) +macdef inc_i() = $UN.ptr0_addby(p_i, 1) +macdef set_i(i0) = $UN.ptr0_set(p_i, ,(i0)) +// +implement +getpos<>() = get_i() +// +implement +is_end<>() = get_i() >= n0 +// +implement +char_at<>() = let + val i = get_i() + val i = ckastloc_gintGte(i, 0) +// +in + if i < n0 then char2u2int0(line[i]) else ~1 +end // end of [char_at] +// +implement +Strptr1_at<>(i0) = let +// + val i1 = get_i() + val i0 = ckastloc_gintGte(i0, 0) + val i1 = ckastloc_gintBtwe(i1, i0, n0) +// +in + $UN.castvwtp0( + string_make_substring(line, i2sz(i0), i2sz(i1-i0)) + ) (* $UN.castvwtp0 *) +end // end of [Strptr1_at] +// +implement +rmove<>() = + if get_i() < n0 then inc_i() +// +vtypedef res_vt = List0_vt(Strptr1) +// +fun +loop +( + i: int, res: res_vt +) : res_vt = +if +is_end() +then res +else let + val () = + ( + if i > 0 then rmove() + ) + val i0 = getpos() + var f0 = + ( + lam@(c: char) = c != ',' + ) + val () = rmove_while($UN.cast(addr@f0)) + val s0 = Strptr1_at(i0) +in + loop(i+1, list_vt_cons(s0, res)) +end // end of [else] +// +in + list_vt_reverse(loop(0(*i*), list_vt_nil((*void*)))) +end // end of [csv_parse_line] + +end // end of [local] + +(* ****** ****** *) + +(* end of [csv_parse.hats] *) diff --git a/samples/ATS/linset.hats b/samples/ATS/linset.hats deleted file mode 100644 index 29e44c44..00000000 --- a/samples/ATS/linset.hats +++ /dev/null @@ -1,187 +0,0 @@ -(***********************************************************************) -(* *) -(* Applied Type System *) -(* *) -(***********************************************************************) - -(* -** ATS/Postiats - Unleashing the Potential of Types! -** Copyright (C) 2011-2013 Hongwei Xi, ATS Trustful Software, Inc. -** All rights reserved -** -** ATS is free software; you can redistribute it and/or modify it under -** the terms of the GNU GENERAL PUBLIC LICENSE (GPL) as published by the -** Free Software Foundation; either version 3, or (at your option) any -** later version. -** -** ATS is distributed in the hope that it will be useful, but WITHOUT ANY -** WARRANTY; without even the implied warranty of MERCHANTABILITY or -** FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -** for more details. -** -** You should have received a copy of the GNU General Public License -** along with ATS; see the file COPYING. If not, please write to the -** Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA -** 02110-1301, USA. -*) - -(* ****** ****** *) - -(* Author: Hongwei Xi *) -(* Authoremail: hwxi AT cs DOT bu DOT edu *) -(* Start time: December, 2012 *) - -(* ****** ****** *) -// -// HX: shared by linset_listord (* ordered list *) -// HX: shared by linset_avltree (* AVL-tree-based *) -// -(* ****** ****** *) -// -// HX-2013-02: -// for sets of nonlinear elements -// -absvtype set_vtype (a:t@ype+) = ptr -// -(* ****** ****** *) - -vtypedef set (a:t0p) = set_vtype (a) - -(* ****** ****** *) - -fun{a:t0p} -compare_elt_elt (x1: a, x2: a):<> int - -(* ****** ****** *) - -fun{} linset_nil{a:t0p} ():<> set(a) -fun{} linset_make_nil{a:t0p} ():<> set(a) - -(* ****** ****** *) - -fun{a:t0p} linset_sing (x: a): set(a) -fun{a:t0p} linset_make_sing (x: a): set(a) - -(* ****** ****** *) - -fun{a:t0p} -linset_make_list (xs: List(INV(a))): set(a) - -(* ****** ****** *) - -fun{} -linset_is_nil {a:t0p} (xs: !set(INV(a))):<> bool -fun{} -linset_isnot_nil {a:t0p} (xs: !set(INV(a))):<> bool - -(* ****** ****** *) - -fun{a:t0p} linset_size (!set(INV(a))): size_t - -(* ****** ****** *) - -fun{a:t0p} -linset_is_member (xs: !set(INV(a)), x0: a):<> bool -fun{a:t0p} -linset_isnot_member (xs: !set(INV(a)), x0: a):<> bool - -(* ****** ****** *) - -fun{a:t0p} -linset_copy (!set(INV(a))): set(a) -fun{a:t0p} -linset_free (xs: set(INV(a))): void - -(* ****** ****** *) -// -fun{a:t0p} -linset_insert - (xs: &set(INV(a)) >> _, x0: a): bool -// -(* ****** ****** *) -// -fun{a:t0p} -linset_takeout -( - &set(INV(a)) >> _, a, res: &(a?) >> opt(a, b) -) : #[b:bool] bool(b) // endfun -fun{a:t0p} -linset_takeout_opt (&set(INV(a)) >> _, a): Option_vt(a) -// -(* ****** ****** *) -// -fun{a:t0p} -linset_remove - (xs: &set(INV(a)) >> _, x0: a): bool -// -(* ****** ****** *) -// -// HX: choosing an element in an unspecified manner -// -fun{a:t0p} -linset_choose -( - xs: !set(INV(a)), x: &a? >> opt (a, b) -) : #[b:bool] bool(b) -// -fun{a:t0p} -linset_choose_opt (xs: !set(INV(a))): Option_vt(a) -// -(* ****** ****** *) - -fun{a:t0p} -linset_takeoutmax -( - xs: &set(INV(a)) >> _, res: &a? >> opt(a, b) -) : #[b:bool] bool (b) -fun{a:t0p} -linset_takeoutmax_opt (xs: &set(INV(a)) >> _): Option_vt(a) - -(* ****** ****** *) - -fun{a:t0p} -linset_takeoutmin -( - xs: &set(INV(a)) >> _, res: &a? >> opt(a, b) -) : #[b:bool] bool (b) -fun{a:t0p} -linset_takeoutmin_opt (xs: &set(INV(a)) >> _): Option_vt(a) - -(* ****** ****** *) -// -fun{} -fprint_linset$sep (FILEref): void // ", " -// -fun{a:t0p} -fprint_linset (out: FILEref, xs: !set(INV(a))): void -// -overload fprint with fprint_linset -// -(* ****** ****** *) -// -fun{ -a:t0p}{env:vt0p -} linset_foreach$fwork - (x: a, env: &(env) >> _): void -// -fun{a:t0p} -linset_foreach (set: !set(INV(a))): void -fun{ -a:t0p}{env:vt0p -} linset_foreach_env - (set: !set(INV(a)), env: &(env) >> _): void -// end of [linset_foreach_env] -// -(* ****** ****** *) - -fun{a:t0p} -linset_listize (xs: set(INV(a))): List0_vt (a) - -(* ****** ****** *) - -fun{a:t0p} -linset_listize1 (xs: !set(INV(a))): List0_vt (a) - -(* ****** ****** *) - -(* end of [linset.hats] *)