我是 moonbit 新手,最近在研究 wasm 组件相关的内容。我一直跟随着官网的博客写,如果不引用 math 中的 sin 那些,都没任何问题,也能通过 wasmtime 运行。
如果引用了 math 里面的内容,在转换为 wasm 组件时会报错。
wasm-tools component new target/wasm/release/build/gen/gen.wasm -o target/wasm/release/build/gen/gen.wasm
error: failed to encode a component from module
Caused by:
0: failed to decode world from module
1: module was not valid
2: failed to resolve import `math::tan`
3: module requires an import interface named `math`
我的 mbt 文件如下:
// Generated by `wit-bindgen` 0.34.0.
fn sin(x : Double) -> Double = "math" "sin"
fn cos(x : Double) -> Double = "math" "cos"
fn tan(x : Double) -> Double = "math" "tan"
pub fn walk( ast : AstType ) -> AstType {
let mut sum: Double = 0.0
for i = 0UL; i < ast.end; i = i + 1 {
sum += tan(cos(sin(i.to_double())));
}
return AstType::{ ..ast, content: (sum.floor().to_int64().reinterpret_as_uint64()) };
}
请问有相关的资料可以查看吗?