cl-ast: Remove Param, replace with flat Pattern
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user