跳到主要内容

White

White

White 是一门编译为原生程序的静态类型语言。编译器使用 White 编写,并通过 LLVM 完成代码生成。

Apache-2.0使用 White 编写使用 LLVM 构建
hello.wlwlc
class Greeting {
let name: String;

init(name: String) {
self.name = name;
}

func write() -> Void {
print("hello, ", self.name);
}
}

func main() -> Int {
let greeting = Greeting("White");
greeting.write();
return 0;
}
$ wlc hello.wl && ./hello
hello, White

语言

一些基本功能

White 具有静态类型、class、interface、ARC、可失败返回值,以及调用原生库的 FFI。语法目前保持得比较小。

01

静态类型

类型可以显式写出,也可以从初始化式推导。推导在编译期完成,不会在运行时增加类型信息。

let count = 10;
const limit: Int = 64;
02

错误处理

可能失败的函数返回 T?。调用时使用 ?,再在合适的位置用 catch 处理错误。

let text: String = input("name: ")?;
catch(err) { print(err); }
03

内存管理

String、class、interface 和闭包使用 ARC 管理。class 可以定义 deinit,用于释放文件、句柄等资源。

deinit() {
    file.close();
}

编译器

wlc 如何构建程序

wlc 读取并检查 White 源码,然后生成 LLVM IR。之后由 Clang 生成可执行文件、目标文件、汇编或共享库。wlc 本身也使用同一流程构建。

编译器源码
  1. 01.wl
  2. 02Lexer / Parser
  3. 03Typed AST
  4. 04LLVM IR
  5. 05Native

平台

支持的系统

发布流水线会为这里列出的目标构建并测试 wlc。跨系统编译仍需要目标系统的 SDK 或 sysroot。

Windows

x86-64 / x86

Linux

x86-64 / x86 / AArch64 / ARMv7

macOS

Apple silicon / Intel

下载

工具

项目的其它部分

当前限制

ARC 还不能回收循环引用,弱引用尚未实现,泛型系统与标准库也没有完成。White 目前还不适合一般的生产环境。

阅读限制