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
+73
-46
@@ -5,12 +5,14 @@ import:
|
||||
utf8: "../text/utf8.mq.md"
|
||||
---
|
||||
|
||||
# @exec console
|
||||
|
||||
## 读取行
|
||||
|
||||
`()`
|
||||
`params()`
|
||||
|
||||
从已授权的 `stdio/stdin` 资源读取一行。按有界块读取并增量解码 UTF-8;
|
||||
EOF 返回 `{ok:false, code:"io.eof"}`,无效 UTF-8 返回可恢复错误。
|
||||
从已授权的 stdio/stdin 资源读取一行。按有界块读取并增量解码 UTF-8;
|
||||
EOF 返回 {ok:false, code:"io.eof"},无效 UTF-8 返回可恢复错误。
|
||||
|
||||
**流 = resource.open("stdio", "stdin", ["read"])**
|
||||
|
||||
@@ -22,98 +24,123 @@ EOF 返回 `{ok:false, code:"io.eof"}`,无效 UTF-8 返回可恢复错误。
|
||||
|
||||
**错误 = ""**
|
||||
|
||||
- `not 结束`
|
||||
`while not 结束`
|
||||
|
||||
**读取 = resource.read(流, 内存, 0, 1)**
|
||||
**读取 = resource.read(流, 内存, 0, 1)**
|
||||
|
||||
1. `not 读取.ok`
|
||||
`if not 读取.ok`
|
||||
|
||||
**结束 = true**
|
||||
**结束 = true**
|
||||
|
||||
**错误 = 读取.code**
|
||||
**错误 = 读取.code**
|
||||
|
||||
2. `读取.value.eof and 读取.value.count == 0`
|
||||
`else`
|
||||
`if 读取.value.eof and 读取.value.count == 0`
|
||||
|
||||
**结束 = true**
|
||||
**结束 = true**
|
||||
|
||||
3. `内存[0] == 10`
|
||||
`else`
|
||||
`if 内存[0] == 10`
|
||||
|
||||
**结束 = true**
|
||||
**结束 = true**
|
||||
|
||||
4. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**字节 = list.append(字节, 内存[0])**
|
||||
**字节 = list.append(字节, 内存[0])**
|
||||
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
**关闭 = resource.close(流)**
|
||||
|
||||
1. `错误 != ""`
|
||||
`if 错误 != ""`
|
||||
|
||||
*{ok: false, code: 错误, message: "stdin read failed"}*
|
||||
`return {ok: false, code: 错误, message: "stdin read failed"}`
|
||||
|
||||
2. `not 关闭.ok`
|
||||
`else`
|
||||
`if not 关闭.ok`
|
||||
|
||||
*关闭*
|
||||
`return 关闭`
|
||||
|
||||
3. `长度(字节) == 0`
|
||||
`else`
|
||||
`if 长度(字节) == 0`
|
||||
|
||||
*{ok: false, code: "io.eof", message: "end of input"}*
|
||||
`return {ok: false, code: "io.eof", message: "end of input"}`
|
||||
|
||||
4. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**数据长度 = 长度(字节)**
|
||||
**数据长度 = 长度(字节)**
|
||||
|
||||
1. `数据长度 > 0 and 字节[数据长度 - 1] == 13`
|
||||
`if 数据长度 > 0 and 字节[数据长度 - 1] == 13`
|
||||
|
||||
**数据长度 = 数据长度 - 1**
|
||||
**数据长度 = 数据长度 - 1**
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**忽略 = 0**
|
||||
**忽略 = 0**
|
||||
|
||||
**页 = (数据长度 + 65535) // 65536**
|
||||
`end`
|
||||
`end`
|
||||
**页 = (数据长度 + 65535) // 65536**
|
||||
|
||||
**数据 = memory.new(页, 页)**
|
||||
**数据 = memory.new(页, 页)**
|
||||
|
||||
**下标 = 0**
|
||||
**下标 = 0**
|
||||
|
||||
- `下标 < 数据长度`
|
||||
`while 下标 < 数据长度`
|
||||
|
||||
**`数据[下标] = 字节[下标]`**
|
||||
**`数据[下标] = 字节[下标]`**
|
||||
|
||||
**下标 = 下标 + 1**
|
||||
**下标 = 下标 + 1**
|
||||
|
||||
**解码 = utf8.解码(数据, 0, 数据长度)**
|
||||
`end`
|
||||
**解码 = utf8.解码(数据, 0, 数据长度)**
|
||||
|
||||
1. `not 解码.ok`
|
||||
`if not 解码.ok`
|
||||
|
||||
*解码*
|
||||
`return 解码`
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*{ok: true, value: 解码.value}*
|
||||
`return {ok: true, value: 解码.value}`
|
||||
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
## 打印
|
||||
|
||||
`(值)`
|
||||
`params(值)`
|
||||
|
||||
**结果 = stream.写文本(format.显示(值) + "\n")**
|
||||
|
||||
1. `not 结果.ok`
|
||||
`if not 结果.ok`
|
||||
|
||||
*结果*
|
||||
`return 结果`
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*{ok: true, value: None}*
|
||||
`return {ok: true, value: None}`
|
||||
|
||||
`end`
|
||||
`end`
|
||||
## 写文本
|
||||
|
||||
`(文本)`
|
||||
`params(文本)`
|
||||
|
||||
*stream.写文本(文本)*
|
||||
`return stream.写文本(文本)`
|
||||
|
||||
## 写全部
|
||||
|
||||
`(流, 内存, 起点, 长度)`
|
||||
`params(流, 内存, 起点, 长度)`
|
||||
|
||||
*stream.写全部(流, 内存, 起点, 长度)*
|
||||
`return stream.写全部(流, 内存, 起点, 长度)`
|
||||
+55
-34
@@ -4,26 +4,31 @@ import:
|
||||
utf8: "../text/utf8.mq.md"
|
||||
---
|
||||
|
||||
# @exec stream
|
||||
|
||||
## 页数
|
||||
|
||||
`(字节)`
|
||||
`params(字节)`
|
||||
|
||||
**页 = (字节 + 65535) // 65536**
|
||||
|
||||
1. `页 == 0`
|
||||
`if 页 == 0`
|
||||
|
||||
*1*
|
||||
`return 1`
|
||||
|
||||
2. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*页*
|
||||
`return 页`
|
||||
|
||||
`end`
|
||||
`end`
|
||||
## 写全部
|
||||
|
||||
`(流, 内存, 起点, 长度)`
|
||||
`params(流, 内存, 起点, 长度)`
|
||||
|
||||
把 `长度` 字节从 `内存` 写到资源流。短写只返回实际数量,调用方继续;
|
||||
零进度返回 `io.write_zero`,不静默吞掉失败。
|
||||
把 长度 字节从 内存 写到资源流。短写只返回实际数量,调用方继续;
|
||||
零进度返回 io.write_zero,不静默吞掉失败。
|
||||
|
||||
**已写 = 0**
|
||||
|
||||
@@ -33,48 +38,59 @@ import:
|
||||
|
||||
**错误结果 = {ok: false, code: "io.write_zero", message: "resource.write made no progress"}**
|
||||
|
||||
- `已写 < 长度`
|
||||
`while 已写 < 长度`
|
||||
|
||||
**剩余 = 长度 - 已写**
|
||||
**剩余 = 长度 - 已写**
|
||||
|
||||
**本次 = resource.write(流, 内存, 起点 + 已写, 剩余)**
|
||||
**本次 = resource.write(流, 内存, 起点 + 已写, 剩余)**
|
||||
|
||||
1. `not 本次.ok`
|
||||
`if not 本次.ok`
|
||||
|
||||
**失败 = true**
|
||||
**失败 = true**
|
||||
|
||||
**错误结果 = 本次**
|
||||
**错误结果 = 本次**
|
||||
|
||||
**已写 = 长度**
|
||||
**已写 = 长度**
|
||||
|
||||
2. `本次.value.count == 0`
|
||||
`else`
|
||||
`if 本次.value.count == 0`
|
||||
|
||||
**失败 = true**
|
||||
**失败 = true**
|
||||
|
||||
**已写 = 长度**
|
||||
**已写 = 长度**
|
||||
|
||||
3. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
**已写 = 已写 + 本次.value.count**
|
||||
**已写 = 已写 + 本次.value.count**
|
||||
|
||||
1. `失败`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
`if 失败`
|
||||
|
||||
*错误结果*
|
||||
`return 错误结果`
|
||||
|
||||
2. `已写 < 长度`
|
||||
`else`
|
||||
`if 已写 < 长度`
|
||||
|
||||
*错误结果*
|
||||
`return 错误结果`
|
||||
|
||||
3. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*{ok: true, value: {count: 长度}}*
|
||||
`return {ok: true, value: {count: 长度}}`
|
||||
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
## 写文本
|
||||
|
||||
`(文本)`
|
||||
`params(文本)`
|
||||
|
||||
把文本编码为 UTF-8 并写入已授权的 stdout 资源流。内存按实际字节长度增长,
|
||||
写入循环检查 `{ok,count}`;只有全部字节写完并关闭成功才返回成功。
|
||||
写入循环检查 {ok,count};只有全部字节写完并关闭成功才返回成功。
|
||||
|
||||
**字节数 = format.字节长度(文本)**
|
||||
|
||||
@@ -88,14 +104,19 @@ import:
|
||||
|
||||
**关闭 = resource.close(流)**
|
||||
|
||||
1. `not 写结果.ok`
|
||||
`if not 写结果.ok`
|
||||
|
||||
*写结果*
|
||||
`return 写结果`
|
||||
|
||||
2. `not 关闭.ok`
|
||||
`else`
|
||||
`if not 关闭.ok`
|
||||
|
||||
*关闭*
|
||||
`return 关闭`
|
||||
|
||||
3. `true`
|
||||
`else`
|
||||
`if true`
|
||||
|
||||
*{ok: true, value: {count: 长度}}*
|
||||
`return {ok: true, value: {count: 长度}}`
|
||||
`end`
|
||||
`end`
|
||||
`end`
|
||||
Reference in new issue
Block a user