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") 表示配置生效了。

相关推荐
xianyinsuifeng5 小时前
FastAPI + OpenAI 模型 的 GitHub 项目结构模板
github·fastapi
freejackman7 小时前
Git从入门到精通
git·gitee·gitlab·github
Silence4Allen9 小时前
零基础用 Hexo + Matery 搭建博客|Github Pages 免费部署教程
github·hexo·博客搭建·matery
Javatutouhouduan9 小时前
线上问题排查:JVM OOM问题如何排查和解决
java·jvm·数据库·后端·程序员·架构师·oom
qianmoQ9 小时前
GitHub 趋势日报 (2025年05月16日)
github
兔子坨坨10 小时前
pycharm连接github(详细步骤)
windows·git·学习·pycharm·github
大大小小聪明17 小时前
Git合并多个提交方法详解
git·github
Yvonne爱编码1 天前
CSS- 4.1 浮动(Float)
前端·css·html·github·html5·hbuilder
冷yan~1 天前
GitHub文档加载器设计与实现
java·人工智能·spring·ai·github·ai编程
Liigo2 天前
LIIGO ❤️ RUST 12 YEARS
rust·纪念日·编程语言·liigo·十周年