TLL 语言文档

从零开始学习 TLL 高帧率编程语言。

安装与 Hello World

TLL 采用自举编译器,原生支持 Linux / Windows / macOS。从 GitHub 克隆仓库后即可编译。

bash
# 克隆仓库
git clone https://github.com/aliquanhou/tllos.git
cd tllos

# 构建原生启动器
make build

# 运行 Hello World
./tllc examples/hello.tll
hello.tll
import io

fn main() {
    io.println("Hello, TLL OS!")
    io.println("High Frame Rate Language for AI Engineering")
}

基础语法

注释

// 单行注释
/* 多行注释 */

控制流

if (x > 10) {
    io.println("x is large")
} else {
    io.println("x is small")
}

for (let i = 0; i < 10; i = i + 1) {
    io.println(i)
}

while (running) {
    // loop
}

注意:TLL 中 / 是浮点除法,整数除法请使用 div 内置函数。整数为有符号 64 位。

变量与类型

TLL 支持动态类型,基础类型包括 int、float、string、bool、list、map。

let name = "TLL"           // 字符串
let version = 15             // 整数 (int64)
let pi = 3.14159             // 浮点数
let active = true              // 布尔值

let items = [1, 2, 3]        // 列表
let config = { "host": "localhost", "port": 8080 }  // Map

已知限制:空列表 [] 的索引赋值行为尚未完全定义,建议预初始化列表后再使用索引赋值。此问题已登记为后续语言缺陷。

函数与闭包

fn add(a, b) {
    return a + b
}

let result = add(3, 5)  // 8

// 闭包
fn makeCounter() {
    let count = 0
    return fn() {
        count = count + 1
        return count
    }
}

let counter = makeCounter()
counter()  // 1
counter()  // 2

注意:函数定义不会提升,必须在使用前定义。不支持三元运算符,请使用 if/else。

结构体

struct Point {
    x
    y
}

fn Point.new(x, y) {
    let p = Point{}
    p.x = x
    p.y = y
    return p
}

fn Point.distance(other) {
    let dx = this.x - other.x
    let dy = this.y - other.y
    return (dx * dx + dy * dy)
}

let p1 = Point.new(0, 0)
let p2 = Point.new(3, 4)
io.println(p1.distance(p2))  // 25

协程

TLL 原生支持轻量级协程,可并发运行 100K+ 协程。

import coroutine
import io

fn worker(id) {
    for (let i = 0; i < 3; i = i + 1) {
        io.println("Worker " + id + ": step " + i)
        coroutine.yield()
    }
}

fn main() {
    let c1 = coroutine.create(worker, 1)
    let c2 = coroutine.create(worker, 2)

    coroutine.resume(c1)
    coroutine.resume(c2)
    coroutine.resume(c1)
    coroutine.resume(c2)
}

密码学标准库

TLL 自研 Ed25519 密码学实现,RFC 8032 #1/#2/#3 向量通过。

函数说明
crypto.sha256(data)SHA-256 哈希
crypto.sha512(data)SHA-512 哈希
crypto.randomBytes(n)安全随机字节
crypto.ed25519.generateKeypair()生成 Ed25519 密钥对
crypto.ed25519.sign(privateKey, message)签名
crypto.ed25519.verify(publicKey, message, signature)验签
crypto_example.tll
import crypto
import io

fn main() {
    // 生成密钥对
    let keypair = crypto.ed25519.generateKeypair()

    // 签名
    let message = "Hello, TLL!"
    let signature = crypto.ed25519.sign(keypair.privateKey, message)

    // 验签
    let valid = crypto.ed25519.verify(keypair.publicKey, message, signature)
    io.println("Signature valid: " + valid)
}

安全声明:TLL Native Ed25519 为工程验证级实现。RFC 8032 标准向量通过仅证明与标准测试向量的一致性,不等同于生产级密码学安全。独立密码学审计仍处于 Pending 状态。

身份标准库

基于 Ed25519 的 Agent 身份系统,agent_id = SHA256(canonical material)。

函数说明
identity.generate()生成新身份
identity.fromPublicKey(pubKey)从公钥创建身份
identity.computeId(identity)计算确定性 agent_id
identity.validate(identity)验证身份完整性
identity.sign(identity, message)签名
identity.verify(identity, message, sig)验签
identity.encode(identity)规范编码
identity.decode(bytes)解码

输入输出

函数说明
io.println(text)打印一行
io.print(text)打印不换行
io.readFile(path)读取文件
io.writeFile(path, data)写入文件

Agent 开发协议

任何 AI Agent 接入 TLL 生态必须遵循以下协议流程:

  1. 获取 Identity — 调用 identity.generate() 创建密码学身份
  2. 声明 Capability — 调用 capability.create() 声明 Agent 具备的能力
  3. 获得 Authority — 由 Issuer 签名授权,绑定 Agent + Capability + 约束
  4. 提交 Evidence — 每次操作产生可验证证据记录,包含输入/输出哈希
  5. 信任评估 — 系统基于 Identity + Capability + Authority + Evidence 进行确定性信任评估

核心原则:Agent 可以换,LLM 可以换,但 Truth / Protocol / Contract / Verification 保持一致。No Evidence → No Claim。