cl-interpret: Tuple structs + fix tuple member access

This commit is contained in:
2025-02-22 03:31:27 -06:00
parent 697d139cfd
commit 7a8da33de9
4 changed files with 147 additions and 40 deletions

View File

@@ -21,12 +21,16 @@ pub struct Function {
decl: Rc<FnDecl>,
/// Stores data from the enclosing scopes
upvars: RefCell<Upvars>,
is_constructor: bool,
}
impl Function {
pub fn new(decl: &FnDecl) -> Self {
// let upvars = collect_upvars(decl, env);
Self { decl: decl.clone().into(), upvars: Default::default() }
Self { decl: decl.clone().into(), upvars: Default::default(), is_constructor: false }
}
pub fn new_constructor(decl: FnDecl) -> Self {
Self { decl: decl.into(), upvars: Default::default(), is_constructor: true }
}
pub fn decl(&self) -> &FnDecl {
&self.decl
@@ -54,6 +58,9 @@ impl Callable for Function {
if args.len() != bind.len() {
return Err(Error::ArgNumber { want: bind.len(), got: args.len() });
}
if self.is_constructor {
return Ok(ConValue::TupleStruct(Box::new((*name, args.into()))));
}
let Some(body) = body else {
return Err(Error::NotDefined(*name));
};