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

算术运算

这里集中展示 CHIBA level-1 specification,覆盖 core language、control flow、memory、patterns、IR lowering 与 package system 等实现边界。

The docs surface keeps CHIBA level-1 specification pages browsable inside the site, with direct paths into language, control flow, memory, pattern, and lowering rules.

算术运算

语法

当前至少包括:

  • +
  • -
  • *
  • /
  • %

语义

算术运算作用于数值类型,并可参与 operator overloading。

当操作数已经是 concrete numeric type 时,+-*/% 按数值运算检查。

当操作数仍是抽象类型时,type checker 不应直接默认成 i64。例如:

def add(a, b) = a + b

应生成 op_add obligation,并在同类型参数场景下泛化为类似:

def add[T: {t | op_add: (Self, Self) => Self}](a: T, b: T): T

具体 op_add 实现只在 concrete instantiation / explicit behavior source / checked nominal conversion 后确定。

Usage

let x = 1 + 2 * 3
let y = x % 4

注释:这个例子覆盖了加、乘、取模的最基本表面,强调它们首先是数值运算,再谈 overload 扩展。

边界

需要单独明确:

  • 整数与未来浮点的统一规则
  • operator overload 的候选筛选