{"id":50850379,"url":"https://github.com/akeit0/moonbit2csharp","last_synced_at":"2026-06-14T13:32:28.871Z","repository":{"id":361562956,"uuid":"1253097643","full_name":"akeit0/moonbit2csharp","owner":"akeit0","description":"A transpiler from MoonBit to C#. However, it is already close to being usable as a backend.","archived":false,"fork":false,"pushed_at":"2026-06-02T03:37:08.000Z","size":1118,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-14T13:32:24.099Z","etag":null,"topics":["csharp","moonbit"],"latest_commit_sha":null,"homepage":"","language":"C#","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/akeit0.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-29T06:38:30.000Z","updated_at":"2026-06-04T08:31:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/akeit0/moonbit2csharp","commit_stats":null,"previous_names":["akeit0/moonbit2csharp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/akeit0/moonbit2csharp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akeit0%2Fmoonbit2csharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akeit0%2Fmoonbit2csharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akeit0%2Fmoonbit2csharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akeit0%2Fmoonbit2csharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akeit0","download_url":"https://codeload.github.com/akeit0/moonbit2csharp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akeit0%2Fmoonbit2csharp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34323994,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"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":["csharp","moonbit"],"created_at":"2026-06-14T13:32:28.220Z","updated_at":"2026-06-14T13:32:28.857Z","avatar_url":"https://github.com/akeit0.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MoonBit2CSharp\n\nMoonBit2CSharp is a prototype MoonBit-to-C# transpiler with a compiler-style\npipeline. The current implementation is centered on the vnext frontend and C#\nbackend.\n\n```text\nMoonBit source\n  -\u003e vnext MoonBit frontend\n  -\u003e semantic JSON IR\n  -\u003e C# backend emitter\n  -\u003e generated C# project\n  -\u003e dotnet build/run\n```\n\n## Repository layout\n\n```text\ncsharp/\n  MoonBit2CSharp.Cli/          CLI entry point\n  MoonBit2CSharp.Transpiler/   project orchestration, moon check, cache, frontend bridge\n  MoonBit2CSharp.VNext.Backend/ semantic IR to C# emitter\n  MoonBit2CSharp.Backend/      project file helpers and legacy backend pieces\n  MoonBit.Runtime/             runtime project used by generated vnext projects\n\nmoonbit/\n  src/vnext/                   MoonBit frontend implementation\n  src/vnext_cli/               MoonBit CLI wrapper that emits semantic JSON IR\n  builtin/overrides/           C#-targeted MoonBit builtin overrides\n\nmoonbitlang/\n  core/                        official MoonBit core sources used as declarations/inputs\n\nsamples/\n  simple_project/              small integration sample\n  moonbit-project/             larger dependency-oriented sample\n\nscripts/\n  vnext-pipeline-self-check.ps1 generated C# pipeline proof tool\n\nartifacts/\n  vnext_pipeline_csharp_dev/   generated C# version of the vnext frontend\n```\n\n## Default transpilation path\n\nThe normal CLI path uses the MoonBit implementation of the vnext frontend:\n\n```text\nMoonBit project\n  -\u003e moon check\n  -\u003e moon -C moonbit run ./src/vnext_cli\n  -\u003e semantic JSON IR\n  -\u003e MoonBit2CSharp.VNext.Backend\n  -\u003e _build/csharp\n  -\u003e dotnet build/run\n```\n\nExample:\n\n```powershell\ndotnet run --project csharp\\MoonBit2CSharp.Cli -- build samples\\simple_project --no-cache\ndotnet run --project csharp\\MoonBit2CSharp.Cli -- run samples\\simple_project\n```\n\nFor local development in this repository, prefer `dnrelay` for CLI runs because it\ncaptures logs under `csharp/.dnrelay/logs`:\n\n```powershell\ndnrelay run --project csharp\\MoonBit2CSharp.Cli\\MoonBit2CSharp.Cli.csproj -- build samples\\simple_project --no-cache\n```\n\n## Optional generated frontend path\n\nThe CLI can optionally use a generated C# version of the vnext frontend instead\nof invoking `moonbit/src/vnext_cli`.\n\n```powershell\ndotnet run --project csharp\\MoonBit2CSharp.Cli -- build samples\\simple_project --no-cache --vnext-frontend csharp:artifacts\\vnext_pipeline_csharp_dev\\frontend.csproj\n```\n\nThis path is intended for self-hosting work:\n\n```text\nMoonBit project\n  -\u003e moon check\n  -\u003e temporary generated frontend host\n  -\u003e artifacts/vnext_pipeline_csharp_dev/frontend.csproj\n  -\u003e semantic JSON IR\n  -\u003e MoonBit2CSharp.VNext.Backend\n  -\u003e _build/csharp\n```\n\nThe generated frontend host is created under the transpiler cache directory. It\nbuilds separately and then runs with `--no-build` so stdout remains pure JSON IR.\n\nFor direct runner or NativeAOT usage, use the standalone runner project at\n`csharp/MoonBit2CSharp.VNextFrontendRunner`. It is intentionally not part of\n`MoonBit2CSharp.slnx` because it depends on the generated frontend project:\n\n```powershell\ndotnet publish csharp\\MoonBit2CSharp.VNextFrontendRunner\\MoonBit2CSharp.VNextFrontendRunner.csproj `\n  -c Release `\n  -p:GeneratedVNextFrontendProject=$PWD\\artifacts\\vnext_pipeline_csharp_dev\\frontend.csproj `\n  -o artifacts\\vnext_pipeline_runner\n\ndotnet run --project csharp\\MoonBit2CSharp.Cli -- run samples\\moonbit-project `\n  --vnext-frontend csharp:artifacts\\vnext_pipeline_runner\\MoonBit2CSharp.VNextFrontendRunner.dll\n```\n\nNativeAOT is the same runner published as an executable:\n\n```powershell\ndotnet publish csharp\\MoonBit2CSharp.VNextFrontendRunner\\MoonBit2CSharp.VNextFrontendRunner.csproj `\n  -c Release `\n  -r win-x64 `\n  -p:PublishAot=true `\n  -p:GeneratedVNextFrontendProject=$PWD\\artifacts\\vnext_pipeline_csharp_dev\\frontend.csproj `\n  -o artifacts\\vnext_pipeline_runner_aot\n```\n\n## Caching\n\n`run` and `build` use a run-project cache. If source inputs, MoonBit manifests,\nbuiltin/declaration sources, runtime assemblies, or the selected generated\nfrontend project have not changed, the CLI can skip `moon check` and\ntranspilation and run the generated project with `--no-build`.\n\nUseful options:\n\n```text\n--no-cache\n--cache-dir \u003cdir\u003e\n--release\n--vnext-frontend moon|csharp:\u003cexe|dll|csproj\u003e\n```\n\n`--release` forwards to generated project execution/build as `-c Release`.\n\n## Output project shape\n\nThe generated C# project is an executable only for main-package or single-file\ntargets. Non-main package targets are generated as libraries.\n\nMoonBit main-package detection uses package/module metadata, including:\n\n```moonbit\noptions(\n  \"is-main\": true,\n)\n```\n\nGenerated projects no longer reference the old `MoonBit.Runtime` project by\ndefault. Runtime support needed by the emitted code is generated into\n`moonbit_runtime.g.cs`, and generated package/type names follow MoonBit package\nstructure rather than hard-coded `MoonBit*` type prefixes.\n\n## MoonBit frontend notes\n\nThe vnext frontend resolves:\n\n```text\nsource files + moon.pkg/moon.mod manifests\n  -\u003e parsed AST\n  -\u003e declarations/import index\n  -\u003e type/function/trait resolution\n  -\u003e reachable semantic IR\n```\n\nImportant implementation details:\n\n- `moon.mod` and `moon.mod.json` are both supported.\n- `moon.mod` uses MoonBit manifest syntax, not JSON.\n- `options(source: \"src\")`, `options(\"source\": \".\")`, `options(\"source\": \"\")`, and JSON `source` values are handled by module/package discovery.\n- C# target builtin behavior is primarily modeled in MoonBit sources and builtin overrides; C# intrinsics should remain the small boundary for operations that cannot be expressed in MoonBit.\n- Attribute parsing is lexer-level generic. Parser logic interprets attributes such as `#alias`, `#intrinsic`, `#cfg`, and `#valtype`.\n- CRLF attribute lines are supported; `#cfg(...)` token text must not include `\\r`.\n\n## Generated C# pipeline proof\n\nUse the self-check script to prove that the generated C# frontend can emit the\nsame semantic JSON as the MoonBit `vnext_cli` for small proof cases:\n\n```powershell\npowershell -NoProfile -ExecutionPolicy Bypass -File scripts\\vnext-pipeline-self-check.ps1\n```\n\nThe script:\n\n- builds `artifacts/vnext_pipeline_csharp_dev/frontend.csproj`;\n- creates a temporary proof runner;\n- runs proof cases through the generated C# pipeline;\n- runs the same cases through MoonBit `vnext_cli`;\n- compares normalized JSON.\n\n## Regenerating the generated frontend artifact\n\nRegenerate the current development C# frontend artifact with:\n\n```powershell\ndnrelay run --project csharp\\MoonBit2CSharp.Cli\\MoonBit2CSharp.Cli.csproj -- --project artifacts\\vnext_pipeline_csharp_dev --csproj frontend --no-cache moonbit\\src\\vnext\\pipeline\n```\n\nThen run:\n\n```powershell\npowershell -NoProfile -ExecutionPolicy Bypass -File scripts\\vnext-pipeline-self-check.ps1\ndnrelay run --project csharp\\MoonBit2CSharp.Cli\\MoonBit2CSharp.Cli.csproj -- build samples\\simple_project --no-cache --vnext-frontend csharp:artifacts\\vnext_pipeline_csharp_dev\\frontend.csproj\n```\n\n## Development checks\n\nCommon focused checks:\n\n```powershell\nmoon test ./src/vnext/syntax\ndnrelay run --project csharp\\MoonBit2CSharp.Cli\\MoonBit2CSharp.Cli.csproj -- build samples\\simple_project --no-cache\ndnrelay run --project csharp\\MoonBit2CSharp.Cli\\MoonBit2CSharp.Cli.csproj -- build samples\\simple_project --no-cache --vnext-frontend csharp:artifacts\\vnext_pipeline_csharp_dev\\frontend.csproj\n```\n\nRun `moon` commands from the `moonbit/` module root when using package-relative\npaths such as `./src/vnext/syntax`.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakeit0%2Fmoonbit2csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakeit0%2Fmoonbit2csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakeit0%2Fmoonbit2csharp/lists"}