use crate::{
env::{EnvironmentRef, ScopeGuard},
mem::Pointer,
types::Type,
};
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct Parameters<'a> {
pub fixed: Vec<(Pointer<'a, Box<str>>, Type)>,
pub variadic: Option<(Pointer<'a, Box<str>>, Type)>,
}
impl<'a> Parameters<'a> {
#[must_use]
#[inline]
pub fn len(&self) -> usize {
self.fixed.len() + usize::from(self.variadic.is_some())
}
#[must_use]
#[inline]
pub fn is_empty(&self) -> bool {
self.fixed.is_empty() && self.variadic.is_none()
}
#[must_use]
#[inline]
pub const fn is_variadic(&self) -> bool {
self.variadic.is_some()
}
#[must_use]
pub fn define(&self, env: &EnvironmentRef<'a>) -> ScopeGuard<'a> {
let guard = ScopeGuard::new(env.clone());
let mut env = env.borrow_mut();
for (name, typedef) in &self.fixed {
env.define(name.as_ref(), typedef.to_owned(), None);
}
if let Some((name, typedef)) = &self.variadic {
env.define(name.as_ref(), typedef.to_owned(), None);
}
guard
}
}