Skip to content

IGCrystal/Whatever

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

162 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Whatever:系统编程语言与工具链(骨架)

本仓库包含一个面向“内核/驱动/嵌入式”的 AOT 系统语言与工具链的可编译骨架

  • compiler/:编译器分阶段 crate(astlexerparsersemantictypecheckerborrow_checkeriroptimizercodegendriver)以及兼容 facade whatever_compiler
  • runtime/:最小运行时(可 no_std;显式 init;可选 panic handler)
  • stdlib/:标准库骨架(core types / collections / sync primitives 的占位与接口)
  • tools/:formatter 与 LSP skeleton
  • docs/:EBNF、类型推导/trait 规则、所有权/借用规则、内存模型与 UB 定义

完整规格总览(按 AGENTS 11 段顺序):docs/full_spec.md

优先级与里程碑(按 AGENTS 对照持续更新):docs/roadmap.md

当前版本重点在:模块边界、关键数据结构、诊断引擎、SSA IR 与借用检查框架;前端已接入 if/while/matchbreak/continue、基础 enum 声明解析与构造器 pattern(如 Some(v)),类型检查已提供 while 条件类型检查、break/continue 循环上下文检查,以及 bool 与基础 enum 场景的 match 穷尽检查;LLVM 后端默认以“生成 LLVM IR 文本”为主,后续可接入 llvm-sys/inkwell 以直接产出 object。

快速开始

需要先安装 Rust 工具链(cargo/rustc 在 PATH 中可用)。

powershell -NoProfile -ExecutionPolicy Bypass -File ./scripts/dev-check.ps1
# Windows(未在 Developer Shell / vcvars 环境中)建议直接:
powershell -NoProfile -ExecutionPolicy Bypass -File ./scripts/dev-check.ps1 -Run

cargo test
cargo run -p whatever -- check examples/hello.w

CLI 命令(当前可用)

# 语义/类型/借用/IR 校验
cargo run -p whatever -- check examples/hello.w

# 构建:可选输出 LLVM IR / object / 可执行
cargo run -p whatever -- build examples/hello.w --emit-llvm-ir
cargo run -p whatever -- build examples/hello.w --emit-object
cargo run -p whatever -- build examples/hello.w --emit-object --link
# 指定产物输出目录
cargo run -p whatever -- build examples/hello.w --emit-object --link --out-dir build/out

# 指定后端工具(默认 clang)
cargo run -p whatever -- build examples/hello.w --emit-object --link --cc clang

# 运行:编译 + 链接 + 执行
cargo run -p whatever -- run examples/hello.w

# 运行时也可指定后端工具
cargo run -p whatever -- run examples/hello.w --cc clang
# 运行时也可指定产物输出目录
cargo run -p whatever -- run examples/hello.w --out-dir build/out

# 测试:默认跑 compiler/driver/tests/fixtures
cargo run -p whatever -- test

# 格式化
cargo run -p whatever -- fmt examples/hello.w

# 或通过环境变量指定后端工具
WHATEVER_CC=clang cargo run -p whatever -- build examples/hello.w --emit-object --link

包管理(最小实现)

当前提供 pkg init / pkg add / pkg resolve 的最小可用流程:

# 在当前目录生成清单
cargo run -p whatever -- pkg init

# 添加依赖(支持 name 或 name@version)
cargo run -p whatever -- pkg add foo
cargo run -p whatever -- pkg add bar@^1.2.0

# 解析并生成锁文件
cargo run -p whatever -- pkg resolve

默认文件名:

  • 清单:whatever.pkg.json
  • 锁文件:whatever.lock.json
  • 本地索引(可选):whatever.index.json

whatever.index.json 格式

{
	"packages": {
		"foo": ["0.1.0", "0.2.0", "1.0.0"],
		"bar": ["1.2.0", "1.2.3", "1.3.0"]
	}
}

版本选择规则

  • *:选择可用版本中的最高版本
  • 精确版本(如 1.2.3):必须在索引中存在
  • ^x.y.z:同 major 且 >= x.y.z,取最高
  • ~x.y.z:同 major/minor 且 >= x.y.z,取最高

whatever.index.json 不存在时,pkg resolve 会使用兼容回退策略(保留原最小实现行为)。

后端故障排查(build/run)

build --emit-objectbuild --link / run 失败时,可优先查看诊断码:

  • ETOOL:后端工具无法启动(未安装、不可执行、PATH 未包含)
  • ECODEGEN:生成 object 失败(通常是 LLVM IR 与工具链不兼容或参数问题)
  • ELINK:链接失败(通常是系统链接库、目标平台或工具链配置问题)

后端调用相关诊断会包含统一信息:

  • 阶段:objectlink
  • 工具:实际使用的后端工具名(来自 --ccWHATEVER_CC,默认 clang
  • 原始错误:系统错误或工具 stderr

建议排查顺序:

  1. 确认工具可执行:clang --version(或你指定的 --cc
  2. 明确工具来源:优先 --cc,其次 WHATEVER_CC,最后默认 clang
  3. 若为链接错误(ELINK),检查本机 SDK / 系统库是否完整(Windows 常见为缺失 kernel32.lib 等)

About

从零实现的系统级语言,用于消耗 Copilot 次数。

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors