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

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-tuplefn 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.lryc.cn/news/530795.html

相关文章:

  • 使用 DeepSeek-R1 与 AnythingLLM 搭建本地知识库
  • 网络工程师 (13)时间管理
  • 【xdoj-离散线上练习】T251(C++)
  • 定时器按键tim_key模版
  • Kanass快速安装配置教程(入门级)
  • 无用知识之:std::initializer_list的秘密
  • 论文阅读笔记 —— 英文论文常见缩写及含义
  • 实验9 JSP访问数据库(二)
  • [c语言日寄]C语言类型转换规则详解
  • Airflow:选择合适执行器扩展任务执行
  • 使用冒泡排序模拟实现qsort函数
  • AI大模型开发原理篇-4:神经概率语言模型NPLM
  • Eigen::Tensor使用帮助
  • git基础使用--3---git安装和基本使用
  • html的字符实体和颜色表示
  • OpenAI发布o3-mini:免费推理模型,DeepSeek引发的反思
  • Zemax 中带有体素探测器的激光谐振腔
  • 大模型训练(5):Zero Redundancy Optimizer(ZeRO零冗余优化器)
  • C# 实现 “Hello World” 教程
  • LabVIEW无线齿轮监测系统
  • IM 即时通讯系统-01-概览
  • 【人工智能】 在本地运行 DeepSeek 模型:Ollama 安装指南
  • 【Linux系统】信号:信号保存 / 信号处理、内核态 / 用户态、操作系统运行原理(中断)
  • 探索 Copilot:开启智能助手新时代
  • 解锁豆瓣高清海报(二) 使用 OpenCV 拼接和压缩
  • 我用Ai学Android Jetpack Compose之Card
  • NLP深度学习 DAY4:Word2Vec详解:两种模式(CBOW与Skip-gram)
  • 论文阅读(十):用可分解图模型模拟连锁不平衡
  • Python中容器类型的数据(上)
  • PySPARK带多组参数和标签的SparkSQL批量数据导出到S3的程序