{"id":15056335,"url":"https://github.com/daniel-boll/beam-sys","last_synced_at":"2025-09-03T01:41:47.546Z","repository":{"id":214809059,"uuid":"737408022","full_name":"Daniel-Boll/beam-sys","owner":"Daniel-Boll","description":"🔦 Rust library designed for the creation and manipulation of BEAM (Erlang VM) bytecode","archived":false,"fork":false,"pushed_at":"2023-12-30T23:34:47.000Z","size":446,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T04:07:27.456Z","etag":null,"topics":["beam","codegen","erlang","erlang-beam","erlang-vm","rust"],"latest_commit_sha":null,"homepage":"https://beam-sys.org","language":"Rust","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/Daniel-Boll.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-12-30T23:19:41.000Z","updated_at":"2025-02-15T21:32:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"b214d64f-6b21-4cad-8173-2422713c3d3d","html_url":"https://github.com/Daniel-Boll/beam-sys","commit_stats":null,"previous_names":["daniel-boll/beam-sys"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Daniel-Boll/beam-sys","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel-Boll%2Fbeam-sys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel-Boll%2Fbeam-sys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel-Boll%2Fbeam-sys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel-Boll%2Fbeam-sys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Daniel-Boll","download_url":"https://codeload.github.com/Daniel-Boll/beam-sys/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Daniel-Boll%2Fbeam-sys/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273377161,"owners_count":25094528,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["beam","codegen","erlang","erlang-beam","erlang-vm","rust"],"created_at":"2024-09-24T21:49:58.755Z","updated_at":"2025-09-03T01:41:47.523Z","avatar_url":"https://github.com/Daniel-Boll.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e🔦 beam-sys\u003c/h1\u003e\n\n\u003cimg align=\"left\" src=\"./assets/logo.png\" width=200 /\u003e\n\n\u003e A Rust library designed for the creation and manipulation of BEAM (Erlang VM) bytecode\n\nThe `beam_sys` project is a personal exploration and it try to provide an intuitive API to generate `.beam` files, abstracting the intricacies of lower-level details. This project is inspired by the [Tsoding](https://github.com/tsoding) [bada project](https://github.com/tsoding/bada) and incorporates ideas from the [`llvm-sys`](https://lib.rs/crates/llvm-sys) and [`cranelift`](https://lib.rs/crates/cranelift) crates.\n\n\u003cbr /\u003e\n\n## Features\n\n- **Shared Context Management:** Uses a shared context (`beam_sys::context::Context`) for enhanced code generation.\n- **High-Level Abstractions:** Offers high-level constructs to build functions, manage export tables, and handle bytecode encoding.\n- **Erlang VM Compatibility:** Generated bytecode seamlessly integrates with Erlang systems.\n\n## Usage Examples\n\n### Basic Example\n\nTo create a `.beam` file:\n\n```rust\nuse beam_sys;\n\nfn main() {\n    let module = beam_sys::context::Context::create(\"sys\".to_string());\n    module.add_basic_bif();\n\n    let code = module.code();\n    let mut function_block = code.build_function_block(\"empty\".to_string(), 0);\n    {\n        function_block.build_return();\n    }\n\n    let function_metadata = function_block.function_metadata();\n    module.export_table_mut().export_function(function_metadata);\n\n    std::fs::write(\"sys.beam\", module.encode()).unwrap();\n}\n```\n\nVerify with Erlang shell:\n\n```erl\n1\u003e beam_disasm:file(sys).\n{beam_file,sys,\n           [{'-',0,2}],\n           [],[],\n           [{function,empty,0,2,\n                      [{label,1},\n                       {line,1},\n                       {func_info,{atom,sys},{atom,empty},0},\n                       {label,2},\n                       return]}]}\n```\n\n### Context Reusability Example\n\nDemonstrating the shared context's reusability across different functions:\n\n```rust\nuse beam_sys;\n\nfn main() {\n    initialize_module();\n    add_function();\n    // ... more operations\n}\n\nfn initialize_module() {\n    let module = beam_sys::context::Context::create(\"sys\".to_string());\n    module.add_basic_bif();\n    // ... additional initializations\n}\n\nfn add_function() {\n    let module = beam_sys::context::Context::get(\"sys\".to_string());\n    let code = module.code();\n    let mut function_block = code.build_function_block(\"test_func\".to_string(), 0);\n    {\n        // ... build the function\n        function_block.build_return();\n    }\n\n    let function_metadata = function_block.function_metadata();\n    module.export_table_mut().export_function(function_metadata);\n}\n```\n\nIn this example, the shared context is created in `initialize_module` and reused in `add_function` without the need to pass the context around, simplifying the API usage.\n\n## Development Status\n\n`beam_sys` is in active development. The API is evolving and may undergo significant changes.\n\n## Contributions\n\nContributions are welcome! Feel free to submit pull requests or open issues to propose features or discuss bugs.\n\n## License\n\nThis project is under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-boll%2Fbeam-sys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel-boll%2Fbeam-sys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-boll%2Fbeam-sys/lists"}