当前位置: 首页 > article >正文

MoonBit 编译器(留档学习)

MoonBit 编译器

MoonBit 是一个用户友好,构建快,产出质量高的编程语言。

MoonBit | Documentation | Tour | Core

This is the source code repository for MoonBit, a programming language that is user-friendly, builds fast, and produces high quality output.

安装

先安装依赖:

sudo apt install ocaml

安装opam

bash -c "sh <(curl -fsSL https://opam.ocaml.org/install.sh)"

如果这个下载不下来,可以使用apt安装: 

sudo apt install opam

初始化opam

如果是第一次用opam,那就就要先初始化:

opam init

提示完成初始化

<><> Creating initial switch 'default' (invariant ["ocaml" {>= "4.05.0"}] - initially with ocaml-system)

<><> Installing new switch packages <><><><><><><><><><><><><><><><><><><><><><>
Switch invariant: ["ocaml" {>= "4.05.0"}]

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
∗ installed host-arch-x86_64.1
∗ installed host-system-other.1
⬇ retrieved ocaml-system.4.14.1  (https://opam.ocaml.org/cache)
⬇ retrieved ocaml-config.2  (2 extra sources)
∗ installed ocaml-system.4.14.1
∗ installed ocaml-config.2
∗ installed ocaml.4.14.1
Done.
# Run eval $(opam env --switch=default) to update the current shell environment

安装

sudo apt install ocaml-dune
 下载源代码
git clone https://github.com/moonbitlang/moonbit-compiler
编译安装 

进入源代码目录moonbit-compiler,安装:

opam switch create 4.14.2
opam install -y dune
dune build -p moonbit-lang

opam的知识

Using opam

This document starts with a quick introduction, then covers most commonly-used opam features.

If you are a developer and want to get a project packaged or change an existing package, see the step-by-step packaging guide.

The full documentation is available inline, using

opam --help
opam <command> --help

This document is intended as a quicker overview, use the above to dig into the details.

Basics

# ** Get started **
opam init            # Initialize ~/.opam

# ** Lookup **
opam list -a         # List all available packages
opam search QUERY    # List packages with QUERY in their name or description
opam show PACKAGE    # Display information about PACKAGE

# ** Install **
opam install PACKAGE # Download, build and install the latest version of PACKAGE
                     # and all its dependencies
opam remove PACKAGE  # Uninstall the given package

# ** Upgrade **
opam update          # Update the packages database
opam upgrade         # Bring everything to the latest version possible

# ** More **
opam CMD --help      # Command-specific manpage

MoonBit

MoonBit 新手之旅 | MoonBit Docs

构建系统教程 - Moon 手册

开始编码​

本文中我们会把以下所有的代码都写在 main.mbt 中。main 函数是程序的入口点,并且只能出现在 main 包中。 更细致的介绍可以在我们的《MoonBit 构建系统配置》一文中找到。

变量

let e = 2.718281828459045 // double
let int_min = -2147483648 // int
let int_max : Int = 2147483647 // 显式类型标注
let tuple = (1, 2) // 2-tuple

fn init {
  let array = [1, 2, 3, 4, 5]
  // array = [4, 5, 6, 7, 8] // 错误:`let` 创建的是不可变绑定。
  let mut mut_array = [1, 2, 3, 4, 5]
  mut_array = [4, 5, 6, 7, 8]
  println(mut_array)
}

调试

安装opam下载文件报错curl -fsSL https://opam.ocaml.org/install.sh

直接使用wget下载,也报错

wget https://opam.ocaml.org/install.sh
--2024-12-22 19:33:18--  https://opam.ocaml.org/install.sh
Resolving opam.ocaml.org (opam.ocaml.org)... 51.158.232.133, 151.115.76.159, 2001:bc8:5090:bf9:dc00:ff:fe2e:c1e9
Connecting to opam.ocaml.org (opam.ocaml.org)|51.158.232.133|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh [following]
--2024-12-22 19:33:19--  https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 0.0.0.0, ::
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|0.0.0.0|:443... failed: Connection refused.
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|::|:443... failed: Connection refused.

使用apt安装

opam build moonbit报错

dune build -p moonbit-lang
Command 'dune' not found, but can be installed with:
sudo apt install ocaml-dune

安装ocaml-dune

sudo apt install ocaml-dune

dune build -p moonbit-lang 报错

dune build -p moonbit-lang
Error: I don't know about package moonbit-lang (passed through
--only-packages)

原来是要在moonbit-lang的目录下执行:

dune build -p moonbit-lang


http://www.kler.cn/a/529782.html

相关文章:

  • [免费]微信小程序智能商城系统(uniapp+Springboot后端+vue管理端)【论文+源码+SQL脚本】
  • 本地部署DeepSeek教程(Mac版本)
  • 跨域问题解决实践
  • linux 函数 sem_init () 信号量、sem_destroy()
  • 信息学奥赛一本通 ybt 1608:【 例 3】任务安排 3 | 洛谷 P5785 [SDOI2012] 任务安排
  • WebForms DataList 深入解析
  • SAP HCM insufficient authorization, no.skipped personnel 总结归纳
  • 【含文档+PPT+源码】基于微信小程序的社区便民防诈宣传系统设计与实现
  • React中使用箭头函数定义事件处理程序
  • 小红的小球染色期望
  • 武汉科技大学计算机课程设置,武汉科技大学计算机控制与接口技术课程实施方案
  • 笔灵ai写作技术浅析(四):知识图谱
  • 代理模式——C++实现
  • MVC 文件夹:架构之美与实际应用
  • 从零开始:用Qt开发一个功能强大的文本编辑器——WPS项目全解析
  • 在K8S中,pending状态一般由什么原因导致的?
  • 苹果CMSV10仿茶杯狐自适应视频模板源码 PC+WAP自适应视频模板
  • 【Qt】界面优化
  • day37|完全背包基础+leetcode 518.零钱兑换II ,377.组合总和II
  • 记录 | 基于MaxKB的仿小红书旅游文章AI制作(含图文、视频)
  • 边缘检测算法(sobel)
  • redis集群理论详解
  • 安卓pad仿写element-ui表单验证
  • 关于合并两个有序链表
  • STM32CUBEIDE编译的hex使用flymcu下载后不能运行
  • Ubuntu 22.04系统安装部署Kubernetes v1.29.13集群