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>
This commit is contained in:
1 parent
a23fdedfa2
commit
5456d9ff83
25 files changed
+590
-41
No files matched your search
+12
-4
@@ -55,6 +55,8 @@ pub struct Function {
|
||||
pub params: Vec<Param>,
|
||||
pub body: Vec<Stmt>,
|
||||
pub children: Vec<Function>,
|
||||
/// Base type name for `# Child = > Parent` (objects only).
|
||||
pub base: Option<String>,
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user