{"id":21180205,"url":"https://github.com/phucvin/vmgen-langs","last_synced_at":"2026-05-18T06:38:57.746Z","repository":{"id":260356310,"uuid":"881061129","full_name":"phucvin/vmgen-langs","owner":"phucvin","description":"Interpreted programming languages using vmgen","archived":false,"fork":false,"pushed_at":"2024-11-27T05:11:38.000Z","size":417,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T12:08:54.437Z","etag":null,"topics":["assembly","interpreter","programming-language","register-vm","stack-vm","virtual-machine","vm","vmgen"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phucvin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-10-30T21:07:42.000Z","updated_at":"2024-11-27T05:11:42.000Z","dependencies_parsed_at":"2024-11-17T01:16:19.833Z","dependency_job_id":"bacd03e2-10ce-4f2a-89bd-b54ce7a14079","html_url":"https://github.com/phucvin/vmgen-langs","commit_stats":null,"previous_names":["phucvin/vmgen-langs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucvin%2Fvmgen-langs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucvin%2Fvmgen-langs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucvin%2Fvmgen-langs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phucvin%2Fvmgen-langs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phucvin","download_url":"https://codeload.github.com/phucvin/vmgen-langs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243632408,"owners_count":20322382,"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":["assembly","interpreter","programming-language","register-vm","stack-vm","virtual-machine","vm","vmgen"],"created_at":"2024-11-20T17:41:55.329Z","updated_at":"2026-05-18T06:38:52.725Z","avatar_url":"https://github.com/phucvin.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vmgen-langs\nInterpreted programming languages using vmgen\n\n## Build\n\nBuild vmgen:\n```\n$ mkdir tmp01 \u0026\u0026 cd tmp01\n$ git clone https://github.com/phucvin/gforth\n$ cd gforth\n$ source ./install-deps.sh\n$ vmgen --help\n$ sudo apt update \u0026\u0026 sudo apt install flex -y\n$ cd vmgen-myex01\n$ make\n$ time ./mini fib.mini\nresult = 102334155\nreal    0m2.213s\n```\n\nBuild stack-assembly-01:\n```\n$ cd stack-assembly-01\n$ make vm \u0026\u0026 time ./vm.out examples/fib01.asm\n\nvm assembly:\n0x643741b3f2a0: push_l i0=110188488291016 \n0x643741b3f2b0: s_pljl _IP0=0x6  _IP1=0x643741b3f2d0 \n0x643741b3f2c8: end\n0x643741b3f2d0: dup\n0x643741b3f2d8: push_l i0=2 \n0x643741b3f2e8: jump_l_if_lt target0=0x643741b3f3a0 \n0x643741b3f2f8: dup\n0x643741b3f300: push_l i0=1 \n0x643741b3f310: sub\n0x643741b3f318: push_l i0=110188488291136 \n0x643741b3f328: swap\n0x643741b3f330: jump_l target0=0x643741b3f2d0 \n0x643741b3f340: swap\n0x643741b3f348: push_l i0=2 \n0x643741b3f358: sub\n0x643741b3f360: push_l i0=110188488291208 \n0x643741b3f370: swap\n0x643741b3f378: jump_l target0=0x643741b3f2d0 \n0x643741b3f388: add\n0x643741b3f390: swap\n0x643741b3f398: jump\n0x643741b3f3a0: swap\n0x643741b3f3a8: jump\n\nvm run:\nreturn code: 102334155\n\nreal    0m3.873s\n```\n\nBuild register-assembly-01:\n```\n$ cd register-assembly-01\n$ make vm \u0026\u0026 time ./vm.out examples/fib01.asm\n\nvm assembly:\n0x629a870822a0: set_rl i0=0  i1=40 \n0x629a870822b8: s_call0 _IP0=0x629a870822d0  _IP1=0x629a870822e0 \n0x629a870822d0: halt_r i0=0 \n0x629a870822e0: jump_l_if_r_lt_l target0=0x629a870823d0  i0=0  i1=2 \n0x629a87082300: push_r i0=0 \n0x629a87082310: sub_rrl i0=0  i1=0  i2=1 \n0x629a87082330: s_call0 _IP0=0x629a87082348  _IP1=0x629a870822e0 \n0x629a87082348: pop_r i0=1 \n0x629a87082358: push_r i0=0 \n0x629a87082368: sub_rrl i0=0  i1=1  i2=2 \n0x629a87082388: s_call0 _IP0=0x629a870823a0  _IP1=0x629a870822e0 \n0x629a870823a0: pop_r i0=1 \n0x629a870823b0: add_rrr i0=0  i1=0  i2=1 \n0x629a870823d0: jump_tos\n\nvm run:\nreturn code: 102334155\n\nreal    0m2.135s\n```\n\nBuild variable-assembly-01:\n```\n$ cd variable-assembly-01\n$ make vm \u0026\u0026 time ./vm.out examples/fib01.asm\n\nvm assembly:\n0x5d2f649c92a0: set_rl i0=0  i1=40 \n0x5d2f649c92b8: s_call0 _IP0=0x9  _IP1=0x5d2f649c92d8  _IP2=0x5d2f649c92e8 \n0x5d2f649c92d8: halt_r i0=0 \n0x5d2f649c92e8: jump_l_if_r_lt_l target0=0x5d2f649c9410  i0=0  i1=2 \n0x5d2f649c9308: alloc_v i0=3 \n0x5d2f649c9318: set_vr i0=0  i1=0 \n0x5d2f649c9330: set_vr i0=1  i1=9 \n0x5d2f649c9348: sub_rvl i0=0  i1=0  i2=1 \n0x5d2f649c9368: s_call0 _IP0=0x9  _IP1=0x5d2f649c9388  _IP2=0x5d2f649c92e8 \n0x5d2f649c9388: set_vr i0=2  i1=0 \n0x5d2f649c93a0: sub_rvl i0=0  i1=0  i2=2 \n0x5d2f649c93c0: s_call0 _IP0=0x9  _IP1=0x5d2f649c93e0  _IP2=0x5d2f649c92e8 \n0x5d2f649c93e0: add_rrv i0=0  i1=0  i2=2 \n0x5d2f649c9400: jump_v_dealloc i0=1 \n0x5d2f649c9410: jump_r i0=9 \n\nvm run:\nreturn code: 102334155\n\nreal    0m2.690s\n```\n\nBuild stack-assembly-03:\n```\n$ cd stack-assembly-03\n$ make vm \u0026\u0026 time ./vm.out examples/fib01.asm\nvm assembly:\n0x6075598892a0: push_l i0=40 \n0x6075598892b0: call1 target0=0x6075598892d0 \n0x6075598892c0: halt_d i0=1 \n0x6075598892d0: jump_l_if_d_lt_l target0=0x607559889360  i0=1  i1=2 \n0x6075598892f0: sub_dl i0=1  i1=1 \n0x607559889308: call1 target0=0x6075598892d0 \n0x607559889318: sub_dl i0=2  i1=2 \n0x607559889330: call1 target0=0x6075598892d0 \n0x607559889340: add\n0x607559889348: ret_dd i0=3  i1=1 \n0x607559889360: ret_dd i0=2  i1=1 \n\nvm run:\nreturn code: 102334155\n\nreal    0m1.822s\nuser    0m1.812s\nsys     0m0.004s\n```\nNote that this one is fastest so far probably because it doesn't use frame pointer like in stack-assembly-04.\nBut generating high-level code to this is harder since it uses delta instead of absolute index for accessing local variables.\n\nBuild stack-assembly-04:\n```\n$ cd stack-assembly-04\n$ make vm \u0026\u0026 time ./vm.out examples/fib01.asm\nvm assembly:\n0x5b63221792a0: push_l i0=40 \n0x5b63221792b0: call1 target0=0x5b63221792c8 \n0x5b63221792c0: halt\n0x5b63221792c8: jump_l_if_f_lt_l target0=0x5b6322179340  i0=0  i1=2 \n0x5b63221792e8: sub_fl i0=0  i1=1 \n0x5b6322179300: call1 target0=0x5b63221792c8 \n0x5b6322179310: sub_fl i0=0  i1=2 \n0x5b6322179328: call1 target0=0x5b63221792c8 \n0x5b6322179338: add\n0x5b6322179340: ret\n\nvm run:\nreturn code: 102334155\n\nreal    0m2.617s\nuser    0m2.590s\nsys     0m0.000s\n```\n\n## Appendix\n\nLearn Vmgen:\n- http://www.complang.tuwien.ac.at/anton/vmgen/\n- See commit history of `learn-vmgen-01`\n```\n$ cd learn-vmgen-01\n$ make vm \u0026\u0026 time ./vm.out\n\nvm assembly:\n0x59ec82ebd2a0: set_rl i0=0  i1=40 \n0x59ec82ebd2b8: s_call0 _IP0=0x9  _IP1=0x59ec82ebd2d8  _IP2=0x59ec82ebd2e8 \n0x59ec82ebd2d8: end_r i0=0 \n0x59ec82ebd2e8: jump_l_if_r_lt_l target0=0x59ec82ebd410  i0=0  i1=2 \n0x59ec82ebd308: alloc_v i0=3 \n0x59ec82ebd318: set_vr i0=0  i1=0 \n0x59ec82ebd330: set_vr i0=1  i1=9 \n0x59ec82ebd348: sub_rvl i0=0  i1=0  i2=1 \n0x59ec82ebd368: s_call0 _IP0=0x9  _IP1=0x59ec82ebd388  _IP2=0x59ec82ebd2e8 \n0x59ec82ebd388: set_vr i0=2  i1=0 \n0x59ec82ebd3a0: sub_rvl i0=0  i1=0  i2=2 \n0x59ec82ebd3c0: s_call0 _IP0=0x9  _IP1=0x59ec82ebd3e0  _IP2=0x59ec82ebd2e8 \n0x59ec82ebd3e0: add_rrv i0=0  i1=0  i2=2 \n0x59ec82ebd400: jump_v_dealloc i0=1 \n0x59ec82ebd410: jump_r i0=9\n\nvm run:\nreturn code: 102334155\n\nreal    0m2.455s\n```\n\nPerformance of fib(40) in other interpreters:\n```\n$ time tmp02/wasm3-cosmopolitan.com --func fib tmp02/fib32.wasm 40\nResult: 102334155\nreal    0m4.991s\n\n$ time luajit -joff tmp02/fib01.lua\n102334155\nreal    0m4.504s\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucvin%2Fvmgen-langs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphucvin%2Fvmgen-langs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphucvin%2Fvmgen-langs/lists"}