conlang: PATTERN MATCHING AND DESTRUCTURED BINDINGS WOOOOO

- Integrate the Match and Pattern nodes into the AST
  - TODO: `let x: T` is ambiguous with `let x: {}`. Currently the latter takes precedence in the parser.

- Implement pattern matching through unification in the interpreter.
  - It's not fast, but it works!

- Refactor destructuring assignments to use the new pattern functionality
This commit is contained in:
2025-01-29 04:15:33 -06:00
parent 6e94b702c9
commit 6ee9bbd72e
14 changed files with 285 additions and 119 deletions

View File

@@ -32,7 +32,7 @@ impl Source<'_> {
Source::Const(v) => Some(v.name),
Source::Static(v) => Some(v.name),
Source::Function(v) => Some(v.name),
Source::Local(l) => Some(l.name),
Source::Local(_) => None,
Source::Impl(_) | Source::Use(_) | Source::Ty(_) => None,
}
}

View File

@@ -146,11 +146,11 @@ impl<'a> Visit<'a> for Populator<'_, 'a> {
}
fn visit_let(&mut self, l: &'a cl_ast::Let) {
let cl_ast::Let { mutable, name, ty, init } = l;
let cl_ast::Let { mutable, name: _, ty, init } = l;
let mut entry = self.new_entry(NodeKind::Local);
entry.inner.set_source(Source::Local(l));
entry.set_name(*name);
// entry.set_name(*name);
entry.visit_mutability(mutable);
if let Some(ty) = ty {
@@ -160,7 +160,8 @@ impl<'a> Visit<'a> for Populator<'_, 'a> {
entry.visit_expr(init)
}
let child = entry.inner.id();
self.inner.add_child(*name, child);
// let child = entry.inner.id();
// self.inner.add_child(*name, child);
todo!("Pattern destructuring in cl-typeck")
}
}