cl-ast: Add syntax support for generics

This commit is contained in:
2025-04-22 07:22:44 -04:00
parent 681fbc88d3
commit 8ff17fd475
14 changed files with 124 additions and 36 deletions

View File

@@ -54,7 +54,7 @@ impl Callable for Function {
name
}
fn call(&self, env: &mut Environment, args: &[ConValue]) -> IResult<ConValue> {
let FnDecl { name, bind, body, sign: _ } = &*self.decl;
let FnDecl { name, gens: _, bind, body, sign: _ } = &*self.decl;
// Check arg mapping
if self.is_constructor {

View File

@@ -65,7 +65,7 @@ impl<'a> Visit<'a> for CollectUpvars<'_> {
}
fn visit_function(&mut self, f: &'a cl_ast::Function) {
let Function { name: _, sign: _, bind, body } = f;
let Function { name: _, gens: _, sign: _, bind, body } = f;
// parameters can never be upvars
self.visit_pattern(bind);
if let Some(body) = body {

View File

@@ -114,13 +114,14 @@ impl Interpret for Function {
}
impl Interpret for Struct {
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
let Self { name, kind } = self;
let Self { name, gens: _, kind } = self;
match kind {
StructKind::Empty => {}
StructKind::Tuple(args) => {
// Constructs the AST from scratch. TODO: This, better.
let constructor = Function {
name: *name,
gens: Default::default(),
sign: TyFn {
args: TyKind::Tuple(TyTuple {
types: args.iter().map(|ty| ty.kind.clone()).collect(),
@@ -152,7 +153,7 @@ impl Interpret for Struct {
}
impl Interpret for Enum {
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
let Self { name, variants: kind } = self;
let Self { name, gens: _, variants: kind } = self;
if let Some(variants) = kind {
env.push_frame(name.to_ref(), Default::default());
for (idx, Variant { name, kind }) in variants.iter().enumerate() {