MoonBit 最新动态:MoonBit 引入实验性的测试覆盖率统计工具

MoonBit更新

支持 array.iter intrinsic 并且已经对标准库中的函数进行标注,从而可以在特定情况下将循环进行内联,以提升运行效率

java 复制代码
/// @intrinsic %array.iter
pub fn iter[T](self : Array[T], f : (T) -> Unit) -> Unit {
  for i = 0; i < self.length(); i = i + 1 {
    f(self[i])
  }
}

工具链更新

1. 支持实验性的测试覆盖率统计工具

  • 工具已经实验性支持 MoonBit Core CI

  • 我们正在优化面向用户的接口

2. Alerts pragmas 中默认启用 deprecated 类别的警告,默认关闭 unsafe/throw/raise 类别的警告

3. 修复 moonfmt 的相关问题

  • 修复带负号的字面量打印后注释错位的问题

  • 修复带负号字面量打印后括号消失的问题

4. moonrun 支持 UTF-16 字符串的打印

构建系统更新

1. expect test 支持处理 Unicode 字符

2. moon.pkg.json 中支持自定义函数导出名称

moon.pkg.json 中支持使用 ["link"][BACKEND]["exports] 字段自定义函数导出名称,并且默认不再导出所有的 pub 函数,必须要在 exports 中显式指定。此外,现在支持通过设置 link 字段链接非 main 包。

例如使用 moon new hello 创建一个新项目,其目录结构为:

rust 复制代码
.
├── README.md
├── lib
│   ├── hello.mbt
│   ├── hello_test.mbt
│   └── moon.pkg.json
├── main
│   ├── main.mbt
│   └── moon.pkg.json
└── moon.mod.json

在过去,执行 moon build,只有 main 包会生成 wasm 文件。

现在,在 moon.pkg.json 中支持 link 字段,可以对非 main 包生成 wasm 文件。link 字段的内容可以是一个布尔值:

rust 复制代码
{
  "link": true // 表示当前包需要被链接
}

或者是一个对象,可以给不同的后端如 wasm 或者 wasm-gc ,设定链接选项。目前只支持 exports 选项,exports 是一个字符串数组,包含需要导出的函数及其需要导出的名称:

rust 复制代码
{
  "link": {
    "wasm": {
      "exports": [
        "hello" // 这里将函数 hello 导出为 hello,
      ]
    },
    "wasm-gc": {
      "exports": [
        "hello:hello_wasm_gc" // 这里将函数 hello 导出为 hello_wasm_gc
      ]
    }
  }
}

如果将 lib/moon.pkg.json 中的内容修改为:

rust 复制代码
{
  "link": {
    "wasm": {
      "exports": [
        "hello"
      ]
    }
  }
}

然后执行 moon build --output-wat,可以观察到输出的 target/wasm/release/build/lib/lib.wat 中包含如下内容:

rust 复制代码
(func $$username/hello/lib.hello.fn/1 (export "hello") (result i32)
 (i32.const 10000))

其中的 (export "hello") 表示配置生效了。

相关推荐
wflynn11 小时前
GitHub 日榜趋势速报 | 2026-11-14
开源·github
一条Go12 小时前
接收方合并去重:同一个人为什么只该收到一次通知
后端·架构·github
guuguo13 小时前
Gemini 4 屠榜后连夜切到 Antigravity,顺手用一行命令搞定全中文界面与思考
人工智能·开源·github
为思念酝酿的痛14 小时前
Git基本操作
git·github
芯门15 小时前
GitHub「用好 AI」工具生态全景:2409 个仓库 Star 排行调研(2026-11)
人工智能·github
2分钟速写快排1 天前
孔乙己的茴字有多少种写法?|AI 对话实时通信的三种实现
前端·javascript·github
wangruofeng1 天前
同一行代码,百种渲染:Asuka、React Native 与 Flutter 跨平台渲染机制深度拆解
前端·github
杨凯凡1 天前
IT日报|2026-11-13:GitHub 大规模凭据攻击、Signal 形式化验证、Claude 新模型与 AI 安全诉讼
人工智能·安全·github
liuzheng66211 天前
我给 Agent 测试注入了 72 种谎话,它抓住了 44 种
github
feasibility.2 天前
一物降一物?AI逆向没有终局:REA拆App,BLA设套,LASIK清场
人工智能·爬虫·github·逆向·skill·rea