test(rfc-cm): close P2 evidence gaps for C01/C06/C12

- Add alloc.double_free detection to the .mq.md free-list allocator and a
  fixture assertion for a second free returning a recoverable Result.
- Add table group fixture 69 (table.row -> Map of value lists).
- Add Int matrix-multiply fixture 70 for C12 layout/iteration.
- Update counts and P2 evidence/status docs.

Gate: fmt, clippy -D warnings, 407 tests passed.
This commit is contained in:
cflmy committed 2026-11-20 21:22:44 +08:00
1 parent 92bfbf2568
commit 5d3a5fb13b
12 files changed
+414 -11

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ portable/tested locally but the native platform lane has not run here;
| Feature | Ubuntu Linux x86_64 | macOS arm64 | Windows x86_64 | | Feature | Ubuntu Linux x86_64 | macOS arm64 | Windows x86_64 |
|---|---|---|---| |---|---|---|---|
| Markdown profile / AST goldens (160) | PASS | UNVERIFIED (cfg fix + CRLF fix) | UNVERIFIED (cfg fix + CRLF fix) | | Markdown profile / AST goldens (160) | PASS | UNVERIFIED (cfg fix + CRLF fix) | UNVERIFIED (cfg fix + CRLF fix) |
| Rust interpreter / semantics (68) | PASS | UNVERIFIED | UNVERIFIED | | Rust interpreter / semantics (70) | PASS | UNVERIFIED | UNVERIFIED |
| Addressable `Memory` P1 (ADR-0022) | PASS | UNVERIFIED | UNVERIFIED | | Addressable `Memory` P1 (ADR-0022) | PASS | UNVERIFIED | UNVERIFIED |
| Resource streams CM-A06 (ADR-0025/0026: stdout + project file read/write) | PASS | UNVERIFIED | **FAIL-CLOSED** (`strict` refuses resource opens) | | Resource streams CM-A06 (ADR-0025/0026: stdout + project file read/write) | PASS | UNVERIFIED | **FAIL-CLOSED** (`strict` refuses resource opens) |
| `run` / `call` / `check` / `inspect` / `fmt` | PASS | UNVERIFIED | UNVERIFIED | | `run` / `call` / `check` / `inspect` / `fmt` | PASS | UNVERIFIED | UNVERIFIED |
+1 -1
View File
@@ -81,7 +81,7 @@ executes anything.
## What works (implemented and tested) ## What works (implemented and tested)
* **P0 contracts** — frozen Markdown profile, AST → program mapping, strict * **P0 contracts** — frozen Markdown profile, AST → program mapping, strict
expression grammar, evaluation semantics; 160 AST goldens, 68 semantic expression grammar, evaluation semantics; 160 AST goldens, 70 semantic
goldens, 52 compile-error fixtures and 21 runtime-error fixtures goldens, 52 compile-error fixtures and 21 runtime-error fixtures
(`tests/`). (`tests/`).
* **P1 interpreter** — native Rust tree-walk interpreter: values, scopes, * **P1 interpreter** — native Rust tree-walk interpreter: values, scopes,
+3 -3
View File
@@ -71,7 +71,7 @@ This is still a **local VM lane**, not a self-hosted GitHub Actions security URL
| 2 | Cross-platform strict `cfg` | **Fixed locally; native CI UNVERIFIED** | `#[cfg]` dispatch + non-Linux regression test | | 2 | Cross-platform strict `cfg` | **Fixed locally; native CI UNVERIFIED** | `#[cfg]` dispatch + non-Linux regression test |
| 3 | Strict probe→launch race | **Fixed locally; GitHub Linux CI UNVERIFIED** | fail-closed CLI contract + probe-OK/launch-EAGAIN seam test | | 3 | Strict probe→launch race | **Fixed locally; GitHub Linux CI UNVERIFIED** | fail-closed CLI contract + probe-OK/launch-EAGAIN seam test |
| 4 | Parallel security matrix isolation | **Fixed** | unique paths + helper `OnceLock`; 7/7 in parallel workspace run | | 4 | Parallel security matrix isolation | **Fixed** | unique paths + helper `OnceLock`; 7/7 in parallel workspace run |
| 5 | Markdown/power/control-flow corpus | **Done locally** | 160 AST, 68 semantic, 52 compile-negative, 21 runtime-negative fixtures | | 5 | Markdown/power/control-flow corpus | **Done locally** | 160 AST, 70 semantic, 52 compile-negative, 21 runtime-negative fixtures |
| 6 | Condition header + source spans | **Fixed** | executable tails rejected; literal-inside-backtick mapping tests | | 6 | Condition header + source spans | **Fixed** | executable tails rejected; literal-inside-backtick mapping tests |
| 7 | Independent Tool consumers | **Done locally** | `sample-view`/`sample-knowledge`/`sample-proof` E2E test | | 7 | Independent Tool consumers | **Done locally** | `sample-view`/`sample-knowledge`/`sample-proof` E2E test |
| 8 | lock v3 reproducibility | **Implemented; tamper test added** | `package_env` PASS | | 8 | lock v3 reproducibility | **Implemented; tamper test added** | `package_env` PASS |
@@ -86,7 +86,7 @@ This is still a **local VM lane**, not a self-hosted GitHub Actions security URL
- Frozen Markdown profile `marqdo.md.v1` with 160 AST goldens and explicit - Frozen Markdown profile `marqdo.md.v1` with 160 AST goldens and explicit
CRLF byte semantics. CRLF byte semantics.
- Native Rust interpreter with 68 semantic goldens, 52 compile-error fixtures, - Native Rust interpreter with 70 semantic goldens, 52 compile-error fixtures,
and runtime error source attribution. and runtime error source attribution.
- Native `**` power is pinned end-to-end: right associativity, unary-minus - Native `**` power is pinned end-to-end: right associativity, unary-minus
precedence, parentheses, float negative exponents, branch/loop conditions, precedence, parentheses, float negative exponents, branch/loop conditions,
@@ -166,7 +166,7 @@ behavior. This table records only what is in this tree now.
|---|---|---| |---|---|---|
| P0 freeze (ADRs, spec deltas, baseline) | **P1 + partial P2 slice done** | ADR-0022 freezes CM-A01/CM-A02/CM-A03; ADR-0023 freezes CM-A04 (minimal List/Map/Text/Table observation and construction); ADR-0024 freezes CM-A05 (recoverable `Result` map convention); `spec/expression.ebnf`, `spec/evaluation.md`, `spec/value-wire.md`, `spec/analysis-v2.md`, `spec/security.md` updated; existing AST/value goldens unchanged | | P0 freeze (ADRs, spec deltas, baseline) | **P1 + partial P2 slice done** | ADR-0022 freezes CM-A01/CM-A02/CM-A03; ADR-0023 freezes CM-A04 (minimal List/Map/Text/Table observation and construction); ADR-0024 freezes CM-A05 (recoverable `Result` map convention); `spec/expression.ebnf`, `spec/evaluation.md`, `spec/value-wire.md`, `spec/analysis-v2.md`, `spec/security.md` updated; existing AST/value goldens unchanged |
| P1 Memory + place assignment | **Implemented locally** | `Value::Memory`, run-scoped `MemoryStore` (64 KiB pages, 64 MiB total / 16 MiB region), `memory.new/size/grow`, `m[i]` read, `m[i] = byte`; semantic fixtures 45–47, runtime negatives 13–18, `examples/memory-buffer.mq.md`; evidence [`evidence/2026-11-20-memory-p1.md`](evidence/2026-11-20-memory-p1.md) | | P1 Memory + place assignment | **Implemented locally** | `Value::Memory`, run-scoped `MemoryStore` (64 KiB pages, 64 MiB total / 16 MiB region), `memory.new/size/grow`, `m[i]` read, `m[i] = byte`; semantic fixtures 45–47, runtime negatives 13–18, `examples/memory-buffer.mq.md`; evidence [`evidence/2026-11-20-memory-p1.md`](evidence/2026-11-20-memory-p1.md) |
| P2 Marqdo-written allocator/data structures + minimal structure observation | **PARTIAL, gate NOT passed** | `.mq.md`-only evidence: bump allocator with u32 codec, linked list, failed-allocation atomicity (48–50); CM-A04 structure primitives and a table filter (51–54, ADR-0023); a first-fit free-list allocator with block reuse, splitting, address-adjacent coalescing and `Result` maps (55, ADR-0024), a `Memory`-backed binary tree with recursive insert/in-order traversal (56), a `.mq.md` CSV row splitter (57), an open-addressing hash table with linear probing, update and `hash.full` (58), a `.mq.md` UTF-8 encoder over `Memory` (59), a validating UTF-8 decoder rejecting truncated, bad-continuation and surrogate/overlong input (60), a `Memory`-backed graph adjacency list (61), a recursive JSON parser for nested arrays/objects, strings with escapes, integers, booleans, null and error Results (62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (63), big-endian 16/32/64-bit plus LEB128 integer codecs (64), a `.mq.md` table sort rebuilding a new table from `table.row/columns/cell` (65), a table join (67), and a quoted/escaped CSV row parser (68). Evidence: [`memory-p2-closure`](evidence/2026-11-20-memory-p2-closure.md), [`structure-api-p2`](evidence/2026-11-20-structure-api-p2.md), [`result-and-free-list-p2`](evidence/2026-11-20-result-and-free-list-p2.md). Still missing: separate `marqdo-stdlib` repo, JSON floats, table group, EOF/partial stream contract, and a frozen-CLI closure lane. | | P2 Marqdo-written allocator/data structures + minimal structure observation | **PARTIAL, gate NOT passed** | `.mq.md`-only evidence: bump allocator with u32 codec, linked list, failed-allocation atomicity (48–50); CM-A04 structure primitives and a table filter (51–54, ADR-0023); a first-fit free-list allocator with block reuse, splitting, address-adjacent coalescing and `Result` maps (55, ADR-0024), a `Memory`-backed binary tree with recursive insert/in-order traversal (56), a `.mq.md` CSV row splitter (57), an open-addressing hash table with linear probing, update and `hash.full` (58), a `.mq.md` UTF-8 encoder over `Memory` (59), a validating UTF-8 decoder rejecting truncated, bad-continuation and surrogate/overlong input (60), a `Memory`-backed graph adjacency list (61), a recursive JSON parser for nested arrays/objects, strings with escapes, integers, booleans, null and error Results (62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (63), big-endian 16/32/64-bit plus LEB128 integer codecs (64), a `.mq.md` table sort rebuilding a new table from `table.row/columns/cell` (65), a table join (67), a quoted/escaped CSV row parser (68), table group (69), and an Int matrix multiply (70); the first-fit allocator also detects double free (`alloc.double_free`). Evidence: [`memory-p2-closure`](evidence/2026-11-20-memory-p2-closure.md), [`structure-api-p2`](evidence/2026-11-20-structure-api-p2.md), [`result-and-free-list-p2`](evidence/2026-11-20-result-and-free-list-p2.md). P2 remaining: JSON floats/formatter, a separate stdlib repository/package, and the frozen-CLI closure lane. C01–C06/C11/C12 now each have `.mq.md` evidence. |
| P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict refuses all opens. Fixture 66 + CLI/host tests. CM-A07 is **Compat-A only**: `examples/stdlib` provides an explicitly imported `.mq.md` `format/utf8/io` chain whose output matches builtin `打印` for Unit/None/Bool/Int/Float/Text/List/Map/Table; builtin `打印` remains default, no alias routing, and Formula/Code/FunctionRef/PluginHandle formatting is still unobservable. Still missing: Compat-B/C, directories, network, generic provider registry. | | P3 Resource/Stream ABI | **PARTIAL** | ADR-0025/0026 CM-A06 slices: opaque `Resource`, `resource.open/read/write/close`, stdout write in pure/project, granted project-file read and buffered project-file write in project, EOF/closed/handle errors, wire/host rejection; strict refuses all opens. Fixture 66 + CLI/host tests. CM-A07 is **Compat-A only**: `examples/stdlib` provides an explicitly imported `.mq.md` `format/utf8/io` chain whose output matches builtin `打印` for Unit/None/Bool/Int/Float/Text/List/Map/Table; builtin `打印` remains default, no alias routing, and Formula/Code/FunctionRef/PluginHandle formatting is still unobservable. Still missing: Compat-B/C, directories, network, generic provider registry. |
| P4 Table logical/physical migration | **NOT IMPLEMENTED** | `Value::Table` remains `Vec<Vec<Value>>`; no stdlib table algorithms | | P4 Table logical/physical migration | **NOT IMPLEMENTED** | `Value::Table` remains `Vec<Vec<Value>>`; no stdlib table algorithms |
| P5 third-party Provider / TCP / HTTP | **NOT IMPLEMENTED** | `fs.write`, `net.request`, `process`, `clock`, `random` remain unavailable broker services (see §4) | | P5 third-party Provider / TCP / HTTP | **NOT IMPLEMENTED** | `fs.write`, `net.request`, `process`, `clock`, `random` remain unavailable broker services (see §4) |
+1 -1
View File
@@ -6,7 +6,7 @@ normative RFC text stays at its reviewable path under `docs/`.
| Document | Status | Implemented part | | Document | Status | Implemented part |
|---|---|---| |---|---|---|
| [RFC-CM-0001: compute machine, addressable memory and system boundary](../MARQDO_COMPUTE_MACHINE_RFC_0001.md) | Draft / design input | R1 (P1): `Memory` value, `memory.new/size/grow`, byte read/write, Memory-index assignment, budgets, wire/host rejection. Implemented per [ADR-0022](../adr/0022-addressable-memory-and-place-assignment.md); see [STATUS §5](../STATUS.md). | | [RFC-CM-0001: compute machine, addressable memory and system boundary](../MARQDO_COMPUTE_MACHINE_RFC_0001.md) | Draft / design input | R1 (P1): `Memory` value, `memory.new/size/grow`, byte read/write, Memory-index assignment, budgets, wire/host rejection. Implemented per [ADR-0022](../adr/0022-addressable-memory-and-place-assignment.md); see [STATUS §5](../STATUS.md). |
| [RFC-CM-0002: minimal core, stdlib self-hosting and system capability migration](../MARQDO_COMPUTE_CORE_STDLIB_MIGRATION_RFC_0002.md) | Draft / design input | P0/P1, a **partial P2**, and a **partial P3** first slice (ADR-0025/0026: stdout write, granted project-file read and buffered project-file write via `resource.*`; strict refuses all opens; ADR-0027 Compat-A `.mq.md` print prototype, builtin still default). P2: fixtures 48–50 (`.mq.md` bump allocator, u32 codec, linked list/traversal, failed-allocation atomicity), CM-A04 structure primitives for List/Map/Text/Table (ADR-0023, fixtures 51–54), and a `.mq.md` first-fit free-list allocator with block splitting, address-adjacent coalescing and `Result` maps (ADR-0024, fixture 55), plus a `Memory`-backed binary tree with recursive insert/in-order traversal (fixture 56), a `.mq.md` CSV row splitter (fixture 57), an open-addressing hash table with linear probing (fixture 58), a `.mq.md` UTF-8 encoder and validating decoder (`utf8.truncated`/`invalid_continuation`/`invalid_scalar`) (fixtures 59–60), a `Memory`-backed graph adjacency list (fixture 61), a recursive JSON parser for arrays, objects, strings with escapes, integers/booleans/null and error Results (fixture 62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (fixture 63), big-endian 16/32/64-bit plus LEB128 integer codecs (fixture 64), a `.mq.md` table sort rebuilding the table without mutating the input (fixture 65), a table join built from `table.row/columns/cell` (fixture 67), and a quoted/escaped CSV row parser (fixture 68). No separate stdlib repo, JSON floats, network/generic providers, P4 Table migration, P5 providers or P6 performance work. | | [RFC-CM-0002: minimal core, stdlib self-hosting and system capability migration](../MARQDO_COMPUTE_CORE_STDLIB_MIGRATION_RFC_0002.md) | Draft / design input | P0/P1, a **partial P2**, and a **partial P3** first slice (ADR-0025/0026: stdout write, granted project-file read and buffered project-file write via `resource.*`; strict refuses all opens; ADR-0027 Compat-A `.mq.md` print prototype, builtin still default). P2: fixtures 48–50 (`.mq.md` bump allocator, u32 codec, linked list/traversal, failed-allocation atomicity), CM-A04 structure primitives for List/Map/Text/Table (ADR-0023, fixtures 51–54), and a `.mq.md` first-fit free-list allocator with block splitting, address-adjacent coalescing and `Result` maps (ADR-0024, fixture 55), plus a `Memory`-backed binary tree with recursive insert/in-order traversal (fixture 56), a `.mq.md` CSV row splitter (fixture 57), an open-addressing hash table with linear probing (fixture 58), a `.mq.md` UTF-8 encoder and validating decoder (`utf8.truncated`/`invalid_continuation`/`invalid_scalar`) (fixtures 59–60), a `Memory`-backed graph adjacency list (fixture 61), a recursive JSON parser for arrays, objects, strings with escapes, integers/booleans/null and error Results (fixture 62), a `Memory`-backed stack bytecode VM with PUSH/ADD/MUL/JMP/JZ/HALT (fixture 63), big-endian 16/32/64-bit plus LEB128 integer codecs (fixture 64), a `.mq.md` table sort rebuilding the table without mutating the input (fixture 65), a table join built from `table.row/columns/cell` (fixture 67), and a quoted/escaped CSV row parser (fixture 68), table group (fixture 69) and an Int matrix multiply (fixture 70). No separate stdlib repo, JSON floats, network/generic providers, P4 Table migration, P5 providers or P6 performance work. |
The RFCs are architecture constraints, not evidence that a feature exists. The The RFCs are architecture constraints, not evidence that a feature exists. The
implementation status lives in `docs/STATUS.md`; frozen behavior is in implementation status lives in `docs/STATUS.md`; frozen behavior is in
@@ -339,9 +339,31 @@ a,,c -> ["a", "", "c"]
No Rust CSV parser or new `Value` type was added. No Rust CSV parser or new `Value` type was added.
## Table group fixture 69
`tests/conformance/semantics/69-table-group-stdlib.mq.md` groups a table by a
Text key column into a `Map` of value lists using `table.row`, `map.has/get/set`
and `list.append`. Input rows `a1,b2,a3,b4,a5` yield
`{a:[1,3,5], b:[2,4]}`; the source table is unchanged.
## Matrix multiply fixture 70
`tests/conformance/semantics/70-matrix-multiply.mq.md` implements Int
list-of-list row-major matrix multiplication with three explicit loops
(C12's layout/iteration shape). `[[1,2,3],[4,5,6]] × [[7,8],[9,10],[11,12]]`
yields `[[58,64],[139,154]]`; no numeric backend or Rust matrix code is used.
## Duplicate-free allocator path
`tests/conformance/semantics/55-first-fit-free-list-allocator.mq.md` now
scans the free list before insertion and returns
`{ok:false, code:"alloc.double_free", ...}` when a block is freed twice. The
second free in fixture 55 returns that Result instead of corrupting the list.
## What remains open ## What remains open
* JSON floats, table group, and an independent `marqdo-stdlib` repository; * JSON floats/formatter, and an independent `marqdo-stdlib` repository plus
frozen-CLI closure lane;
* CM-A06 `Resource`/`Stream` byte-transfer ABI; EOF/partial semantics are * CM-A06 `Resource`/`Stream` byte-transfer ABI; EOF/partial semantics are
reserved by ADR-0024 but not implemented; reserved by ADR-0024 but not implemented;
* CM-A07–CM-A11 (stdlib naming, Table storage, provider ABI, packaging, * CM-A07–CM-A11 (stdlib naming, Table storage, provider ABI, packaging,
+8 -2
View File
@@ -15,7 +15,7 @@ no test commits, copies or rewrites files outside a throw-away temp directory.
tests/ tests/
├── conformance/ ├── conformance/
│ ├── ast/ 160 × *.mq.md + sibling *.ast.json goldens │ ├── ast/ 160 × *.mq.md + sibling *.ast.json goldens
│ └── semantics/ 68 × *.mq.md + sibling *.expected.json goldens │ └── semantics/ 70 × *.mq.md + sibling *.expected.json goldens
├── negative/ ├── negative/
│ ├── *.mq.md 52 × compile-time hard-error fixtures + *.expected.json │ ├── *.mq.md 52 × compile-time hard-error fixtures + *.expected.json
│ ├── warnings/ 6 × inert-executable warning fixtures + *.expected.json │ ├── warnings/ 6 × inert-executable warning fixtures + *.expected.json
@@ -163,7 +163,13 @@ by:
tables remain unchanged; tables remain unchanged;
* semantic fixture 68: a quoted/escaped CSV single-row parser using Unicode * semantic fixture 68: a quoted/escaped CSV single-row parser using Unicode
scalar primitives; `""` is a literal quote and commas inside quotes are scalar primitives; `""` is a literal quote and commas inside quotes are
preserved. Multi-line fields and whitespace trimming are out of scope. preserved. Multi-line fields and whitespace trimming are out of scope;
* semantic fixture 69: table group by a Text key column into a `Map` of value
lists, using `table.row/cell`, `map.has/get/set` and `list.append`;
* semantic fixture 70: Int matrix multiply over list-of-list row-major data,
covering C12's layout/iteration shape without a numeric backend;
* fixture 55 additionally has a second-free detection path: freeing an
already-free block returns `{ok:false, code:"alloc.double_free"}`.
RFC-CM CM-A07 Compat-A (ADR-0027) is pinned by: RFC-CM CM-A07 Compat-A (ADR-0027) is pinned by:
@@ -220,6 +220,35 @@
}, },
"type": "map" "type": "map"
}, },
{
"entries": {
"ok": {
"type": "bool",
"value": true
},
"value": {
"type": "none"
}
},
"type": "map"
},
{
"entries": {
"code": {
"type": "text",
"value": "alloc.double_free"
},
"message": {
"type": "text",
"value": "块已在空闲链表"
},
"ok": {
"type": "bool",
"value": false
}
},
"type": "map"
},
{ {
"decimal": "33", "decimal": "33",
"type": "int" "type": "int"
@@ -221,14 +221,40 @@ first-fit:先查空闲链表,必要时切分;否则从 bump 指针处取
*成功(None)* *成功(None)*
## 已在空闲表
`(内存, 块)`
线性扫描空闲链表,检测重复释放。
**当前 = 读32(内存, 0)**
**结果 = false**
- `当前 != 0 and not 结果`
1. `当前 == 块`
**结果 = true**
2. `true`
**当前 = 读32(内存, 当前 + 4)**
*结果*
## 释放 ## 释放
`(内存, 地址)` `(内存, 地址)`
把 payload 偏移换算回块头,按地址插入空闲链表并由“合并”处理相邻块。 把 payload 偏移换算回块头;重复释放返回可恢复错误,正常释放按地址插入并由“合并”处理相邻块。
**块 = 地址 - 8** **块 = 地址 - 8**
1. `已在空闲表(内存, 块)`
*失败("alloc.double_free", "块已在空闲链表")*
> 插入空闲(内存, 块) > 插入空闲(内存, 块)
*成功(None)* *成功(None)*
@@ -305,4 +331,8 @@ first-fit:先查空闲链表,必要时切分;否则从 bump 指针处取
**戊2 = 分配(内存2, 65536, 8)** **戊2 = 分配(内存2, 65536, 8)**
*[甲, 乙, 丙, 丁, 戊, 己, 庚, 辛, 壬, 癸, 失败结果, 甲2, 乙2, 丙2, 丁2, 戊2, 内存[甲.value], 内存[乙.value], 内存[丙.value], 内存[丁.value], 内存[戊.value], 内存[庚.value], 内存[辛.value], 内存[壬.value], 内存[癸.value]]* **释放一次 = 释放(内存2, 丁2.value)**
**重复释放 = 释放(内存2, 丁2.value)**
*[甲, 乙, 丙, 丁, 戊, 己, 庚, 辛, 壬, 癸, 失败结果, 甲2, 乙2, 丙2, 丁2, 戊2, 释放一次, 重复释放, 内存[甲.value], 内存[乙.value], 内存[丙.value], 内存[丁.value], 内存[戊.value], 内存[庚.value], 内存[辛.value], 内存[壬.value], 内存[癸.value]]*
@@ -0,0 +1,104 @@
{
"args": {},
"function": "main",
"stdout": "",
"value": {
"items": [
{
"header": [
"类别",
"值"
],
"rows": [
[
{
"type": "text",
"value": "a"
},
{
"decimal": "1",
"type": "int"
}
],
[
{
"type": "text",
"value": "b"
},
{
"decimal": "2",
"type": "int"
}
],
[
{
"type": "text",
"value": "a"
},
{
"decimal": "3",
"type": "int"
}
],
[
{
"type": "text",
"value": "b"
},
{
"decimal": "4",
"type": "int"
}
],
[
{
"type": "text",
"value": "a"
},
{
"decimal": "5",
"type": "int"
}
]
],
"type": "table"
},
{
"entries": {
"a": {
"items": [
{
"decimal": "1",
"type": "int"
},
{
"decimal": "3",
"type": "int"
},
{
"decimal": "5",
"type": "int"
}
],
"type": "list"
},
"b": {
"items": [
{
"decimal": "2",
"type": "int"
},
{
"decimal": "4",
"type": "int"
}
],
"type": "list"
}
},
"type": "map"
}
],
"type": "list"
}
}
@@ -0,0 +1,41 @@
## 分组
`(数据, 键列, 值列)`
按文本键列分组,把值列聚合成 Map:键 -> List。输入表不变。
**结果 = {}**
**行号 = 0**
- `行号 < 长度(数据)`
**行 = table.row(数据, 行号)**
**键 = 行[键列]**
**当前 = map.get(结果, 键)**
**列表 = []**
1. `map.has(结果, 键)`
**列表 = 当前**
2. `true`
**忽略 = 0**
**列表 = list.append(列表, 行[值列])**
**结果 = map.set(结果, 键, 列表)**
**行号 = 行号 + 1**
*结果*
## main
**数据 = 表(["类别", "值"], [["a", 1], ["b", 2], ["a", 3], ["b", 4], ["a", 5]])**
*[数据, 分组(数据, 0, 1)]*
@@ -0,0 +1,124 @@
{
"args": {},
"function": "main",
"stdout": "",
"value": {
"items": [
{
"items": [
{
"items": [
{
"decimal": "1",
"type": "int"
},
{
"decimal": "2",
"type": "int"
},
{
"decimal": "3",
"type": "int"
}
],
"type": "list"
},
{
"items": [
{
"decimal": "4",
"type": "int"
},
{
"decimal": "5",
"type": "int"
},
{
"decimal": "6",
"type": "int"
}
],
"type": "list"
}
],
"type": "list"
},
{
"items": [
{
"items": [
{
"decimal": "7",
"type": "int"
},
{
"decimal": "8",
"type": "int"
}
],
"type": "list"
},
{
"items": [
{
"decimal": "9",
"type": "int"
},
{
"decimal": "10",
"type": "int"
}
],
"type": "list"
},
{
"items": [
{
"decimal": "11",
"type": "int"
},
{
"decimal": "12",
"type": "int"
}
],
"type": "list"
}
],
"type": "list"
},
{
"items": [
{
"items": [
{
"decimal": "58",
"type": "int"
},
{
"decimal": "64",
"type": "int"
}
],
"type": "list"
},
{
"items": [
{
"decimal": "139",
"type": "int"
},
{
"decimal": "154",
"type": "int"
}
],
"type": "list"
}
],
"type": "list"
}
],
"type": "list"
}
}
@@ -0,0 +1,47 @@
## 矩阵乘
`(左, 右)`
List-of-List 行主序矩阵乘法;调用方保证维度匹配。使用 Int 精确算术。
**结果 = []**
**行号 = 0**
- `行号 < 长度(左)`
**左行 = 左[行号]**
**新行 = []**
**列号 = 0**
- `列号 < 长度(右[0])`
**总和 = 0**
**内号 = 0**
- `内号 < 长度(左行)`
**总和 = 总和 + 左行[内号] * 右[内号][列号]**
**内号 = 内号 + 1**
**新行 = list.append(新行, 总和)**
**列号 = 列号 + 1**
**结果 = list.append(结果, 新行)**
**行号 = 行号 + 1**
*结果*
## main
**左 = [[1, 2, 3], [4, 5, 6]]**
**右 = [[7, 8], [9, 10], [11, 12]]**
*[左, 右, 矩阵乘(左, 右)]*