{"id":19773080,"url":"https://github.com/r-unic/simple-vm","last_synced_at":"2026-06-07T22:32:51.773Z","repository":{"id":160901921,"uuid":"635698251","full_name":"R-unic/simple-vm","owner":"R-unic","description":"A simple user-defined bytecode VM","archived":false,"fork":false,"pushed_at":"2024-07-07T19:22:41.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-26T04:54:59.108Z","etag":null,"topics":["bytecode","crystal","virtual-machine","vm"],"latest_commit_sha":null,"homepage":"","language":"Crystal","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/R-unic.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":"2023-05-03T09:06:40.000Z","updated_at":"2024-07-07T19:22:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"e16f63f5-7595-41c4-aeb2-463d344f4015","html_url":"https://github.com/R-unic/simple-vm","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-unic%2Fsimple-vm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-unic%2Fsimple-vm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-unic%2Fsimple-vm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/R-unic%2Fsimple-vm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/R-unic","download_url":"https://codeload.github.com/R-unic/simple-vm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241104145,"owners_count":19910381,"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":["bytecode","crystal","virtual-machine","vm"],"created_at":"2024-11-12T05:08:34.160Z","updated_at":"2025-11-22T22:03:44.162Z","avatar_url":"https://github.com/R-unic.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-vm\n\n### boolean logic\n```rb\nvm = VM.new [ # 10 \u003e 20\n  Op::PUSH, 0,\n  Op::PUSH, 1,\n  Op::GT,\n  Op::ECHO,\n  Op::END\n], [10, 20]\nvm.run # =\u003e 0.0 (false)\n```\n\n### simple arithmetic\n```rb\nvm = VM.new [ # 14 + 6 - 12 * 3\n  Op::PUSH, 0,\n  Op::PUSH, 1,\n  Op::PUSH, 2,\n  Op::PUSH, 3,\n  Op::MUL,\n  Op::SUB,\n  Op::ADD,\n  Op::ECHO,\n  Op::END\n], [14, 6, 12, 3]\nvm.run # =\u003e -16.0\n```\n\n### arrays \u0026 indexing\n```rb\nvm = VM.new [ # a = [\"hello\", \"world\"]; puts a[1]\n  Op::PUSH, 0,\n  Op::STORE, 1,\n  Op::LOAD, 1,\n  Op::INDEX, 2,\n  Op::ECHO,\n  Op::END\n], [[\"hello\", \"world\"] of BaseValidType, \"a\", 1_i64] of ValidType\n\nvm.run # =\u003e world\n```\n\n### closures\n```rb\ndo_something = VM.new [ # fn do_something(b) { echo a; echo b; }\n  Op::LOAD, 0,\n  Op::ECHO,\n  Op::LOAD, 1,\n  Op::ECHO,\n  Op::END\n], [\"a\", \"b\"] of Types::ValidType\n\nvm = VM.new [ # a = \"something\" (define do_something) do_something(\"some value\")\n  Op::PUSH, 0, # \"something\"\n  Op::STORE, 1, # a = \"something\"\n\n  # start of function def, first values are arguments. second to last value is the function body (as it's own VM).\n  Op::PUSH, 4, # \"b\"\n  Op::PUSH, 2, # VM\u003cdo_something\u003e\n  Op::PROC, 3, 1, # create fn with name at address 3 (\"func\"), and 1 argument (\"b\")\n\n  Op::PUSH, 5, # \"some value\"\n  Op::CALL, 2, 1, # lookup and call closure name at address 2 with 1 argument (\"some value\")\n  Op::END\n], [\n  \"something\", \"a\",\n  do_something \"func\", \"b\",\n  \"some value\"\n] of Types::ValidType\n\nvm.run # =\u003e something some value\n```\n\n### fibonacci sequence\n```rb\nfib = VM.new [\n  Op::LOAD, 0,\n  Op::PUSH, 1,\n  Op::LT,\n\n  Op::JZ, 10, # if false jump to 10 (noop)\n  Op::LOAD, 0, # n\n  Op::RETURN,\n\n  Op::NOOP, # else (this is unnecessary, just for readability)\n  Op::LOAD, 0, # n\n  Op::PUSH, 2, # 1\n  Op::SUB, # n - 1\n  Op::CALL, 3, 1, # fib(n - 1)\n\n  Op::LOAD, 0, # n\n  Op::PUSH, 1, # 2\n  Op::SUB, # n - 2\n  Op::CALL, 3, 1, # fib(n - 2)\n  Op::ADD, # fib(n - 1) + fib(n - 2)\n\n  Op::RETURN\n], [\"n\", 2, 1, \"fib\"] of Types::ValidType\n\nvm = VM.new [\n  Op::PUSH, 2,\n  Op::PUSH, 0,\n  Op::PROC, 1, 1,\n\n  Op::PUSH, 3,\n  Op::CALL, 1, 1,\n  Op::ECHO,\n  Op::END\n], [fib, \"fib\", \"n\", 25] of Types::ValidType\n\nvm.run # 75025\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-unic%2Fsimple-vm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-unic%2Fsimple-vm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-unic%2Fsimple-vm/lists"}