V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Moonbit
V2EX  ›  程序员

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

  •  1
     
  •   Moonbit · 142 天前 · 1309 次点击
    这是一个创建于 142 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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. 内置类型改进

    • 字符串

      • 添加 String::make
    fn init {
      let s = String::make(3, 'a')
      println(s) // Output: aaa
    }
    
    • 修复 String::compare,修改前 String::compare 只比较长度,修改后,按照字典序比较

    • Bytes 和 Buffer

      • 添加 Bytes 相关函数: blit, to_string, of_string, sub_string, blit_from_string, copy, set_utf8_char

      • 新增 Buffer 类型和相关函数: to_string, make, write_string, write_char, length

    • Option 添加 Eq/Compare/Show/Default 的默认实现, Ref/Array 添加 Show 的默认实现

    4 条回复    2023-12-14 09:55:33 +08:00
    Leviathann
        1
    Leviathann  
       142 天前
    感觉强制写 trailing comma 挺好的
    Altar
        2
    Altar  
       142 天前 via Android
    你们是怎么想到在小红书做推广的?
    keepRun
        3
    keepRun  
       141 天前 via Android
    大力支持
    Moonbit
        4
    Moonbit  
    OP
       139 天前
    @keepRun 谢谢❤️
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2122 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:00 · PVG 00:00 · LAX 09:00 · JFK 12:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.