{"id":22425702,"url":"https://github.com/gabrielemaurina/while-machine","last_synced_at":"2025-06-18T02:34:21.267Z","repository":{"id":62588846,"uuid":"346676878","full_name":"GabrieleMaurina/while-machine","owner":"GabrieleMaurina","description":"While Abstract Machine implemented in python.","archived":false,"fork":false,"pushed_at":"2021-03-11T17:00:56.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-04T06:27:02.185Z","etag":null,"topics":["abstract-machine","python","turing","turing-complete","turing-machine","while","while-abstract-machine"],"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/GabrieleMaurina.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}},"created_at":"2021-03-11T11:19:16.000Z","updated_at":"2021-03-11T17:00:58.000Z","dependencies_parsed_at":"2022-11-03T17:01:46.730Z","dependency_job_id":null,"html_url":"https://github.com/GabrieleMaurina/while-machine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/GabrieleMaurina/while-machine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrieleMaurina%2Fwhile-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrieleMaurina%2Fwhile-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrieleMaurina%2Fwhile-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrieleMaurina%2Fwhile-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GabrieleMaurina","download_url":"https://codeload.github.com/GabrieleMaurina/while-machine/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GabrieleMaurina%2Fwhile-machine/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260474848,"owners_count":23014780,"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":["abstract-machine","python","turing","turing-complete","turing-machine","while","while-abstract-machine"],"created_at":"2024-12-05T19:15:02.887Z","updated_at":"2025-06-18T02:34:16.253Z","avatar_url":"https://github.com/GabrieleMaurina.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# while-machine\nWhile Abstract Machine implemented in python.\n\nWhile Machine is an abstract machine that is turing complete and can compute any partial recursive function. Find out more here https://en.wikipedia.org/wiki/Abstract_machine\n\nIts simpler brother is called Random Access Machine and you can find its implementation here https://github.com/GabrieleMaurina/random-access-machine\n\n### Install\n\nRun inside terminal:\n\n```python -m pip install while-machine```\n\n### Usage\n\nTo execute a ram source file:\n\n```python -m while_machine \u003cwhile source file\u003e \u003cinteger input\u003e```\n\nTo import it in your script:\n\n```python\nfrom while_machine import WhileMachine\n\ndata = 4\nprogram = 'begin inc 0 inc 0 end'\n\nwm = WhileMachine()\nresult = wm.compute(program, data)\n\nprint(result) # 2\n```\n\n### How it works\n\nA while machine has 21 registers numbered from 0, 1, 2..., the input is loaded on register 1 before the execution starts, the output is taken from register 0 when the execution ends.\n\n### Instructions:\n\nA while machine supports only 4 basic instructions:\n\nIncrement register k by 1:\n\n```inc k```\n\nDecrement register k by 1:\n\n```dec k```\n\nSet register k to zero:\n\n```zero k```\n\nWhile register k is not zero, do the following command:\n\n```while k```\n\nCommands can be grouped with:\n\n```\nbegin\n\t...\n\t...\n\nend\n```\n\n### Example\n\nAn example program that will double whatever input you give to the machine:\n\n```\nwhile 1\nbegin\n\tinc 0\n\tinc 0\n\tdec 1\nend\n```\n\n### RAM compiler\n\nIt is possible to compile a While program into a Ram program using the method compile_ram of the class WhileMachine. You can find an implementation of the ram machine here https://github.com/GabrieleMaurina/random-access-machine\n\nHere is an example of how to compile from While to RAM:\n\n```python\nfrom while_machine import WhileMachine\nimport sys\n\ndef main():\n\twm = WhileMachine()\n\twith open(sys.argv[1],'r') as while_prog, open(sys.argv[2],'w') as ram_prog:\n\t\twhile_prog = while_prog.read()\n\t\tcompiled = wm.compile_ram(while_prog)\n\t\tram_prog.write(compiled)\n\nif __name__ == '__main__':\n\tmain()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielemaurina%2Fwhile-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabrielemaurina%2Fwhile-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrielemaurina%2Fwhile-machine/lists"}