更新目录
· WASM 后端支持将 extern type T 存储到数组等数据结构中
· C FFI 支持 borrow
· type 和 trait支持了 #deprecated attribute
· FFI 的 extern 函数的声明添加了后端一致性的检查
· 新增了对 .mbt.md 的测试和调试支持
· moon info --package 支持模糊匹配包名
MoonBit 更新
1、 WASM 后端支持 extern type T 存储到数组等数据结构中
在 FFI 边界(导入/导出函数的签名)上,extern type T 依然会被编译成 WASM 的 externref 类型。2、 C FFI 支持 borrow现在,你可以通过在extern "c"的函数上方指定#borrow(args, ...) 来修改 C FFI 对参数的生命周期管理方式,其中args是 C FFI 的参数名字的一个子集。
默认情况下,C FFI 需要负责把参数释放掉,这意味着,绑定 C FFI 时,往往需要写一个辅助函数来释放掉参数:
kotlin
fn open(path : Bytes, flags : Int, mode : Int) -> Int = "open_wrapper"
arduino
int open_wrapper(moonbit_bytes_t path, int flags, int mode) {
int rc = open(path, flags, mode);
moonbit_decref(path)
return rc;
}
使用borrow attribute,我们可以指示 MoonBit 对 C FFI 函数调用不生成引用计数指令,从而不用再写辅助函数,可以直接绑定 C 库中的函数:
kotlin
#borrow(path)
fn open(path : Bytes, flags : Int, mode : Int) -> Int = "open"
由于 #borrow 标记,MoonBit 会自动在调用完 open 后释放掉 path3、type&trait支持#deprecated attribute我们下次发布将移除旧的 pragmas 机制,建议使用 attribute 替代:
csharp
/// the @alert pragmas is deprecated
/// @alert deprecated "message"
fn f() -> Unit {...}
/// use attribute #deprecated instead
#deprecated("message")
fn f() -> Unit {...}
4、 FFI 的 extern 函数声明添加后端一致性检查例如下列函数会在非 Native 后端构建的时候报错。
kotlin
extern "c" fn open(path : Bytes, flags : Int, mode : Int) -> Int = "open"
工具链更新
1、从本周开始,工具链的发布从周一改到周四。
2、修复了 test explorer 的 bug,并新增了对 .mbt.md 的测试和调试支持:

可通过开启以下设置来允许在 Markdown 文件中设置断点:
Settings > Debug: Allow Breakpoint Everywhere

3、moon info --package 支持模糊匹配包名。