{"id":19864144,"url":"https://github.com/sr-lab/tiny-synth","last_synced_at":"2025-10-09T23:38:35.898Z","repository":{"id":75386403,"uuid":"80112659","full_name":"sr-lab/tiny-synth","owner":"sr-lab","description":"An experiment in synthesis of C code from a functional language.","archived":false,"fork":false,"pushed_at":"2017-01-27T11:18:58.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-11T15:34:16.866Z","etag":null,"topics":["c","code-generation","functional-language","python","refinement","synthesis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sr-lab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-26T12:28:50.000Z","updated_at":"2017-03-20T22:57:47.000Z","dependencies_parsed_at":"2023-07-26T04:16:50.241Z","dependency_job_id":null,"html_url":"https://github.com/sr-lab/tiny-synth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sr-lab%2Ftiny-synth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sr-lab%2Ftiny-synth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sr-lab%2Ftiny-synth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sr-lab%2Ftiny-synth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sr-lab","download_url":"https://codeload.github.com/sr-lab/tiny-synth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241273088,"owners_count":19937096,"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","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":["c","code-generation","functional-language","python","refinement","synthesis"],"created_at":"2024-11-12T15:17:36.970Z","updated_at":"2025-10-09T23:38:30.878Z","avatar_url":"https://github.com/sr-lab.png","language":"Python","readme":"# Tiny Synth\nAn experiment in synthesis of C code from a functional language.\n\nThe basic idea of this very simple and naive Python program is to transform a nameless functional language that looks a bit like this:\n\n```\nint,bin:int;\n(add (rotate_right bin 1) (rotate_left (bitwise_and bin 1) 15)))\n```\n\nInto C code that can be compiled using [TinyC](http://bellard.org/tcc/).\n\n## Structure\nA specification file (`.spec` extension) is written in a nameless functional language with one function per file, with the function's name being the name of the file without extension. The basic structure of a specification file looks like this:\n\n```\n\u003creturn_type\u003e,\u003cparam_name\u003e:\u003cparam_type\u003e;\n\u003cfunctional_code\u003e\n```\n\nThis includes the following:\n\n* `\u003creturn_type\u003e` - The return type of the C method to be generated.\n* `\u003cparam_name\u003e:\u003cparam_type\u003e` - The name and type of each parameter to be included in the generated C method. Can be repeated arbitratily many times (comma-separated).\n* `\u003cfunctional_code\u003e` - The functional code to compile as the body of the generated C method.\n\nA primitive file (`.pc` extension) is written as a very small piece of C code with substitution placeholders for each argument of the function that corresponds to that primitive. For example `add.pc` contains this:\n\n```\n(%1 + %2)\n```\n\n## Usage\nInvoke the program on the command line like this:\n\n```\npython tiny-synth.py \u003cfunction_name\u003e\n```\n\nWhere `function_name` is the name of the function you want to compile.\n\n## Reason\nWith functional programs being easier to reason about in general than imperative programs, I thought it'd a be a fun little experiment to try to synthesise some imperative code from functional code.\n\n## Limitations\nThis isn't a serious development tool, and comes with some serious limitations and caveats. I'm sure there are a billion and one ways this could behave differently than expected.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsr-lab%2Ftiny-synth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsr-lab%2Ftiny-synth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsr-lab%2Ftiny-synth/lists"}