cl-ast: Add syntax support for generics
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user