Add wasm2elf: i32 WebAssembly to static x86-64 ELF compiler in MoonBit

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-21 00:53:04 -08:00
commit b8617c7aaa
22 files changed
+1219

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
///|
async fn main {
let args = @env.args()
// args[0] is the program name
if args.length() < 3 {
println("usage: wasm2elf <input.wasm> <output> [entry-export]")
@env.exit(2)
}
let wasm = @fs.read_binary(args[1])
let entry : String? = if args.length() > 3 { Some(args[3]) } else { None }
try {
let elf = @lib.compile(wasm, entry)
@fs.write_binary(args[2], elf, permission=0o755)
println("wrote \{args[2]} (\{elf.length()} bytes)")
} catch {
@lib.CompileError(msg) => {
println("error: \{msg}")
@env.exit(1)
}
err => {
println("error: \{err}")
@env.exit(1)
}
}
}
+11
View File
@@ -0,0 +1,11 @@
import {
"nandi/wasm2elf" @lib,
"moonbitlang/core/async/fs" @fs,
"moonbitlang/core/async",
"moonbitlang/core/env",
}
options(
"is-main": true,
"allow-experimental-packages": ["moonbitlang/core/async/fs", "moonbitlang/core/async"],
)