Skip to content

yjl9903/minimoonbit-moca

Repository files navigation

MiniMoonBit

moonbit-check

Mini Moonbit implementation from 摩卡猫猫.

Presentation (Chinese): https://www.bilibili.com/video/BV1tNzVYsEyC/

Quickstart

Install moonbit compiler.

curl -fsSL https://cli.moonbitlang.cn/install/unix.sh | bash -s minimoonbit

Install moonbit VS Code extension moonbit.moonbit-lang.

Then:

moon update
moon install
Build RISC-V simulator and RISC-V runtime

Make sure you have installed zig 0.13.0 (here) and cmake.

git submodule update --init --recursive
./build_rvlinux.sh
./build_riscvrt.sh

You will have rvlinux linked in the project root directory.

Install WebAssembly text format parser wasm-tools (optional)

Make sure you have installed Rust toolchains.

cargo install --locked wasm-tools

Run

You can directly use the following scripts to run our MiniMoonbit implementation.

./run_riscv.sh test/test_src/print.mbt
./run_wasm.sh test/test_src/print.mbt
./run_js.sh test/test_src/print.mbt
./run_ssa.sh test/test_src/print.mbt
./run_machine_ir.sh test/test_src/print.mbt

Run with RSIC-V backend manually.

moon run src/bin/main.mbt -- <input> -o <output>
zig build-exe -target riscv64-linux -femit-bin=<exe_file> \
  <output> /runtime/riscv_rt/zig-out/lib/libmincaml.a \
  -O Debug -fno-strip -mcpu=baseline_rv64
rvlinux -n <exe_file>

Run with JS backend manually.

moon run src/bin/main.mbt -- --js <input> -o <output>.mjs
node ./js_rt/runtime.mjs <output>.mjs

Run with WASM backend manually.

moon run src/bin/main.mbt -- --wasm <input> -o <output>.wat
wasm-tools parse <output>.wat -o <output>.wasm
node ./wasm_rt/runtime.mjs <output>.wasm

Test

Install Just.

just test-parse
just test-typecheck
just test-knf
just test-closure
just test-js
just test-wasm
just test-riscv

Reference