diff --git a/compiler/cl-ast/src/ast.rs b/compiler/cl-ast/src/ast.rs
index 02c8e18..93e306c 100644
--- a/compiler/cl-ast/src/ast.rs
+++ b/compiler/cl-ast/src/ast.rs
@@ -145,17 +145,10 @@ pub enum ModuleKind {
pub struct Function {
pub name: Sym,
pub sign: TyFn,
- pub bind: Vec,
+ pub bind: Vec,
pub body: Option,
}
-/// A single parameter for a [Function]
-#[derive(Clone, Debug, PartialEq, Eq, Hash)]
-pub struct Param {
- pub mutability: Mutability,
- pub bind: Pattern,
-}
-
/// A user-defined product type
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Struct {
diff --git a/compiler/cl-ast/src/ast_impl.rs b/compiler/cl-ast/src/ast_impl.rs
index decf56e..2fbf564 100644
--- a/compiler/cl-ast/src/ast_impl.rs
+++ b/compiler/cl-ast/src/ast_impl.rs
@@ -192,13 +192,6 @@ mod display {
}
}
- impl Display for Param {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- let Self { mutability, bind } = self;
- write!(f, "{mutability}{bind}")
- }
- }
-
impl Display for Struct {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { name, kind } = self;
diff --git a/compiler/cl-ast/src/ast_visitor/fold.rs b/compiler/cl-ast/src/ast_visitor/fold.rs
index 753ee65..29939ed 100644
--- a/compiler/cl-ast/src/ast_visitor/fold.rs
+++ b/compiler/cl-ast/src/ast_visitor/fold.rs
@@ -106,14 +106,10 @@ pub trait Fold {
Function {
name: self.fold_sym(name),
sign: self.fold_ty_fn(sign),
- bind: bind.into_iter().map(|p| self.fold_param(p)).collect(),
+ bind: bind.into_iter().map(|p| self.fold_pattern(p)).collect(),
body: body.map(|b| self.fold_expr(b)),
}
}
- fn fold_param(&mut self, p: Param) -> Param {
- let Param { mutability, bind } = p;
- Param { mutability: self.fold_mutability(mutability), bind: self.fold_pattern(bind) }
- }
fn fold_struct(&mut self, s: Struct) -> Struct {
let Struct { name, kind } = s;
Struct { name: self.fold_sym(name), kind: self.fold_struct_kind(kind) }
diff --git a/compiler/cl-ast/src/ast_visitor/visit.rs b/compiler/cl-ast/src/ast_visitor/visit.rs
index 522e5ca..bf159a9 100644
--- a/compiler/cl-ast/src/ast_visitor/visit.rs
+++ b/compiler/cl-ast/src/ast_visitor/visit.rs
@@ -83,16 +83,11 @@ pub trait Visit<'a>: Sized {
let Function { name, sign, bind, body } = f;
self.visit_sym(name);
self.visit_ty_fn(sign);
- bind.iter().for_each(|p| self.visit_param(p));
+ bind.iter().for_each(|p| self.visit_pattern(p));
if let Some(b) = body {
self.visit_expr(b)
}
}
- fn visit_param(&mut self, p: &'a Param) {
- let Param { mutability, bind } = p;
- self.visit_mutability(mutability);
- self.visit_pattern(bind);
- }
fn visit_struct(&mut self, s: &'a Struct) {
let Struct { name, kind } = s;
self.visit_sym(name);
diff --git a/compiler/cl-interpret/src/function.rs b/compiler/cl-interpret/src/function.rs
index a4281a2..fcd2b7f 100644
--- a/compiler/cl-interpret/src/function.rs
+++ b/compiler/cl-interpret/src/function.rs
@@ -3,7 +3,7 @@
use collect_upvars::collect_upvars;
use super::{pattern, Callable, ConValue, Environment, Error, IResult, Interpret};
-use cl_ast::{Function as FnDecl, Param, Sym};
+use cl_ast::{Function as FnDecl, Sym};
use std::{
cell::{Ref, RefCell},
collections::HashMap,
@@ -70,7 +70,7 @@ impl Callable for Function {
// TODO: completely refactor data storage
let mut frame = env.frame("fn args");
- for (Param { mutability: _, bind }, value) in bind.iter().zip(args) {
+ for (bind, value) in bind.iter().zip(args) {
for (name, value) in pattern::substitution(bind, value.clone())? {
frame.insert(*name, Some(value));
}
diff --git a/compiler/cl-interpret/src/function/collect_upvars.rs b/compiler/cl-interpret/src/function/collect_upvars.rs
index 84555e5..77cec91 100644
--- a/compiler/cl-interpret/src/function/collect_upvars.rs
+++ b/compiler/cl-interpret/src/function/collect_upvars.rs
@@ -1,6 +1,6 @@
//! Collects the "Upvars" of a function at the point of its creation, allowing variable capture
use crate::{convalue::ConValue, env::Environment};
-use cl_ast::{ast_visitor::visit::*, Function, Let, Param, Path, PathPart, Pattern, Sym};
+use cl_ast::{ast_visitor::visit::*, Function, Let, Path, PathPart, Pattern, Sym};
use std::collections::{HashMap, HashSet};
pub fn collect_upvars(f: &Function, env: &Environment) -> super::Upvars {
@@ -67,9 +67,7 @@ impl<'a> Visit<'a> for CollectUpvars<'_> {
fn visit_function(&mut self, f: &'a cl_ast::Function) {
let Function { name: _, sign: _, bind, body } = f;
// parameters can never be upvars
- for Param { mutability: _, bind } in bind {
- self.visit_pattern(bind);
- }
+ bind.iter().for_each(|pat| self.visit_pattern(pat));
if let Some(body) = body {
self.visit_expr(body);
}
diff --git a/compiler/cl-interpret/src/interpret.rs b/compiler/cl-interpret/src/interpret.rs
index dc1dd40..5a646fa 100644
--- a/compiler/cl-interpret/src/interpret.rs
+++ b/compiler/cl-interpret/src/interpret.rs
@@ -137,10 +137,7 @@ impl Interpret for Struct {
bind: args
.iter()
.enumerate()
- .map(|(idx, _)| Param {
- mutability: Mutability::Not,
- bind: Pattern::Name(idx.to_string().into()),
- })
+ .map(|(idx, _)| Pattern::Name(idx.to_string().into()))
.collect(),
body: None,
};
diff --git a/compiler/cl-parser/src/parser.rs b/compiler/cl-parser/src/parser.rs
index 4c80265..440b02d 100644
--- a/compiler/cl-parser/src/parser.rs
+++ b/compiler/cl-parser/src/parser.rs
@@ -469,7 +469,7 @@ impl Parse<'_> for Function {
}
}
-type FnSig = (Vec, Vec);
+type FnSig = (Vec, Vec);
impl Parse<'_> for FnSig {
/// Parses the [parameters](Param) associated with a Function
@@ -488,16 +488,17 @@ impl Parse<'_> for FnSig {
}
}
-type TypedParam = (Param, TyKind);
+type TypedParam = (Pattern, TyKind);
impl Parse<'_> for TypedParam {
/// Parses a single function [parameter](Param)
- fn parse(p: &mut Parser) -> PResult<(Param, TyKind)> {
+ fn parse(p: &mut Parser) -> PResult<(Pattern, TyKind)> {
Ok((
- Param { mutability: Mutability::parse(p)?, bind: Pattern::parse(p)? },
- {
- p.match_type(TokenKind::Colon, Parsing::Param)?;
+ Pattern::parse(p)?,
+ if p.match_type(TokenKind::Colon, Parsing::Param).is_ok() {
TyKind::parse(p)?
+ } else {
+ TyKind::Path(Path::from(Sym::from("_")))
},
))
}
diff --git a/compiler/cl-repl/examples/yaml.rs b/compiler/cl-repl/examples/yaml.rs
index 58246b6..76f6663 100644
--- a/compiler/cl-repl/examples/yaml.rs
+++ b/compiler/cl-repl/examples/yaml.rs
@@ -641,12 +641,6 @@ pub mod yamlify {
y.value(self);
}
}
- impl Yamlify for Param {
- fn yaml(&self, y: &mut Yamler) {
- let Self { mutability, bind } = self;
- y.key("Param").yaml(mutability).pair("pat", bind);
- }
- }
impl Yamlify for Ty {
fn yaml(&self, y: &mut Yamler) {
let Self { extents: _, kind } = self;
diff --git a/compiler/cl-typeck/src/stage/populate.rs b/compiler/cl-typeck/src/stage/populate.rs
index 5e890e5..60310a2 100644
--- a/compiler/cl-typeck/src/stage/populate.rs
+++ b/compiler/cl-typeck/src/stage/populate.rs
@@ -106,7 +106,7 @@ impl<'a> Visit<'a> for Populator<'_, 'a> {
self.set_name(*name);
self.visit_ty_fn(sign);
- bind.iter().for_each(|p| self.visit_param(p));
+ bind.iter().for_each(|p| self.visit_pattern(p));
if let Some(b) = body {
self.visit_expr(b)
}