cl-interpret: Tuple structs + fix tuple member access
This commit is contained in:
@@ -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));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user