A toy translator C to ATS

Posted on July 19, 2019 / Tags: ats, idiomaticca, haskell, c, translator

Table of contents


TL;DR

We can translate a simple for and while loop in C language into a recursive function in ATS language, using the idiomaticca tool.

Why difficult to make real products in ATS language?

We believe ATS language is a better choice than C language. Because it can:

But there are following barriers to make real products in ATS:

  1. Hard to learn ATS language.
  2. Hard to reuse existing programs and libraries written in C.

Why is c2ats not useful?

We have already create c2ats to fix above barriers. But people should write own ATS code side of existing C code, because the c2ats only translate C function signature into ATS. It can’t translate C function body.

Please imagine that someone tries to translate a file system driver using c2ats:

  1. Choose target files to be translated.
  2. Translate headers included by the target files into ATS using c2ats.
  3. Manually re-write the target files by ATS

Undoubtedly, the step 3 requires more man-hours, and is sometimes unrealistic.

Let’s start to create new translator C to ATS

If so, how about translate both function signature and function body into ATS? The translator may fix:

Of course, we know it seems like a crazy attempt. Let’s try to create a toy translator C to ATS. We call it idiomaticca.

How to install

$ git clone https://github.com/metasepi/idiomaticca.git -b v0.1.0.0
$ cd idiomaticca
$ make install
$ which idiomaticca
/home/YourName/.local/bin/idiomaticca

Some examples

while loop in C

$ vi loop_while.c
$ gcc loop_while.c
$ ./a.out
$ echo $?
55
$ idiomaticca trans loop_while.c > loop_while.dats
$ cat loop_while.dats
$ patscc loop_while.dats
$ ./a.out
$ echo $?
55

for loop in C

$ vi loop_for.c
$ gcc loop_for.c
$ ./a.out
$ echo $?
15
$ idiomaticca trans loop_for.c > loop_for.dats
$ cat loop_for.dats
$ patscc loop_for.dats
$ ./a.out
$ echo $?
15

the others

Please see regress tests.

Next?

Acknowledgements

blog comments powered by Disqus