{"id":15684615,"url":"https://github.com/tenderlove/jit_buffer","last_synced_at":"2025-05-07T17:20:46.899Z","repository":{"id":56879151,"uuid":"468876648","full_name":"tenderlove/jit_buffer","owner":"tenderlove","description":"General purpose buffer for use with building JITs","archived":false,"fork":false,"pushed_at":"2023-10-13T23:41:25.000Z","size":31,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T06:04:36.283Z","etag":null,"topics":["jit","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tenderlove.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2022-03-11T19:32:08.000Z","updated_at":"2025-03-02T19:09:07.000Z","dependencies_parsed_at":"2024-10-23T18:09:21.913Z","dependency_job_id":"c7713298-e8e8-4af4-bbbb-3515e319ec82","html_url":"https://github.com/tenderlove/jit_buffer","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"d6d2dbedf3760b2d68f91250e29074ec07a7e19d"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Fjit_buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Fjit_buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Fjit_buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenderlove%2Fjit_buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tenderlove","download_url":"https://codeload.github.com/tenderlove/jit_buffer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252922308,"owners_count":21825641,"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":["jit","ruby"],"created_at":"2024-10-03T17:20:13.944Z","updated_at":"2025-05-07T17:20:46.866Z","avatar_url":"https://github.com/tenderlove.png","language":"Ruby","readme":"# JIT Buffer\n\nThis is a general purpose JIT Buffer object for building JITs in Ruby.\n\n## Usage\n\nCreate a JIT Buffer, then specify the size.  The JIT Buffer can only be\nwriteable or executable, but not both at the same time.\n\nIt starts life as executable, so you need to mark it writeable before writing.\n\n```ruby\n# Make a buffer of size 4096\nbuffer = JITBuffer.new 4096\n\n# Make writeable\nbuffer.writeable!\n\n# Write some stuff\nbuffer.write \"hello\"\n```\n\nIf you want to execute the JIT instructions, you need to mark it executable\nagain.\n\nHere is a full example that only works on ARM64:\n\n```ruby\nrequire \"jit_buffer\"\n\n# ARM instructions\ndef movz reg, imm\n  insn = 0b0_10_100101_00_0000000000000000_00000\n  insn |= (1 \u003c\u003c 31)  # 64 bit\n  insn |= (imm \u003c\u003c 5) # immediate\n  insn |= reg        # reg\nend\n\ndef ret xn = 30\n  insn = 0b1101011_0_0_10_11111_0000_0_0_00000_00000\n  insn |= (xn \u003c\u003c 5)\n  insn\nend\n\nbuffer = JITBuffer.new 4096\n\n# Assemble some instructions\ninsns = [\n  movz(0, 42),  # mov X0, 42\n  ret           # ret\n].pack(\"L\u003cL\u003c\")\n\n# Write the instructions to the JIT buffer\nbuffer.writeable!\nbuffer.write insns\nbuffer.executable!\n\n# Call the instructions.  We JIT'd a function that\n# returns an integer \"42\"\nfunc = buffer.to_function([], Fiddle::TYPE_INT)\nputs func.call # returns 42\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenderlove%2Fjit_buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftenderlove%2Fjit_buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenderlove%2Fjit_buffer/lists"}