diff --git a/.cursor/skills/marqdo/SKILL.md b/.cursor/skills/marqdo/SKILL.md
index a1a6301..19b5da9 100644
--- a/.cursor/skills/marqdo/SKILL.md
+++ b/.cursor/skills/marqdo/SKILL.md
@@ -30,7 +30,7 @@ Canonical design (repo): `doc/design/markdown-mapping.md`, `doc/design/keywords.
| Marker | Meaning |
|--------|---------|
-| `#` | **Object / type** (constructor body). `# main` = entry object. |
+| `#` | **Object / type** (constructor body). `# main` = entry object. `# Child = > Parent` = inherit. |
| `##` … `######` | **Function / method** (nesting by heading depth). |
| `` + `name` `` under heading | Parameter (optional `` `name`=default ``) |
| `1.` `2.` … in body | Branch arm (condition or `N. *` else). **Same-indent restart at `1.` = new branch statement** (not more arms of the previous list). |
diff --git a/.cursor/skills/marqdo/examples.md b/.cursor/skills/marqdo/examples.md
index d39f006..6b55321 100644
--- a/.cursor/skills/marqdo/examples.md
+++ b/.cursor/skills/marqdo/examples.md
@@ -155,6 +155,28 @@ description: loads math
See `tests/structure/object-handle.mq.md` and `ext/llm.mq.md`: `# Type` constructs a map with `_type`; methods use `` > `obj`.method `` and read `self` / `自`.
+## 10b. Object inheritance
+
+```markdown
+# Greeter
+
+## hello
+ + `who`
+
+*`msg` = "Hello, `who`!" *
+**`msg`**
+
+# Loud = > Greeter
+
+## hello
+ + `who`
+
+*`msg` = "HELLO, `who`!" *
+**`msg`**
+```
+
+`_type` stays the most specific name (`Loud`). Methods walk the base chain; same-name `##` on the child overrides. No implicit super in v1.
+
## 11. Agent layout (ABI)
```markdown
diff --git a/doc/README.md b/doc/README.md
index 2dde29e..82f6091 100644
--- a/doc/README.md
+++ b/doc/README.md
@@ -53,7 +53,7 @@
| [roadmap/next-phase.md](roadmap/next-phase.md) | **下一阶段:input / 诊断 / 标准库 / view 调试** |
| [roadmap/okf-near-match.md](roadmap/okf-near-match.md) | **规划:OKF 相近任务命中**(精确 sig 之外的可选软复用) |
| [roadmap/agent-streaming.md](roadmap/agent-streaming.md) | **规划:智能体 / LLM 流式输出**(事件模型 + step/plan 透传) |
-| [roadmap/object-inheritance.md](roadmap/object-inheritance.md) | **规划:对象继承**(`# 子类 = > 父类`) |
+| [roadmap/object-inheritance.md](roadmap/object-inheritance.md) | **对象继承**(`# 子类 = > 父类`;I0–I2 已落地) |
| [roadmap/tables-maps-footnotes.md](roadmap/tables-maps-footnotes.md) | **表格语义**(竖表 / 横表字典 / 脚注取元 / 行向记录;T0–T4 已落地) |
| [roadmap/ext-web.md](roadmap/ext-web.md) | **规划:`ext/web` 动态网页**(env/DB init·迁移·样式脚手架·ABI) |
| [roadmap/ext-quantum.md](roadmap/ext-quantum.md) | **规划:`ext/quantum` 量子模拟**(基础门·电路·ABI·`ext add`) |
diff --git a/doc/design/markdown-mapping.md b/doc/design/markdown-mapping.md
index 1803c0b..70a5dfc 100644
--- a/doc/design/markdown-mapping.md
+++ b/doc/design/markdown-mapping.md
@@ -40,7 +40,7 @@ Markdown **标记即语法**。输出**不是**语言架构原语,而是内置
| 标记 | 语义 |
|------|------|
-| `#` … `######` | **`#` = 对象/类型**;**`##`+ = 函数/方法**(层差=嵌套)。见 [objects.md](objects.md) |
+| `#` … `######` | **`#` = 对象/类型**(可 `# Child = > Parent`);**`##`+ = 函数/方法**(层差=嵌套)。见 [objects.md](objects.md) |
| 函数头下 `+ `` `名` `` ` | 形参 / 构造参数(可选 `` `名`=默认值 ``) |
| 体内 `1.` `2.` … | **分支**(有序列表臂;条件行或 else) |
| 体内 `-` | **循环**(`while` 条件,或 `` [`项`](`集合`) `` 遍历) |
@@ -129,6 +129,7 @@ Markdown **标记即语法**。输出**不是**语言架构原语,而是内置
## 6. 对象、函数、形参
- `# Name`:对象(构造体);`# main` 为入口对象。
+- `# Child = > Parent`:单继承(基类须为已定义对象名;方法沿链查找,子类可覆盖)。见 [objects.md](objects.md) §5。
- `##` / `###` …:函数或方法;挂在对象下则为方法。
- 标准库顶层 API 使用自由函数 `## name`(见 [objects.md](objects.md))。
diff --git a/doc/design/objects.md b/doc/design/objects.md
index 2c03fa0..06e1a3a 100644
--- a/doc/design/objects.md
+++ b/doc/design/objects.md
@@ -58,13 +58,44 @@
官方 `lib/*.mq.md` 以**顶层自由函数**为主:全部为 `##`(不再使用 `#` 冒充类型)。
真正的类型化扩展(如 `ext/llm`)使用 `# 类型` + `##` 方法。
-## 5. 非目标(本波)
+## 5. 继承(`# 子类 = > 父类`)
-- 继承 / 接口 / 可见性 — **继承语法已单独立项规划**,见 [object-inheritance.md](../roadmap/object-inheritance.md)(提案:`# 子类 = > 父类`)
+```markdown
+# Greeter
+
+## hello
+ + `who`
+
+*`msg` = "Hello, `who`!" *
+**`msg`**
+
+# Loud = > Greeter
+
+## hello
+ + `who`
+
+*`msg` = "HELLO, `who`!" *
+**`msg`**
+```
+
+| 规则 | 说明 |
+|------|------|
+| 语法 | `# Child = > Parent`(右侧必须是 `>` + 简单类型名;无路径) |
+| `_type` | 构造后仍为**最具体子类名** |
+| 方法查找 | 先子类 `##`,未命中再沿基类链;同名则子类覆盖 |
+| 构造 | v1 **不**隐式调用父构造;需要时在子类正文显式 `` `self` = > Parent … `` |
+| 多继承 | 不支持 |
+| 诊断 | 未知基类、循环继承、非法 RHS(如 `# Foo = 1`) |
+
+详见 [object-inheritance.md](../roadmap/object-inheritance.md)。
+
+## 6. 非目标(本波)
+
+- 接口 / 可见性 / 多继承
- 无 `_type` 的「鸭子」方法分发
-- 用表格声明字段 schema(表格仍表示数据集合;几何语义打磨见 [tables-maps-footnotes.md](../roadmap/tables-maps-footnotes.md))
+- 用表格声明字段 schema(表格仍表示数据集合;见 [tables-maps-footnotes.md](../roadmap/tables-maps-footnotes.md))
-## 6. 迁移摘要
+## 7. 迁移摘要
| 旧 | 新 |
|----|----|
diff --git a/doc/roadmap/object-inheritance.md b/doc/roadmap/object-inheritance.md
index 39f026b..1b33cdd 100644
--- a/doc/roadmap/object-inheritance.md
+++ b/doc/roadmap/object-inheritance.md
@@ -2,8 +2,8 @@
| | |
|---|---|
-| 状态 | **规划 / 未开工** |
-| 日期 | 2026-08-09 |
+| 状态 | **I0–I2 已落地**(I3 隐式 super 仍可选) |
+| 日期 | 2026-08-10 |
| 相关 | [objects.md](../design/objects.md) · [markdown-mapping.md](../design/markdown-mapping.md) · [keywords.md](../design/keywords.md) |
| 提案语法 | `# 子类 = > 父类` |
@@ -136,9 +136,9 @@
## 6. 推荐落地顺序
```text
-I0 语法 + AST + 金样(解析/循环继承错误)
-I1 方法解析沿基类链;构造 _type=子类
-I2 覆盖方法;文档更新 objects.md(移出「非目标」)
+I0 语法 + AST + 金样(解析/循环继承错误) ✅
+I1 方法解析沿基类链;构造 _type=子类 ✅
+I2 覆盖方法;文档更新 objects.md ✅
I3 (可选)子构造约定:显式 > 父类 … 或隐式 super
```
diff --git a/public/structure/09-inherit.mq.md b/public/structure/09-inherit.mq.md
new file mode 100644
index 0000000..0fd2d79
--- /dev/null
+++ b/public/structure/09-inherit.mq.md
@@ -0,0 +1,29 @@
+---
+title: Object inheritance
+description: "# Child = > Parent; methods walk the base chain"
+---
+
+# Greeter
+
+## hello
+ + `who`
+
+*`msg` = "Hello, `who`!" *
+**`msg`**
+
+# Loud = > Greeter
+
+## hello
+ + `who`
+
+*`msg` = "HELLO, `who`!" *
+**`msg`**
+
+# main
+
+*`g` = > Greeter *
+*`m` = > `g`.hello who=world *
+> print text=`m`
+*`l` = > Loud *
+*`m2` = > `l`.hello who=world *
+> print text=`m2`
diff --git a/public/structure/09-继承.mq.md b/public/structure/09-继承.mq.md
new file mode 100644
index 0000000..476f6b2
--- /dev/null
+++ b/public/structure/09-继承.mq.md
@@ -0,0 +1,29 @@
+---
+title: 对象继承
+description: "# 子类 = > 父类;方法沿基类链查找"
+---
+
+# 问候者
+
+## 你好
+ + `谁`
+
+*`msg` = "你好,`谁`!" *
+**`msg`**
+
+# 大声 = > 问候者
+
+## 你好
+ + `谁`
+
+*`msg` = "你好,`谁`!!!" *
+**`msg`**
+
+# main
+
+*`g` = > 问候者 *
+*`m` = > `g`.你好 谁=世界 *
+> 打印 内容=`m`
+*`l` = > 大声 *
+*`m2` = > `l`.你好 谁=世界 *
+> 打印 内容=`m2`
diff --git a/skills/marqdo/SKILL.md b/skills/marqdo/SKILL.md
index d3ca9d5..e339bee 100644
--- a/skills/marqdo/SKILL.md
+++ b/skills/marqdo/SKILL.md
@@ -29,7 +29,7 @@ Canonical design (repo): `doc/design/markdown-mapping.md`, `doc/design/keywords.
| Marker | Meaning |
|--------|---------|
-| `#` | **Object / type** (constructor body). `# main` = entry object. |
+| `#` | **Object / type** (constructor body). `# main` = entry object. `# Child = > Parent` = inherit. |
| `##` … `######` | **Function / method** (nesting by heading depth). |
| `` + `name` `` under heading | Parameter (optional `` `name`=default ``) |
| `1.` `2.` … in body | Branch arm (condition or `N. *` else). **Same-indent restart at `1.` = new branch statement** (not more arms of the previous list). |
diff --git a/skills/marqdo/examples.md b/skills/marqdo/examples.md
index d39f006..6b55321 100644
--- a/skills/marqdo/examples.md
+++ b/skills/marqdo/examples.md
@@ -155,6 +155,28 @@ description: loads math
See `tests/structure/object-handle.mq.md` and `ext/llm.mq.md`: `# Type` constructs a map with `_type`; methods use `` > `obj`.method `` and read `self` / `自`.
+## 10b. Object inheritance
+
+```markdown
+# Greeter
+
+## hello
+ + `who`
+
+*`msg` = "Hello, `who`!" *
+**`msg`**
+
+# Loud = > Greeter
+
+## hello
+ + `who`
+
+*`msg` = "HELLO, `who`!" *
+**`msg`**
+```
+
+`_type` stays the most specific name (`Loud`). Methods walk the base chain; same-name `##` on the child overrides. No implicit super in v1.
+
## 11. Agent layout (ABI)
```markdown
diff --git a/src/ast.rs b/src/ast.rs
index 56433eb..f92f7a9 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -55,6 +55,8 @@ pub struct Function {
pub params: Vec,
pub body: Vec,
pub children: Vec,
+ /// Base type name for `# Child = > Parent` (objects only).
+ pub base: Option,
}
impl Function {
@@ -211,10 +213,16 @@ pub fn format_ast_dump(path: &str, module: &Module) -> String {
fn dump_fun(out: &mut String, fun: &Function, depth: usize) {
let pad = " ".repeat(depth);
let kind = if fun.is_object() { "object" } else { "fun" };
- out.push_str(&format!(
- "{pad}({kind} level={} {:?} params={:?} @{}\n",
- fun.level, fun.name, fun.params, fun.span
- ));
+ match &fun.base {
+ Some(base) => out.push_str(&format!(
+ "{pad}({kind} level={} {:?} extends={base:?} params={:?} @{}\n",
+ fun.level, fun.name, fun.params, fun.span
+ )),
+ None => out.push_str(&format!(
+ "{pad}({kind} level={} {:?} params={:?} @{}\n",
+ fun.level, fun.name, fun.params, fun.span
+ )),
+ }
for stmt in &fun.body {
dump_stmt(out, stmt, depth + 1);
}
diff --git a/src/bytecode/compile.rs b/src/bytecode/compile.rs
index 5cdd4e1..7d1372b 100644
--- a/src/bytecode/compile.rs
+++ b/src/bytecode/compile.rs
@@ -15,6 +15,8 @@ struct FlatFun {
name: String,
level: u8,
parent: Option,
+ /// Inheritance base type name (`# Child = > Parent`), objects only.
+ base: Option,
params: Vec,
body: Vec,
children: Vec,
@@ -60,6 +62,19 @@ pub fn compile_module(path: Option<&Path>, module: &Module) -> Result {
}
}
}
+ let name_to_flat: HashMap<&str, usize> = objects
+ .iter()
+ .map(|(n, i)| (n.as_str(), *i))
+ .collect();
+ let mut object_bases = Vec::with_capacity(objects.len());
+ for (name, _) in &objects {
+ let flat_i = name_to_flat[name.as_str()];
+ let base = flat[flat_i]
+ .base
+ .as_deref()
+ .and_then(|b| name_to_flat.get(b).copied());
+ object_bases.push(base);
+ }
let path_buf = path.map(|p| p.to_path_buf());
let mut functions = Vec::new();
@@ -74,6 +89,7 @@ pub fn compile_module(path: Option<&Path>, module: &Module) -> Result {
functions,
entry,
objects,
+ object_bases,
methods,
parents,
children,
@@ -134,6 +150,7 @@ fn collect_fun(
name: fun.name.clone(),
level: fun.level,
parent,
+ base: fun.base.clone(),
params: fun.params.clone(),
body: fun.body.clone(),
children: Vec::new(),
diff --git a/src/bytecode/mod.rs b/src/bytecode/mod.rs
index 5190d7a..5c4f7a3 100644
--- a/src/bytecode/mod.rs
+++ b/src/bytecode/mod.rs
@@ -92,6 +92,8 @@ pub struct Program {
pub entry: usize,
/// Top-level object name → function index (level-1).
pub objects: Vec<(String, usize)>,
+ /// Parallel to `objects`: base object flat index (`# Child = > Parent`).
+ pub object_bases: Vec