feat(lang): implement RFC-LANG-0002 unified semantics (breaking)

One Markdown-to-program mapping, no version selector or legacy mapper.

Frontend/runtime:
- resolve @exec/@knowledge heading declarations with nearest-ancestor
  inheritance; only an Exec H2 is callable; add UnitKind::Knowledge and
  sem.* diagnostics (mode marker, unit name, exec-without-function,
  payload nesting/empty, syntax, control stack, params position,
  version directive, inferred-signature lint)
- extract Strong/Emph/inline Code as one-statement carriers, refuse
  nested carriers, and honour heading segment boundaries so an if/while
  cannot be closed across a heading
- lower if/else/while/end to the existing Branch/Loop/Return IR with a
  compile-time control stack; keep payload-relative source spans through
  expression parsing and rewrite them onto the file
- accept params(...) only as the first direct Exec H2 payload; keep the
  existing free-variable inference and named-only rule for inferred
  signatures; fix duplicate-mode/else/end and Knowledge-body inertness
- reject marqdo_semantics/syntax front matter directives

Data and tests:
- migrate stdlib/**/*.mq.md, regenerate stdlib.json digest
- migrate examples and the full semantics/negative/runtime corpus to
  the only current syntax; expected values/runtime codes preserved
- migrate Rust-embedded .mq.md fixtures, init template, CLI help and
  security-lane fixtures

Verified: cargo fmt --check, cargo clippy -D warnings and
cargo test --workspace --locked (green).
This commit is contained in:
cflmy committed 2026-11-21 12:26:46 +08:00
1 parent 49835424ee
commit e029853e32
375 files changed
+6591 -4790

No files matched your search

@@ -3,236 +3,274 @@ import:
数据表: "std:data/table"
---
## 转表
## @exec 转表
`(列存)`
`params(列存: Map)`
**列 = 列存["列"]**
`列 = 列存["列"]`
**数据 = 列存["数据"]**
`数据 = 列存["数据"]`
**行数 = 0**
`行数 = 0`
1. `长度(数据) > 0`
`if 长度(数据) > 0`
**行数 = 长度(数据[0])**
`行数 = 长度(数据[0])`
2. `true`
`else`
**忽略 = 0**
`忽略 = 0`
**行列表 = []**
`end`
**行号 = 0**
`行列表 = []`
- `行号 < 行数`
`行号 = 0`
**行 = []**
`while 行号 < 行数`
**列号 = 0**
`行 = []`
- `列号 < 长度(列)`
`列号 = 0`
**行 = list.append(行, 数据[列号][行号])**
`while 列号 < 长度(列)`
**列号 = 列号 + 1**
`行 = list.append(行, 数据[列号][行号])`
**行列表 = list.append(行列表, 行)**
`列号 = 列号 + 1`
**行号 = 行号 + 1**
`end`
*表(列, 行列表)*
`行列表 = list.append(行列表, 行)`
## 列存排序
`行号 = 行号 + 1`
`(列存, 目标列)`
`end`
**列 = 列存["列"]**
`return 表(列, 行列表)`
**数据 = 列存["数据"]**
## @exec 列存排序
**行数 = 长度(数据[目标列])**
`params(列存: Map, 目标列: Int)`
**顺序 = []**
`列 = 列存["列"]`
**行号 = 0**
`数据 = 列存["数据"]`
- `行号 < 行数`
`行数 = 长度(数据[目标列])`
**顺序 = list.append(顺序, 行号)**
`顺序 = []`
**行号 = 行号 + 1**
`行号 = 0`
**下标 = 1**
`while 行号 < 行数`
- `下标 < 行数`
`顺序 = list.append(顺序, 行号)`
**当前 = 下标**
`行号 = 行号 + 1`
**新顺序 = []**
`end`
**已插入 = false**
`下标 = 1`
**位 = 0**
`while 下标 < 行数`
- `位 < 长度(顺序)`
`当前 = 下标`
**已有 = 顺序[位]**
`新顺序 = []`
1. `not 已插入 and 数据[目标列][已有] > 数据[目标列][当前]`
`已插入 = false`
**新顺序 = list.append(新顺序, 当前)**
`位 = 0`
**新顺序 = list.append(新顺序, 已有)**
`while 位 < 长度(顺序)`
**已插入 = true**
`已有 = 顺序[位]`
2. `true`
`if not 已插入 and 数据[目标列][已有] > 数据[目标列][当前]`
**新顺序 = list.append(新顺序, 已有)**
`新顺序 = list.append(新顺序, 当前)`
**位 = 位 + 1**
`新顺序 = list.append(新顺序, 已有)`
1. `not 已插入`
`已插入 = true`
**新顺序 = list.append(新顺序, 当前)**
`else`
2. `true`
`新顺序 = list.append(新顺序, 已有)`
**忽略 = 0**
`end`
**顺序 = 新顺序**
`位 = 位 + 1`
**下标 = 下标 + 1**
`end`
**新数据 = []**
`if not 已插入`
**列号 = 0**
`新顺序 = list.append(新顺序, 当前)`
- `列号 < 长度(列)`
`else`
**新列 = []**
`忽略 = 0`
**位 = 0**
`end`
- `位 < 行数`
`顺序 = 新顺序`
**新列 = list.append(新列, 数据[列号][顺序[位]])**
`下标 = 下标 + 1`
**位 = 位 + 1**
`end`
**新数据 = list.append(新数据, 新列)**
`新数据 = []`
**列号 = 列号 + 1**
`列号 = 0`
*{列: 列, 数据: 新数据}*
`while 列号 < 长度(列)`
## 列存过滤
`新列 = []`
`(列存, 目标列, 阈值)`
`位 = 0`
**列 = 列存["列"]**
`while 位 < 行数`
**数据 = 列存["数据"]**
`新列 = list.append(新列, 数据[列号][顺序[位]])`
**行数 = 长度(数据[目标列])**
`位 = 位 + 1`
**保留 = []**
`end`
**行号 = 0**
`新数据 = list.append(新数据, 新列)`
- `行号 < 行数`
`列号 = 列号 + 1`
1. `数据[目标列][行号] > 阈值`
`end`
**保留 = list.append(保留, 行号)**
`return {列: 列, 数据: 新数据}`
2. `true`
## @exec 列存过滤
**忽略 = 0**
`params(列存: Map, 目标列: Int, 阈值: Int)`
**行号 = 行号 + 1**
`列 = 列存["列"]`
**新数据 = []**
`数据 = 列存["数据"]`
**列号 = 0**
`行数 = 长度(数据[目标列])`
- `列号 < 长度(列)`
`保留 = []`
**新列 = []**
`行号 = 0`
**位 = 0**
`while 行号 < 行数`
- `位 < 长度(保留)`
`if 数据[目标列][行号] > 阈值`
**新列 = list.append(新列, 数据[列号][保留[位]])**
`保留 = list.append(保留, 行号)`
**位 = 位 + 1**
`else`
**新数据 = list.append(新数据, 新列)**
`忽略 = 0`
**列号 = 列号 + 1**
`end`
*{列: 列, 数据: 新数据}*
`行号 = 行号 + 1`
## 表相等
`end`
`(左, 右)`
`新数据 = []`
**左列 = table.columns(左)**
`列号 = 0`
**右列 = table.columns(右)**
`while 列号 < 长度(列)`
**相等 = 长度(左列) == 长度(右列) and 长度(左) == 长度(右)**
`新列 = []`
**列号 = 0**
`位 = 0`
- `列号 < 长度(左列) and 相等`
`while 位 < 长度(保留)`
1. `左列[列号] != 右列[列号]`
`新列 = list.append(新列, 数据[列号][保留[位]])`
**相等 = false**
`位 = 位 + 1`
2. `true`
`end`
**忽略 = 0**
`新数据 = list.append(新数据, 新列)`
**列号 = 列号 + 1**
`列号 = 列号 + 1`
**行号 = 0**
`end`
- `行号 < 长度(左) and 相等`
`return {列: 列, 数据: 新数据}`
**列号 = 0**
## @exec 表相等
- `列号 < 长度(左列) and 相等`
`params(左: Table, 右: Table)`
1. `table.cell(左, 行号, 列号) != table.cell(右, 行号, 列号)`
`左列 = table.columns(左)`
**相等 = false**
`右列 = table.columns(右)`
2. `true`
`相等 = 长度(左列) == 长度(右列) and 长度(左) == 长度(右)`
**忽略 = 0**
`列号 = 0`
**列号 = 列号 + 1**
`while 列号 < 长度(左列) and 相等`
**行号 = 行号 + 1**
`if 左列[列号] != 右列[列号]`
*相等*
`相等 = false`
## main
`else`
**列存 = {列: ["名称", "分数"], 数据: [["甲", "乙", "丙"], [87, 92, 71]]}**
`忽略 = 0`
**行表 = 转表(列存)**
`end`
**排序行 = 数据表.排序(行表, 1)**
`列号 = 列号 + 1`
**排序列 = 转表(列存排序(列存, 1))**
`end`
**过滤行 = 数据表.过滤数值大于(行表, 1, 80)**
`行号 = 0`
**过滤列 = 转表(列存过滤(列存, 1, 80))**
`while 行号 < 长度(左) and 相等`
*[表相等(转表(列存), 行表), 表相等(排序行, 排序列), 表相等(过滤行, 过滤列)]*
`列号 = 0`
`while 列号 < 长度(左列) and 相等`
`if table.cell(左, 行号, 列号) != table.cell(右, 行号, 列号)`
`相等 = false`
`else`
`忽略 = 0`
`end`
`列号 = 列号 + 1`
`end`
`行号 = 行号 + 1`
`end`
`return 相等`
## @exec main
`列存 = {列: ["名称", "分数"], 数据: [["甲", "乙", "丙"], [87, 92, 71]]}`
`行表 = 转表(列存)`
`排序行 = 数据表.排序(行表, 1)`
`排序列 = 转表(列存排序(列存, 1))`
`过滤行 = 数据表.过滤数值大于(行表, 1, 80)`
`过滤列 = 转表(列存过滤(列存, 1, 80))`
`return [表相等(转表(列存), 行表), 表相等(排序行, 排序列), 表相等(过滤行, 过滤列)]`