Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
38
Task/Reverse-a-string/ATS/reverse-a-string.ats
Normal file
38
Task/Reverse-a-string/ATS/reverse-a-string.ats
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
//
|
||||
// How to compile:
|
||||
// patscc -DATS_MEMALLOC_LIBC -o string_reverse string_reverse.dats
|
||||
//
|
||||
|
||||
#include
|
||||
"share/atspre_staload.hats"
|
||||
|
||||
fun
|
||||
string_reverse
|
||||
(
|
||||
x: string
|
||||
) : Strptr1 = let
|
||||
//
|
||||
val [n:int] x = g1ofg0(x)
|
||||
val y = string1_copy(x)
|
||||
val n = string1_length(x)
|
||||
val (pf, fpf | p) =
|
||||
$UNSAFE.ptr_vtake{array(char,n)}(ptrcast(y))
|
||||
val () = array_subreverse(!p, i2sz(0), n)
|
||||
prval () = fpf(pf)
|
||||
//
|
||||
in
|
||||
$UNSAFE.castvwtp0{Strptr1}(y)
|
||||
end (* end of [string_reverse] *)
|
||||
|
||||
(* ****** ****** *)
|
||||
|
||||
implement
|
||||
main0 () = let
|
||||
//
|
||||
val rev = string_reverse("asdf")
|
||||
val ((*void*)) = println! ("reverse(\"asdf\") = \"", rev, "\"")
|
||||
val ((*freed*)) = strptr_free (rev)
|
||||
//
|
||||
in
|
||||
// nothing
|
||||
end // end of [main0]
|
||||
Loading…
Add table
Add a link
Reference in a new issue