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:
1 parent
49835424ee
commit
e029853e32
375 files changed
+6591
-4790
No files matched your search
@@ -1,108 +1,118 @@
|
||||
## 写大端
|
||||
## @exec 写大端
|
||||
|
||||
`(内存, 基址, 值, 宽度)`
|
||||
`params(内存: Memory, 基址: Int, 值: Int, 宽度: Int)`
|
||||
|
||||
从最低字节开始写,放到 `基址 + 宽度 - 1 - 下标`,因此最终是大端序。
|
||||
调用方保证 `值` 能放进 `宽度` 字节。
|
||||
从最低字节开始写,放到 基址 + 宽度 - 1 - 下标,因此最终是大端序。
|
||||
调用方保证 值 能放进 宽度 字节。
|
||||
|
||||
**当前 = 值**
|
||||
`当前 = 值`
|
||||
|
||||
**下标 = 0**
|
||||
`下标 = 0`
|
||||
|
||||
- `下标 < 宽度`
|
||||
`while 下标 < 宽度`
|
||||
|
||||
**`内存[基址 + 宽度 - 1 - 下标] = 当前 % 256`**
|
||||
`内存[基址 + 宽度 - 1 - 下标] = 当前 % 256`
|
||||
|
||||
**当前 = 当前 // 256**
|
||||
`当前 = 当前 // 256`
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
`下标 = 下标 + 1`
|
||||
|
||||
*None*
|
||||
`end`
|
||||
|
||||
## 读大端
|
||||
`return None`
|
||||
|
||||
`(内存, 基址, 宽度)`
|
||||
## @exec 读大端
|
||||
|
||||
**值 = 0**
|
||||
`params(内存: Memory, 基址: Int, 宽度: Int)`
|
||||
|
||||
**下标 = 0**
|
||||
`值 = 0`
|
||||
|
||||
- `下标 < 宽度`
|
||||
`下标 = 0`
|
||||
|
||||
**值 = 值 * 256 + 内存[基址 + 下标]**
|
||||
`while 下标 < 宽度`
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
`值 = 值 * 256 + 内存[基址 + 下标]`
|
||||
|
||||
*值*
|
||||
`下标 = 下标 + 1`
|
||||
|
||||
## 写变长
|
||||
`end`
|
||||
|
||||
`(内存, 基址, 值)`
|
||||
`return 值`
|
||||
|
||||
## @exec 写变长
|
||||
|
||||
`params(内存: Memory, 基址: Int, 值: Int)`
|
||||
|
||||
LEB128:每字节低 7 位,最高位表示是否还有后续;返回写入字节数。
|
||||
|
||||
**当前 = 值**
|
||||
`当前 = 值`
|
||||
|
||||
**偏移 = 0**
|
||||
`偏移 = 0`
|
||||
|
||||
- `当前 >= 128`
|
||||
`while 当前 >= 128`
|
||||
|
||||
**`内存[基址 + 偏移] = 当前 % 128 + 128`**
|
||||
`内存[基址 + 偏移] = 当前 % 128 + 128`
|
||||
|
||||
**当前 = 当前 // 128**
|
||||
`当前 = 当前 // 128`
|
||||
|
||||
**偏移 = 偏移 + 1**
|
||||
`偏移 = 偏移 + 1`
|
||||
|
||||
**`内存[基址 + 偏移] = 当前`**
|
||||
`end`
|
||||
|
||||
*偏移 + 1*
|
||||
`内存[基址 + 偏移] = 当前`
|
||||
|
||||
## 读变长
|
||||
`return 偏移 + 1`
|
||||
|
||||
`(内存, 基址)`
|
||||
## @exec 读变长
|
||||
|
||||
返回 `[值, 消耗字节数]`。
|
||||
`params(内存: Memory, 基址: Int)`
|
||||
|
||||
**值 = 0**
|
||||
返回 [值, 消耗字节数]。
|
||||
|
||||
**倍数 = 1**
|
||||
`值 = 0`
|
||||
|
||||
**偏移 = 0**
|
||||
`倍数 = 1`
|
||||
|
||||
**继续 = true**
|
||||
`偏移 = 0`
|
||||
|
||||
- `继续`
|
||||
`继续 = true`
|
||||
|
||||
**字节 = 内存[基址 + 偏移]**
|
||||
`while 继续`
|
||||
|
||||
**值 = 值 + 字节 % 128 * 倍数**
|
||||
`字节 = 内存[基址 + 偏移]`
|
||||
|
||||
1. `字节 < 128`
|
||||
`值 = 值 + 字节 % 128 * 倍数`
|
||||
|
||||
**继续 = false**
|
||||
`if 字节 < 128`
|
||||
|
||||
2. `true`
|
||||
`继续 = false`
|
||||
|
||||
**倍数 = 倍数 * 128**
|
||||
`else`
|
||||
|
||||
**偏移 = 偏移 + 1**
|
||||
`倍数 = 倍数 * 128`
|
||||
|
||||
*[值, 偏移 + 1]*
|
||||
`偏移 = 偏移 + 1`
|
||||
|
||||
## main
|
||||
`end`
|
||||
|
||||
**内存 = memory.new(1, 1)**
|
||||
`end`
|
||||
|
||||
> 写大端(内存, 0, 4660, 2)
|
||||
`return [值, 偏移 + 1]`
|
||||
|
||||
> 写大端(内存, 16, 305419896, 4)
|
||||
## @exec main
|
||||
|
||||
> 写大端(内存, 32, 1311768467463790320, 8)
|
||||
`内存 = memory.new(1, 1)`
|
||||
|
||||
> 写大端(内存, 48, 18446744073709551615, 8)
|
||||
`写大端(内存, 0, 4660, 2)`
|
||||
|
||||
**变长长度 = 写变长(内存, 128, 123456789)**
|
||||
`写大端(内存, 16, 305419896, 4)`
|
||||
|
||||
**变长 = 读变长(内存, 128)**
|
||||
`写大端(内存, 32, 1311768467463790320, 8)`
|
||||
|
||||
*[读大端(内存, 0, 2), 读大端(内存, 16, 4), 读大端(内存, 32, 8), 读大端(内存, 48, 8), 变长长度, 变长[0], 变长[1], 内存[48], 内存[55]]*
|
||||
`写大端(内存, 48, 18446744073709551615, 8)`
|
||||
|
||||
`变长长度 = 写变长(内存, 128, 123456789)`
|
||||
|
||||
`变长 = 读变长(内存, 128)`
|
||||
|
||||
`return [读大端(内存, 0, 2), 读大端(内存, 16, 4), 读大端(内存, 32, 8), 读大端(内存, 48, 8), 变长长度, 变长[0], 变长[1], 内存[48], 内存[55]]`
|
||||
Reference in new issue
Block a user