{"id":32161762,"url":"https://github.com/metasepi/c2ats","last_synced_at":"2025-10-21T13:58:37.040Z","repository":{"id":62435666,"uuid":"65356493","full_name":"metasepi/c2ats","owner":"metasepi","description":"generate ATS interface from C code","archived":false,"fork":false,"pushed_at":"2016-12-31T05:21:38.000Z","size":2075,"stargazers_count":20,"open_issues_count":10,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-10-21T13:58:35.440Z","etag":null,"topics":["ats","c","generate","haskell","header"],"latest_commit_sha":null,"homepage":"","language":"ATS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/metasepi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-10T06:29:47.000Z","updated_at":"2024-12-29T02:48:23.000Z","dependencies_parsed_at":"2022-11-01T21:16:11.433Z","dependency_job_id":null,"html_url":"https://github.com/metasepi/c2ats","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/metasepi/c2ats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metasepi%2Fc2ats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metasepi%2Fc2ats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metasepi%2Fc2ats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metasepi%2Fc2ats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/metasepi","download_url":"https://codeload.github.com/metasepi/c2ats/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/metasepi%2Fc2ats/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280272339,"owners_count":26302260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ats","c","generate","haskell","header"],"created_at":"2025-10-21T13:58:30.505Z","updated_at":"2025-10-21T13:58:37.033Z","avatar_url":"https://github.com/metasepi.png","language":"ATS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# c2ats - generate ATS interface from C code [![Build Status](https://travis-ci.org/metasepi/c2ats.svg)](https://travis-ci.org/metasepi/c2ats)\n\n## What's this?\n\n[ATS](http://www.ats-lang.org/) is a statically typed programming language that unifies implementation with formal specification. It can powerfully capture invariant in program.\n\nHowever, don't you feel frustration to use API of many C language libraries from ATS code? Don't you manually import such API into ATS code?\n\nThe c2ats is an utility to generate ATS's sats file importing from C language header, semi-automatically.\n\n## Requirements\n\n* [GCC](https://gcc.gnu.org/) to parse C language header\n* [Haskell Platform](https://www.haskell.org/platform/) to build [Haskell](https://www.haskell.org/) code\n* [ATS](http://www.ats-lang.org/) to compile ATS code generated by c2ats\n\nWe are testing this tool on [Debian GNU/Linux](https://www.debian.org/).\n\n## Install\n\nCheckout source code of the c2ats:\n\n```\n$ git clone https://github.com/metasepi/c2ats.git\n$ cd c2ats\n```\n\nThen install it using stack:\n\n```\n$ cabal update\n$ cabal install\n$ which c2ats\n/home/YourName/.cabal/bin/c2ats\n```\n\n## Usage\n\nStart from [Hello World example](./example/hello). Create following fake C language header to use `printf(3)` function in C language:\n\n```\n$ vi example.h\n#include \u003cstdio.h\u003e\n```\n\nNext, let the c2ats to generate ATS sats file from above header:\n\n```\n$ c2ats gen example.h \u003e example.sats\n$ wc -l example.sats\n318 example.sats\n$ grep _printf example.sats\nfun fun_c2ats_printf: {l1:addr} (!ptr_v_1(char, l1) | ptr l1) -\u003e int = \"mac#printf\"\n```\n\nThe sats file has many ATS declarations generated from the C header. It includes a declaration of `printf(3)` which can be used as following in dats:\n\n```\n$ vi main.dats\n#include \"share/atspre_define.hats\"\n#include \"share/atspre_staload.hats\"\n\nstaload UN = \"prelude/SATS/unsafe.sats\"\n\nstaload \"example.sats\"\n\nfun my_printf (s: string): void = {\n  val p = string2ptr s\n  val (pfat, fpfat | p) = $UN.ptr_vtake p\n  val ret = fun_c2ats_printf (pfat | p)\n  prval () = fpfat pfat\n}\n\nimplement main0 () = {\n  val s = \"Hello, world!\\n\"\n  val () = my_printf s\n}\n$ patscc main.dats\n$ ./a.out\nHello, world!\n```\n\nOf course, above code is so messy. It's caused by assigning a bad signature to `fun_c2ats_printf` function. You can get better dats code, if modify sats file as following:\n\n```\n$ vi example.sats\n--snip--\nfun fun_c2ats_printf: (string) -\u003e int = \"mac#printf\"\n--snip--\n$ vi main.dats\n#include \"share/atspre_define.hats\"\n#include \"share/atspre_staload.hats\"\n\nstaload UN = \"prelude/SATS/unsafe.sats\"\n\nstaload \"example.sats\"\n\nimplement main0 () = {\n  val s = \"Hello, world!\\n\"\n  val _ = fun_c2ats_printf s\n}\n$ patscc main.dats\n$ ./a.out\nHello, world!\n```\n\nTotally, the c2ats generates a scaffold (you may be familiar with [Ruby on Rails](http://rubyonrails.org/)) to build ATS application. Sometimes, it's useful to create application rapidly. However, such scaffold should be replaced with better signature until shipping your product.\n\nThe other examples are found at [example](./example/) directory.\n\n## See also\n\n* [c2ats - An utility to generate ATS interface from C code - Metasepi](http://metasepi.org/en/posts/2016-09-17-c2ats.html)\n\n## License\n\nGPLv3 or later.\n\nCopyright (c) 2016 Metasepi Team.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetasepi%2Fc2ats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetasepi%2Fc2ats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetasepi%2Fc2ats/lists"}