Chiba Logo CHIBA v0.6.13
CHIBA blog RSS feed
CHIBA / DOCS / LEVEL-1

Docs

这里接入了站内版 CHIBA level-1 spec,包含 core language、control flow、memory model、package system、IR lowering 与配套设计说明。

This page turns the level-1 spec into a navigable documentation surface, grouped by subsystem so readers can jump directly into the language boundary they need.

Sections
15
Pages
160
Section Map
Spec Section

01 core language

23 documents
01-core-language/atom-symbol-literals

Atom Symbol Literal

atom symbol literal 使用类似 `:tag` 的语法。

Open Doc
01-core-language/block-expression

Block Expression

block 使用花括号包裹语句与尾表达式。

Open Doc
01-core-language/boolean-literals

布尔字面量

布尔字面量由固定关键字构成,例如:

Open Doc
01-core-language/data

`data`

`data` 用于定义代数数据类型与构造子。

Open Doc
01-core-language/def

`def`

`def` 定义普通函数,也可参与 `extern` 形式与 method-style 定义。

Open Doc
01-core-language/expression-statements

表达式语句

表达式可以出现在语句位置。

Open Doc
01-core-language/item-attrs

Item Attrs

当前方向下,attribute 语法统一使用:

Open Doc
01-core-language/keywords

关键字集合

关键字是在词法层具有保留意义的一组标识符,例如:

Open Doc
01-core-language/let

`let`

当前大纲至少包括:

Open Doc
01-core-language/let-destruct

`let` Destruct

`let` destruct 支持 tuple / record destruct,以及它们的递归嵌套组合。

Open Doc
01-core-language/namespace

标识符与 Namespace Path

标识符用于命名:

Open Doc
01-core-language/numeric-literals

数字字面量

level-1 当前需要覆盖:

Open Doc
01-core-language/operators-and-lexical-ambiguity

运算符集合与词法歧义

level-1 当前涉及:

Open Doc
01-core-language/precedence-and-associativity

表达式优先级与结合性

表达式层需要给每类运算符与复合结构赋予优先级与结合性。

Open Doc
01-core-language/private

`private`

`private` 作为显式可见性修饰符出现在定义前。

Open Doc
01-core-language/return

`return`

`return` 用于提前从当前函数或 closure 返回。

Open Doc
01-core-language/semicolon

`;` 在语句序列中的地位

分号用于分隔语句,尤其在 block 中标识某个表达式被当作语句处理。

Open Doc
01-core-language/source-files

源文件编码、空白、换行、注释

Chiba 源文件按文本文件处理。

Open Doc
01-core-language/static-values

顶层静态值定义

使用 `def` 但是不加 `()` 来创建顶层静态值类型

Open Doc
01-core-language/type

`type`

`type` 用于引入类型级名字,例如别名、名义类型或将来更复杂的类型声明形式。

Open Doc
01-core-language/union

`union`

`union` 用于声明联合类型或低级数据布局相关类型。

Open Doc
01-core-language/use

Use

`use` 用于导入名称,当前大纲包括:

Open Doc
01-core-language/visibility

Public / Private 可见性

当前方向是:

Open Doc
Spec Section

02 control flow

17 documents
02-control-flow/answer-type-checking

`reset` / `shift` 的 Answer Type Checking

该条目描述 `reset` / `shift` 的类型检查规则,而不是新增语法。

Open Doc
02-control-flow/break

`break`

`break` 从最近的循环中离开。

Open Doc
02-control-flow/continue

`continue`

`continue` 跳到最近循环的下一轮。

Open Doc
02-control-flow/delimited-continuations

Delimited Continuation 的正式语义

该条目讨论 `reset` / `shift` 的正式类型与 continuation 语义。

Open Doc
02-control-flow/else-requirement

`else` 是否总是必需

该条目讨论 `if` / `if let` 是否允许省略 `else`。

Open Doc
02-control-flow/exhaustiveness

Exhaustiveness 规则

该条目讨论 `match` 与其他 pattern 分支结构是否需要穷尽性检查。

Open Doc
02-control-flow/for

`for { ... }`

`for { ... }` 表示无显式条件的循环体。

Open Doc
02-control-flow/for-cond

`for cond { ... }`

该形式在 `for` 关键字后直接接一个条件表达式。

Open Doc
02-control-flow/for-lowering

`for` 的 Desugar / Lowering

该条目不新增 surface syntax,而是描述 `for` 到内部 IR 的降解规则。

Open Doc
02-control-flow/if

`if { } else { }`

`if` 以条件表达式和两个分支 block 构成基本条件分支。

Open Doc
02-control-flow/if-else-if

`if else if`

`if` 允许串联多个 `else if` 分支。

Open Doc
02-control-flow/if-else-if-let

`if else if let`

`else if` 分支允许直接引入 `if let` 形式。

Open Doc
02-control-flow/if-let

`if let`

`if let pattern = expr { ... } else { ... }`

Open Doc
02-control-flow/match

`match`

`match expr { ... }` 由被匹配表达式与若干 pattern arm 构成。

Open Doc
02-control-flow/pattern-guard

Pattern Guard

pattern guard 为 `match` arm 或其他 pattern 分支附加额外布尔条件。

Open Doc
02-control-flow/reset

`reset`

`reset` 建立一个 delimited continuation 边界。

Open Doc
02-control-flow/shift

`shift`

`shift` 从最近的 `reset` 捕获 continuation。

Open Doc
Spec Section

03 memory and lifetimes

23 documents
03-memory-and-lifetimes/chiba2-roadmap-relation

Level-1 内存管理与 `chiba2.md` 长期路线图的关系

该条目不新增语法,描述路线图关系。

Open Doc
03-memory-and-lifetimes/closure-implicit-reset

Closure 调用蕴含隐式 `reset`

该条目描述 closure 调用时的默认控制/内存边界。

Open Doc
03-memory-and-lifetimes/continuation-answer-type-and-arena

Continuation / Answer Type 与 Arena 边界的关系

该条目描述 continuation、answer type 与内存边界的交叉规则。

Open Doc
03-memory-and-lifetimes/default-storage-semantics

普通 `data` / Tuple / Record / Closure Env 的默认存储语义

该条目描述默认存储模型,不新增 surface syntax。

Open Doc
03-memory-and-lifetimes/escape-semantics

值跨出当前 `reset` 的 Escape 语义

该条目描述 escape 点,不新增新语法。

Open Doc
03-memory-and-lifetimes/function-implicit-reset

普通函数调用蕴含隐式 `reset`

该条目描述默认调用语义,不新增表面语法。

Open Doc
03-memory-and-lifetimes/managed-object-model

Level-1 Managed Object Model

该条目不新增 surface syntax,而是描述 level-1 默认对象管理模型。

Open Doc
03-memory-and-lifetimes/managed-values

普通值默认是 Managed Value

该条目描述默认语义,不新增独立语法。

Open Doc
03-memory-and-lifetimes/minimal-lifetime-commitments

Arena / Escape / RC / Uniqueness / FBIP 在 Level-1 的最小承诺

该条目描述规范承诺,不新增语法。

Open Doc
03-memory-and-lifetimes/promotion-rules

Callee `reset` / Caller `reset` / Heap 之间的提升规则

该条目描述内部提升策略,不新增 surface syntax。

Open Doc
03-memory-and-lifetimes/ptr

`Ptr[T]`

`Ptr[T]` 表示裸指针或低级地址能力。

Open Doc
03-memory-and-lifetimes/ptr-ffi-metal-abi

`Ptr[T]` 与 FFI / Metal / ABI 边界

该条目不新增语法,描述 `Ptr[T]` 在边界场景中的合法使用。

Open Doc
03-memory-and-lifetimes/ptr-ref-unsafe-ref-relationship

`Ptr[T]` / `Ref[T]` / `UnsafeRef[T]` 的关系

该条目描述三者的角色边界。

Open Doc
03-memory-and-lifetimes/ref

`Ref[T]`

`Ref[T]` 表示受控可变引用单元。

Open Doc
03-memory-and-lifetimes/ref-and-send

`Ref[T]` 与 `send`

该条目描述 `Ref[T]` 在 `send` 语义中的地位。

Open Doc
03-memory-and-lifetimes/ref-read-write

`Ref[T]` 的读写与受控可变性

该条目描述 `Ref[T]` 的 surface 读写操作与方法面。

Open Doc
03-memory-and-lifetimes/reset-as-arena

`reset` 作为 Arena 边界

该条目描述 `reset` 的内存语义,不新增语法。

Open Doc
03-memory-and-lifetimes/send

`send` 标注

`send` 表示某个值或类型可能跨 world 边界传递。

Open Doc
03-memory-and-lifetimes/sync-attribute

`#[sync]`

当前方向不提供内建 `#[sync]` attribute。

Open Doc
03-memory-and-lifetimes/uniqueness

Uniqueness 作为编译器内部事实

该条目描述内部优化事实,不要求用户普遍书写 surface annotation。

Open Doc
03-memory-and-lifetimes/unsafe-ref

`UnsafeRef[T]`

`UnsafeRef[T]` 表示可跨 world 传递的 shared-owned unsafe handle。

Open Doc
03-memory-and-lifetimes/value-vs-reference

Level-1 区分值类型与引用类型

该条目描述类型分类,不新增 surface syntax。

Open Doc
03-memory-and-lifetimes/world-boundaries

World 边界上的对象传递

该条目描述跨 world 数据移动规则,不新增核心 surface syntax。

Open Doc
Spec Section

04 patterns

9 documents
Spec Section

05 expressions

22 documents
05-expressions/asm-tuple-semantics

ASM 输入/输出 Tuple 语义

该条目描述 inline `asm` 的 tuple 化输入输出接口。

Open Doc
05-expressions/block-expression

Block Expression

block expression 使用花括号包裹语句序列与尾表达式。

Open Doc
05-expressions/cast-as

Cast `as`

cast 使用 `expr as Ty` 形式。

Open Doc
05-expressions/field-access

Field Access

field access 使用点号语法。

Open Doc
05-expressions/function-call

Function Call

function call 使用普通调用语法,把 callee 与实参列表组合。

Open Doc
05-expressions/grouped-expression

Grouped Expr `(a)`

单个表达式被括号包裹时,默认表示 grouped expr。

Open Doc
05-expressions/indexing

Indexing

indexing 使用方括号语法访问元素。

Open Doc
05-expressions/inline-asm

Inline `asm`

inline `asm` 允许在表达式层嵌入低级汇编片段。

Open Doc
05-expressions/interpolation-format-string

Interpolation / Format String

该条目描述字符串插值与格式字符串表面语法。

Open Doc
05-expressions/lambda

Lambda

lambda 使用箭头语法引入匿名函数。

Open Doc
05-expressions/method-call-surface

Method Call Surface Syntax

method call 使用 `receiver.method(args...)` 风格。

Open Doc
05-expressions/named-arguments

Named Arguments

named arguments 允许在调用时按参数名传值。

Open Doc
05-expressions/one-tuple

1-Tuple Literal `(a,)`

单元素 tuple 通过尾随逗号与 grouped expr 区分。

Open Doc
05-expressions/pipe

Pipe `|>`

`|>` 表示把左侧表达式流入右侧调用或可调用体。

Open Doc
05-expressions/postfix-deref

Postfix Deref `.*`

level-1 当前方向把取值语法写成 postfix `.*`。

Open Doc
05-expressions/record-literal

Record Literal

record literal 通过字段名和值构造 record。

Open Doc
05-expressions/record-update

Record Update

当前方向复用既有语法:

Open Doc
05-expressions/slice-literal

Slice Literal

slice literal 使用当前语言既有的 slice 表面语法。

Open Doc
05-expressions/trailing-closure

Trailing Closure

当函数调用的最后一个实参是 lambda 时,允许把该 lambda 从调用括号中移出,直接写在调用之后。

Open Doc
05-expressions/tuple-literal

Tuple Literal

tuple literal 使用圆括号包裹多个元素。

Open Doc
05-expressions/unsafe-block

`unsafe { ... }`

`unsafe` block 显式包裹需要低级能力的表达式区域。

Open Doc
05-expressions/variable-reference

变量引用

变量引用使用普通标识符表达。

Open Doc
Spec Section

06 operators

9 documents
Spec Section

07 functions closures calling

19 documents
07-functions-closures-calling/closure-capture

Closure Capture 语义

该条目描述 closure 对外部绑定的 capture 规则。

Open Doc
07-functions-closures-calling/closure-env-allocation-and-promotion

Closure Env 的分配与提升

该条目描述实现语义,不新增表面语法。

Open Doc
07-functions-closures-calling/closure-implicit-reset

Closure Body 的隐式 `reset`

该条目描述 closure 调用时的默认边界。

Open Doc
07-functions-closures-calling/def-type-method

`def Type.method(...)`

该条目描述 method-style 定义在函数系统中的位置。

Open Doc
07-functions-closures-calling/entry-attribute

`#[entry]`

`#[entry]` 标记程序入口函数。

Open Doc
07-functions-closures-calling/extern-c

`extern "c"`

`extern "c"` 声明使用 C ABI 的外部函数或定义。

Open Doc
07-functions-closures-calling/extern-cbx

`extern "cbx"`

`extern "cbx"` 表示 Chiba 自定义的某种外部调用约定。

Open Doc
07-functions-closures-calling/extern-syscall

`extern "syscall"` 的现状

该条目描述 `extern "syscall"` 的表面形式与当前支持状态。

Open Doc
07-functions-closures-calling/function-implicit-reset

普通函数体的隐式 `reset`

该条目描述默认语义,不新增语法。

Open Doc
07-functions-closures-calling/functions

普通函数

普通函数通过 `def` 定义。

Open Doc
07-functions-closures-calling/lambda-closures

Lambda / Closure

lambda 引入匿名可调用体,并在需要时形成 closure。

Open Doc
07-functions-closures-calling/local-def

局部 `def`

局部 `def` 指在 block 或函数体内部定义函数。

Open Doc
07-functions-closures-calling/method-call

Method Call

method call 使用 `receiver.method(...)`。

Open Doc
07-functions-closures-calling/method-receiver

Method Receiver 规则

该条目描述 receiver 在方法定义与调用中的角色。

Open Doc
07-functions-closures-calling/method-resolution

Method Resolution

该条目描述 method lookup 规则,不新增 surface syntax。

Open Doc
07-functions-closures-calling/namespace-block-items

Namespace Block 内的 Item 定义

inline namespace block 允许在 block 内部声明顶层样式 item。

Open Doc
07-functions-closures-calling/no-callee-arena-reference-in-return

返回值不能引用 Callee 局部 Arena

该条目描述 legality 规则,不新增语法。

Open Doc
07-functions-closures-calling/operator-overload-and-methods

Operator Overload 与 Method 的关系

该条目描述运算符重载与方法系统的统一模型。

Open Doc
07-functions-closures-calling/return-as-escape

`return` 作为 Escape 点

该条目描述 `return` 的内存和类型后果。

Open Doc
Spec Section

08 literals and representation

16 documents
08-literals-and-representation/array-literals

Array Literal 的正式语义

该条目描述数组字面量 surface syntax 与元素列表语法。

Open Doc
08-literals-and-representation/bool-literals

Bool Literal

布尔字面量使用固定关键字形式。

Open Doc
08-literals-and-representation/cstr-literal

CStr Literal

`c"..."` 表示 C ABI 边界上的字符串字面量。

Open Doc
08-literals-and-representation/float-literals

Float Literal

该条目描述未来浮点字面量的词法和后缀。

Open Doc
08-literals-and-representation/int-literals

Int Literal 的 Base 与后缀处理

整数支持多进制与可能的类型后缀。

Open Doc
08-literals-and-representation/literal-prefix

`literal_prefix(#*)"..."(#*)`

该条目描述 prefix + raw 标记 + 字面量本体的统一结构。

Open Doc
08-literals-and-representation/multiline-string

Multiline String

multiline string 允许普通字符串跨越多行。

Open Doc
08-literals-and-representation/raw-string

Raw String

raw string 通过 `#` 或同类标记关闭普通 escape 解释。

Open Doc
08-literals-and-representation/runtime-representation

Bool / Unit / Tuple / ADT 的 Runtime 表示

该条目不新增语法,描述值表示。

Open Doc
08-literals-and-representation/string-interpolation

String Interpolation

该条目描述字符串内部嵌入表达式的语法。

Open Doc
08-literals-and-representation/string-literal

String Literal

普通字符串使用双引号,并与 raw、multiline、interpolation 规则共同构成字符串字面量体系。

Open Doc
08-literals-and-representation/string-literal-handler

String Literal Handler

当前方向预留类似:

Open Doc
08-literals-and-representation/string-literal-protocol

String Literal Protocol

该条目描述普通字符串如何进入 handler / desugar 协议。

Open Doc
08-literals-and-representation/symbol-literal

Symbol Literal

symbol literal 使用 atom / symbol 风格记法,如 `:tag`。

Open Doc
08-literals-and-representation/tuple-representation

Tuple Value Representation

该条目不新增 surface syntax,描述 tuple 的值表示。

Open Doc
08-literals-and-representation/unit-literal

Unit Literal

unit literal 表示唯一的空值。

Open Doc
Spec Section

09 strings str cstr string

11 documents
09-strings-str-cstr-string/c-string-and-abi

`c"..."` 与 ABI 边界

该条目描述 `c"..."` 与 `cstr` 在 ABI 边界中的职责。

Open Doc
09-strings-str-cstr-string/escape-raw-multiline-definition

字符串 Escape / Raw String / Multiline String 的正式定义

该条目描述字符串词法最核心的正式规则。

Open Doc
09-strings-str-cstr-string/multiline-standard-strings

标准字符串允许多行

该条目描述普通字符串跨行的合法形式。

Open Doc
09-strings-str-cstr-string/non-c-string-desugar

除 `c""` 外的字符串字面量 Desugar 为函数调用

该条目描述普通字符串字面量的 desugar 方向。

Open Doc
09-strings-str-cstr-string/ownership-and-borrowing-boundaries

`str` / `cstr` / `String` 的所有权与借用边界

该条目描述字符串家族的生命周期与边界,不新增新语法。

Open Doc
09-strings-str-cstr-string/prefix-string-handler-resolution

Prefix String Handler Resolution

该条目描述带 prefix 的字符串字面量如何解析到具体 handler。

Open Doc
09-strings-str-cstr-string/raw-nonraw-interpolation

Raw / Non-Raw 与 Interpolation 的组合规则

该条目描述 raw 标记、普通字符串与插值的组合语法。

Open Doc
09-strings-str-cstr-string/str-cstr-string-surface

`str` / `cstr` / `String` 的语法面

该条目描述三者在类型层与字面量层的公开写法。

Open Doc
09-strings-str-cstr-string/string-api-as-methods

字符串相关 API 改为 Method Surface

字符串操作倾向于以 method surface 暴露,而不是散落 helper 函数。

Open Doc
09-strings-str-cstr-string/string-to-cstr

`String -> cstr`

该条目描述从拥有型字符串到 C 风格字符串的转换路径。

Open Doc
09-strings-str-cstr-string/utf8-and-codepoints

UTF-8 语义与 Codepoint 级规则

该条目描述字符串和字符相关文本的编码假设。

Open Doc
Spec Section

10 ir and lowering

6 documents
Spec Section

chibacc

1 documents
Spec Section

chibalex

1 documents
Spec Section

memory model

1 documents
Spec Section

package system

1 documents
Spec Section

readme

1 documents