Files
marqdo/doc/design/objects.md
T
cflmyandCursor 5456d9ff83 Implement object inheritance: # Child = > Parent (I0-I2)
- Parse `# Child = > Parent` object decls (base must be a simple
  name after `>`; dotted bases and `# Foo = 1` are diagnostics).
- Validate in load: unknown base types and cyclic inheritance (A → B → A)
  fail with line/col.
- Method resolution walks the base chain (most specific first) on both
  tree and bytecode backends; `_type` stays the child name; same-name
  child ## overrides the parent.
- Add inherit.rs, wire Program.object_bases, gold fixtures
  (inherit-parent-method / inherit-override + cycle/unknown-base/bad-rhs)
  and public 09-inherit demo pages. Docs: objects.md, markdown-mapping,
  roadmap, skill.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-10 10:01:05 +08:00

2.8 KiB
Raw Blame History

Objects(#)与函数(##+)

状态 Accepted
日期 2026-08-06
相关 markdown-mapping.md · ext-llm.md

1. 约定

标题层 含义
#(恰好一层) 对象 / 类型。正文 = 构造体;调用类型名 = 构造实例。
## 及更深 函数(自由函数或方法)。层数差表示嵌套,与 v0.1 相同。

# main 是入口对象:运行文件 = 执行其构造体。若无 main,且文件恰好只有一个无参顶层 # 对象(如 # Hello World),则把它当作入口。

2. 实例句柄

构造返回值若为 map,运行时写入 _type(文本,值为类型名),形成句柄。
方法调用通过 _type 找到定义对象,再解析其下的 ## 方法。

方法体内自动绑定:

  • 自(中文)
  • self(英文)

二者同一接收者。

3. 调用外形

# 大模型
    + `模型名`

*`自` = …配置 map…*
**`自`**

## 运行
    + `提示`

…使用 `自` …
**`内容`**

# main

*`模型` = > 大模型 模型名=gpt-4o-mini *
*`回复` = > `模型`.运行 提示=你好 *
> print text=`回复`
  • > 大模型 … — 构造
  • > `模型`.运行 … — 方法(接收者 + . + 方法名)
  • ## 自由函数 挂在模块顶层(非某对象子标题)— 与旧版顶层 # http_get 对等,现写为 ## http_get

4. 标准库

官方 lib/*.mq.md 以顶层自由函数为主:全部为 ##(不再使用 # 冒充类型)。
真正的类型化扩展(如 ext/llm)使用 # 类型 + ## 方法。

5. 继承(# 子类 = > 父类)

# 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。

6. 非目标(本波)

  • 接口 / 可见性 / 多继承
  • 无 _type 的「鸭子」方法分发
  • 用表格声明字段 schema(表格仍表示数据集合;见 tables-maps-footnotes.md)

7. 迁移摘要

旧 新
库顶层 # http_get ## http_get
# main + ## 嵌套 不变(main = 入口对象)
ext 顶层 # complete # llm / # 大模型 构造 + ## complete / ## 运行