The MoonBit Update——0527

MoonBit Update 0527

MoonBit is a Rust-like programming language (with GC support) and toolchain optimized for WebAssembly.

Language Update

  • Breaking Change: Restructure APIs of MoonBit Core library.

    • Placing all immutable data structures under the immut path, for example, from @immutable_hashmap.Map to @immut/hashmap.Map.

// Before

let a : @immutable_hashmap.Map[Int, Int] = @immutable_hashmap.make()

// After

let a : @immut/hashmap.Map[Int, Int] = @immut/hashmap.make()

  • Performance optimization for the Option[T] type in the core library:

    • When the type T is a reference type, for values of type Option[T], Some(v) will be directly compiled into v, and None will be compiled into ref.null in the wasm-gc backend, or undefined in the JavaScript backend, thus avoiding memory allocation.
  • Introduced fn panicT -> T function in the core library, which can be used within test blocks where the test name must start with "panic":


test "panic test ok" {

panic() // Test passes

}

test "panic test failed" {

() // Test fails

}

IDE Update

  • VS Code extension: Added test and for code snippets.

test snippet:
test

for snippet:
for

Build System Update

  • Initialization: moon new now automatically initializes version control for new projects, currently supporting git

  • Testing: You can now specify multiple packages to test


moon test -p a b c

moon test -p a -p b -p c

Toolchain Update

  • Installation: You can now specify a version number for installation

# Mac and Linux Users

# Download the latest version

curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash

# Download the bleeding edge version

curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s bleeding

# Download a specific version

curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s 0.1.20240520+b1f30d5e1


# Windows Users

# Download the latest version

irm cli.moonbitlang.cn/install/powershell.ps1 | iex

# Download a specific version

$env:MOONBIT_INSTALL_VERSION = "0.1.20240520+b1f30d5e1"; irm cli.moonbitlang.cn/install/powershell.ps1 | iex