安装它
Loment 以包的形式发布。从最新发布里取对应你平台的压缩包。
Linux / WSL
一个 linux-x64.tar.gz。解开它,运行 sh install.sh。
唯一的要求是 POSIX sh。
Windows
一个 windows-x64.zip —— 解开它,运行
powershell -File install.ps1 —— 或一个双击即可的
windows-x64-setup.exe。
你会得到 loment 命令、包管理器(lompi),以及语言服务器。
编译和运行不需要 Python、不需要 clang、不需要 WSL:这个包是原生二进制
加上标准库,安装器在写入任何东西之前会核对 SHA256SUMS。
如果你想改动这门语言本身,而不是使用它,那就从一个检出开始:
git clone https://github.com/Loment-Lang/loment.git。编译器是用 Loment
写的,从仓库里提交的一颗种子重建 —— sh loment/bootstrap.sh 会构建它,
并核对种子能否逐字节地重现自己。
写一个程序
把这段放进 hello.lomt。
module hello fn _start() { let s: str = "hello from Loment\n"; syscall4(1, 1, str_ptr(s) as u64, str_len(s) as u64); syscall4(60, 0, 0, 0);}
_start 是机器开始的地方。一个 sealed 程序 — 一个什么都不链接的程序
— 底下没有 runtime 来替你调用入口,所以入口得你自己点名;它也没有
printf,所以输出走 write 系统调用:文件描述符、字符串的指针、
它的长度。第二次调用是 exit。改成写 choose hosted,你就得到
一个普通的 C 程序,入口点是 fn main() -> u32。
编译并运行它
$ loment run hello.lomt # compile, link, run$ loment build hello.lomt -o hello$ loment check hello.lomt # check only, nothing written$ loment ir hello.lomt # the LLVM IR it generates
在 Windows 上目标是 PE,所以把输出命名为 .exe —— 链接器从这个名字来判断格式。
四处看看这门语言
工具链会解释它自己。这四条覆盖了其中大半。
$ loment example tour # the whole language in one file$ loment cheat # the traps, ordered by how easily they bite$ loment builtins # every built-in function there is$ loment syntax # syntax summary
loment example tour 把整门语言打印成一个带注释的源码文件。它的注释是中文,
而在 0.1.4 上那个文件链接不过;示例页上那四个
程序才是已验证能跑的。