c2ats - An utility to generate ATS interface from C code

26 views
Skip to first unread message

Kiwamu Okabe

unread,
Sep 17, 2016, 10:30:13 PM9/17/16
to ats-lang-users
Hi all,

I create an utility to generate ATS interface from C code. It's useful
to create application rapidly.

http://metasepi.org/en/posts/2016-09-17-c2ats.html

The utility generates ATS's sats file importing from C language
header, semi-automatically.

If you have following header:

```
$ vi example.h
#include <stdio.h>
```

then you can get the sats file using c2ats:

```
$ c2ats gen example.h > example.sats
$ wc -l example.sats
318 example.sats
$ grep _printf example.sats
fun fun_c2ats_printf: {l1:addr} (!ptr_v_1(char, l1) | ptr l1) -> int =
"mac#printf"
```

Now you can create ATS application using the example.sats:

```
$ vi main.dats
#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"

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

staload "example.sats"

fun my_printf (s: string): void = {
val p = string2ptr s
val (pfat, fpfat | p) = $UN.ptr_vtake p
val ret = fun_c2ats_printf (pfat | p)
prval () = fpfat pfat
}

implement main0 () = {
val s = "Hello, world!\n"
val () = my_printf s
}
$ patscc main.dats
$ ./a.out
Hello, world!
```

More detail and usage is found at following:

https://github.com/metasepi/c2ats

Best regards,
--
Kiwamu Okabe at METASEPI DESIGN

gmhwxi

unread,
Sep 18, 2016, 9:20:59 AM9/18/16
to ats-lang-users, kiw...@debian.or.jp
Great!

This is a very important step to partially/gradually rewriting existing C code.
Reply all
Reply to author
Forward
0 new messages