Implements the first vertical slices of RFC-CM-0001/0002 on top of a113d89:
- P1: opaque Memory regions (64 KiB pages, budgets, grow-only), byte
read/write, Memory-index place assignment, wire/host-boundary rejection.
- CM-A04/A05: value-semantics List/Map/Text/Table primitives and the
recoverable Result map convention.
- CM-A06: opaque Resource handles, resource.open/read/write/close, stdout
write, granted project-file read and buffered write, strict fail-closed.
- CM-A07 Compat-A: explicit .mq.md format/utf8/io chain matching builtin
print for the covered value types; builtin remains default.
- P2 fixtures: allocators, list/tree/graph/hash, integer codecs, UTF-8
encode/decode, CSV/JSON subsets, table filter/sort/join, bytecode VM.
- ADRs 0022-0027, spec updates, evidence reports and 68 semantic goldens.
Gate: cargo fmt --check, clippy -D warnings, 407 tests passed.
1.7 KiB
写大端
(内存, 基址, 值, 宽度)
从最低字节开始写,放到 基址 + 宽度 - 1 - 下标,因此最终是大端序。
调用方保证 值 能放进 宽度 字节。
当前 = 值
下标 = 0
-
下标 < 宽度内存[基址 + 宽度 - 1 - 下标] = 当前 % 256当前 = 当前 // 256
下标 = 下标 + 1
None
读大端
(内存, 基址, 宽度)
值 = 0
下标 = 0
-
下标 < 宽度值 = 值 * 256 + 内存[基址 + 下标]
下标 = 下标 + 1
值
写变长
(内存, 基址, 值)
LEB128:每字节低 7 位,最高位表示是否还有后续;返回写入字节数。
当前 = 值
偏移 = 0
-
当前 >= 128内存[基址 + 偏移] = 当前 % 128 + 128当前 = 当前 // 128
偏移 = 偏移 + 1
内存[基址 + 偏移] = 当前
偏移 + 1
读变长
(内存, 基址)
返回 [值, 消耗字节数]。
值 = 0
倍数 = 1
偏移 = 0
继续 = true
-
继续字节 = 内存[基址 + 偏移]
值 = 值 + 字节 % 128 * 倍数
-
字节 < 128继续 = false
-
true倍数 = 倍数 * 128
偏移 = 偏移 + 1
-
[值, 偏移 + 1]
main
内存 = memory.new(1, 1)
写大端(内存, 0, 4660, 2)
写大端(内存, 16, 305419896, 4)
写大端(内存, 32, 1311768467463790320, 8)
写大端(内存, 48, 18446744073709551615, 8)
变长长度 = 写变长(内存, 128, 123456789)
变长 = 读变长(内存, 128)
[读大端(内存, 0, 2), 读大端(内存, 16, 4), 读大端(内存, 32, 8), 读大端(内存, 48, 8), 变长长度, 变长[0], 变长[1], 内存[48], 内存[55]]