-
MoonBit支持native后端
-
Wasm-gc 后端支持 Js-string-builtins proposal
当通过编译选项 -use-js-builtin-string 开启使用 Js-string-builtins 之后,Moonbit 面向 wasm-gc 后端时,会使用 JavaScript 中的字符串类型表示 MoonBit 中的字符串,这时生成的 wasm 可执行文件中将需要从 JavaScript 宿主中导入字符串类型相关的函数,这个过程可以通过在 JS 的胶水代码中,使用如下选项来实现:
// glue.js
// read wasm file
let bytes = read_file_to_bytes(module_name);
// compile the wasm module with js-string-builtin on
let module = new WebAssembly.Module(bytes, { builtins: ['js-string'], importedStringConstants: "moonbit:constant_strings" });
// instantiate the wasm module
let instance = new WebAssembly.Instance(module, spectest);
- 整数字面量重载支持表示Byte类型
let b : Byte = 65
println(b) // b'\x41'
- 多行字符串插值和转义支持
考虑到多行字符串有时用于保存raw string,即字符串内可能包含与转义序列冲突的字符序列。 MoonBit拓展了原先的多行字符串插值语法,用户可以通过开头的标记单独控制每行是否启用插值和转义序列:$|表示启用插值和转义,#|表示raw string。
let a = "string"
let b = 20
let c = #| This is a multiline string$| \ta is \{a},$| \tb is \{b}#| raw string \{not a interpolation}
println(c)
输出:
This is a multiline stringa is string,b is 20raw string \{not a interpolation}
- 带标签参数的语法调整
移除函数调用中f(~label=value)和模式匹配中Constr(~label=pattern)的语法,仅保留省略~符号的形式:f(label=value)和Constr(label=pattern)。f(~value)和Constr(~name)不受影响。
IDE 更新
- 修复了字符串插值的高亮
标准库更新
- Builtin包引入
StringBuilder
StringBuilder针对不同的后端的字符串拼接操作进行了特化,例如JS后端在使用StringBuilder后相比原先的Buffer实现有大约五倍的速度提升。原先Builtin包的Buffer已经弃用,相关API移入moonbitlang/core/buffer包,后续会对Bytes和Buffer的API进行相关的调整。
- 位运算函数调整
弃用了标准库中各个类型的lsr, asr, lsl, shr, shl等左移和右移位运算操作函数,只保留op_shl和op_shr。目前lxor, lor, land, op_shr, op_shl都有对应的中缀运算符,我们推荐使用中缀表达式的风格。
- 破坏性更新
immut/List 的 Last 函数现在返回 Option[T]
构建系统更新
-
初步适配 native 后端
run | test | build | check支持--target native- native 后端的
moon test在 debug 模式下(默认)用 tcc 编译;release 模式下用 cc 编译(unix),windows 暂未支持 - 暂未支持 panic test
-
支持
@json.inspect,被检查的对象需要实现ToJson。使用样例:
enum Color {Red
} derive(ToJson)struct Point {x : Inty : Intcolor : Color
} derive(ToJson)test {@json.inspect!({ x: 0, y: 0, color: Color::Red })
}
执行 moon test -u 后,测试块被自动更新成:
test {@json.inspect!({ x: 0, y: 0, color: Color::Red }, content={"x":0,"y":0,"color":{"$tag":"Red"}})
}
与 inspect 相比,@json.inspect 的自动更新结果可以使用代码格式化工具:
test {@json.inspect!({ x: 0, y: 0, color: Color::Red },content={ "x": 0, "y": 0, "color": { "$tag": "Red" } },)
}
此外 moon test 会自动对 @json.inspect 中的JSON进行结构化对比,例如,对于如下代码
enum Color {RedGreen
} derive(ToJson)struct Point {x : Inty : Intz : Intcolor : Color
} derive(ToJson)test {@json.inspect!({ x: 0, y: 0, z: 0, color: Color::Green },content={ "x": 0, "y": 0, "color": { "$tag": "Red" } },)
}
moon test 的输出的 diff 结果类似:
Diff:{
+ z: 0color: {
- $tag: "Red"
+ $tag: "Green"}}
-
moon.mod.json中支持include与exclude字段。include与exclude是个字符串数组,字符串的格式与.gitignore中每行的格式相同。具体的规则如下:- 如果
include与exclude字段都不存在,只考虑.gitignore文件 - 如果
exclude字段存在,同时考虑exclude中的路径与.gitignore文件 - 如果
include字段存在,那么exclude与.gitignore都失效,只有在include中的文件才会被打包 moon.mod.json忽略上述规则,无论如何都会被打包/target与/.mooncakes忽略上述规则,无论如何都不会被打包
- 如果
-
添加
moon package命令,用于只打包而不上传moon package --list用于列出包中的所有文件
-
支持
moon publish --dry-run,服务端会进行校验,但是不会更新索引数据