Files
cflmy e029853e32 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).
2026-11-21 12:26:46 +08:00

3.4 KiB

import
import
数据表
std:data/table

@exec 转表

params(列存: Map)

列 = 列存["列"]

数据 = 列存["数据"]

行数 = 0

if 长度(数据) > 0

行数 = 长度(数据[0])

else

忽略 = 0

end

行列表 = []

行号 = 0

while 行号 < 行数

行 = []

列号 = 0

while 列号 < 长度(列)

行 = list.append(行, 数据[列号][行号])

列号 = 列号 + 1

end

行列表 = list.append(行列表, 行)

行号 = 行号 + 1

end

return 表(列, 行列表)

@exec 列存排序

params(列存: Map, 目标列: Int)

列 = 列存["列"]

数据 = 列存["数据"]

行数 = 长度(数据[目标列])

顺序 = []

行号 = 0

while 行号 < 行数

顺序 = list.append(顺序, 行号)

行号 = 行号 + 1

end

下标 = 1

while 下标 < 行数

当前 = 下标

新顺序 = []

已插入 = false

位 = 0

while 位 < 长度(顺序)

已有 = 顺序[位]

if not 已插入 and 数据[目标列][已有] > 数据[目标列][当前]

新顺序 = list.append(新顺序, 当前)

新顺序 = list.append(新顺序, 已有)

已插入 = true

else

新顺序 = list.append(新顺序, 已有)

end

位 = 位 + 1

end

if not 已插入

新顺序 = list.append(新顺序, 当前)

else

忽略 = 0

end

顺序 = 新顺序

下标 = 下标 + 1

end

新数据 = []

列号 = 0

while 列号 < 长度(列)

新列 = []

位 = 0

while 位 < 行数

新列 = list.append(新列, 数据[列号][顺序[位]])

位 = 位 + 1

end

新数据 = list.append(新数据, 新列)

列号 = 列号 + 1

end

return {列: 列, 数据: 新数据}

@exec 列存过滤

params(列存: Map, 目标列: Int, 阈值: Int)

列 = 列存["列"]

数据 = 列存["数据"]

行数 = 长度(数据[目标列])

保留 = []

行号 = 0

while 行号 < 行数

if 数据[目标列][行号] > 阈值

保留 = list.append(保留, 行号)

else

忽略 = 0

end

行号 = 行号 + 1

end

新数据 = []

列号 = 0

while 列号 < 长度(列)

新列 = []

位 = 0

while 位 < 长度(保留)

新列 = list.append(新列, 数据[列号][保留[位]])

位 = 位 + 1

end

新数据 = list.append(新数据, 新列)

列号 = 列号 + 1

end

return {列: 列, 数据: 新数据}

@exec 表相等

params(左: Table, 右: Table)

左列 = table.columns(左)

右列 = table.columns(右)

相等 = 长度(左列) == 长度(右列) and 长度(左) == 长度(右)

列号 = 0

while 列号 < 长度(左列) and 相等

if 左列[列号] != 右列[列号]

相等 = false

else

忽略 = 0

end

列号 = 列号 + 1

end

行号 = 0

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 [表相等(转表(列存), 行表), 表相等(排序行, 排序列), 表相等(过滤行, 过滤列)]