安庆信德建设咨询有限公司网站短视频培训课程
安庆信德建设咨询有限公司网站,短视频培训课程,延安网站建设推广,网络推广的主要内容MoonBit支持native后端 Wasm-gc 后端支持 Js-string-builtins proposal
当通过编译选项 -use-js-builtin-string 开启使用 Js-string-builtins 之后#xff0c;Moonbit 面向 wasm-gc 后端时#xff0c;会使用 JavaScript 中的字符串类型表示 MoonBit 中的字符串#xff0… 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(~labelvalue)和模式匹配中Constr(~labelpattern)的语法仅保留省略符号的形式f(labelvalue)和Constr(labelpattern)。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 nativenative 后端的 moon test 在 debug 模式下默认用 tcc 编译release 模式下用 cc 编译unixwindows 暂未支持暂未支持 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服务端会进行校验但是不会更新索引数据
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/88701.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!