Files
marqdo-cli/docs/evidence/2026-11-20-stdlib-print-compat-a.md
T
cflmy 1377af1601 feat(stdlib): ship a verified bundled stdlib with std: imports
- Move the Compat-A print prototype into stdlib/ as the official offline
  bundle with stdlib.json (version 0.1.0 + sha256 content digest).
- Add std:<relative> import resolution in the loader with bundle path
  confinement, extension inference and fail-closed digest verification.
- Record the verified version/digest/instance_id in Analysis v2
  project.stdlib; stdlib modules get a std:name@version#digest instance id.
- Add CLI tests: std:io execution, digest-tamper rejection, missing manifest,
  Analysis identity, no foreign/plugin calls, and frozen binary hash equality.
- Update ADR-0028, specs, status, changelog and evidence.

Gate: fmt, clippy -D warnings, 415 tests passed.
2026-11-20 21:43:14 +08:00

95 lines
3.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# RFC-CM CM-A07 Compat-A evidence: `.mq.md` print prototype
Date: 2026-11-20 (Asia/Shanghai)
Repository: `marqdo-cli`
Baseline: `a113d89` plus the uncommitted RFC-CM P0–P3 changes.
Decision record: [ADR-0027](../adr/0027-print-migration-compat-a.md)
Related: [Resource P3](2026-11-20-resource-stream-p3.md),
[file write](2026-11-20-resource-file-write-p3.md), [STATUS §5](../STATUS.md).
Scope: **Compat-A only**. Builtin `打印` is not migrated; no alias routing and
no removal of `HostOp::Print`.
## Environment and gate
Ubuntu 26.04 development container, Linux x86_64, Rust 1.100.0.
```text
cargo fmt --all -- --check PASS
cargo clippy --workspace --all-targets -- -D warnings PASS
cargo test --workspace --locked PASS
407 passed, 0 failed, 2 ignored (existing plugin-sdk doc-tests)
```
No GitHub CI is available from this checkout; this is local evidence.
## Prototype
Ordinary `.mq.md` modules (now the bundled `stdlib/` tree, ADR-0028):
| File | Responsibility |
|---|---|
| `format.mq.md` | `显示` for Unit/None/Bool/Int/Float/Text/List/Map/Table, `值显示` (repr), `转义文本`, `列表显示`, `映射显示`, `表格显示`, `连接文本` |
| `text.mq.md` | `utf8编码(文本, 内存, 基址)` — 1–4 byte UTF-8 into `Memory` |
| `io.mq.md` | `写文本` (encode → `resource.write(stdout)` → close) and `写值` (format + newline) |
| `demo.mq.md` | side-by-side `io.写值(x)` and builtin `打印(x)` for a nested list and a table |
The call chain is exactly the RFC target shape:
```text
io.写值(value)
-> format.显示(value) # .mq.md value formatting, no Rust display()
-> text.utf8编码(text, memory) # .mq.md UTF-8 encoder
-> resource.open(stdout)
-> resource.write(memory, ...) # bytes through Memory
-> resource.close(stdout)
```
No `HostOp`, no new builtin, no parser change and no special stdlib dispatch.
The module is loaded only through an explicit Markdown import alias.
## Output comparison
```text
$ marqdo run stdlib/demo.mq.md
["文本", 2, 1.5, [3, true], {a: 1, b: "x"}, None]
["文本", 2, 1.5, [3, true], {a: 1, b: "x"}, None]
Table[名称 | 分数]{甲 | 87; 乙 | 92}
Table[名称 | 分数]{甲 | 87; 乙 | 92}
```
The first and third lines are `io.写值`; the second and fourth are builtin
`打印`. They are byte-identical.
CLI test:
`crates/cli/tests/examples_r6.rs::mqmd_stdlib_print_output_matches_builtin_print`
asserts exactly four lines, pairwise equality, and the exact list/table text.
## Covered and uncovered values
Covered by Compat-A comparison: `Unit`, `None`, `Bool`, `Int`, `Float`, `Text`,
`List`, `Map`, `Table`.
Not covered: `Formula`, `Code`, `FunctionRef`, `PluginHandle`. The language
still has no public observation for the module/name/handle identity needed to
reproduce `Value::display()`/`repr()` for those types; adding it is a CM-A04
extension, not part of this slice. This is the explicit blocker for Compat-B.
## What is not migrated
* `打印`/`print` still resolves to the existing builtin and `HostOp::Print`.
* No alias table, no bundled stdlib resolution, no `std` package.
* No stdlib version/digest or offline distribution (CM-A10).
* No Compat-B/C comparison lane or removal of the Rust `Value::display()` path.
* The demo/stdlib is an `examples/` prototype, not a shipped standard library.
## Reproduce
```bash
export PATH=/root/.cargo/bin:$PATH
export CARGO_HOME=/root/work/marqdo-cli/.cache/cargo
export CARGO_TARGET_DIR=/root/work/marqdo-cli/.cache/target
cargo run -q -p marqdo-cli -- run stdlib/demo.mq.md
cargo test -p marqdo-cli --test examples_r6
cargo test --workspace --locked
```