国产编程语言 MoonBit 目前已支持内联 Wasm 函数

163 天前
 Moonbit

MoonBit 更新

1. 支持使用 type 关键字定义 newtype

type MyInt Int derive(Show)

fn init {
    let x = MyInt::MyInt(5)
    println(x) // Output: MyInt(5)
    println(x.0) // Output: 5
}

2. 支持内联 Wasm 函数,例如

fn char_to_string(c: Char) -> String =
   "(func $char_to_string (param $c i32) (result (ref $moonbit.string)) (array.new $moonbit.string (local.get $c) (i32.const 1)))"

不过目前内联 Wasm 指令只支持 wasm-gc 后端

3. 改进自动分号插入

现在 MoonBit 支持下面的链式调用写法:

fn init {
  receiver
    .method1()
    .method2()
    .method3()
}

此外,多行的函数调用和结构体创建不再需要在最后加上逗号了:

fn init {
  let record = {
    x: 1,
    y: "abc" // 以前这里必须加逗号
  }
  function(
    arg1,
    arg2 // 以前这里必须加逗号
  )
}

4. 字符串插值现在支持 Unicode

let s = "string interpolate unicode \( 中文 )"

5. 优化字符串高亮

修改前

修改后

6. 内置类型改进

fn init {
  let s = String::make(3, 'a')
  println(s) // Output: aaa
}
1337 次点击
所在节点    程序员
4 条回复
Leviathann
163 天前
感觉强制写 trailing comma 挺好的
Altar
163 天前
你们是怎么想到在小红书做推广的?
keepRun
162 天前
大力支持
Moonbit
160 天前
@keepRun 谢谢❤️

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/999461

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX